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:
parent
2429b00638
commit
6f444488a5
10 changed files with 113 additions and 46 deletions
|
|
@ -57,18 +57,17 @@ public static class IncomingAccountPackets
|
|||
|
||||
public static unsafe void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0x00, 104, false, &CreateCharacter);
|
||||
IncomingPackets.Register(0x5D, 73, false, &PlayCharacter);
|
||||
IncomingPackets.Register(0x80, 62, false, &AccountLogin);
|
||||
IncomingPackets.Register(0x83, 39, false, &DeleteCharacter);
|
||||
IncomingPackets.Register(0x91, 65, false, &GameLogin);
|
||||
IncomingPackets.Register(0xA0, 3, false, &PlayServer);
|
||||
IncomingPackets.Register(0xBB, 9, false, &AccountID);
|
||||
IncomingPackets.Register(0xBD, 0, false, &ClientVersion);
|
||||
IncomingPackets.Register(0xCF, 0, false, &AccountLogin);
|
||||
IncomingPackets.Register(0xE1, 0, false, &ClientType);
|
||||
IncomingPackets.Register(0xEF, 21, false, &LoginServerSeed);
|
||||
IncomingPackets.Register(0xF8, 106, false, &CreateCharacter);
|
||||
IncomingPackets.Register(0x00, &CreateCharacter, 104, outgameOnly: true);
|
||||
IncomingPackets.Register(0x5D, &PlayCharacter, 73, outgameOnly: true);
|
||||
IncomingPackets.Register(0x80, &AccountLogin, 62, outgameOnly: true);
|
||||
IncomingPackets.Register(0x83, &DeleteCharacter, 39, outgameOnly: true);
|
||||
IncomingPackets.Register(0x91, &GameLogin, 65, outgameOnly: true);
|
||||
IncomingPackets.Register(0xA0, &PlayServer, 3, outgameOnly: true);
|
||||
IncomingPackets.Register(0xBD, &ClientVersion);
|
||||
IncomingPackets.Register(0xCF, &AccountLogin, outgameOnly: true);
|
||||
IncomingPackets.Register(0xE1, &ClientType);
|
||||
IncomingPackets.Register(0xEF, &LoginServerSeed, 21, outgameOnly: true);
|
||||
IncomingPackets.Register(0xF8, &CreateCharacter, 106, outgameOnly: true);
|
||||
}
|
||||
|
||||
public static void CreateCharacter(NetState state, SpanReader reader)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.ContextMenus;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
|
@ -70,12 +71,18 @@ public static class IncomingExtendedCommandPackets
|
|||
{
|
||||
}
|
||||
|
||||
public static unsafe void RegisterExtended(int packetID, bool ingame,
|
||||
delegate*<NetState, SpanReader, void> onReceive)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void RegisterExtended(
|
||||
int packetID, bool ingame, delegate*<NetState, SpanReader, void> onReceive
|
||||
) => RegisterExtended(packetID, ingame, false, onReceive);
|
||||
|
||||
public static unsafe void RegisterExtended(
|
||||
int packetID, bool ingame, bool outgame, delegate*<NetState, SpanReader, void> onReceive
|
||||
)
|
||||
{
|
||||
if (packetID is >= 0 and < 0x100)
|
||||
{
|
||||
_extendedHandlers[packetID] = new PacketHandler(packetID, 0, ingame, onReceive);
|
||||
_extendedHandlers[packetID] = new PacketHandler(packetID, onReceive, inGameOnly: ingame, outGameOnly: outgame);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,21 +109,30 @@ public static class IncomingExtendedCommandPackets
|
|||
return;
|
||||
}
|
||||
|
||||
if (ph.Ingame && state.Mobile?.Deleted != false)
|
||||
var from = state.Mobile;
|
||||
|
||||
if (ph.InGameOnly)
|
||||
{
|
||||
if (state.Mobile == null)
|
||||
if (from == null)
|
||||
{
|
||||
state.LogInfo(
|
||||
$"Sent in-game packet (0xBFx{packetId:X2}) before having been attached to a mobile"
|
||||
);
|
||||
state.Disconnect($"Received packet 0x{packetId:X2} before having been attached to a mobile.");
|
||||
return;
|
||||
}
|
||||
|
||||
state.Disconnect($"Sent in-game packet(0xBFx{packetId:X2}) but mobile is deleted.");
|
||||
if (from.Deleted)
|
||||
{
|
||||
state.Disconnect($"Received packet 0x{packetId:X2} after having been attached to a deleted mobile.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (ph.OutOfGameOnly && from?.Deleted == false)
|
||||
{
|
||||
ph.OnReceive(state, reader);
|
||||
state.Disconnect($"Received packet 0x{packetId:X2} after having been attached to a mobile.");
|
||||
return;
|
||||
}
|
||||
|
||||
ph.OnReceive(state, reader);
|
||||
}
|
||||
|
||||
public static void ScreenSize(NetState state, SpanReader reader)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public static class IncomingItemPackets
|
|||
public static unsafe void Configure()
|
||||
{
|
||||
IncomingPackets.Register(0x07, 7, true, &LiftReq);
|
||||
IncomingPackets.Register(new ContainerGridPacketHandler(0x08, 14, true, &DropReq));
|
||||
IncomingPackets.Register(new ContainerGridPacketHandler(0x08, 14, &DropReq));
|
||||
IncomingPackets.Register(0x13, 10, true, &EquipReq);
|
||||
IncomingPackets.Register(0xEC, 0, false, &EquipMacro);
|
||||
IncomingPackets.Register(0xED, 0, false, &UnequipMacro);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue