added inactive player kicking. Closes #51

This commit is contained in:
oy 2010-10-09 19:14:42 +02:00
parent b3c81e7258
commit cd95f1869e
5 changed files with 65 additions and 1 deletions

View file

@ -51,6 +51,7 @@ public:
virtual void SnapSetStaticsize(int ItemType, int Size) = 0;
virtual bool IsAuthed(int ClientID) = 0;
virtual void Kick(int ClientID, const char *pReason) = 0;
};
class IGameServer : public IInterface

View file

@ -443,7 +443,9 @@ void IGameController::Tick()
}
// move the player to the other team
int Temp = pP->m_LastActionTick;
pP->SetTeam(M^1);
pP->m_LastActionTick = Temp;
pP->Respawn();
pP->m_ForceBalanced = true;
@ -453,6 +455,47 @@ void IGameController::Tick()
}
m_UnbalancedTick = -1;
}
// check for inactive players
if(g_Config.m_SvInactiveKickTime > 0)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1)
{
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(-1);
}
break;
case 1:
{
// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
int Spectators = 0;
for(int j = 0; j < MAX_CLIENTS; ++j)
if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == -1)
++Spectators;
if(Spectators >= g_Config.m_SvSpectatorSlots)
Server()->Kick(i, "kicked for inactivity");
else
GameServer()->m_apPlayers[i]->SetTeam(-1);
}
break;
case 2:
{
// kick the player
Server()->Kick(i, "Kicked for inactivity");
}
}
}
}
}
}
// update browse info
int Prog = -1;

View file

@ -15,6 +15,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int CID, int Team)
Character = 0;
this->m_ClientID = CID;
m_Team = GameServer()->m_pController->ClampTeam(Team);
m_LastActionTick = Server()->Tick();
}
CPlayer::~CPlayer()
@ -126,6 +127,16 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput)
if(!Character && m_Team == -1)
m_ViewPos = vec2(NewInput->m_TargetX, NewInput->m_TargetY);
// check for activity
if(NewInput->m_Direction || m_LatestActivity.m_TargetX != NewInput->m_TargetX ||
m_LatestActivity.m_TargetY != NewInput->m_TargetY || NewInput->m_Jump ||
NewInput->m_Fire&1 || NewInput->m_Hook)
{
m_LatestActivity.m_TargetX = NewInput->m_TargetX;
m_LatestActivity.m_TargetY = NewInput->m_TargetY;
m_LastActionTick = Server()->Tick();
}
}
CCharacter *CPlayer::GetCharacter()
@ -165,6 +176,7 @@ void CPlayer::SetTeam(int Team)
KillCharacter();
m_Team = Team;
m_LastActionTick = Server()->Tick();
// we got to wait 0.5 secs before respawning
m_RespawnTick = Server()->Tick()+Server()->TickSpeed()/2;
str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", m_ClientID, Server()->ClientName(m_ClientID), m_Team);

View file

@ -62,6 +62,12 @@ public:
int m_Score;
int m_ScoreStartTick;
bool m_ForceBalanced;
int m_LastActionTick;
struct
{
int m_TargetX;
int m_TargetY;
} m_LatestActivity;
private:
CCharacter *Character;

View file

@ -49,7 +49,7 @@ MACRO_CONFIG_INT(UiColorAlpha, ui_color_alpha, 228, 0, 255, CFGFLAG_CLIENT|CFGFL
MACRO_CONFIG_INT(GfxNoclip, gfx_noclip, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Disable clipping")
// server
MACRO_CONFIG_INT(SvWarmup, sv_warmup, 0, 0, 0, CFGFLAG_SERVER, "Number of seconds to do warpup before round starts")
MACRO_CONFIG_INT(SvWarmup, sv_warmup, 0, 0, 0, CFGFLAG_SERVER, "Number of seconds to do warmup before round starts")
MACRO_CONFIG_STR(SvMotd, sv_motd, 900, "", CFGFLAG_SERVER, "Message of the day to display for the clients")
MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage")
MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between")
@ -63,6 +63,8 @@ MACRO_CONFIG_INT(SvSpamprotection, sv_spamprotection, 1, 0, 1, CFGFLAG_SERVER, "
MACRO_CONFIG_INT(SvSpectatorSlots, sv_spectator_slots, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Number of slots to reserve for spectators")
MACRO_CONFIG_INT(SvTeambalanceTime, sv_teambalance_time, 1, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before autobalancing teams")
MACRO_CONFIG_INT(SvInactiveKickTime, sv_inactivekick_time, 3, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before taking care of inactive players")
MACRO_CONFIG_INT(SvInactiveKick, sv_inactivekick, 1, 0, 2, CFGFLAG_SERVER, "How to deal with inactive players (0=move to spectator, 1=move to free spectator slot/kick, 2=kick)")
MACRO_CONFIG_INT(SvVoteKick, sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players")
MACRO_CONFIG_INT(SvVoteKickBantime, sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick")