Fix/bulletsync shot multiplication - #5116
Open
QueryOfficial wants to merge 2 commits into
Open
Conversation
A single shot could be reported many times: every copy carried the trajectory of the original, and nothing bounded how many bullet sync packets a player could send. Drop a shot that repeats the previous trajectory within 100ms - the game applies weapon spread and the muzzle moves, so a player firing normally cannot reproduce both endpoints - and run every packet through a per-player token bucket, following the pattern already used for satchel detonation and resource start acks. The bucket arithmetic lives in CTokenBucket.h so it can be covered by unit tests.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A shot fired once could be reported to the server many times, so the damage of a single
bullet stacks. Two defences are added to
CGame::Packet_Bulletsync:that player within 100 ms is dropped.
CClientGame::BulletFirecaptures the vectorsafter the game applies weapon spread, so two real shots differ well beyond
CVector'sepsilon, and no weapon fires fast enough for this window to catch a genuine pair.
sustained, 30 burst); a player who keeps exhausting it is disconnected. Same shape as
the existing throttles for satchel detonation and resource start acks.
The bucket arithmetic lives in
Shared/mods/deathmatch/logic/CTokenBucket.hso it can beunit tested.
Packet_PlayerResourceStarthas equivalent logic inline; migrating it is aseparate change I did not want to fold into this one.
Motivation
Nothing bounded how often bullet sync could be sent, and nothing recognised the same shot
arriving twice. Every copy passes weapon, ammo, trajectory and range validation, because
it is a faithful copy of a shot that really happened.
Neither check works alone: a rate ceiling high enough for fast weapons leaves slow ones
unbounded, and the trajectory check can be defeated by jittering the copies. The limits
are deliberately conservative — no player firing normally should ever be affected, at the
cost of leaving a low rate, jittered multiplier undetected. Bounding that properly needs
server side ammo accounting, since ammo is currently reported by the client in puresync.
I could not find an open issue tracking this.
Test plan
Tests/client/CTokenBucket_Tests.cpp— 10 cases run by the existingTestsworkflow,covering burst capacity, refill pacing and cap, sub-token accumulation, the drop counter
surviving partial refill and clearing on full refill, and degenerate parameters. One case
runs 5000 shots at 13/s — above the fastest bullet sync weapon — without a throttle.
Local result: 10/10 new, 338/338 total.
In game:
and sniper fire at range — no shot lost, no disconnect.
onPlayerWeaponFirestill fires once per shot and damage is unchanged.Checklist