From 96c430c9943b5749011565327fb722d7267c4b78 Mon Sep 17 00:00:00 2001 From: dongresource Date: Thu, 12 Oct 2023 01:44:31 +0200 Subject: [PATCH] Restore rapid-fire anti-cheat for projectiles For a while we had made the temporary rapid-fire anti-cheat optional on master, but had removed it entirely on the refactor branch. The modification on master was acidentally only applied to the regular (non-projectile) combat handler, while the removal on refactor removed both that and the projectile check. When the refactor branch was merged, that resulted in the removal of only the projectile rapid-fire check, while the conditional regular combat rapid-fire check was kept. This change restores the projectile rapid-fire check such that it is conditional, just like for regular combat. --- src/Combat.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Combat.cpp b/src/Combat.cpp index 87c10a7..37565ee 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -365,7 +365,7 @@ static std::pair getDamage(int attackPower, int defensePower, bool shou return ret; } -static bool checkRapidFire(CNSocket *sock, int targetCount) { +static bool checkRapidFire(CNSocket *sock, int targetCount, bool allowManyTargets) { Player *plr = PlayerManager::getPlayer(sock); time_t currTime = getTime(); @@ -377,7 +377,7 @@ static bool checkRapidFire(CNSocket *sock, int targetCount) { plr->lastShot = currTime; // 3+ targets should never be possible - if (targetCount > 3) + if (!allowManyTargets && targetCount > 3) plr->suspicionRating += 10001; // kill the socket when the player is too suspicious @@ -396,7 +396,7 @@ static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) { auto targets = (int32_t*)data->trailers; // kick the player if firing too rapidly - if (settings::ANTICHEAT && checkRapidFire(sock, pkt->iNPCCnt)) + if (settings::ANTICHEAT && checkRapidFire(sock, pkt->iNPCCnt, false)) return; /* @@ -837,6 +837,10 @@ static void projectileHit(CNSocket* sock, CNPacketData* data) { return; } + // kick the player if firing too rapidly + if (settings::ANTICHEAT && checkRapidFire(sock, pkt->iTargetCnt, true)) + return; + /* * initialize response struct * rocket style hit doesn't work properly, so we're always sending this one