From 3714e1cbf5b72756a3c04aaaed077830016fb8cc Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 26 Jan 2010 16:56:07 +0100 Subject: [PATCH] server crash fix --- common/server_player.cpp | 3 +++ common/server_protocolhandler.cpp | 15 +++++++++++++-- common/server_protocolhandler.h | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/server_player.cpp b/common/server_player.cpp index fda88403..74fa8dd5 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -17,6 +17,9 @@ Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_ Server_Player::~Server_Player() { delete deck; + + if (handler) + handler->playerRemovedFromGame(game); } int Server_Player::newCardId() diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 3d96f64d..31e11513 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -45,7 +45,13 @@ Server_ProtocolHandler::~Server_ProtocolHandler() chatChannelIterator.next().value()->removeClient(this); } -void Server_ProtocolHandler::processCommand(Command *command) +void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game) +{ + qDebug() << "Server_ProtocolHandler::playerRemovedFromGame(): gameId =" << game->getGameId(); + games.remove(game->getGameId()); +} + +void Server_ProtocolHandler::processCommandHelper(Command *command) { lastCommandTime = QDateTime::currentDateTime(); @@ -77,6 +83,7 @@ void Server_ProtocolHandler::processCommand(Command *command) } if (!games.contains(gameCommand->getGameId())) { + qDebug() << "invalid game"; sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound)); return; } @@ -128,6 +135,11 @@ void Server_ProtocolHandler::processCommand(Command *command) } if (response != RespNothing) sendProtocolItem(new ProtocolResponse(command->getCmdId(), response)); +} + +void Server_ProtocolHandler::processCommand(Command *command) +{ + processCommandHelper(command); delete command; @@ -293,7 +305,6 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd) ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player) { - games.remove(game->getGameId()); game->removePlayer(player); return RespOk; } diff --git a/common/server_protocolhandler.h b/common/server_protocolhandler.h index 910879e5..c6694f47 100644 --- a/common/server_protocolhandler.h +++ b/common/server_protocolhandler.h @@ -72,11 +72,14 @@ private: ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player); + + void processCommandHelper(Command *command); private slots: void pingClockTimeout(); public: Server_ProtocolHandler(Server *_server, QObject *parent = 0); ~Server_ProtocolHandler(); + void playerRemovedFromGame(Server_Game *game); bool getAcceptsGameListChanges() const { return acceptsGameListChanges; } bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }