From 7899f66cf68113fe468d905f4c627d910388ccc6 Mon Sep 17 00:00:00 2001 From: lotodore Date: Wed, 14 Jul 2010 08:17:07 +0000 Subject: [PATCH] The server now sends a notification if the game name is already in use. --- src/net/common/serverlobbythread.cpp | 28 ++++++++++++++++++++++++++-- src/net/common/sessionmanager.cpp | 4 ++-- src/net/serverlobbythread.h | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 4a6da19d..7fa115fc 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1283,9 +1283,14 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: // Create a new game. GameData tmpData; NetPacket::GetGameData(&newGame.gameInfo, tmpData); + string gameName(STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName)); unsigned gameId = GetNextGameId(); - if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST + if (IsGameNameInUse(gameName)) + { + SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GAME_NAME_IN_USE); + } + else if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST && tmpData.gameType != GAME_TYPE_NORMAL) { SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN); @@ -1296,7 +1301,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: new ServerGame( shared_from_this(), gameId, - STL_STRING_FROM_OCTET_STRING(newGame.gameInfo.gameName), + gameName, password, tmpData, session.playerData->GetUniqueId(), @@ -1639,6 +1644,25 @@ ServerLobbyThread::TimerCleanupAvatarCache(const boost::system::error_code &ec) } } +bool +ServerLobbyThread::IsGameNameInUse(const std::string &gameName) const +{ + bool found = false; + GameMap::const_iterator i = m_gameMap.begin(); + GameMap::const_iterator end = m_gameMap.end(); + + while (i != end) + { + if ((*i).second->GetName() == gameName) + { + found = true; + break; + } + ++i; + } + return found; +} + boost::shared_ptr ServerLobbyThread::InternalGetGameFromId(unsigned gameId) { diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 29a272be..8645931d 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -199,7 +199,7 @@ SessionManager::IsPlayerConnected(const string &playerName) const SessionWrapper tmpSession = GetSessionByPlayerName(playerName); - if (tmpSession.sessionData.get() && tmpSession.playerData.get()) + if (tmpSession.sessionData && tmpSession.playerData) retVal = true; return retVal; @@ -212,7 +212,7 @@ SessionManager::IsPlayerConnected(unsigned uniqueId) const SessionWrapper tmpSession = GetSessionByUniquePlayerId(uniqueId); - if (tmpSession.sessionData.get() && tmpSession.playerData.get()) + if (tmpSession.sessionData && tmpSession.playerData) retVal = true; return retVal; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index b94484e9..19ce9fd0 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -154,6 +154,7 @@ protected: void TimerCheckSessionTimeouts(const boost::system::error_code &ec); void TimerCleanupAvatarCache(const boost::system::error_code &ec); + bool IsGameNameInUse(const std::string &gameName) const; boost::shared_ptr InternalGetGameFromId(unsigned gameId); void InternalAddGame(boost::shared_ptr game); void InternalRemoveGame(boost::shared_ptr game);