From 9e039182ecacbddcb1e56c878805f5505e779530 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 1 Aug 2010 20:15:49 +0000 Subject: [PATCH] Also check ranking game restrictions on server. --- src/gui/qt/startwindow/startwindowimpl.cpp | 7 ++++++- src/net/common/clientstate.cpp | 3 +++ src/net/common/servergame.cpp | 19 +++++++++++++++++++ src/net/common/servergamestate.cpp | 5 ++++- src/net/common/serverlobbythread.cpp | 15 ++++++++++----- src/net/servergame.h | 1 + src/net/socket_msg.h | 1 + 7 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index 2afc5b83..7c68a70e 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -875,7 +875,12 @@ void startWindowImpl::networkNotification(int notificationId) tr("You cannot join this type of game as guest."), QMessageBox::Close); } break; - case NTF_NET_NEW_RELEASE_AVAILABLE: + case NTF_NET_JOIN_INVALID_SETTINGS: + { QMessageBox::warning(this, tr("Network Notification"), + tr("The settings are invalid for this type of game."), + QMessageBox::Close); } + break; + case NTF_NET_NEW_RELEASE_AVAILABLE: { QMessageBox msgBox(QMessageBox::Information, tr("Network Notification"), tr("A new release of PokerTH is available.
Please go to http://www.pokerth.net and download the latest version."), QMessageBox::Close, this); diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 5c1bb8af..90cdca30 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -1400,6 +1400,9 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr client case joinGameFailureReason_gameNameInUse : failureCode = NTF_NET_JOIN_GAME_NAME_IN_USE; break; + case joinGameFailureReason_invalidSettings : + failureCode = NTF_NET_JOIN_INVALID_SETTINGS; + break; default : failureCode = NTF_NET_INTERNAL; break; diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 652914a1..f61a8a0d 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -837,6 +837,25 @@ ServerGame::CheckPassword(const string &password) const return (password == m_password); } +bool +ServerGame::CheckSettings(const GameData &data) +{ + bool retVal = true; + if (data.gameType == GAME_TYPE_RANKING) + { + if ((data.startMoney != RANKING_GAME_START_CASH) + || (data.maxNumberOfPlayers != RANKING_GAME_NUMBER_OF_PLAYERS) + || (data.firstSmallBlind != RANKING_GAME_START_SBLIND) + || (data.raiseIntervalMode != RAISE_ON_HANDNUMBER) + || (data.raiseMode != DOUBLE_BLINDS) + || (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND)) + { + retVal = false; + } + } + return retVal; +} + GuiInterface & ServerGame::GetGui() { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index a623432e..273f58c8 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -498,7 +498,10 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr server, { StartEventMessage_t *netStartEvent = &packet->GetMsg()->choice.startEventMessage; // Only admins are allowed to start the game. - if (session.playerData->IsGameAdmin() && netStartEvent->gameId == server->GetId()) + if (session.playerData->IsGameAdmin() + && netStartEvent->gameId == server->GetId() + && (server->GetGameData().gameType != GAME_TYPE_RANKING // ranking games need to be full + || server->GetGameData().maxNumberOfPlayers == server->GetCurNumberOfPlayers())) { SendStartEvent(*server, netStartEvent->fillWithComputerPlayers); } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index dcd12012..1d3ba654 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1331,6 +1331,10 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: { SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN); } + else if (!ServerGame::CheckSettings(tmpData)) + { + SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_INVALID_SETTINGS); + } else { boost::shared_ptr game( @@ -1360,28 +1364,26 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st if (pos != m_gameMap.end()) { - bool doJoin = true; ServerGame &game = *pos->second; const GameData &tmpData = game.GetGameData(); if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST && tmpData.gameType != GAME_TYPE_NORMAL) { SendJoinGameFailed(session.sessionData, joinGame.gameId, NTF_NET_JOIN_GUEST_FORBIDDEN); - doJoin = false; } else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY && !game.IsPlayerInvited(session.playerData->GetUniqueId())) { SendJoinGameFailed(session.sessionData, joinGame.gameId, NTF_NET_JOIN_NOT_INVITED); - doJoin = false; } else if (!game.CheckPassword(password)) { SendJoinGameFailed(session.sessionData, joinGame.gameId, NTF_NET_JOIN_INVALID_PASSWORD); - doJoin = false; } - if (doJoin) + else + { MoveSessionToGame(game, session); + } } else { @@ -1925,6 +1927,9 @@ ServerLobbyThread::SendJoinGameFailed(boost::shared_ptr s, unsigned case NTF_NET_JOIN_GAME_NAME_IN_USE : joinFailed->joinGameFailureReason = joinGameFailureReason_gameNameInUse; break; + case NTF_NET_JOIN_INVALID_SETTINGS : + joinFailed->joinGameFailureReason = joinGameFailureReason_invalidSettings; + break; default : joinFailed->joinGameFailureReason = joinGameFailureReason_invalidGame; break; diff --git a/src/net/servergame.h b/src/net/servergame.h index 1ff2dff4..b1469512 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -68,6 +68,7 @@ public: bool IsPasswordProtected() const; bool CheckPassword(const std::string &password) const; + static bool CheckSettings(const GameData &data); const GameData &GetGameData() const; boost::shared_ptr GetPlayerDataByUniqueId(unsigned playerId) const; diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index ff86fde0..b57e65b6 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -115,6 +115,7 @@ #define NTF_NET_JOIN_GUEST_FORBIDDEN 214 #define NTF_NET_JOIN_NOT_INVITED 215 #define NTF_NET_JOIN_GAME_NAME_IN_USE 216 +#define NTF_NET_JOIN_INVALID_SETTINGS 217 // Notifications - version #define NTF_NET_NEW_RELEASE_AVAILABLE 220