GameController: Extract DoActivityCheck()

Apply refactoring from the upstream.
This commit is contained in:
Alexander Akulich 2021-01-12 00:21:48 +03:00
parent 242aa63178
commit ffe3f110eb
2 changed files with 54 additions and 47 deletions

View file

@ -49,6 +49,56 @@ IGameController::~IGameController()
{
}
void IGameController::DoActivityCheck()
{
if(g_Config.m_SvInactiveKickTime == 0)
return;
for(int i = 0; i < MAX_CLIENTS; ++i)
{
#ifdef CONF_DEBUG
if(g_Config.m_DbgDummies)
{
if(i >= MAX_CLIENTS - g_Config.m_DbgDummies)
break;
}
#endif
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && Server()->GetAuthedState(i) == AUTHED_NO)
{
if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick + g_Config.m_SvInactiveKickTime * Server()->TickSpeed() * 60)
{
switch(g_Config.m_SvInactiveKick)
{
case 0:
{
// move player to spectator
GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
}
break;
case 1:
{
// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
int Spectators = 0;
for(auto &pPlayer : GameServer()->m_apPlayers)
if(pPlayer && pPlayer->GetTeam() == TEAM_SPECTATORS)
++Spectators;
if(Spectators >= g_Config.m_SvSpectatorSlots)
Server()->Kick(i, "Kicked for inactivity");
else
GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
}
break;
case 2:
{
// kick the player
Server()->Kick(i, "Kicked for inactivity");
}
}
}
}
}
}
float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos)
{
float Score = 0.0f;
@ -437,53 +487,8 @@ void IGameController::Tick()
m_RoundCount++;
}
}
// check for inactive players
if(g_Config.m_SvInactiveKickTime > 0)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
#ifdef CONF_DEBUG
if(g_Config.m_DbgDummies)
{
if(i >= MAX_CLIENTS - g_Config.m_DbgDummies)
break;
}
#endif
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && Server()->GetAuthedState(i) == AUTHED_NO)
{
if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick + g_Config.m_SvInactiveKickTime * Server()->TickSpeed() * 60)
{
switch(g_Config.m_SvInactiveKick)
{
case 0:
{
// move player to spectator
GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
}
break;
case 1:
{
// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
int Spectators = 0;
for(auto &pPlayer : GameServer()->m_apPlayers)
if(pPlayer && pPlayer->GetTeam() == TEAM_SPECTATORS)
++Spectators;
if(Spectators >= g_Config.m_SvSpectatorSlots)
Server()->Kick(i, "Kicked for inactivity");
else
GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
}
break;
case 2:
{
// kick the player
Server()->Kick(i, "Kicked for inactivity");
}
}
}
}
}
}
DoActivityCheck();
}
void IGameController::Snap(int SnappingClient)

View file

@ -37,6 +37,8 @@ protected:
CConfig *Config() { return m_pConfig; }
IServer *Server() const { return m_pServer; }
void DoActivityCheck();
struct CSpawnEval
{
CSpawnEval()