Skip to content

Commit

Permalink
Add Anticamper from zCatch
Browse files Browse the repository at this point in the history
  • Loading branch information
M0REKZ committed Jul 22, 2024
1 parent 5e4c569 commit 76f8e10
Show file tree
Hide file tree
Showing 4 changed files with 93 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 @@ -32,6 +32,10 @@ MACRO_CONFIG_INT(SvKillingspreeKills, sv_killingspree_kills, 0, 0, 20, CFGFLAG_S
MACRO_CONFIG_INT(SvDamageNeededForKill, sv_damage_needed_for_kill, 4, 0, 5, CFGFLAG_SERVER, "Damage needed to kill")
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(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
82 changes: 82 additions & 0 deletions src/game/server/gamemodes/base_instagib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ void CGameControllerInstagib::Tick()
GameServer()->SendBroadcast(aBuf, pPlayer->GetCid());
}
}
//call anticamper
if(g_Config.m_SvAnticamper && !GameServer()->m_World.m_Paused)
Anticamper();
}

bool CGameControllerInstagib::OnCharacterTakeDamage(vec2 &Force, int &Dmg, int &From, int &Weapon, CCharacter &Character)
Expand Down Expand Up @@ -463,3 +466,82 @@ void CGameControllerInstagib::DoTeamChange(CPlayer *pPlayer, int Team, bool DoCh
}
CheckReadyStates();
}

void CGameControllerInstagib::Anticamper()
{
for(CPlayer *pPlayer : GameServer()->m_apPlayers)
{
if(!pPlayer)
continue;

CCharacter *pChr = pPlayer->GetCharacter();

//Dont do anticamper if there is no character
if(!pChr)
{
pPlayer->m_CampTick = -1;
pPlayer->m_SentCampMsg = false;
continue;
}

//Dont do anticamper if player is already frozen
if(pChr->m_FreezeTime > 0 || pChr->GetCore().m_DeepFrozen)
{
pPlayer->m_CampTick = -1;
pPlayer->m_SentCampMsg = false;
continue;
}

int AnticamperTime = g_Config.m_SvAnticamperTime;
int AnticamperRange = g_Config.m_SvAnticamperRange;

if(pPlayer->m_CampTick == -1)
{
pPlayer->m_CampPos = pChr->m_Pos;
pPlayer->m_CampTick = Server()->Tick() + Server()->TickSpeed()*AnticamperTime;
}

// Check if the player is moving
if((pPlayer->m_CampPos.x - pChr->m_Pos.x >= (float)AnticamperRange || pPlayer->m_CampPos.x - pChr->m_Pos.x <= -(float)AnticamperRange)
|| (pPlayer->m_CampPos.y - pChr->m_Pos.y >= (float)AnticamperRange || pPlayer->m_CampPos.y - pChr->m_Pos.y <= -(float)AnticamperRange))
{
pPlayer->m_CampTick = -1;
pPlayer->m_SentCampMsg = false;
}

// Send warning to the player
if(pPlayer->m_CampTick <= Server()->Tick() + Server()->TickSpeed() * 5 && pPlayer->m_CampTick != -1 && !pPlayer->m_SentCampMsg)
{
GameServer()->SendBroadcast("ANTICAMPER: Move or die", pPlayer->GetCid());
pPlayer->m_SentCampMsg = true;
}

// Kill him
if((pPlayer->m_CampTick <= Server()->Tick()) && (pPlayer->m_CampTick > 0))
{
if(g_Config.m_SvAnticamperFreeze)
{
//Freeze player
pChr->Freeze(g_Config.m_SvAnticamperFreeze);
GameServer()->CreateSound(pChr->m_Pos, SOUND_PLAYER_PAIN_LONG);

//Reset anticamper
pPlayer->m_CampTick = -1;
pPlayer->m_SentCampMsg = false;

continue;
}
else
{
//Kill Player
pChr->Die(pPlayer->GetCid(), WEAPON_WORLD);

//Reset counter on death
pPlayer->m_CampTick = -1;
pPlayer->m_SentCampMsg = false;

continue;
}
}
}
}
3 changes: 3 additions & 0 deletions src/game/server/gamemodes/base_instagib.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ class CGameControllerInstagib : public CGameControllerDDRace
// ddnet-insta only
bool OnCharacterTakeDamage(vec2 &Force, int &Dmg, int &From, int &Weapon, CCharacter &Character) override;
bool OnChatMessage(const CNetMsg_Cl_Say *pMsg, int Length, int &Team, CPlayer *pPlayer) override;

//Anticamper
void Anticamper();
};
#endif // GAME_SERVER_GAMEMODES_BASE_INSTAGIB_H
4 changes: 4 additions & 0 deletions src/game/server/gamemodes/instagib/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class CPlayer
*******************************************************************/
// Will also be set if spree chat messages are turned off
int m_Spree;
//Anticamper
bool m_SentCampMsg;
int m_CampTick;
vec2 m_CampPos;

/*
m_HasGhostCharInGame
Expand Down

0 comments on commit 76f8e10

Please sign in to comment.