Fix classicAttackSpeed makes server lag (#4676) #4677
Merged
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.
classicAttackSpeed
algorithm is bugged and may generate infinite number of scheduler (dispatcher) events.g_scheduler.addEvent(task);
, which callsPlayer::doAttacking
again withgetAttackSpeed()
delay. So there is repeating event every 0.2 sec (with attack speed 200) and TFS still callsPlayer::doAttacking
every second creating new event.That way server can create infinite number of events for 1 player. 1 new event every second.
Often it all stops on
if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
- player cannot attack as fast as these events execute, so if there is more than 1 dispatcher event for given player, it won't re-create it after execution (addEvent
is inside that IF).But if player uses melee weapon and his target is not within 1 sqm, his attack will never execute and
lastAttack
will never update, so it will be able to re-create events, even if there is more than 1 running in same time.Fixed code limits number of scheduled
doAttacking
events to 1 per player.