From e18e459434c7373db788d591450fc4b31f178f98 Mon Sep 17 00:00:00 2001 From: Kai Philipp Date: Mon, 9 Sep 2019 19:21:15 +0200 Subject: [PATCH] limitrank - draft with return false always --- src/net/common/serverlobbythread.cpp | 11 +++++--- src/net/common/sessiondata.cpp | 16 ++++++++++++ src/net/common/sessionmanager.cpp | 39 ++++++++++++++++++++++++++++ src/net/sessiondata.h | 5 ++++ src/net/sessionmanager.h | 2 ++ 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index d9c5169d..850ad4b7 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1427,13 +1427,18 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr sessio SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_NOT_INVITED); } else if (!game->CheckPassword(password)) { SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_INVALID_PASSWORD); - } else if (tmpData.gameType == GAME_TYPE_RANKING - && !joinGame.spectateonly() + } else if (tmpData.gameType == GAME_TYPE_RANKING) { + if(!joinGame.spectateonly() && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6 && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4 && game->IsClientAddressConnected(session->GetClientAddr())) { - SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); + SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); + }else if (!session->IsPlayerAllowedToJoinLimitRank(session->GetPlayerData()->GetUniqueId())) { + SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); + } + } + } else { MoveSessionToGame(game, session, joinGame.autoleave(), false); diff --git a/src/net/common/sessiondata.cpp b/src/net/common/sessiondata.cpp index 549f79ca..1b844511 100644 --- a/src/net/common/sessiondata.cpp +++ b/src/net/common/sessiondata.cpp @@ -38,6 +38,8 @@ #include #include +// #include // @TODO: remove if really not necessary + using namespace std; using boost::asio::ip::tcp; @@ -398,6 +400,20 @@ SessionData::GetPlayerData() return m_playerData; } +void +SessionData::SetPlayerLastGames(std::array lastGames) +{ + boost::mutex::scoped_lock lock(m_dataMutex); + m_lastGames = player; +} + +std::array +SessionData::GetPlayerLastGames() +{ + boost::mutex::scoped_lock lock(m_dataMutex); + return m_lastGames; +} + string SessionData::GetRemoteIPAddressFromSocket() const { diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index f4e00461..b674ab79 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -34,9 +34,13 @@ #include #include +#include + using namespace std; #define SERVER_MAX_GUEST_USERS_LOBBY 50 // LG: Maximum number of guests users in lobby allowed +#define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5 +#define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60 SessionManager::SessionManager() { @@ -229,6 +233,41 @@ SessionManager::IsPlayerConnected(unsigned uniqueId) const return retVal; } +bool +SessionManager::IsPlayerAllowedToJoinLimitRank(const string &playerName) const +{ + bool retVal = false; + + // boost::shared_ptr tmpSession = GetSessionByPlayerName(playerName); + + // if (tmpSession){ + // std::array lastGames = tmpSession->GetPlayerLastGames(); + // std::time_t now = std::time(nullptr); + + + // retVal = true; + // } + + return retVal; +} + +bool +SessionManager::IsPlayerAllowedToJoinLimitRank(unsigned uniqueId) const +{ + bool retVal = false; + + // boost::shared_ptr tmpSession = GetSessionByUniquePlayerId(uniqueId); + + // if (tmpSession){ + // std::array lastGames = tmpSession->GetPlayerLastGames(); + // std::time_t now = std::time(nullptr); + + // retVal = true; + // } + + return retVal; +} + bool SessionManager::IsClientAddressConnected(const std::string &clientAddress) const { diff --git a/src/net/sessiondata.h b/src/net/sessiondata.h index 8521e00f..71041166 100644 --- a/src/net/sessiondata.h +++ b/src/net/sessiondata.h @@ -126,6 +126,9 @@ public: void SetPlayerData(boost::shared_ptr player); boost::shared_ptr GetPlayerData(); + void SetPlayerLastGames(std::array lastGames); + std::array GetPlayerLastGames(); + std::string GetRemoteIPAddressFromSocket() const; protected: @@ -159,6 +162,8 @@ private: std::string m_password; boost::shared_ptr m_playerData; + std::array m_lastGames; + mutable boost::mutex m_dataMutex; }; diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index 36f7fb4f..9a4b9622 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -65,6 +65,8 @@ public: bool IsPlayerConnected(unsigned uniqueId) const; bool IsClientAddressConnected(const std::string &clientAddress) const; bool IsGuestAllowedToConnect(const std::string &clientAddress) const; + bool IsPlayerAllowedToJoinLimitRank(const std::string &playerName) const; + bool IsPlayerAllowedToJoinLimitRank(unsigned uniqueId) const; void ForEach(boost::function)> func);