From 6bd080842729d44b42266f27b62528a602799966 Mon Sep 17 00:00:00 2001 From: Albert Medela Date: Thu, 4 Aug 2016 21:34:38 +0200 Subject: [PATCH] Block duplicated IP for guests configurable --- src/config/configfile.cpp | 1 + src/net/common/serverlobbythread.cpp | 2 +- src/net/common/sessionmanager.cpp | 4 ++-- src/net/sessionmanager.h | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 701199f5..9d4ec0cf 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -311,6 +311,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) configList.push_back(ConfigInfo("DBServerDatabaseName", CONFIG_TYPE_STRING, "pokerth")); configList.push_back(ConfigInfo("DBServerEncryptionKey", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("GameNameBadWordList", CONFIG_TYPE_STRING_LIST, "Regex")); + configList.push_back(ConfigInfo("ServerBlockGuestDuplicateIP", CONFIG_TYPE_INT, "0")); //fill tempList firstTime configBufferList = configList; diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index fddbe7d9..5e76f908 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1062,7 +1062,7 @@ ServerLobbyThread::HandleNetPacketInit(boost::shared_ptr session, c } // check if a guest session in lobby with same ip is already connected and // if number of lobby guests >= SERVER_MAX_GUEST_USERS_LOBBY - if(!m_sessionManager.IsGuestAllowedToConnect(session->GetClientAddr())) { + if(!m_sessionManager.IsGuestAllowedToConnect(session->GetClientAddr(), m_serverConfig.readConfigInt("ServerBlockGuestDuplicateIP"))) { SessionError(session, ERR_NET_SERVER_FULL); return; } diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index f4e00461..1017b45f 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -249,7 +249,7 @@ SessionManager::IsClientAddressConnected(const std::string &clientAddress) const } bool -SessionManager::IsGuestAllowedToConnect(const std::string &clientAddress) const +SessionManager::IsGuestAllowedToConnect(const std::string &clientAddress, int blockDup) const { bool retVal = true; boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -262,7 +262,7 @@ SessionManager::IsGuestAllowedToConnect(const std::string &clientAddress) const boost::shared_ptr tmpPlayer(i->second->GetPlayerData()); if (tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_GUEST) { num++; - if (i->second->GetClientAddr() == clientAddress) { + if (blockDup && i->second->GetClientAddr() == clientAddress) { // guest has same ip as another guest in lobby or retVal = false; break; diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index 36f7fb4f..ec3e3af3 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -64,7 +64,7 @@ public: bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(unsigned uniqueId) const; bool IsClientAddressConnected(const std::string &clientAddress) const; - bool IsGuestAllowedToConnect(const std::string &clientAddress) const; + bool IsGuestAllowedToConnect(const std::string &clientAddress, int) const; void ForEach(boost::function)> func);