mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
GameController: Extract DoActivityCheck()
Apply refactoring from the upstream.
This commit is contained in:
parent
242aa63178
commit
ffe3f110eb
|
@ -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)
|
||||
|
|
|
@ -37,6 +37,8 @@ protected:
|
|||
CConfig *Config() { return m_pConfig; }
|
||||
IServer *Server() const { return m_pServer; }
|
||||
|
||||
void DoActivityCheck();
|
||||
|
||||
struct CSpawnEval
|
||||
{
|
||||
CSpawnEval()
|
||||
|
|
Loading…
Reference in a new issue