From 9c4264b491ae48687057fbe121096b8c480b00be Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 18 Jan 2010 13:11:18 +0100 Subject: [PATCH] fixed server crash bug --- cockatrice/src/tab_server.cpp | 2 +- common/protocol.cpp | 1 + common/protocol_datastructures.h | 2 +- common/server_game.cpp | 2 +- common/server_protocolhandler.cpp | 3 +++ 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/tab_server.cpp b/cockatrice/src/tab_server.cpp index 4934e06e..2c1be031 100644 --- a/cockatrice/src/tab_server.cpp +++ b/cockatrice/src/tab_server.cpp @@ -65,7 +65,7 @@ void GameSelector::checkResponse(ResponseCode response) switch (response) { case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break; case RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break; - case RespContextError: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; + case RespGameFull: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; case RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break; default: ; } diff --git a/common/protocol.cpp b/common/protocol.cpp index 79e7718b..26c5dc4d 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -144,6 +144,7 @@ void ProtocolResponse::initializeHash() responseHash.insert("login_needed", RespLoginNeeded); responseHash.insert("function_not_allowed", RespFunctionNotAllowed); responseHash.insert("game_not_started", RespGameNotStarted); + responseHash.insert("game_full", RespGameFull); responseHash.insert("context_error", RespContextError); responseHash.insert("wrong_password", RespWrongPassword); responseHash.insert("spectators_not_allowed", RespSpectatorsNotAllowed); diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 9f25f177..1ab73b1a 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -8,7 +8,7 @@ class DeckList; -enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed }; +enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed }; // PrivateZone: Contents of the zone are always visible to the owner, // but not to anyone else. diff --git a/common/server_game.cpp b/common/server_game.cpp index 1771bfdb..307a7663 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -156,7 +156,7 @@ ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator) if (!spectatorsAllowed) return RespSpectatorsNotAllowed; } else if (gameStarted || (getPlayerCount() >= getMaxPlayers())) - return RespContextError; + return RespGameFull; return RespOk; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index b4d62f0a..3d96f64d 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -274,6 +274,9 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd) ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd) { + if (games.contains(cmd->getGameId())) + return RespContextError; + Server_Game *g = server->getGame(cmd->getGameId()); if (!g) return RespNameNotFound;