about summary refs log tree commit diff
path: root/src/game/server/player.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/server/player.cpp')
-rw-r--r--src/game/server/player.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp
index ea1e0233..7464e3c7 100644
--- a/src/game/server/player.cpp
+++ b/src/game/server/player.cpp
@@ -60,6 +60,8 @@ void CPlayer::Tick()
 	if(m_ChatTicks > 0)
 		m_ChatTicks--;
 	
+	if(g_Config.m_SvAnticamper && m_pCharacter && !GameServer()->m_World.m_Paused)
+		Anticamper();
 	/* end zCatch*/
 
 	// do latency stuff
@@ -303,3 +305,39 @@ void CPlayer::TryRespawn()
 	m_pCharacter->Spawn(this, SpawnPos);
 	GameServer()->CreatePlayerSpawn(SpawnPos);
 }
+
+int CPlayer::Anticamper()
+{
+	int AnticamperTime = g_Config.m_SvAnticamperTime;
+	int AnticamperRange = g_Config.m_SvAnticamperRange;
+
+	if(m_CampTick == -1)
+	{
+		m_CampPos = m_pCharacter->m_Pos;
+		m_CampTick = Server()->Tick() + Server()->TickSpeed()*AnticamperTime;
+	}
+
+	// Check if the player is moving
+	if((m_CampPos.x - m_pCharacter->m_Pos.x >= (float)AnticamperRange || m_CampPos.x - m_pCharacter->m_Pos.x <= -(float)AnticamperRange)
+	|| (m_CampPos.y - m_pCharacter->m_Pos.y >= (float)AnticamperRange || m_CampPos.y - m_pCharacter->m_Pos.y <= -(float)AnticamperRange))
+		{
+			m_CampTick = -1;
+		}
+
+	// Send warning to the player
+	if(m_CampTick <= Server()->Tick() + Server()->TickSpeed() * AnticamperTime/2 && m_CampTick != -1 && !m_SentCampMsg)
+	{
+		GameServer()->SendBroadcast("ANTICAMPER: Move or die", m_ClientID);
+		m_SentCampMsg = true;
+	}
+
+	// Kill him
+	if((m_CampTick <= Server()->Tick()) && (m_CampTick > 0))
+	{
+		m_pCharacter->Die(m_ClientID, WEAPON_ANTICAMPER);
+		m_CampTick = -1;
+		m_SentCampMsg = false;
+		return 1;
+	}
+	return 0;
+}