mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
kick users out of games
This commit is contained in:
parent
d6083a85c7
commit
731dfcad5c
13 changed files with 263 additions and 86 deletions
|
|
@ -16,65 +16,67 @@ ItemId_Command_JoinRoom = 1014,
|
|||
ItemId_Command_LeaveRoom = 1015,
|
||||
ItemId_Command_RoomSay = 1016,
|
||||
ItemId_Command_JoinGame = 1017,
|
||||
ItemId_Command_LeaveGame = 1018,
|
||||
ItemId_Command_Say = 1019,
|
||||
ItemId_Command_Shuffle = 1020,
|
||||
ItemId_Command_Mulligan = 1021,
|
||||
ItemId_Command_RollDie = 1022,
|
||||
ItemId_Command_DrawCards = 1023,
|
||||
ItemId_Command_UndoDraw = 1024,
|
||||
ItemId_Command_FlipCard = 1025,
|
||||
ItemId_Command_AttachCard = 1026,
|
||||
ItemId_Command_CreateToken = 1027,
|
||||
ItemId_Command_CreateArrow = 1028,
|
||||
ItemId_Command_DeleteArrow = 1029,
|
||||
ItemId_Command_SetCardAttr = 1030,
|
||||
ItemId_Command_SetCardCounter = 1031,
|
||||
ItemId_Command_IncCardCounter = 1032,
|
||||
ItemId_Command_ReadyStart = 1033,
|
||||
ItemId_Command_Concede = 1034,
|
||||
ItemId_Command_IncCounter = 1035,
|
||||
ItemId_Command_CreateCounter = 1036,
|
||||
ItemId_Command_SetCounter = 1037,
|
||||
ItemId_Command_DelCounter = 1038,
|
||||
ItemId_Command_NextTurn = 1039,
|
||||
ItemId_Command_SetActivePhase = 1040,
|
||||
ItemId_Command_DumpZone = 1041,
|
||||
ItemId_Command_StopDumpZone = 1042,
|
||||
ItemId_Command_RevealCards = 1043,
|
||||
ItemId_Event_Say = 1044,
|
||||
ItemId_Event_Leave = 1045,
|
||||
ItemId_Event_GameClosed = 1046,
|
||||
ItemId_Event_Shuffle = 1047,
|
||||
ItemId_Event_RollDie = 1048,
|
||||
ItemId_Event_MoveCard = 1049,
|
||||
ItemId_Event_FlipCard = 1050,
|
||||
ItemId_Event_DestroyCard = 1051,
|
||||
ItemId_Event_AttachCard = 1052,
|
||||
ItemId_Event_CreateToken = 1053,
|
||||
ItemId_Event_DeleteArrow = 1054,
|
||||
ItemId_Event_SetCardAttr = 1055,
|
||||
ItemId_Event_SetCardCounter = 1056,
|
||||
ItemId_Event_SetCounter = 1057,
|
||||
ItemId_Event_DelCounter = 1058,
|
||||
ItemId_Event_SetActivePlayer = 1059,
|
||||
ItemId_Event_SetActivePhase = 1060,
|
||||
ItemId_Event_DumpZone = 1061,
|
||||
ItemId_Event_StopDumpZone = 1062,
|
||||
ItemId_Event_RemoveFromList = 1063,
|
||||
ItemId_Event_ServerMessage = 1064,
|
||||
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
|
||||
ItemId_Command_KickFromGame = 1018,
|
||||
ItemId_Command_LeaveGame = 1019,
|
||||
ItemId_Command_Say = 1020,
|
||||
ItemId_Command_Shuffle = 1021,
|
||||
ItemId_Command_Mulligan = 1022,
|
||||
ItemId_Command_RollDie = 1023,
|
||||
ItemId_Command_DrawCards = 1024,
|
||||
ItemId_Command_UndoDraw = 1025,
|
||||
ItemId_Command_FlipCard = 1026,
|
||||
ItemId_Command_AttachCard = 1027,
|
||||
ItemId_Command_CreateToken = 1028,
|
||||
ItemId_Command_CreateArrow = 1029,
|
||||
ItemId_Command_DeleteArrow = 1030,
|
||||
ItemId_Command_SetCardAttr = 1031,
|
||||
ItemId_Command_SetCardCounter = 1032,
|
||||
ItemId_Command_IncCardCounter = 1033,
|
||||
ItemId_Command_ReadyStart = 1034,
|
||||
ItemId_Command_Concede = 1035,
|
||||
ItemId_Command_IncCounter = 1036,
|
||||
ItemId_Command_CreateCounter = 1037,
|
||||
ItemId_Command_SetCounter = 1038,
|
||||
ItemId_Command_DelCounter = 1039,
|
||||
ItemId_Command_NextTurn = 1040,
|
||||
ItemId_Command_SetActivePhase = 1041,
|
||||
ItemId_Command_DumpZone = 1042,
|
||||
ItemId_Command_StopDumpZone = 1043,
|
||||
ItemId_Command_RevealCards = 1044,
|
||||
ItemId_Event_Say = 1045,
|
||||
ItemId_Event_Leave = 1046,
|
||||
ItemId_Event_GameClosed = 1047,
|
||||
ItemId_Event_Kicked = 1048,
|
||||
ItemId_Event_Shuffle = 1049,
|
||||
ItemId_Event_RollDie = 1050,
|
||||
ItemId_Event_MoveCard = 1051,
|
||||
ItemId_Event_FlipCard = 1052,
|
||||
ItemId_Event_DestroyCard = 1053,
|
||||
ItemId_Event_AttachCard = 1054,
|
||||
ItemId_Event_CreateToken = 1055,
|
||||
ItemId_Event_DeleteArrow = 1056,
|
||||
ItemId_Event_SetCardAttr = 1057,
|
||||
ItemId_Event_SetCardCounter = 1058,
|
||||
ItemId_Event_SetCounter = 1059,
|
||||
ItemId_Event_DelCounter = 1060,
|
||||
ItemId_Event_SetActivePlayer = 1061,
|
||||
ItemId_Event_SetActivePhase = 1062,
|
||||
ItemId_Event_DumpZone = 1063,
|
||||
ItemId_Event_StopDumpZone = 1064,
|
||||
ItemId_Event_RemoveFromList = 1065,
|
||||
ItemId_Event_ServerMessage = 1066,
|
||||
ItemId_Event_ConnectionClosed = 1067,
|
||||
ItemId_Event_Message = 1068,
|
||||
ItemId_Event_GameJoined = 1069,
|
||||
ItemId_Event_UserLeft = 1070,
|
||||
ItemId_Event_LeaveRoom = 1071,
|
||||
ItemId_Event_RoomSay = 1072,
|
||||
ItemId_Context_ReadyStart = 1073,
|
||||
ItemId_Context_Concede = 1074,
|
||||
ItemId_Context_DeckSelect = 1075,
|
||||
ItemId_Context_UndoDraw = 1076,
|
||||
ItemId_Context_MoveCard = 1077,
|
||||
ItemId_Command_UpdateServerMessage = 1078,
|
||||
ItemId_Command_BanFromServer = 1079,
|
||||
ItemId_Other = 1080
|
||||
};
|
||||
|
|
|
|||
|
|
@ -88,6 +88,11 @@ Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_pas
|
|||
insertItem(new SerializableItem_String("password", _password));
|
||||
insertItem(new SerializableItem_Bool("spectator", _spectator));
|
||||
}
|
||||
Command_KickFromGame::Command_KickFromGame(int _gameId, int _playerId)
|
||||
: GameCommand("kick_from_game", _gameId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("player_id", _playerId));
|
||||
}
|
||||
Command_LeaveGame::Command_LeaveGame(int _gameId)
|
||||
: GameCommand("leave_game", _gameId)
|
||||
{
|
||||
|
|
@ -263,6 +268,10 @@ Event_GameClosed::Event_GameClosed(int _playerId)
|
|||
: GameEvent("game_closed", _playerId)
|
||||
{
|
||||
}
|
||||
Event_Kicked::Event_Kicked(int _playerId)
|
||||
: GameEvent("kicked", _playerId)
|
||||
{
|
||||
}
|
||||
Event_Shuffle::Event_Shuffle(int _playerId)
|
||||
: GameEvent("shuffle", _playerId)
|
||||
{
|
||||
|
|
@ -478,6 +487,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
|
||||
itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
|
||||
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
|
||||
itemNameHash.insert("cmdkick_from_game", Command_KickFromGame::newItem);
|
||||
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
|
||||
itemNameHash.insert("cmdsay", Command_Say::newItem);
|
||||
itemNameHash.insert("cmdshuffle", Command_Shuffle::newItem);
|
||||
|
|
@ -507,6 +517,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_eventsay", Event_Say::newItem);
|
||||
itemNameHash.insert("game_eventleave", Event_Leave::newItem);
|
||||
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
||||
itemNameHash.insert("game_eventkicked", Event_Kicked::newItem);
|
||||
itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem);
|
||||
itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem);
|
||||
itemNameHash.insert("game_eventmove_card", Event_MoveCard::newItem);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
1:leave_room
|
||||
1:room_say:s,message
|
||||
1:join_game:i,game_id:s,password:b,spectator
|
||||
2:kick_from_game:i,player_id
|
||||
2:leave_game
|
||||
2:say:s,message
|
||||
2:shuffle
|
||||
|
|
@ -44,6 +45,7 @@
|
|||
3:say:s,message
|
||||
3:leave
|
||||
3:game_closed
|
||||
3:kicked
|
||||
3:shuffle
|
||||
3:roll_die:i,sides:i,value
|
||||
3:move_card:i,card_id:s,card_name:s,start_zone:i,position:i,target_player_id:s,target_zone:i,x:i,y:i,new_card_id:b,face_down
|
||||
|
|
|
|||
|
|
@ -141,6 +141,14 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_JoinGame; }
|
||||
int getItemId() const { return ItemId_Command_JoinGame; }
|
||||
};
|
||||
class Command_KickFromGame : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_KickFromGame(int _gameId = -1, int _playerId = -1);
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_KickFromGame; }
|
||||
int getItemId() const { return ItemId_Command_KickFromGame; }
|
||||
};
|
||||
class Command_LeaveGame : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -403,6 +411,13 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_GameClosed; }
|
||||
int getItemId() const { return ItemId_Event_GameClosed; }
|
||||
};
|
||||
class Event_Kicked : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Kicked(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_Kicked; }
|
||||
int getItemId() const { return ItemId_Event_Kicked; }
|
||||
};
|
||||
class Event_Shuffle : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -247,6 +247,18 @@ void Server_Game::removePlayer(Server_Player *player)
|
|||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||
}
|
||||
|
||||
bool Server_Game::kickPlayer(int playerId)
|
||||
{
|
||||
Server_Player *playerToKick = players.value(playerId);
|
||||
if (!playerToKick)
|
||||
return false;
|
||||
|
||||
removePlayer(playerToKick);
|
||||
sendGameEventToPlayer(playerToKick, new Event_Kicked);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server_Game::setActivePlayer(int _activePlayer)
|
||||
{
|
||||
activePlayer = _activePlayer;
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public:
|
|||
ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator);
|
||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
bool kickPlayer(int playerId);
|
||||
void startGameIfReady();
|
||||
void stopGameIfFinished();
|
||||
int getActivePlayer() const { return activePlayer; }
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
case ItemId_Command_DeckSelect: return cmdDeckSelect(static_cast<Command_DeckSelect *>(command), cont, game, player);
|
||||
case ItemId_Command_SetSideboardPlan: return cmdSetSideboardPlan(static_cast<Command_SetSideboardPlan *>(command), cont, game, player);
|
||||
case ItemId_Command_LeaveGame: return cmdLeaveGame(static_cast<Command_LeaveGame *>(command), cont, game, player);
|
||||
case ItemId_Command_KickFromGame: return cmdKickFromGame(static_cast<Command_KickFromGame *>(command), cont, game, player);
|
||||
case ItemId_Command_ReadyStart: return cmdReadyStart(static_cast<Command_ReadyStart *>(command), cont, game, player);
|
||||
case ItemId_Command_Concede: return cmdConcede(static_cast<Command_Concede *>(command), cont, game, player);
|
||||
case ItemId_Command_Say: return cmdSay(static_cast<Command_Say *>(command), cont, game, player);
|
||||
|
|
@ -456,6 +457,17 @@ ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, C
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdKickFromGame(Command_KickFromGame *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (game->getCreatorInfo()->getName() != player->getUserInfo()->getName())
|
||||
return RespFunctionNotAllowed;
|
||||
|
||||
if (!game->kickPlayer(cmd->getPlayerId()))
|
||||
return RespNameNotFound;
|
||||
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (player->getSpectator())
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ private:
|
|||
ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room);
|
||||
ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room);
|
||||
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdKickFromGame(Command_KickFromGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue