server crash fix

This commit is contained in:
Max-Wilhelm Bruker 2010-01-26 16:56:07 +01:00
parent 9c4264b491
commit 3714e1cbf5
3 changed files with 19 additions and 2 deletions

View file

@ -17,6 +17,9 @@ Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_
Server_Player::~Server_Player() Server_Player::~Server_Player()
{ {
delete deck; delete deck;
if (handler)
handler->playerRemovedFromGame(game);
} }
int Server_Player::newCardId() int Server_Player::newCardId()

View file

@ -45,7 +45,13 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
chatChannelIterator.next().value()->removeClient(this); 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(); lastCommandTime = QDateTime::currentDateTime();
@ -77,6 +83,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
} }
if (!games.contains(gameCommand->getGameId())) { if (!games.contains(gameCommand->getGameId())) {
qDebug() << "invalid game";
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound)); sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
return; return;
} }
@ -128,6 +135,11 @@ void Server_ProtocolHandler::processCommand(Command *command)
} }
if (response != RespNothing) if (response != RespNothing)
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response)); sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
}
void Server_ProtocolHandler::processCommand(Command *command)
{
processCommandHelper(command);
delete 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) ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
{ {
games.remove(game->getGameId());
game->removePlayer(player); game->removePlayer(player);
return RespOk; return RespOk;
} }

View file

@ -72,11 +72,14 @@ private:
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpZone(Command_DumpZone *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); ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
void processCommandHelper(Command *command);
private slots: private slots:
void pingClockTimeout(); void pingClockTimeout();
public: public:
Server_ProtocolHandler(Server *_server, QObject *parent = 0); Server_ProtocolHandler(Server *_server, QObject *parent = 0);
~Server_ProtocolHandler(); ~Server_ProtocolHandler();
void playerRemovedFromGame(Server_Game *game);
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; } bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; } bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }