Skip to content

Commit

Permalink
Port Anticamper from zCatch
Browse files Browse the repository at this point in the history
  • Loading branch information
M0REKZ committed May 18, 2024
1 parent 092474d commit 6529470
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/engine/shared/variables_insta.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ MACRO_CONFIG_INT(SvDamageNeededForKill, sv_damage_needed_for_kill, 4, 0, 5, CFGF
MACRO_CONFIG_INT(SvAllowZoom, sv_allow_zoom, 0, 0, 1, CFGFLAG_SERVER, "allow ddnet clients to use the client side zoom feature")
MACRO_CONFIG_STR(SvSpawnWeapons, sv_spawn_weapons, 900, "grenade", CFGFLAG_SERVER, "possible values: grenade, laser")
MACRO_CONFIG_INT(SvPlasmaKills, sv_plasma_kills, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Plasma turret kills player")
MACRO_CONFIG_INT(SvAnticamper, sv_anticamper, 1, 0, 1, CFGFLAG_SERVER, "Toggle to enable/disable Anticamper")
MACRO_CONFIG_INT(SvAnticamperFreeze, sv_anticamper_freeze, 7, 0, 15, CFGFLAG_SERVER, "If a player should freeze on camping (and how long) or die")
MACRO_CONFIG_INT(SvAnticamperTime, sv_anticamper_time, 10, 5, 120, CFGFLAG_SERVER, "How long to wait till the player dies/freezes")
MACRO_CONFIG_INT(SvAnticamperRange, sv_anticamper_range, 200, 0, 1000, CFGFLAG_SERVER, "Distance how far away the player must move to escape anticamper")
/*
sv_chat_ratelimit_long_messages
Expand Down
9 changes: 9 additions & 0 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,11 @@ bool CCharacter::IncreaseArmor(int Amount)

void CCharacter::Die(int Killer, int Weapon, bool SendKillMsg)
{

//Anticamper: Reset counter on death
m_pPlayer->m_CampTick = -1;
m_pPlayer->m_SentCampMsg = false;

if(Server()->IsRecording(m_pPlayer->GetCid()))
{
CPlayerData *pData = GameServer()->Score()->PlayerData(m_pPlayer->GetCid());
Expand Down Expand Up @@ -2259,6 +2264,10 @@ bool CCharacter::Freeze(int Seconds)
m_Armor = 0;
m_FreezeTime = Seconds * Server()->TickSpeed();
m_Core.m_FreezeStart = Server()->Tick();

//Reset anticamper
m_pPlayer->m_CampTick = -1;
m_pPlayer->m_SentCampMsg = false;
return true;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions src/game/server/entities/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class CCharacter : public CEntity
useful for votes
*/
void ResetInstaSettings();
bool IsDeepFrozen() { return m_Core.m_DeepFrozen; } //Needed for Anticamper
bool m_IsGodmode;
};

Expand Down
51 changes: 51 additions & 0 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ void CPlayer::Tick()

if(m_ChatScore > 0)
m_ChatScore--;

if(g_Config.m_SvAnticamper && m_pCharacter && !GameServer()->m_World.m_Paused) //call anticamper
Anticamper();

Server()->SetClientScore(m_ClientId, m_Score);

Expand Down Expand Up @@ -989,3 +992,51 @@ void CPlayer::ProcessScoreResult(CScorePlayerResult &Result)
}
}
}

int CPlayer::Anticamper()
{

//Dont do anticamper if player is already frozen
if(m_pCharacter->m_FreezeTime > 0 || m_pCharacter->IsDeepFrozen())
return 0;

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))
{
if(g_Config.m_SvAnticamperFreeze)
{
m_pCharacter->Freeze(g_Config.m_SvAnticamperFreeze);
GameServer()->CreateSound(m_pCharacter->m_Pos, SOUND_PLAYER_PAIN_LONG);
return 2;
}
else
{
m_pCharacter->Die(m_ClientId, WEAPON_WORLD);
return 1;
}
}
return 0;
}
6 changes: 6 additions & 0 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ class CPlayer
int m_Min;
int m_Max;
} m_Latency;

//Anticamper
int Anticamper();
bool m_SentCampMsg;
int m_CampTick;
vec2 m_CampPos;

private:
const uint32_t m_UniqueClientId;
Expand Down

0 comments on commit 6529470

Please sign in to comment.