## Summary
Server-side movement throttle that prevents speed hacking while accurately identifying cheaters with detection of lagging connections.
**Key features:**
- Credit buffer (200ms) absorbs timing jitter from legitimate players
- Movement queue handles larger bursts, draining at proper game-tick intervals
- RTT measurement distinguishes network lag from speed hacks
- Queue depth detection catches ACK-throttled speed hacks (going straight)
## How It Works
**Throttle** (prevention): Movements arriving too early either consume credit or get queued. The queue drains at
correct intervals, so speed hackers can't move faster regardless of what they send.
**Detection** (identification): Combines multiple signals to identify cheaters:
| Signal | What it catches |
|--------|-----------------|
| Queue depth ≥4 sustained | ACK-throttled speed hacks (client limits unacked moves to 5) |
| Movement rate >1.05x | Direction-change speed hacks where timing is visible |
| Stable RTT + high queue | Eliminates false positives from laggy players |
**RTT-Aware Logic:**
- Probes only sent to players actively moving (event-driven, not global loop)
- Stable low-latency + problems = suspicious
- Unstable/high-latency + problems = probably just lag, throttle handles it
## Configuration
```json
{
"movementThrottle.maxCredit": 200,
"movementThrottle.softQueueLimit": 6,
"movementThrottle.hardQueueLimit": 10,
"movementThrottle.debugLogging": false
}
```
99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
/*************************************************************************
|
|
* ModernUO *
|
|
* Copyright 2019-2026 - ModernUO Development Team *
|
|
* Email: hi@modernuo.com *
|
|
* File: IncomingMovementPackets.cs *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
*************************************************************************/
|
|
|
|
using System.Buffers;
|
|
|
|
namespace Server.Network;
|
|
|
|
public static class IncomingMovementPackets
|
|
{
|
|
public static unsafe void Configure()
|
|
{
|
|
IncomingPackets.Register(0x02, 7, true, &MovementReq);
|
|
// Not used by OSI, and interferes with ClassicUO/Razor protocol extensions
|
|
// IncomingPackets.Register(0xF0, 0, true, NewMovementReq);
|
|
// IncomingPackets.Register(0xF1, 9, true, TimeSyncReq);
|
|
}
|
|
|
|
public static void NewMovementReq(NetState ns, SpanReader reader)
|
|
{
|
|
var from = ns.Mobile;
|
|
|
|
if (from == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var steps = reader.ReadByte();
|
|
for (var i = 0; i < steps; i++)
|
|
{
|
|
var t1 = reader.ReadUInt64(); // start time?
|
|
var t2 = reader.ReadUInt64(); // end time?
|
|
int seq = reader.ReadByte();
|
|
var dir = (Direction)reader.ReadByte();
|
|
var mode = reader.ReadInt32(); // 1 = walk, 2 = run
|
|
if (mode == 2)
|
|
{
|
|
dir |= Direction.Running;
|
|
}
|
|
|
|
// Location
|
|
reader.ReadInt32(); // x
|
|
reader.ReadInt32(); // y
|
|
reader.ReadInt32(); // z
|
|
|
|
if (ns.Sequence == 0 && seq != 0 || !from.Move(dir))
|
|
{
|
|
ns.SendMovementRej(seq, from);
|
|
ns.Sequence = 0;
|
|
}
|
|
else
|
|
{
|
|
++seq;
|
|
|
|
if (seq == 256)
|
|
{
|
|
seq = 1;
|
|
}
|
|
|
|
ns.Sequence = seq;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void TimeSyncReq(NetState ns, SpanReader reader)
|
|
{
|
|
reader.ReadUInt64(); // Client Time?
|
|
|
|
ns.SendTimeSyncResponse();
|
|
}
|
|
|
|
public static void MovementReq(NetState state, SpanReader reader)
|
|
{
|
|
var from = state.Mobile;
|
|
|
|
if (from == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var dir = (Direction)reader.ReadByte();
|
|
int seq = reader.ReadByte();
|
|
var key = reader.ReadUInt32(); // FastWalkStack key - not used (not on EA servers)
|
|
|
|
// Delegate to MovementThrottle which has full context for timing validation
|
|
MovementThrottle.ValidateAndQueueMovement(state, from, dir, seq);
|
|
}
|
|
}
|