fix: Fixes crashing due to bad packet assumptions. (#1829)

### Summary
- Fixes various exploits that can crash the shard when the client misbehaves.
- Clients will now be disconnected if they send packets that are marked as out of game only (new flag), while they are in-game.


> [!Note]
> **Developer Note**
> Added an `OutOfGameOnly` which should be used to flag packets as only available out of the game.
> This is the opposite of, yet not the converse to `InGameOnly`.
This commit is contained in:
Kamron Batman 2024-06-07 18:08:07 -07:00 • committed by GitHub
parent 2429b00638
commit 6f444488a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 113 additions and 46 deletions

View file

@ -46,19 +46,30 @@ namespace Server.Network
return;
}
if (ph.Ingame && state.Mobile == null)
var from = state.Mobile;
if (ph.InGameOnly)
{
state.LogInfo($"Sent in-game packet (0x{packetId:X2}x{cmd:X2}) before having been attached to a mobile");
state.Disconnect("Sent in-game packet before being attached to a mobile.");
if (from == null)
{
state.Disconnect($"Received packet 0x{packetId:X2}x{cmd:X2} before having been attached to a mobile.");
return;
}
if (from.Deleted)
{
state.Disconnect($"Received packet 0x{packetId:X2}x{cmd:X2} after having been attached to a deleted mobile.");
return;
}
}
else if (ph.Ingame && state.Mobile.Deleted)
if (ph.OutOfGameOnly && from?.Deleted == false)
{
state.Disconnect(string.Empty);
}
else
{
ph.OnReceive(state, reader);
state.Disconnect($"Received packet 0x{packetId:X2}x{cmd:X2} after having been attached to a mobile.");
return;
}
ph.OnReceive(state, reader);
}
}
}