-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PlayerPositionUpdateHandler
, PlayerHeadingUpdateHandler
: Rework t…
…o no longer broadcast immediately * Prevents a potential abuse where a client could send hundreds of forged update packets every second, flooding other clients. * Created `PlayerMovementComponent` for this purpose. The last received packet will be broadcasted from there. Called by `ClientService`. * This may also eventually give the option to reduce the broadcast rate in some areas if the game loop can't keep up. * Made `PlayerMovementComponent` check for "soft" LD (when a client stops sending position update packets) instead of the client service directly. * Fixes soft LD sometimes triggering again too soon after being canceled. * Fixes soft LD triggering during zoning, and kicking the player out if it takes more than ~65 seconds. * Removed LD chat message for soft LD so as to not confuse other players. * Various changes to the way “action” and “state” flags are handled.
- Loading branch information
Showing
20 changed files
with
1,266 additions
and
1,181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Reflection; | ||
using DOL.GS.PacketHandler.Client.v168; | ||
using log4net; | ||
|
||
namespace DOL.GS | ||
{ | ||
public class PlayerMovementComponent : MovementComponent | ||
{ | ||
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
|
||
private const int BROADCAST_MINIMUM_INTERVAL = 200; // Clients send a position or heading update packet every 200ms at most (when moving or rotating). | ||
private const int SOFT_LINK_DEATH_TRESHOLD = 5000; // How long does it take without receiving a packet for a client to enter the soft link death state. | ||
|
||
private long _lastPositionUpdatePacketReceivedTime; | ||
private long _nextPositionBroadcast; | ||
private bool _needBroadcastPosition; | ||
|
||
private long _lastHeadingUpdatePacketReceivedTime; | ||
private long _nextHeadingBroadcast; | ||
private bool _needBroadcastHeading; | ||
|
||
public new GamePlayer Owner { get; } | ||
public ref long LastPositionUpdatePacketReceivedTime => ref _lastPositionUpdatePacketReceivedTime; | ||
public ref long LastHeadingUpdatePacketReceivedTime => ref _lastHeadingUpdatePacketReceivedTime; | ||
|
||
public PlayerMovementComponent(GameLiving owner) : base(owner) | ||
{ | ||
Owner = owner as GamePlayer; | ||
} | ||
|
||
public override void Tick() | ||
{ | ||
if (!Owner.IsLinkDeathTimerRunning) | ||
{ | ||
if (ServiceUtils.ShouldTickNoEarly(_lastPositionUpdatePacketReceivedTime + SOFT_LINK_DEATH_TRESHOLD)) | ||
{ | ||
if (log.IsInfoEnabled) | ||
log.Info($"Position update timeout on client. Calling link death. ({Owner.Client})"); | ||
|
||
// The link death timer will handle the position broadcast. | ||
Owner.Client.OnLinkDeath(true); | ||
return; | ||
} | ||
|
||
// Position and heading broadcasts are mutually exclusive. | ||
if (_needBroadcastPosition && ServiceUtils.ShouldTickAdjust(ref _nextPositionBroadcast)) | ||
{ | ||
BroadcastPosition(); | ||
_nextPositionBroadcast += BROADCAST_MINIMUM_INTERVAL; | ||
_needBroadcastPosition = false; | ||
} | ||
else if (_needBroadcastHeading && ServiceUtils.ShouldTickAdjust(ref _nextHeadingBroadcast)) | ||
{ | ||
BroadcastHeading(); | ||
_nextHeadingBroadcast += BROADCAST_MINIMUM_INTERVAL; | ||
_needBroadcastHeading = false; | ||
} | ||
} | ||
|
||
base.Tick(); | ||
} | ||
|
||
public void BroadcastPosition() | ||
{ | ||
PlayerPositionUpdateHandler.BroadcastPosition(Owner.Client); | ||
} | ||
|
||
public void BroadcastHeading() | ||
{ | ||
PlayerHeadingUpdateHandler.BroadcastHeading(Owner.Client); | ||
} | ||
|
||
public void OnPositionPacketReceivedEnd() | ||
{ | ||
_needBroadcastPosition = true; | ||
_lastPositionUpdatePacketReceivedTime = GameLoop.GameLoopTime; | ||
} | ||
|
||
public void OnHeadingPacketReceived() | ||
{ | ||
_needBroadcastHeading = true; | ||
_lastHeadingUpdatePacketReceivedTime = GameLoop.GameLoopTime; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.