diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 96da31a1..913a6aeb 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1006,6 +1006,12 @@ void ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr session, const InitMessage &initMessage) { LOG_VERBOSE("Received init for session #" << session->GetId() << "."); + + // @XXX: debug tests + if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){ + LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Should be declined!"); + } + // @XXX: end debug tests // Before any other processing, perform some denial of service and // brute force attack prevention by checking whether the user recently sent an @@ -1057,6 +1063,11 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr session, c validGuest = true; noAuth = true; } + // @XXX: check if a guest session with same ip is already connected - decline if true + if(m_sessionManager.IsGuestConnectedMultiple(session->GetClientAddr())){ + LOG_ERROR("Guest with IP " << session->GetClientAddr() << " already connected! Decline!"); + validGuest = false; + } } if (!validGuest) { SessionError(session, ERR_NET_INVALID_PLAYER_NAME); diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index bd8b65eb..f2b417aa 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -247,6 +247,31 @@ SessionManager::IsClientAddressConnected(const std::string &clientAddress) const return retVal; } +bool +SessionManager::IsGuestConnectedMultiple(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(); + + int j = 0; + + while (i != end) { + // @XXX: comparing PlayerRights does not yet work (e.g. throws an exception) + //if ((*i).second->GetClientAddr() == clientAddress && (*i).second->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST) { + if ((*i).second->GetClientAddr() == clientAddress) { + j++; + } + ++i; + } + if (j > 1) { + retVal = true; + } + return retVal; +} + void SessionManager::ForEach(boost::function)> func) { diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index 8e90a544..5eec02fc 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -64,6 +64,7 @@ public: bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(unsigned uniqueId) const; bool IsClientAddressConnected(const std::string &clientAddress) const; + bool IsGuestConnectedMultiple(const std::string &clientAddress) const; void ForEach(boost::function)> func);