From 93b45c13717b6eb9972bfcc3e2d975d737367f70 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 28 Mar 2010 14:53:08 +0000 Subject: [PATCH] Sending error if guest tries to join non-standard game. --- src/net/common/clientstate.cpp | 3 ++ src/net/common/serverlobbythread.cpp | 53 +++++++++++++++++++--------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index aedd05bc..0e80dc1c 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -1387,6 +1387,9 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr client case joinGameFailureReason_invalidPassword : failureCode = NTF_NET_JOIN_INVALID_PASSWORD; break; + case joinGameFailureReason_notAllowedAsGuest : + failureCode = NTF_NET_JOIN_GUEST_FORBIDDEN; + break; default : failureCode = NTF_NET_INTERNAL; break; diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 513fbc1c..cbd50d75 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1261,22 +1261,31 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: // Create a new game. GameData tmpData; NetPacket::GetGameData(&newGame.gameInfo, tmpData); - boost::shared_ptr game( - new ServerGame( - shared_from_this(), - GetNextGameId(), - STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName), - password, - tmpData, - session.playerData->GetUniqueId(), - GetGui(), - m_playerConfig)); - game->Init(); - // Add game to list of games. - InternalAddGame(game); + if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST + && tmpData.gameType != GAME_TYPE_NORMAL) + { + SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN); + } + else + { + boost::shared_ptr game( + new ServerGame( + shared_from_this(), + GetNextGameId(), + STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName), + password, + tmpData, + session.playerData->GetUniqueId(), + GetGui(), + m_playerConfig)); + game->Init(); - MoveSessionToGame(*game, session); + // Add game to list of games. + InternalAddGame(game); + + MoveSessionToGame(*game, session); + } } void @@ -1287,15 +1296,22 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st if (pos != m_gameMap.end()) { + bool joinGame = true; ServerGame &game = *pos->second; - if (game.CheckPassword(password)) + const GameData &tmpData = game.GetGameData(); + if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST + && tmpData.gameType != GAME_TYPE_NORMAL) { - MoveSessionToGame(game, session); + SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN); + joinGame = false; } - else + else if (!game.CheckPassword(password)) { SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_INVALID_PASSWORD); + joinGame = false; } + if (joinGame) + MoveSessionToGame(game, session); } else { @@ -1779,6 +1795,9 @@ ServerLobbyThread::SendJoinGameFailed(boost::shared_ptr s, int reas case NTF_NET_JOIN_INVALID_PASSWORD : joinFailed->joinGameFailureReason = joinGameFailureReason_invalidPassword; break; + case NTF_NET_JOIN_GUEST_FORBIDDEN : + joinFailed->joinGameFailureReason = joinGameFailureReason_notAllowedAsGuest; + break; default : joinFailed->joinGameFailureReason = joinGameFailureReason_invalidGame; break;