client/server version bump; eventConnectionStateChanged

This commit is contained in:
Max-Wilhelm Bruker 2011-06-25 17:50:28 +02:00
parent d892d320ea
commit 4b84168bda
24 changed files with 1232 additions and 1076 deletions

View file

@ -43,43 +43,44 @@ 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_ServerShutdown = 1067,
ItemId_Event_ConnectionClosed = 1068,
ItemId_Event_Message = 1069,
ItemId_Event_GameJoined = 1070,
ItemId_Event_UserLeft = 1071,
ItemId_Event_LeaveRoom = 1072,
ItemId_Event_RoomSay = 1073,
ItemId_Context_ReadyStart = 1074,
ItemId_Context_Concede = 1075,
ItemId_Context_DeckSelect = 1076,
ItemId_Context_UndoDraw = 1077,
ItemId_Context_MoveCard = 1078,
ItemId_Context_Mulligan = 1079,
ItemId_Command_UpdateServerMessage = 1080,
ItemId_Command_ShutdownServer = 1081,
ItemId_Command_BanFromServer = 1082,
ItemId_Other = 1083
ItemId_Event_ConnectionStateChanged = 1045,
ItemId_Event_Say = 1046,
ItemId_Event_Leave = 1047,
ItemId_Event_GameClosed = 1048,
ItemId_Event_Kicked = 1049,
ItemId_Event_Shuffle = 1050,
ItemId_Event_RollDie = 1051,
ItemId_Event_MoveCard = 1052,
ItemId_Event_FlipCard = 1053,
ItemId_Event_DestroyCard = 1054,
ItemId_Event_AttachCard = 1055,
ItemId_Event_CreateToken = 1056,
ItemId_Event_DeleteArrow = 1057,
ItemId_Event_SetCardAttr = 1058,
ItemId_Event_SetCardCounter = 1059,
ItemId_Event_SetCounter = 1060,
ItemId_Event_DelCounter = 1061,
ItemId_Event_SetActivePlayer = 1062,
ItemId_Event_SetActivePhase = 1063,
ItemId_Event_DumpZone = 1064,
ItemId_Event_StopDumpZone = 1065,
ItemId_Event_RemoveFromList = 1066,
ItemId_Event_ServerMessage = 1067,
ItemId_Event_ServerShutdown = 1068,
ItemId_Event_ConnectionClosed = 1069,
ItemId_Event_Message = 1070,
ItemId_Event_GameJoined = 1071,
ItemId_Event_UserLeft = 1072,
ItemId_Event_LeaveRoom = 1073,
ItemId_Event_RoomSay = 1074,
ItemId_Context_ReadyStart = 1075,
ItemId_Context_Concede = 1076,
ItemId_Context_DeckSelect = 1077,
ItemId_Context_UndoDraw = 1078,
ItemId_Context_MoveCard = 1079,
ItemId_Context_Mulligan = 1080,
ItemId_Command_UpdateServerMessage = 1081,
ItemId_Command_ShutdownServer = 1082,
ItemId_Command_BanFromServer = 1083,
ItemId_Other = 1084
};

View file

@ -255,6 +255,11 @@ Command_RevealCards::Command_RevealCards(int _gameId, const QString &_zoneName,
insertItem(new SerializableItem_Int("card_id", _cardId));
insertItem(new SerializableItem_Int("player_id", _playerId));
}
Event_ConnectionStateChanged::Event_ConnectionStateChanged(int _playerId, bool _connected)
: GameEvent("connection_state_changed", _playerId)
{
insertItem(new SerializableItem_Bool("connected", _connected));
}
Event_Say::Event_Say(int _playerId, const QString &_message)
: GameEvent("say", _playerId)
{
@ -531,6 +536,7 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmddump_zone", Command_DumpZone::newItem);
itemNameHash.insert("cmdstop_dump_zone", Command_StopDumpZone::newItem);
itemNameHash.insert("cmdreveal_cards", Command_RevealCards::newItem);
itemNameHash.insert("game_eventconnection_state_changed", Event_ConnectionStateChanged::newItem);
itemNameHash.insert("game_eventsay", Event_Say::newItem);
itemNameHash.insert("game_eventleave", Event_Leave::newItem);
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);

View file

@ -42,6 +42,7 @@
2:dump_zone:i,player_id:s,zone_name:i,number_cards
2:stop_dump_zone:i,player_id:s,zone_name
2:reveal_cards:s,zone_name:i,card_id:i,player_id
3:connection_state_changed:b,connected
3:say:s,message
3:leave
3:game_closed

View file

@ -389,6 +389,14 @@ public:
static SerializableItem *newItem() { return new Command_RevealCards; }
int getItemId() const { return ItemId_Command_RevealCards; }
};
class Event_ConnectionStateChanged : public GameEvent {
Q_OBJECT
public:
Event_ConnectionStateChanged(int _playerId = -1, bool _connected = false);
bool getConnected() const { return static_cast<SerializableItem_Bool *>(itemMap.value("connected"))->getData(); };
static SerializableItem *newItem() { return new Event_ConnectionStateChanged; }
int getItemId() const { return ItemId_Event_ConnectionStateChanged; }
};
class Event_Say : public GameEvent {
Q_OBJECT
public:

View file

@ -341,6 +341,13 @@ void Server_Game::nextTurn()
setActivePlayer(keys[listPos]);
}
void Server_Game::postConnectionStatusUpdate(Server_Player *player, bool connectionStatus)
{
QMutexLocker locker(&gameMutex);
sendGameEvent(new Event_ConnectionStateChanged(player->getPlayerId(), connectionStatus));
}
QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAsking) const
{
QMutexLocker locker(&gameMutex);

View file

@ -88,6 +88,7 @@ public:
void setActivePlayer(int _activePlayer);
void setActivePhase(int _activePhase);
void nextTurn();
void postConnectionStatusUpdate(Server_Player *player, bool connectionStatus);
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
void sendGameEvent(GameEvent *event, GameEventContext *context = 0, Server_Player *exclude = 0);

View file

@ -46,8 +46,10 @@ void Server_ProtocolHandler::prepareDestroy()
if ((authState == UnknownUser) || p->getSpectator())
g->removePlayer(p);
else
else {
p->setProtocolHandler(0);
g->postConnectionStatusUpdate(p, false);
}
}
gameListMutex.unlock();
@ -392,6 +394,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC
for (int j = 0; j < gamePlayers.size(); ++j)
if (gamePlayers[j]->getUserInfo()->getName() == userInfo->getName()) {
gamePlayers[j]->setProtocolHandler(this);
game->postConnectionStatusUpdate(gamePlayers[j], true);
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, gamePlayers[j]));
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getDescription(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), game->getSpectatorsCanTalk(), game->getSpectatorsSeeEverything(), true));