user banning

This commit is contained in:
Max-Wilhelm Bruker 2011-03-03 01:16:13 +01:00
parent 6145d6d524
commit 57f9e2c3b4
27 changed files with 220 additions and 37 deletions

View file

@ -32,6 +32,7 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
GenericEvent *genericEvent = qobject_cast<GenericEvent *>(item);
if (genericEvent) {
switch (genericEvent->getItemId()) {
case ItemId_Event_ConnectionClosed: emit connectionClosedEventReceived(qobject_cast<Event_ConnectionClosed *>(item)); break;
case ItemId_Event_AddToList: emit addToListEventReceived(qobject_cast<Event_AddToList *>(item)); break;
case ItemId_Event_RemoveFromList: emit removeFromListEventReceived(qobject_cast<Event_RemoveFromList *>(item)); break;
case ItemId_Event_UserJoined: emit userJoinedEventReceived(qobject_cast<Event_UserJoined *>(item)); break;
@ -63,7 +64,6 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
}
}
void AbstractClient::setStatus(const ClientStatus _status)
{
if (_status != status) {

View file

@ -20,6 +20,7 @@ class Event_ServerMessage;
class Event_ListRooms;
class Event_GameJoined;
class Event_Message;
class Event_ConnectionClosed;
enum ClientStatus {
StatusDisconnected,
@ -41,6 +42,7 @@ signals:
// Game events
void gameEventContainerReceived(GameEventContainer *event);
// Generic events
void connectionClosedEventReceived(Event_ConnectionClosed *event);
void addToListEventReceived(Event_AddToList *event);
void removeFromListEventReceived(Event_RemoveFromList *event);
void userJoinedEventReceived(Event_UserJoined *event);

View file

@ -19,6 +19,7 @@ private:
ResponseCode cmdDeckUpload(Command_DeckUpload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDownload(Command_DeckDownload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdBanFromServer(Command_BanFromServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
public:
LocalServerInterface(LocalServer *_server);
~LocalServerInterface();

View file

@ -8,7 +8,7 @@ extern CardDatabase *db;
extern QTranslator *translator;
const QString translationPrefix = "cockatrice";
const QString versionString = "0.20110123";
const QString versionString = "0.20110303";
void installNewTranslator();

View file

@ -31,8 +31,9 @@ RemoteClient::~RemoteClient()
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
{
emit socketError(socket->errorString());
QString errorString = socket->errorString();
disconnectFromServer();
emit socketError(errorString);
}
void RemoteClient::slotConnected()

View file

@ -7,7 +7,7 @@
#include "protocol_items.h"
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
: Tab(_tabSupervisor, parent), locked(true), client(_client)
{
updateServerMessageButton = new QPushButton;
connect(updateServerMessageButton, SIGNAL(clicked()), this, SLOT(actUpdateServerMessage()));
@ -55,6 +55,7 @@ void TabAdmin::actUnlock()
adminGroupBox->setEnabled(true);
lockButton->setEnabled(true);
unlockButton->setEnabled(false);
locked = false;
}
}
@ -63,4 +64,5 @@ void TabAdmin::actLock()
adminGroupBox->setEnabled(false);
lockButton->setEnabled(false);
unlockButton->setEnabled(true);
locked = true;
}

View file

@ -11,6 +11,7 @@ class QPushButton;
class TabAdmin : public Tab {
Q_OBJECT
private:
bool locked;
AbstractClient *client;
QPushButton *updateServerMessageButton;
QGroupBox *adminGroupBox;
@ -24,6 +25,7 @@ public:
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = 0);
void retranslateUi();
QString getTabText() const { return tr("Administration"); }
bool getLocked() const { return locked; }
};
#endif
#endif

View file

@ -132,7 +132,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
gameSelector = new GameSelector(client, this);
userList = new UserList(tabSupervisor->getUserListsTab(), client, UserList::RoomList);
userList = new UserList(tabSupervisor, client, UserList::RoomList);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
chatView = new ChatView(ownName);
@ -205,10 +205,18 @@ void TabRoom::sendMessage()
if (sayEdit->text().isEmpty())
return;
client->sendCommand(new Command_RoomSay(roomId, sayEdit->text()));
Command_RoomSay *cmd = new Command_RoomSay(roomId, sayEdit->text());
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *)));
client->sendCommand(cmd);
sayEdit->clear();
}
void TabRoom::sayFinished(ProtocolResponse *response)
{
if (response->getResponseCode() == RespChatFlood)
chatView->appendMessage(QString(), tr("You are flooding the chat. Please wait a couple of seconds."));
}
void TabRoom::actLeaveRoom()
{
client->sendCommand(new Command_LeaveRoom(roomId));

View file

@ -23,6 +23,7 @@ class Event_ListGames;
class Event_JoinRoom;
class Event_LeaveRoom;
class Event_RoomSay;
class ProtocolResponse;
class TabRoom;
class GameSelector : public QGroupBox {
@ -73,6 +74,7 @@ signals:
private slots:
void sendMessage();
void actLeaveRoom();
void sayFinished(ProtocolResponse *response);
void processListGamesEvent(Event_ListGames *event);
void processJoinRoomEvent(Event_JoinRoom *event);

View file

@ -291,3 +291,10 @@ void TabSupervisor::updateCurrent(int index)
} else
emit setMenu(0);
}
bool TabSupervisor::getAdminLocked() const
{
if (!tabAdmin)
return true;
return tabAdmin->getLocked();
}

View file

@ -45,6 +45,7 @@ public:
void stop();
int getGameCount() const { return gameTabs.size(); }
TabUserLists *getUserListsTab() const { return tabUserLists; }
bool getAdminLocked() const;
signals:
void setMenu(QMenu *menu);
void localGameEnded();

View file

@ -10,9 +10,9 @@
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{
allUsersList = new UserList(this, client, UserList::AllUsersList);
buddyList = new UserList(this, client, UserList::BuddyList);
ignoreList = new UserList(this, client, UserList::IgnoreList);
allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList);
buddyList = new UserList(_tabSupervisor, client, UserList::BuddyList);
ignoreList = new UserList(_tabSupervisor, client, UserList::IgnoreList);
userInfoBox = new UserInfoBox(client, false);
userInfoBox->updateInfo(userInfo);

View file

@ -1,5 +1,6 @@
#include "userlist.h"
#include "tab_userlists.h"
#include "tab_supervisor.h"
#include "abstractclient.h"
#include "pixmapgenerator.h"
#include "userinfobox.h"
@ -8,6 +9,7 @@
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QMenu>
#include <QInputDialog>
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
: QStyledItemDelegate(parent)
@ -45,8 +47,8 @@ bool UserListTWI::operator<(const QTreeWidgetItem &other) const
return data(2, Qt::UserRole).toString().toLower() < other.data(2, Qt::UserRole).toString().toLower();
}
UserList::UserList(TabUserLists *_tabUserLists, AbstractClient *_client, UserListType _type, QWidget *parent)
: QGroupBox(parent), tabUserLists(_tabUserLists), client(_client), type(_type), onlineCount(0)
UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent)
: QGroupBox(parent), tabSupervisor(_tabSupervisor), client(_client), type(_type), onlineCount(0)
{
itemDelegate = new UserListItemDelegate(this);
@ -173,6 +175,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
QAction *aRemoveFromBuddyList = new QAction(tr("Remove from &buddy list"), this);
QAction *aAddToIgnoreList = new QAction(tr("Add to &ignore list"), this);
QAction *aRemoveFromIgnoreList = new QAction(tr("Remove from &ignore list"), this);
QAction *aBan = new QAction(tr("Ban from &server"), this);
QMenu *menu = new QMenu(this);
menu->addAction(aUserName);
@ -180,14 +183,18 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
menu->addAction(aDetails);
menu->addAction(aChat);
menu->addSeparator();
if (tabUserLists->getBuddyList()->userInList(userName))
if (tabSupervisor->getUserListsTab()->getBuddyList()->userInList(userName))
menu->addAction(aRemoveFromBuddyList);
else
menu->addAction(aAddToBuddyList);
if (tabUserLists->getIgnoreList()->userInList(userName))
if (tabSupervisor->getUserListsTab()->getIgnoreList()->userInList(userName))
menu->addAction(aRemoveFromIgnoreList);
else
menu->addAction(aAddToIgnoreList);
if (!tabSupervisor->getAdminLocked()) {
menu->addSeparator();
menu->addAction(aBan);
}
QAction *actionClicked = menu->exec(pos);
if (actionClicked == aDetails) {
@ -204,6 +211,11 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
client->sendCommand(new Command_AddToList("ignore", userName));
else if (actionClicked == aRemoveFromIgnoreList)
client->sendCommand(new Command_RemoveFromList("ignore", userName));
else if (actionClicked == aBan) {
bool ok;
int minutes = QInputDialog::getInt(this, tr("Duration"), tr("Please enter the duration of the ban (in minutes).\nEnter 0 for an indefinite ban."), 0, 0, 2147483647, 10, &ok);
client->sendCommand(new Command_BanFromServer(userName, minutes));
}
delete menu;
delete aUserName;
@ -213,6 +225,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
delete aRemoveFromBuddyList;
delete aAddToIgnoreList;
delete aRemoveFromIgnoreList;
delete aBan;
}
bool UserList::userInList(const QString &userName) const

View file

@ -8,7 +8,7 @@
class QTreeWidget;
class ServerInfo_User;
class AbstractClient;
class TabUserLists;
class TabSupervisor;
class UserListItemDelegate : public QStyledItemDelegate {
public:
@ -27,7 +27,7 @@ class UserList : public QGroupBox {
public:
enum UserListType { AllUsersList, RoomList, BuddyList, IgnoreList };
private:
TabUserLists *tabUserLists;
TabSupervisor *tabSupervisor;
AbstractClient *client;
UserListType type;
QTreeWidget *userTree;
@ -45,7 +45,7 @@ signals:
void addIgnore(const QString &userName);
void removeIgnore(const QString &userName);
public:
UserList(TabUserLists *_tabUserLists, AbstractClient *_client, UserListType _type, QWidget *parent = 0);
UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserListType _type, QWidget *parent = 0);
void retranslateUi();
void processUserInfo(ServerInfo_User *user, bool online);
bool deleteUser(const QString &userName);

View file

@ -47,6 +47,20 @@ void MainWindow::updateTabMenu(QMenu *menu)
menuBar()->insertMenu(helpMenu->menuAction(), menu);
}
void MainWindow::processConnectionClosedEvent(Event_ConnectionClosed *event)
{
QString reason = event->getReason();
client->disconnectFromServer();
QString reasonStr;
if (reason == "too_many_connections")
reasonStr = tr("There are too many concurrent connections from your address.");
else if (reason == "banned")
reasonStr = tr("Banned by moderator.");
else
reasonStr = tr("Unknown reason.");
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
}
void MainWindow::statusChanged(ClientStatus _status)
{
setClientStatusTitle();
@ -273,6 +287,7 @@ MainWindow::MainWindow(QWidget *parent)
QPixmapCache::setCacheLimit(200000);
client = new RemoteClient(this);
connect(client, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed *)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed *)));
connect(client, SIGNAL(serverError(ResponseCode)), this, SLOT(serverError(ResponseCode)));
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));

View file

@ -35,6 +35,7 @@ class MainWindow : public QMainWindow {
private slots:
void updateTabMenu(QMenu *menu);
void statusChanged(ClientStatus _status);
void processConnectionClosedEvent(Event_ConnectionClosed *event);
void serverTimeout();
void serverError(ResponseCode r);
void socketError(const QString &errorStr);