fix: Fixes packet length checks (#953)
Fixes an issue with DropReq where an old client was sending in 14 bytes, but the server was expecting 15 bytes. To fix this we introduced a new packet handler, `ContainerGridPacketHandler` and changed the code to determine the length of the packet dynamically using `GetLength(NetState)`. Also fixed throttling so dropped packets are properly skipped.
This commit is contained in:
parent
1f4162288e
commit
58b907d39e
30 changed files with 1077 additions and 1126 deletions
|
|
@ -52,18 +52,18 @@ public static class IncomingPlayerPackets
|
|||
IncomingPackets.RegisterEncoded(0x32, true, QuestGumpRequest);
|
||||
}
|
||||
|
||||
public static void DeathStatusResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void DeathStatusResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
|
||||
public static void RequestScrollWindow(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void RequestScrollWindow(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
int lastTip = reader.ReadInt16();
|
||||
int type = reader.ReadByte();
|
||||
}
|
||||
|
||||
public static void AttackReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void AttackReq(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void HuePickerResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void HuePickerResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var serial = reader.ReadUInt32();
|
||||
_ = reader.ReadInt16(); // Item ID
|
||||
|
|
@ -97,7 +97,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void SystemInfo(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void SystemInfo(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
int v1 = reader.ReadByte();
|
||||
int v2 = reader.ReadUInt16();
|
||||
|
|
@ -113,7 +113,7 @@ public static class IncomingPlayerPackets
|
|||
var v8 = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public static void TextCommand(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void TextCommand(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void AsciiPromptResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void AsciiPromptResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void UnicodePromptResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void UnicodePromptResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void MenuResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void MenuResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var serial = reader.ReadUInt32();
|
||||
int menuID = reader.ReadInt16(); // unused in our implementation
|
||||
|
|
@ -311,33 +311,33 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void Disconnect(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void Disconnect(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var minusOne = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public static void ConfigurationFile(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void ConfigurationFile(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
}
|
||||
|
||||
public static void LogoutReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void LogoutReq(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
state.SendLogoutAck();
|
||||
}
|
||||
|
||||
public static void ChangeSkillLock(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void ChangeSkillLock(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var s = state.Mobile.Skills[reader.ReadInt16()];
|
||||
|
||||
s?.SetLockNoRelay((SkillLock)reader.ReadByte());
|
||||
}
|
||||
|
||||
public static void HelpRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void HelpRequest(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
EventSink.InvokeHelpRequest(state.Mobile);
|
||||
}
|
||||
|
||||
public static void DisplayGumpResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void DisplayGumpResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
var typeID = reader.ReadInt32();
|
||||
|
|
@ -479,13 +479,13 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void SetWarMode(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void SetWarMode(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
state.Mobile?.DelayChangeWarmode(reader.ReadBoolean());
|
||||
}
|
||||
|
||||
// TODO: Throttle/make this more safe
|
||||
public static void Resynchronize(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void Resynchronize(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
|
|
@ -502,17 +502,17 @@ public static class IncomingPlayerPackets
|
|||
state.Sequence = 0;
|
||||
}
|
||||
|
||||
public static void PingReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void PingReq(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
state.SendPingAck(reader.ReadByte());
|
||||
}
|
||||
|
||||
public static void SetUpdateRange(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void SetUpdateRange(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
state.SendChangeUpdateRange(18);
|
||||
}
|
||||
|
||||
public static void MobileQuery(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void MobileQuery(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
if (from == null)
|
||||
|
|
@ -549,7 +549,7 @@ public static class IncomingPlayerPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void CrashReport(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void CrashReport(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var clientMaj = reader.ReadByte();
|
||||
var clientMin = reader.ReadByte();
|
||||
|
|
@ -593,11 +593,19 @@ public static class IncomingPlayerPackets
|
|||
EventSink.InvokeQuestGumpRequest(state.Mobile);
|
||||
}
|
||||
|
||||
public static void EncodedCommand(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
public static void EncodedCommand(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var e = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
int packetId = reader.ReadUInt16();
|
||||
|
||||
// We will add support if this is ever a real thing.
|
||||
if (packetId > 0xFF)
|
||||
{
|
||||
var reason = $"Sent unsupported encoded packet (0xD7x{packetId:X4}";
|
||||
state.LogInfo(reason);
|
||||
state.Disconnect(reason);
|
||||
}
|
||||
|
||||
var ph = IncomingPackets.GetEncodedHandler(packetId);
|
||||
|
||||
if (ph == null)
|
||||
|
|
@ -608,15 +616,13 @@ public static class IncomingPlayerPackets
|
|||
|
||||
if (ph.Ingame && state.Mobile == null)
|
||||
{
|
||||
state.LogInfo(
|
||||
"Sent in-game packet (0xD7x{0:X2}) before being attached to a mobile",
|
||||
packetId
|
||||
);
|
||||
state.Disconnect($"Sent in-game packet (0xD7x{packetId:X2}) before being attached to a mobile.");
|
||||
var reason = $"Sent in-game packet (0xD7x{packetId:X4}) before being attached to a mobile.";
|
||||
state.LogInfo(reason);
|
||||
state.Disconnect(reason);
|
||||
}
|
||||
else if (ph.Ingame && state.Mobile.Deleted)
|
||||
{
|
||||
state.Disconnect($"Sent in-game packet(0xD7x{packetId:X2}) but mobile is deleted.");
|
||||
state.Disconnect($"Sent in-game packet(0xD7x{packetId:X4}) but mobile is deleted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue