about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2010-10-09 19:14:42 +0200
committeroy <Tom_Adams@web.de>2010-10-09 19:14:42 +0200
commitcd95f1869e12a8ca2983a1b3300d195f043d6391 (patch)
treeb85b0cf35278fd6dc981986ff30f177683ab13c5 /src
parentb3c81e7258cabc72cf9f610da0aa6aa494dd30a9 (diff)
downloadzcatch-cd95f1869e12a8ca2983a1b3300d195f043d6391.tar.gz
zcatch-cd95f1869e12a8ca2983a1b3300d195f043d6391.zip
added inactive player kicking. Closes #51
Diffstat (limited to 'src')
-rw-r--r--src/engine/server.h1
-rw-r--r--src/game/server/gamecontroller.cpp43
-rw-r--r--src/game/server/player.cpp12
-rw-r--r--src/game/server/player.h6
-rw-r--r--src/game/variables.h4
5 files changed, 65 insertions, 1 deletions
diff --git a/src/engine/server.h b/src/engine/server.h
index fa5d2498..7e620658 100644
--- a/src/engine/server.h
+++ b/src/engine/server.h
@@ -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
diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp
index 854787d6..03372ad1 100644
--- a/src/game/server/gamecontroller.cpp
+++ b/src/game/server/gamecontroller.cpp
@@ -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;
diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp
index 8b3c623a..6408707d 100644
--- a/src/game/server/player.cpp
+++ b/src/game/server/player.cpp
@@ -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);
diff --git a/src/game/server/player.h b/src/game/server/player.h
index ca7ab072..7aab0b6e 100644
--- a/src/game/server/player.h
+++ b/src/game/server/player.h
@@ -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;
diff --git a/src/game/variables.h b/src/game/variables.h
index 0c646a0e..47595364 100644
--- a/src/game/variables.h
+++ b/src/game/variables.h
@@ -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")