limit rank games per time unit implemented

This commit is contained in:
Kai Philipp
2019-11-20 18:19:46 +01:00
parent add886ebee
commit 7c538fc436
22 changed files with 312 additions and 13 deletions
+28
View File
@@ -293,11 +293,13 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
PlayerDataList
ServerGame::InternalStartGame()
{
LOG_ERROR("InternalStartGame() entered.");
// Initialize the game.
PlayerDataList playerData(GetFullPlayerDataList());
if (playerData.size() >= 2) {
// Set DB Backend.
// @TODO: check for wec or bbc game with bbcbot as creator
if (GetGameData().gameType == GAME_TYPE_RANKING)
m_database = GetLobbyThread().GetDatabase();
else
@@ -346,6 +348,12 @@ ServerGame::InternalStartGame()
GetDatabase().AsyncCreateGame(GetId(), GetName());
InitRankingMap(playerData);
// @TODO: here to save last_games with mysql per player
if (GetGameData().gameType == GAME_TYPE_RANKING)
StoreLastGames(playerData);
}
return playerData;
}
@@ -442,6 +450,26 @@ ServerGame::StoreAndResetRanking()
m_rankingMap.clear();
}
void
ServerGame::StoreLastGames(const PlayerDataList &playerDataList)
{
// Store players lastgames in database.
PlayerDataList::const_iterator i = playerDataList.begin();
PlayerDataList::const_iterator end = playerDataList.end();
while (i != end) {
boost::shared_ptr<PlayerData> tmpPlayer(*i);
// tmpPlayer->GetUniqueId()
tmpPlayer->AddPlayerLastGame((long)time(NULL));
LOG_ERROR("TimeStamp stored: " << tmpPlayer->GetPlayerLastGames().back());
std::vector<long> last_games = tmpPlayer->GetPlayerLastGames();
LOG_ERROR("Ready for storing vector for player " << tmpPlayer->GetDBId() << " - lastGameTs " << last_games.back());
if(tmpPlayer->GetDBId() != DB_ID_INVALID){
GetDatabase().SetPlayerLastGames(GetId(), tmpPlayer->GetDBId(), last_games, GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->GetUniqueId())->GetClientAddr());
}
++i;
}
}
void
ServerGame::RemoveAutoLeavePlayers()
{