diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 2f0bd94c..451d4da3 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1438,9 +1438,9 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr sessio // ){ // SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); } else { - // @FIXME: debug only - final poition is gamestart + // @FIXME: debug only - final position is gamestart session->AddPlayerLastGame((unsigned long)time(NULL)); - LOG_ERROR("TimeStamp stored: " << session->GetPlayerLastGames().front()); + //LOG_ERROR("TimeStamp stored: " << session->GetPlayerLastGames().front()); MoveSessionToGame(game, session, joinGame.autoleave(), false); } } diff --git a/src/net/common/sessiondata.cpp b/src/net/common/sessiondata.cpp index ce0c82b4..31cafa2c 100644 --- a/src/net/common/sessiondata.cpp +++ b/src/net/common/sessiondata.cpp @@ -49,6 +49,9 @@ using namespace std::chrono; using namespace boost::chrono; #endif +#define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5 +#define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60 + SessionData::SessionData(boost::shared_ptr sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService) : m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true), m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService), @@ -429,9 +432,28 @@ SessionData::IsPlayerAllowedToJoinLimitRank() { bool retVal = false; - // @TODO: iterate m_lastGames +// #define SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES 5 +// #define SERVER_ALLOWED_RANKING_GAMES_MINUTES 60 + + boost::mutex::scoped_lock lock(m_dataMutex); - return true; + // @TODO: iterate m_lastGames + unsigned long then = (unsigned long)time(NULL) - (unsigned long)(SERVER_ALLOWED_RANKING_GAMES_MINUTES * 10); + + unsigned long num = (unsigned long)SERVER_ALLOWED_RANKING_GAMES_PER_MINUTES; + + int count = 0; + for(std::vector::iterator timeStamp = m_lastGames.begin(); timeStamp != m_lastGames.end(); ++timeStamp) { + if(timeStamp > then) + count++; + else + m_lastGames.erase(timeStamp); + } + + if(count < num) + retVal = true; + + return retVal; } string diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 11337f70..4fa89569 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -39,8 +39,6 @@ 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() {