1st timestamp iteration and vector cleanup

This commit is contained in:
Kai Philipp
2019-09-09 22:40:16 +02:00
parent cb51ee79f2
commit 2effd5219a
3 changed files with 26 additions and 6 deletions
+2 -2
View File
@@ -1438,9 +1438,9 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> 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);
}
}
+24 -2
View File
@@ -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<boost::asio::ip::tcp::socket> 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<T>::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
-2
View File
@@ -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()
{