diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 9383f4e0..a5d23109 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -581,6 +581,12 @@ ServerGame::IsPlayerConnected(unsigned playerId) const return GetSessionManager().IsPlayerConnected(playerId); } +bool +ServerGame::IsClientAddressConnected(const std::string &clientAddress) const +{ + return GetSessionManager().IsClientAddressConnected(clientAddress); +} + bool ServerGame::IsRunning() const { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index aeb47324..4ce8cca5 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1395,6 +1395,11 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st { SendJoinGameFailed(session.sessionData, joinGame.gameId, NTF_NET_JOIN_INVALID_PASSWORD); } + else if (tmpData.gameType == GAME_TYPE_RANKING + && game.IsClientAddressConnected(session.sessionData->GetClientAddr())) + { + SendJoinGameFailed(session.sessionData, joinGame.gameId, NTF_NET_JOIN_GAME_FULL); + } else { MoveSessionToGame(game, session); diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 274da580..38037019 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -218,6 +218,27 @@ SessionManager::IsPlayerConnected(unsigned uniqueId) const return retVal; } +bool +SessionManager::IsClientAddressConnected(const std::string &clientAddress) const +{ + bool retVal = false; + boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); + + SessionMap::const_iterator i = m_sessionMap.begin(); + SessionMap::const_iterator end = m_sessionMap.end(); + + while (i != end) + { + if ((*i).second.sessionData->GetClientAddr() == clientAddress) + { + retVal = true; + break; + } + ++i; + } + return retVal; +} + void SessionManager::ForEach(boost::function func) { diff --git a/src/net/servergame.h b/src/net/servergame.h index ab407dc9..4e21c043 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -76,6 +76,7 @@ public: PlayerIdList GetPlayerIdList() const; bool IsPlayerConnected(const std::string &name) const; bool IsPlayerConnected(unsigned playerId) const; + bool IsClientAddressConnected(const std::string &clientAddress) const; bool IsRunning() const; diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index f8fb7427..df8e4a8c 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -61,6 +61,7 @@ public: PlayerIdList GetPlayerIdList(SessionData::State state) const; bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(unsigned uniqueId) const; + bool IsClientAddressConnected(const std::string &clientAddress) const; void ForEach(boost::function func);