mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
user banning
This commit is contained in:
parent
6145d6d524
commit
57f9e2c3b4
27 changed files with 220 additions and 37 deletions
|
|
@ -63,16 +63,18 @@ ItemId_Event_DumpZone = 1061,
|
|||
ItemId_Event_StopDumpZone = 1062,
|
||||
ItemId_Event_RemoveFromList = 1063,
|
||||
ItemId_Event_ServerMessage = 1064,
|
||||
ItemId_Event_Message = 1065,
|
||||
ItemId_Event_GameJoined = 1066,
|
||||
ItemId_Event_UserLeft = 1067,
|
||||
ItemId_Event_LeaveRoom = 1068,
|
||||
ItemId_Event_RoomSay = 1069,
|
||||
ItemId_Context_ReadyStart = 1070,
|
||||
ItemId_Context_Concede = 1071,
|
||||
ItemId_Context_DeckSelect = 1072,
|
||||
ItemId_Context_UndoDraw = 1073,
|
||||
ItemId_Context_MoveCard = 1074,
|
||||
ItemId_Command_UpdateServerMessage = 1075,
|
||||
ItemId_Other = 1076
|
||||
ItemId_Event_ConnectionClosed = 1065,
|
||||
ItemId_Event_Message = 1066,
|
||||
ItemId_Event_GameJoined = 1067,
|
||||
ItemId_Event_UserLeft = 1068,
|
||||
ItemId_Event_LeaveRoom = 1069,
|
||||
ItemId_Event_RoomSay = 1070,
|
||||
ItemId_Context_ReadyStart = 1071,
|
||||
ItemId_Context_Concede = 1072,
|
||||
ItemId_Context_DeckSelect = 1073,
|
||||
ItemId_Context_UndoDraw = 1074,
|
||||
ItemId_Context_MoveCard = 1075,
|
||||
ItemId_Command_UpdateServerMessage = 1076,
|
||||
ItemId_Command_BanFromServer = 1077,
|
||||
ItemId_Other = 1078
|
||||
};
|
||||
|
|
|
|||
|
|
@ -389,6 +389,11 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message)
|
|||
{
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
}
|
||||
Event_ConnectionClosed::Event_ConnectionClosed(const QString &_reason)
|
||||
: GenericEvent("connection_closed")
|
||||
{
|
||||
insertItem(new SerializableItem_String("reason", _reason));
|
||||
}
|
||||
Event_Message::Event_Message(const QString &_senderName, const QString &_receiverName, const QString &_text)
|
||||
: GenericEvent("message")
|
||||
{
|
||||
|
|
@ -448,6 +453,12 @@ Command_UpdateServerMessage::Command_UpdateServerMessage()
|
|||
: AdminCommand("update_server_message")
|
||||
{
|
||||
}
|
||||
Command_BanFromServer::Command_BanFromServer(const QString &_userName, int _minutes)
|
||||
: AdminCommand("ban_from_server")
|
||||
{
|
||||
insertItem(new SerializableItem_String("user_name", _userName));
|
||||
insertItem(new SerializableItem_Int("minutes", _minutes));
|
||||
}
|
||||
void ProtocolItem::initializeHashAuto()
|
||||
{
|
||||
itemNameHash.insert("cmdping", Command_Ping::newItem);
|
||||
|
|
@ -514,6 +525,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
||||
itemNameHash.insert("generic_eventremove_from_list", Event_RemoveFromList::newItem);
|
||||
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
|
||||
itemNameHash.insert("generic_eventconnection_closed", Event_ConnectionClosed::newItem);
|
||||
itemNameHash.insert("generic_eventmessage", Event_Message::newItem);
|
||||
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
|
||||
itemNameHash.insert("generic_eventuser_left", Event_UserLeft::newItem);
|
||||
|
|
@ -525,4 +537,5 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_event_contextundo_draw", Context_UndoDraw::newItem);
|
||||
itemNameHash.insert("game_event_contextmove_card", Context_MoveCard::newItem);
|
||||
itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem);
|
||||
itemNameHash.insert("cmdban_from_server", Command_BanFromServer::newItem);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||
4:remove_from_list:s,list:s,user_name
|
||||
4:server_message:s,message
|
||||
4:connection_closed:s,reason
|
||||
4:message:s,sender_name:s,receiver_name:s,text
|
||||
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
|
||||
4:user_left:s,user_name
|
||||
|
|
@ -73,3 +74,4 @@
|
|||
6:undo_draw
|
||||
6:move_card
|
||||
7:update_server_message
|
||||
7:ban_from_server:s,user_name:i,minutes
|
||||
|
|
@ -583,6 +583,14 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_ServerMessage; }
|
||||
int getItemId() const { return ItemId_Event_ServerMessage; }
|
||||
};
|
||||
class Event_ConnectionClosed : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ConnectionClosed(const QString &_reason = QString());
|
||||
QString getReason() const { return static_cast<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_ConnectionClosed; }
|
||||
int getItemId() const { return ItemId_Event_ConnectionClosed; }
|
||||
};
|
||||
class Event_Message : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -675,5 +683,14 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_UpdateServerMessage; }
|
||||
int getItemId() const { return ItemId_Command_UpdateServerMessage; }
|
||||
};
|
||||
class Command_BanFromServer : public AdminCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_BanFromServer(const QString &_userName = QString(), int _minutes = -1);
|
||||
QString getUserName() const { return static_cast<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||
int getMinutes() const { return static_cast<SerializableItem_Int *>(itemMap.value("minutes"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_BanFromServer; }
|
||||
int getItemId() const { return ItemId_Command_BanFromServer; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
virtual QMap<QString, ServerInfo_User *> getBuddyList(const QString &name) = 0;
|
||||
virtual QMap<QString, ServerInfo_User *> getIgnoreList(const QString &name) = 0;
|
||||
virtual bool getUserBanned(Server_ProtocolHandler * /*client*/, const QString & /*userName*/) const { return false; }
|
||||
protected:
|
||||
QMap<int, Server_Game *> games;
|
||||
QList<Server_ProtocolHandler *> clients;
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
|
||||
switch (command->getItemId()) {
|
||||
case ItemId_Command_UpdateServerMessage: return cmdUpdateServerMessage(static_cast<Command_UpdateServerMessage *>(command), cont);
|
||||
case ItemId_Command_BanFromServer: return cmdBanFromServer(static_cast<Command_BanFromServer *>(command), cont);
|
||||
default: return RespInvalidCommand;
|
||||
}
|
||||
}
|
||||
|
|
@ -244,6 +245,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
QString userName = cmd->getUsername().simplified();
|
||||
if (userName.isEmpty() || (userInfo != 0))
|
||||
return RespContextError;
|
||||
if (server->getUserBanned(this, userName))
|
||||
return RespWrongPassword;
|
||||
authState = server->loginUser(this, userName, cmd->getPassword());
|
||||
if (authState == PasswordWrong)
|
||||
return RespWrongPassword;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ private:
|
|||
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdRevealCards(Command_RevealCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
virtual ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdBanFromServer(Command_BanFromServer *cmd, CommandContainer *cont) = 0;
|
||||
|
||||
ResponseCode processCommandHelper(Command *command, CommandContainer *cont);
|
||||
private slots:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue