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:
Kamron Batman 2022-03-04 12:32:25 -08:00 • committed by GitHub
parent 1f4162288e
commit 58b907d39e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1077 additions and 1126 deletions

View file

@ -1,8 +1,8 @@
/************************************************************************* /*************************************************************************
* ModernUO * * ModernUO *
* Copyright 2019-2020 - ModernUO Development Team * * Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com * * Email: hi@modernuo.com *
* File: ISocket.cs * * File: ContainerGridPacketHandler.cs *
* * * *
* This program is free software: you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
@ -13,32 +13,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/ *************************************************************************/
using System; namespace Server.Network;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace Server.Network public class ContainerGridPacketHandler : PacketHandler
{ {
public interface ISocket public ContainerGridPacketHandler(int packetID, int length, bool ingame, OnPacketReceive onReceive)
: base(packetID, length, ingame, onReceive)
{ {
public IntPtr Handle { get; }
public EndPoint LocalEndPoint { get; }
public EndPoint RemoteEndPoint { get; }
public Task<int> SendAsync(IList<ArraySegment<byte>> buffer, SocketFlags flags);
public int Send(IList<ArraySegment<byte>> buffer, SocketFlags flags);
public Task<int> ReceiveAsync(IList<ArraySegment<byte>> buffer, SocketFlags flags);
public int Receive(IList<ArraySegment<byte>> buffers, SocketFlags flags);
public void Shutdown(SocketShutdown how);
public void Close();
} }
public override int GetLength(NetState ns) => base.GetLength(ns) + (ns.ContainerGridLines ? 1 : 0);
} }

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,43 @@
namespace Server.Network /*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: PacketHandler.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/>. *
*************************************************************************/
namespace Server.Network;
public delegate void OnPacketReceive(NetState state, CircularBufferReader reader, int packetLength);
public delegate bool ThrottlePacketCallback(int packetId, NetState state, out bool drop);
public class PacketHandler
{ {
public delegate void OnPacketReceive(NetState state, CircularBufferReader reader, ref int packetLength); private int _length;
public delegate bool ThrottlePacketCallback(int packetId, NetState state, out bool drop); public PacketHandler(int packetID, int length, bool ingame, OnPacketReceive onReceive)
public class PacketHandler
{ {
public PacketHandler(int packetID, int length, bool ingame, OnPacketReceive onReceive) _length = length;
{ PacketID = packetID;
PacketID = packetID; Ingame = ingame;
Length = length; OnReceive = onReceive;
Ingame = ingame;
OnReceive = onReceive;
}
public int PacketID { get; }
public int Length { get; }
public OnPacketReceive OnReceive { get; }
public ThrottlePacketCallback ThrottleCallback { get; set; }
public bool Ingame { get; }
} }
public int PacketID { get; }
public virtual int GetLength(NetState ns) => _length;
public OnPacketReceive OnReceive { get; }
public ThrottlePacketCallback ThrottleCallback { get; set; }
public bool Ingame { get; }
} }

View file

@ -55,7 +55,7 @@ public static class IncomingAccountPackets
IncomingPackets.Register(0xF8, 106, false, CreateCharacter); IncomingPackets.Register(0xF8, 106, false, CreateCharacter);
} }
public static void CreateCharacter(NetState state, CircularBufferReader reader, ref int packetLength) public static void CreateCharacter(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.Seek(9, SeekOrigin.Current); reader.Seek(9, SeekOrigin.Current);
/* /*
@ -185,7 +185,7 @@ public static class IncomingAccountPackets
} }
} }
public static void DeleteCharacter(NetState state, CircularBufferReader reader, ref int packetLength) public static void DeleteCharacter(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.Seek(30, SeekOrigin.Current); reader.Seek(30, SeekOrigin.Current);
var index = reader.ReadInt32(); var index = reader.ReadInt32();
@ -193,24 +193,24 @@ public static class IncomingAccountPackets
EventSink.InvokeDeleteRequest(state, index); EventSink.InvokeDeleteRequest(state, index);
} }
public static void AccountID(NetState state, CircularBufferReader reader, ref int packetLength) public static void AccountID(NetState state, CircularBufferReader reader, int packetLength)
{ {
} }
public static void AssistVersion(NetState state, CircularBufferReader reader, ref int packetLength) public static void AssistVersion(NetState state, CircularBufferReader reader, int packetLength)
{ {
var unk = reader.ReadInt32(); var unk = reader.ReadInt32();
var av = reader.ReadAscii(); var av = reader.ReadAscii();
} }
public static void ClientVersion(NetState state, CircularBufferReader reader, ref int packetLength) public static void ClientVersion(NetState state, CircularBufferReader reader, int packetLength)
{ {
var version = state.Version = new CV(reader.ReadAscii()); var version = state.Version = new CV(reader.ReadAscii());
EventSink.InvokeClientVersionReceived(state, version); EventSink.InvokeClientVersionReceived(state, version);
} }
public static void ClientType(NetState state, CircularBufferReader reader, ref int packetLength) public static void ClientType(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.ReadUInt16(); reader.ReadUInt16();
@ -220,7 +220,7 @@ public static class IncomingAccountPackets
EventSink.InvokeClientVersionReceived(state, version); EventSink.InvokeClientVersionReceived(state, version);
} }
public static void PlayCharacter(NetState state, CircularBufferReader reader, ref int packetLength) public static void PlayCharacter(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.Seek(4, SeekOrigin.Current); // 0xEDEDEDED reader.Seek(4, SeekOrigin.Current); // 0xEDEDEDED
@ -359,7 +359,7 @@ public static class IncomingAccountPackets
return authID; return authID;
} }
public static void GameLogin(NetState state, CircularBufferReader reader, ref int packetLength) public static void GameLogin(NetState state, CircularBufferReader reader, int packetLength)
{ {
// TODO: Connection throttling // TODO: Connection throttling
@ -413,7 +413,7 @@ public static class IncomingAccountPackets
} }
} }
public static void PlayServer(NetState state, CircularBufferReader reader, ref int packetLength) public static void PlayServer(NetState state, CircularBufferReader reader, int packetLength)
{ {
int index = reader.ReadInt16(); int index = reader.ReadInt16();
var info = state.ServerInfo; var info = state.ServerInfo;
@ -434,7 +434,7 @@ public static class IncomingAccountPackets
} }
} }
public static void LoginServerSeed(NetState state, CircularBufferReader reader, ref int packetLength) public static void LoginServerSeed(NetState state, CircularBufferReader reader, int packetLength)
{ {
state._seed = reader.ReadInt32(); state._seed = reader.ReadInt32();
state.Seeded = true; state.Seeded = true;
@ -454,7 +454,7 @@ public static class IncomingAccountPackets
state.Version = new ClientVersion(clientMaj, clientMin, clientRev, clientPat); state.Version = new ClientVersion(clientMaj, clientMin, clientRev, clientPat);
} }
public static void AccountLogin(NetState state, CircularBufferReader reader, ref int packetLength) public static void AccountLogin(NetState state, CircularBufferReader reader, int packetLength)
{ {
// TODO: Throttle Connection // TODO: Throttle Connection

View file

@ -27,7 +27,7 @@ public static class IncomingEntityPackets
IncomingPackets.Register(0xD6, 0, true, BatchQueryProperties); IncomingPackets.Register(0xD6, 0, true, BatchQueryProperties);
} }
public static void ObjectHelpRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void ObjectHelpRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -56,7 +56,7 @@ public static class IncomingEntityPackets
} }
} }
public static void UseReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void UseReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -100,7 +100,7 @@ public static class IncomingEntityPackets
} }
} }
public static void LookReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void LookReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -149,7 +149,7 @@ public static class IncomingEntityPackets
} }
} }
public static void BatchQueryProperties(NetState state, CircularBufferReader reader, ref int packetLength) public static void BatchQueryProperties(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (!ObjectPropertyList.Enabled) if (!ObjectPropertyList.Enabled)
{ {

View file

@ -1,6 +1,6 @@
/************************************************************************* /*************************************************************************
* ModernUO * * ModernUO *
* Copyright 2019-2020 - ModernUO Development Team * * Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com * * Email: hi@modernuo.com *
* File: IncomingExtendedCommandPackets.cs * * File: IncomingExtendedCommandPackets.cs *
* * * *
@ -13,15 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/ *************************************************************************/
using System.Collections.Generic;
using Server.ContextMenus; using Server.ContextMenus;
namespace Server.Network; namespace Server.Network;
public static class IncomingExtendedCommandPackets public static class IncomingExtendedCommandPackets
{ {
private static readonly PacketHandler[] m_ExtendedHandlersLow = new PacketHandler[0x100]; private static readonly PacketHandler[] _extendedHandlers = new PacketHandler[0x100];
private static readonly Dictionary<int, PacketHandler> m_ExtendedHandlersHigh = new();
// TODO: Change to outside configuration // TODO: Change to outside configuration
public static int[] ValidAnimations { get; set; } = public static int[] ValidAnimations { get; set; } =
@ -61,50 +59,34 @@ public static class IncomingExtendedCommandPackets
RegisterExtended(0x32, true, ToggleFlying); RegisterExtended(0x32, true, ToggleFlying);
} }
private static void UnhandledBF(NetState state, CircularBufferReader reader, ref int packetLength) private static void UnhandledBF(NetState state, CircularBufferReader reader, int packetLength)
{ {
} }
public static void Empty(NetState state, CircularBufferReader reader, ref int packetLength) public static void Empty(NetState state, CircularBufferReader reader, int packetLength)
{ {
} }
public static void RegisterExtended(int packetID, bool ingame, OnPacketReceive onReceive) public static void RegisterExtended(int packetID, bool ingame, OnPacketReceive onReceive)
{ {
if (packetID >= 0 && packetID < 0x100) if (packetID is >= 0 and < 0x100)
{ {
m_ExtendedHandlersLow[packetID] = new PacketHandler(packetID, 0, ingame, onReceive); _extendedHandlers[packetID] = new PacketHandler(packetID, 0, ingame, onReceive);
}
else
{
m_ExtendedHandlersHigh[packetID] = new PacketHandler(packetID, 0, ingame, onReceive);
} }
} }
public static PacketHandler GetExtendedHandler(int packetID) public static PacketHandler GetExtendedHandler(int packetID) =>
{ packetID is >= 0 and < 0x100 ? _extendedHandlers[packetID] : null;
if (packetID >= 0 && packetID < 0x100)
{
return m_ExtendedHandlersLow[packetID];
}
m_ExtendedHandlersHigh.TryGetValue(packetID, out var handler);
return handler;
}
public static void RemoveExtendedHandler(int packetID) public static void RemoveExtendedHandler(int packetID)
{ {
if (packetID >= 0 && packetID < 0x100) if (packetID is >= 0 and < 0x100)
{ {
m_ExtendedHandlersLow[packetID] = null; _extendedHandlers[packetID] = null;
}
else
{
m_ExtendedHandlersHigh.Remove(packetID);
} }
} }
public static void ExtendedCommand(NetState state, CircularBufferReader reader, ref int packetLength) public static void ExtendedCommand(NetState state, CircularBufferReader reader, int packetLength)
{ {
int packetId = reader.ReadUInt16(); int packetId = reader.ReadUInt16();
@ -130,18 +112,18 @@ public static class IncomingExtendedCommandPackets
} }
else else
{ {
ph.OnReceive(state, reader, ref packetLength); ph.OnReceive(state, reader, packetLength);
} }
} }
public static void ScreenSize(NetState state, CircularBufferReader reader, ref int packetLength) public static void ScreenSize(NetState state, CircularBufferReader reader, int packetLength)
{ {
var width = reader.ReadInt32(); var width = reader.ReadInt32();
var unk = reader.ReadInt32(); var unk = reader.ReadInt32();
} }
// TODO: Move out of the core // TODO: Move out of the core
public static void PartyMessage(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (state.Mobile == null) if (state.Mobile == null)
{ {
@ -151,25 +133,25 @@ public static class IncomingExtendedCommandPackets
switch (reader.ReadByte()) switch (reader.ReadByte())
{ {
case 0x01: case 0x01:
PartyMessage_AddMember(state, reader, ref packetLength); PartyMessage_AddMember(state, reader, packetLength);
break; break;
case 0x02: case 0x02:
PartyMessage_RemoveMember(state, reader, ref packetLength); PartyMessage_RemoveMember(state, reader, packetLength);
break; break;
case 0x03: case 0x03:
PartyMessage_PrivateMessage(state, reader, ref packetLength); PartyMessage_PrivateMessage(state, reader, packetLength);
break; break;
case 0x04: case 0x04:
PartyMessage_PublicMessage(state, reader, ref packetLength); PartyMessage_PublicMessage(state, reader, packetLength);
break; break;
case 0x06: case 0x06:
PartyMessage_SetCanLoot(state, reader, ref packetLength); PartyMessage_SetCanLoot(state, reader, packetLength);
break; break;
case 0x08: case 0x08:
PartyMessage_Accept(state, reader, ref packetLength); PartyMessage_Accept(state, reader, packetLength);
break; break;
case 0x09: case 0x09:
PartyMessage_Decline(state, reader, ref packetLength); PartyMessage_Decline(state, reader, packetLength);
break; break;
default: default:
reader.Trace(state); reader.Trace(state);
@ -177,17 +159,17 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void PartyMessage_AddMember(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_AddMember(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnAdd(state.Mobile); PartyCommands.Handler?.OnAdd(state.Mobile);
} }
public static void PartyMessage_RemoveMember(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_RemoveMember(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32())); PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
} }
public static void PartyMessage_PrivateMessage(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_PrivateMessage(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnPrivateMessage( PartyCommands.Handler?.OnPrivateMessage(
state.Mobile, state.Mobile,
@ -196,27 +178,27 @@ public static class IncomingExtendedCommandPackets
); );
} }
public static void PartyMessage_PublicMessage(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_PublicMessage(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnPublicMessage(state.Mobile, reader.ReadBigUniSafe()); PartyCommands.Handler?.OnPublicMessage(state.Mobile, reader.ReadBigUniSafe());
} }
public static void PartyMessage_SetCanLoot(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_SetCanLoot(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnSetCanLoot(state.Mobile, reader.ReadBoolean()); PartyCommands.Handler?.OnSetCanLoot(state.Mobile, reader.ReadBoolean());
} }
public static void PartyMessage_Accept(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_Accept(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32())); PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
} }
public static void PartyMessage_Decline(NetState state, CircularBufferReader reader, ref int packetLength) public static void PartyMessage_Decline(NetState state, CircularBufferReader reader, int packetLength)
{ {
PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32())); PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
} }
public static void Animate(NetState state, CircularBufferReader reader, ref int packetLength) public static void Animate(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -240,7 +222,7 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void CastSpell(NetState state, CircularBufferReader reader, ref int packetLength) public static void CastSpell(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -255,12 +237,12 @@ public static class IncomingExtendedCommandPackets
EventSink.InvokeCastSpellRequest(from, spellID, spellbook); EventSink.InvokeCastSpellRequest(from, spellID, spellbook);
} }
public static void ToggleFlying(NetState state, CircularBufferReader reader, ref int packetLength) public static void ToggleFlying(NetState state, CircularBufferReader reader, int packetLength)
{ {
state.Mobile?.ToggleFlying(); state.Mobile?.ToggleFlying();
} }
public static void StunRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void StunRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -272,7 +254,7 @@ public static class IncomingExtendedCommandPackets
EventSink.InvokeStunRequest(from); EventSink.InvokeStunRequest(from);
} }
public static void DisarmRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void DisarmRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -284,7 +266,7 @@ public static class IncomingExtendedCommandPackets
EventSink.InvokeDisarmRequest(from); EventSink.InvokeDisarmRequest(from);
} }
public static void StatLockChange(NetState state, CircularBufferReader reader, ref int packetLength) public static void StatLockChange(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -315,12 +297,12 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void CloseStatus(NetState state, CircularBufferReader reader, ref int packetLength) public static void CloseStatus(NetState state, CircularBufferReader reader, int packetLength)
{ {
var serial = (Serial)reader.ReadUInt32(); var serial = (Serial)reader.ReadUInt32();
} }
public static void Language(NetState state, CircularBufferReader reader, ref int packetLength) public static void Language(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -332,7 +314,7 @@ public static class IncomingExtendedCommandPackets
from.Language = reader.ReadAscii(4); from.Language = reader.ReadAscii(4);
} }
public static void QueryProperties(NetState state, CircularBufferReader reader, ref int packetLength) public static void QueryProperties(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (!ObjectPropertyList.Enabled) if (!ObjectPropertyList.Enabled)
{ {
@ -364,7 +346,7 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void ContextMenuResponse(NetState state, CircularBufferReader reader, ref int packetLength) public static void ContextMenuResponse(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -420,7 +402,7 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void ContextMenuRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void ContextMenuRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
var target = World.FindEntity((Serial)reader.ReadUInt32()); var target = World.FindEntity((Serial)reader.ReadUInt32());
@ -455,7 +437,7 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void BandageTarget(NetState state, CircularBufferReader reader, ref int packetLength) public static void BandageTarget(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -490,21 +472,21 @@ public static class IncomingExtendedCommandPackets
} }
} }
public static void TargetedSpell(NetState state, CircularBufferReader reader, ref int packetLength) public static void TargetedSpell(NetState state, CircularBufferReader reader, int packetLength)
{ {
var spellId = (short)(reader.ReadInt16() - 1); // zero based; var spellId = (short)(reader.ReadInt16() - 1); // zero based;
EventSink.InvokeTargetedSpell(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), spellId); EventSink.InvokeTargetedSpell(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), spellId);
} }
public static void TargetedSkillUse(NetState state, CircularBufferReader reader, ref int packetLength) public static void TargetedSkillUse(NetState state, CircularBufferReader reader, int packetLength)
{ {
var skillId = reader.ReadInt16(); var skillId = reader.ReadInt16();
EventSink.InvokeTargetedSkillUse(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), skillId); EventSink.InvokeTargetedSkillUse(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), skillId);
} }
public static void TargetByResourceMacro(NetState state, CircularBufferReader reader, ref int packetLength) public static void TargetByResourceMacro(NetState state, CircularBufferReader reader, int packetLength)
{ {
var serial = (Serial)reader.ReadUInt32(); var serial = (Serial)reader.ReadUInt32();

View file

@ -22,7 +22,7 @@ public static class IncomingHousePackets
IncomingPackets.Register(0xFB, 2, false, ShowPublicHouseContent); IncomingPackets.Register(0xFB, 2, false, ShowPublicHouseContent);
} }
public static void ShowPublicHouseContent(NetState state, CircularBufferReader reader, ref int packetLength) public static void ShowPublicHouseContent(NetState state, CircularBufferReader reader, int packetLength)
{ {
var showPublicHouseContent = reader.ReadBoolean(); var showPublicHouseContent = reader.ReadBoolean();
} }

View file

@ -24,13 +24,13 @@ public static class IncomingItemPackets
public static void Configure() public static void Configure()
{ {
IncomingPackets.Register(0x07, 7, true, LiftReq); IncomingPackets.Register(0x07, 7, true, LiftReq);
IncomingPackets.Register(0x08, 15, true, DropReq); IncomingPackets.Register(new ContainerGridPacketHandler(0x08, 14, true, DropReq));
IncomingPackets.Register(0x13, 10, true, EquipReq); IncomingPackets.Register(0x13, 10, true, EquipReq);
IncomingPackets.Register(0xEC, 0, false, EquipMacro); IncomingPackets.Register(0xEC, 0, false, EquipMacro);
IncomingPackets.Register(0xED, 0, false, UnequipMacro); IncomingPackets.Register(0xED, 0, false, UnequipMacro);
} }
public static void LiftReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void LiftReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
var serial = (Serial)reader.ReadUInt32(); var serial = (Serial)reader.ReadUInt32();
int amount = reader.ReadUInt16(); int amount = reader.ReadUInt16();
@ -39,7 +39,7 @@ public static class IncomingItemPackets
state.Mobile.Lift(item, amount, out _, out _); state.Mobile.Lift(item, amount, out _, out _);
} }
public static void EquipReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void EquipReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
var item = from.Holding; var item = from.Holding;
@ -64,20 +64,17 @@ public static class IncomingItemPackets
item.ClearBounce(); item.ClearBounce();
} }
public static void DropReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void DropReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.ReadInt32(); // serial, ignored reader.ReadInt32(); // serial, ignored
int x = reader.ReadInt16(); int x = reader.ReadInt16();
int y = reader.ReadInt16(); int y = reader.ReadInt16();
int z = reader.ReadSByte(); int z = reader.ReadSByte();
if (state.ContainerGridLines) if (state.ContainerGridLines)
{ {
reader.ReadByte(); // Grid Location? reader.ReadByte(); // Grid Location?
} }
else
{
packetLength -= 1;
}
Serial dest = (Serial)reader.ReadUInt32(); Serial dest = (Serial)reader.ReadUInt32();
@ -110,7 +107,7 @@ public static class IncomingItemPackets
} }
} }
public static void DropReq6017(NetState state, CircularBufferReader reader, ref int packetLength) public static void DropReq6017(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.ReadInt32(); // serial, ignored reader.ReadInt32(); // serial, ignored
int x = reader.ReadInt16(); int x = reader.ReadInt16();
@ -148,7 +145,7 @@ public static class IncomingItemPackets
} }
} }
public static void EquipMacro(NetState state, CircularBufferReader reader, ref int packetLength) public static void EquipMacro(NetState state, CircularBufferReader reader, int packetLength)
{ {
int count = reader.ReadByte(); int count = reader.ReadByte();
var serialList = new List<Serial>(count); var serialList = new List<Serial>(count);
@ -160,7 +157,7 @@ public static class IncomingItemPackets
EventSink.InvokeEquipMacro(state.Mobile, serialList); EventSink.InvokeEquipMacro(state.Mobile, serialList);
} }
public static void UnequipMacro(NetState state, CircularBufferReader reader, ref int packetLength) public static void UnequipMacro(NetState state, CircularBufferReader reader, int packetLength)
{ {
int count = reader.ReadByte(); int count = reader.ReadByte();
var layers = new List<Layer>(count); var layers = new List<Layer>(count);

View file

@ -46,7 +46,7 @@ public static class IncomingMessagePackets
IncomingPackets.Register(0xAD, 0, true, UnicodeSpeech); IncomingPackets.Register(0xAD, 0, true, UnicodeSpeech);
} }
public static void AsciiSpeech(NetState state, CircularBufferReader reader, ref int packetLength) public static void AsciiSpeech(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -73,7 +73,7 @@ public static class IncomingMessagePackets
from.DoSpeech(text, Array.Empty<int>(), type, Utility.ClipDyedHue(hue)); from.DoSpeech(text, Array.Empty<int>(), type, Utility.ClipDyedHue(hue));
} }
public static void UnicodeSpeech(NetState state, CircularBufferReader reader, ref int packetLength) public static void UnicodeSpeech(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -27,7 +27,7 @@ public static class IncomingMobilePackets
IncomingPackets.Register(0x6F, 0, true, SecureTrade); IncomingPackets.Register(0x6F, 0, true, SecureTrade);
} }
public static void RenameRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void RenameRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
var targ = World.FindMobile((Serial)reader.ReadUInt32()); var targ = World.FindMobile((Serial)reader.ReadUInt32());
@ -38,7 +38,7 @@ public static class IncomingMobilePackets
} }
} }
public static void MobileNameRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void MobileNameRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var m = World.FindMobile((Serial)reader.ReadUInt32()); var m = World.FindMobile((Serial)reader.ReadUInt32());
@ -48,7 +48,7 @@ public static class IncomingMobilePackets
} }
} }
public static void ProfileReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void ProfileReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
int type = reader.ReadByte(); int type = reader.ReadByte();
var serial = (Serial)reader.ReadUInt32(); var serial = (Serial)reader.ReadUInt32();
@ -88,7 +88,7 @@ public static class IncomingMobilePackets
} }
} }
public static void SecureTrade(NetState state, CircularBufferReader reader, ref int packetLength) public static void SecureTrade(NetState state, CircularBufferReader reader, int packetLength)
{ {
switch (reader.ReadByte()) switch (reader.ReadByte())
{ {

View file

@ -78,7 +78,7 @@ public static class IncomingMovementPackets
ns.SendTimeSyncResponse(); ns.SendTimeSyncResponse();
} }
public static void MovementReq(NetState state, CircularBufferReader reader, ref int packetLength) public static void MovementReq(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -1,6 +1,6 @@
/************************************************************************* /*************************************************************************
* ModernUO * * ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team * * Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com * * Email: hi@modernuo.com *
* File: IncomingPackets.cs * * File: IncomingPackets.cs *
* * * *
@ -13,62 +13,43 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/ *************************************************************************/
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Server.Network; namespace Server.Network;
public static class IncomingPackets public static class IncomingPackets
{ {
private static readonly PacketHandler[] m_6017Handlers = new PacketHandler[0x100]; private static readonly EncodedPacketHandler[] _encodedHandlers = new EncodedPacketHandler[0x100];
private static readonly EncodedPacketHandler[] m_EncodedHandlersLow = new EncodedPacketHandler[0x100];
private static readonly Dictionary<int, EncodedPacketHandler> m_EncodedHandlersHigh =
new();
public static PacketHandler[] Handlers { get; } = new PacketHandler[0x100]; public static PacketHandler[] Handlers { get; } = new PacketHandler[0x100];
public static void Register(int packetID, int length, bool ingame, OnPacketReceive onReceive) [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Register(int packetID, int length, bool ingame, OnPacketReceive onReceive) =>
Register(new PacketHandler(packetID, length, ingame, onReceive));
public static void Register(PacketHandler packetHandler)
{ {
Handlers[packetID] = new PacketHandler(packetID, length, ingame, onReceive); Handlers[packetHandler.PacketID] = packetHandler;
m_6017Handlers[packetID] ??= new PacketHandler(packetID, length, ingame, onReceive);
} }
public static PacketHandler GetHandler(int packetID) => Handlers[packetID]; public static PacketHandler GetHandler(int packetID) => Handlers[packetID];
public static void RegisterEncoded(int packetID, bool ingame, OnEncodedPacketReceive onReceive) public static void RegisterEncoded(int packetID, bool ingame, OnEncodedPacketReceive onReceive)
{ {
if (packetID >= 0 && packetID < 0x100) if (packetID is >= 0 and < 0x100)
{ {
m_EncodedHandlersLow[packetID] = new EncodedPacketHandler(packetID, ingame, onReceive); _encodedHandlers[packetID] = new EncodedPacketHandler(packetID, ingame, onReceive);
}
else
{
m_EncodedHandlersHigh[packetID] = new EncodedPacketHandler(packetID, ingame, onReceive);
} }
} }
public static EncodedPacketHandler GetEncodedHandler(int packetID) public static EncodedPacketHandler GetEncodedHandler(int packetID) =>
{ packetID is >= 0 and < 0x100 ? _encodedHandlers[packetID] : null;
if (packetID >= 0 && packetID < 0x100)
{
return m_EncodedHandlersLow[packetID];
}
m_EncodedHandlersHigh.TryGetValue(packetID, out var handler);
return handler;
}
public static void RemoveEncodedHandler(int packetID) public static void RemoveEncodedHandler(int packetID)
{ {
if (packetID >= 0 && packetID < 0x100) if (packetID is >= 0 and < 0x100)
{ {
m_EncodedHandlersLow[packetID] = null; _encodedHandlers[packetID] = null;
}
else
{
m_EncodedHandlersHigh.Remove(packetID);
} }
} }

View file

@ -52,18 +52,18 @@ public static class IncomingPlayerPackets
IncomingPackets.RegisterEncoded(0x32, true, QuestGumpRequest); 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 // 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 lastTip = reader.ReadInt16();
int type = reader.ReadByte(); 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; 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(); var serial = reader.ReadUInt32();
_ = reader.ReadInt16(); // Item ID _ = 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 v1 = reader.ReadByte();
int v2 = reader.ReadUInt16(); int v2 = reader.ReadUInt16();
@ -113,7 +113,7 @@ public static class IncomingPlayerPackets
var v8 = reader.ReadInt32(); 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; 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; 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; 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(); var serial = reader.ReadUInt32();
int menuID = reader.ReadInt16(); // unused in our implementation 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(); 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(); 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()]; var s = state.Mobile.Skills[reader.ReadInt16()];
s?.SetLockNoRelay((SkillLock)reader.ReadByte()); 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); 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 serial = (Serial)reader.ReadUInt32();
var typeID = reader.ReadInt32(); 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()); state.Mobile?.DelayChangeWarmode(reader.ReadBoolean());
} }
// TODO: Throttle/make this more safe // 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; var from = state.Mobile;
@ -502,17 +502,17 @@ public static class IncomingPlayerPackets
state.Sequence = 0; 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()); 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); 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; var from = state.Mobile;
if (from == null) 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 clientMaj = reader.ReadByte();
var clientMin = reader.ReadByte(); var clientMin = reader.ReadByte();
@ -593,11 +593,19 @@ public static class IncomingPlayerPackets
EventSink.InvokeQuestGumpRequest(state.Mobile); 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()); var e = World.FindEntity((Serial)reader.ReadUInt32());
int packetId = reader.ReadUInt16(); 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); var ph = IncomingPackets.GetEncodedHandler(packetId);
if (ph == null) if (ph == null)
@ -608,15 +616,13 @@ public static class IncomingPlayerPackets
if (ph.Ingame && state.Mobile == null) if (ph.Ingame && state.Mobile == null)
{ {
state.LogInfo( var reason = $"Sent in-game packet (0xD7x{packetId:X4}) before being attached to a mobile.";
"Sent in-game packet (0xD7x{0:X2}) before being attached to a mobile", state.LogInfo(reason);
packetId state.Disconnect(reason);
);
state.Disconnect($"Sent in-game packet (0xD7x{packetId:X2}) before being attached to a mobile.");
} }
else if (ph.Ingame && state.Mobile.Deleted) 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 else
{ {

View file

@ -25,7 +25,7 @@ public static class IncomingTargetingPackets
IncomingPackets.Register(0x6C, 19, true, TargetResponse); IncomingPackets.Register(0x6C, 19, true, TargetResponse);
} }
public static void TargetResponse(NetState state, CircularBufferReader reader, ref int packetLength) public static void TargetResponse(NetState state, CircularBufferReader reader, int packetLength)
{ {
int type = reader.ReadByte(); int type = reader.ReadByte();
var targetID = reader.ReadInt32(); var targetID = reader.ReadInt32();

View file

@ -14,6 +14,7 @@
*************************************************************************/ *************************************************************************/
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
namespace Server.Network; namespace Server.Network;
@ -25,7 +26,7 @@ public static class IncomingVendorPackets
IncomingPackets.Register(0x9F, 0, true, VendorSellReply); IncomingPackets.Register(0x9F, 0, true, VendorSellReply);
} }
public static void VendorBuyReply(NetState state, CircularBufferReader reader, ref int packetLength) public static void VendorBuyReply(NetState state, CircularBufferReader reader, int packetLength)
{ {
var vendor = World.FindMobile((Serial)reader.ReadUInt32()); var vendor = World.FindMobile((Serial)reader.ReadUInt32());
@ -65,7 +66,7 @@ public static class IncomingVendorPackets
state.SendEndVendorBuy(vendor.Serial); state.SendEndVendorBuy(vendor.Serial);
} }
public static void VendorSellReply(NetState state, CircularBufferReader reader, ref int packetLength) public static void VendorSellReply(NetState state, CircularBufferReader reader, int packetLength)
{ {
var serial = (Serial)reader.ReadUInt32(); var serial = (Serial)reader.ReadUInt32();
var vendor = World.FindMobile(serial); var vendor = World.FindMobile(serial);

View file

@ -27,7 +27,7 @@ namespace Server.Engines.Chat
IncomingPackets.Register(0xB3, 0, true, ChatAction); IncomingPackets.Register(0xB3, 0, true, ChatAction);
} }
public static void OpenChatWindowRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void OpenChatWindowRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -48,7 +48,7 @@ namespace Server.Engines.Chat
ChatUser.AddChatUser(from, chatName); ChatUser.AddChatUser(from, chatName);
} }
public static void ChatAction(NetState state, CircularBufferReader reader, ref int packetLength) public static void ChatAction(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (!ChatSystem.Enabled) if (!ChatSystem.Enabled)
{ {

View file

@ -193,7 +193,7 @@ namespace Server.Engines.MLQuests.Gumps
return false; return false;
} }
private static void RaceChangeReply(NetState state, CircularBufferReader reader, ref int packetLength) private static void RaceChangeReply(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (!m_Pending.TryGetValue(state, out var raceChangeState)) if (!m_Pending.TryGetValue(state, out var raceChangeState))
{ {

View file

@ -9,7 +9,7 @@ namespace Server.Engines.UltimaStore
IncomingPackets.Register(0xFA, 1, true, UltimaStoreOpenRequest); IncomingPackets.Register(0xFA, 1, true, UltimaStoreOpenRequest);
} }
public static void UltimaStoreOpenRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void UltimaStoreOpenRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
state.Mobile.SendMessage("Ultima Store is not currently available."); state.Mobile.SendMessage("Ultima Store is not currently available.");
} }

View file

@ -29,7 +29,7 @@ namespace Server.Items
IncomingPackets.Register(0x93, 99, true, OldHeaderChange); IncomingPackets.Register(0x93, 99, true, OldHeaderChange);
} }
public static void OldHeaderChange(NetState state, CircularBufferReader reader, ref int packetLength) public static void OldHeaderChange(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -48,7 +48,7 @@ namespace Server.Items
book.Author = Utility.FixHtml(author); book.Author = Utility.FixHtml(author);
} }
public static void HeaderChange(NetState state, CircularBufferReader reader, ref int packetLength) public static void HeaderChange(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;
@ -84,7 +84,7 @@ namespace Server.Items
book.Author = Utility.FixHtml(author); book.Author = Utility.FixHtml(author);
} }
public static void ContentChange(NetState state, CircularBufferReader reader, ref int packetLength) public static void ContentChange(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -48,7 +48,7 @@ namespace Server.Network
return $"{seconds} second{(seconds == 1 ? "" : "s")}"; return $"{seconds} second{(seconds == 1 ? "" : "s")}";
} }
public static void BBClientRequest(NetState state, CircularBufferReader reader, ref int packetLength) public static void BBClientRequest(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -61,7 +61,7 @@ namespace Server.Engines.Mahjong
RegisterSubCommand(0x18, MoveDealerIndicator); RegisterSubCommand(0x18, MoveDealerIndicator);
} }
public static void OnPacket(NetState state, CircularBufferReader reader, ref int packetLength) public static void OnPacket(NetState state, CircularBufferReader reader, int packetLength)
{ {
var game = World.FindItem((Serial)reader.ReadUInt32()) as MahjongGame; var game = World.FindItem((Serial)reader.ReadUInt32()) as MahjongGame;

View file

@ -25,7 +25,7 @@ namespace Server.Network
IncomingPackets.Register(0x56, 11, true, OnMapCommand); IncomingPackets.Register(0x56, 11, true, OnMapCommand);
} }
private static void OnMapCommand(NetState state, CircularBufferReader reader, ref int packetLength) private static void OnMapCommand(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -141,7 +141,7 @@ namespace Server
} }
} }
public static void OnReceive(NetState state, CircularBufferReader reader, ref int packetLength) public static void OnReceive(NetState state, CircularBufferReader reader, int packetLength)
{ {
reader.ReadByte(); // 1: <4.0.1a, 2>=4.0.1a reader.ReadByte(); // 1: <4.0.1a, 2>=4.0.1a

View file

@ -38,8 +38,8 @@ namespace Server.Network
} }
else else
{ {
Delays[0x03] = 5; // Speech Delays[0x03] = 25; // Speech
Delays[0xAD] = 5; // Speech Delays[0xAD] = 25; // Speech
Delays[0x75] = 500; // Rename request Delays[0x75] = 500; // Rename request
} }
@ -141,7 +141,7 @@ namespace Server.Network
return true; return true;
} }
if (Core.TickCount < ns.GetPacketDelay(packetID) + Delays[packetID]) if (Core.TickCount < ns.GetPacketTime(packetID) + Delays[packetID])
{ {
drop = true; drop = true;
return false; return false;

View file

@ -1766,7 +1766,7 @@ namespace Server.Multis
context.Foundation.SendInfoTo(state); context.Foundation.SendInfoTo(state);
} }
public static void QueryDesignDetails(NetState state, CircularBufferReader reader, ref int packetLength) public static void QueryDesignDetails(NetState state, CircularBufferReader reader, int packetLength)
{ {
var from = state.Mobile; var from = state.Mobile;

View file

@ -70,7 +70,7 @@ namespace Server.Network
} }
} }
public static void PollInfo(NetState ns, CircularBufferReader reader, ref int packetLength) public static void PollInfo(NetState state, CircularBufferReader reader, int packetLength)
{ {
var version = reader.ReadByte(); var version = reader.ReadByte();
@ -83,21 +83,21 @@ namespace Server.Network
if (!span.SequenceEqual(_token)) if (!span.SequenceEqual(_token))
{ {
ns.Disconnect("Invalid token sent for ConnectUO"); state.Disconnect("Invalid token sent for ConnectUO");
return; return;
} }
} }
} }
ns.LogInfo($"ConnectUO (v{version}) is requesting stats."); state.LogInfo($"ConnectUO (v{version}) is requesting stats.");
if (version > ConnectUOProtocolVersion) if (version > ConnectUOProtocolVersion)
{ {
Utility.PushColor(ConsoleColor.Yellow); Utility.PushColor(ConsoleColor.Yellow);
ns.LogInfo("Warning! ConnectUO (v{version}) is newer than what is supported."); state.LogInfo("Warning! ConnectUO (v{version}) is newer than what is supported.");
Utility.PopColor(); Utility.PopColor();
} }
ns.SendServerPollInfo(); state.SendServerPollInfo();
} }
public static void SendServerPollInfo(this NetState ns) public static void SendServerPollInfo(this NetState ns)

View file

@ -36,14 +36,14 @@ namespace Server.Network
public static void Register(int cmd, bool ingame, OnPacketReceive onReceive) => public static void Register(int cmd, bool ingame, OnPacketReceive onReceive) =>
_handlers[cmd] = new PacketHandler(cmd, 0, ingame, onReceive); _handlers[cmd] = new PacketHandler(cmd, 0, ingame, onReceive);
public static void QueryGuildMemberLocations(NetState state, CircularBufferReader reader, ref int packetLength) public static void QueryGuildMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
{ {
Mobile from = state.Mobile; Mobile from = state.Mobile;
state.SendGuildMemberLocations(from, from.Guild as Guild, reader.ReadBoolean()); state.SendGuildMemberLocations(from, from.Guild as Guild, reader.ReadBoolean());
} }
public static void QueryPartyMemberLocations(NetState state, CircularBufferReader reader, ref int packetLength) public static void QueryPartyMemberLocations(NetState state, CircularBufferReader reader, int packetLength)
{ {
Mobile from = state.Mobile; Mobile from = state.Mobile;
var party = Party.Get(from); var party = Party.Get(from);

View file

@ -21,11 +21,11 @@ namespace Server.Network
{ {
var packetHandlers = new PacketHandler[0x100]; var packetHandlers = new PacketHandler[0x100];
void DecodeBundledPacket(NetState state, CircularBufferReader reader, ref int packetLength) void DecodeBundledPacket(NetState state, CircularBufferReader reader, int packetLength)
{ {
int cmd = reader.ReadByte(); int cmd = reader.ReadByte();
PacketHandler ph = cmd >= 0 && cmd < packetHandlers.Length ? packetHandlers[cmd] : null; PacketHandler ph = packetHandlers[cmd];
if (ph == null) if (ph == null)
{ {
@ -43,7 +43,7 @@ namespace Server.Network
} }
else else
{ {
ph.OnReceive(state, reader, ref packetLength); ph.OnReceive(state, reader, packetLength);
} }
} }

View file

@ -33,9 +33,9 @@ namespace Server.Network
} }
} }
public static void QueryCompactShardStats(NetState ns, CircularBufferReader reader, ref int packetLength) public static void QueryCompactShardStats(NetState state, CircularBufferReader reader, int packetLength)
{ {
ns.SendCompactShardStats( state.SendCompactShardStats(
(uint)(Core.TickCount / 1000), (uint)(Core.TickCount / 1000),
TcpServer.Instances.Count - 1, // Shame if you modify this! TcpServer.Instances.Count - 1, // Shame if you modify this!
World.Items.Count, World.Items.Count,
@ -44,10 +44,10 @@ namespace Server.Network
); );
} }
public static void QueryExtendedShardStats(NetState ns, CircularBufferReader reader, ref int packetLength) public static void QueryExtendedShardStats(NetState state, CircularBufferReader reader, int packetLength)
{ {
const long ticksInHour = 1000 * 60 * 60; const long ticksInHour = 1000 * 60 * 60;
ns.SendExtendedShardStats( state.SendExtendedShardStats(
ServerList.ServerName, ServerList.ServerName,
(int)(Core.TickCount / ticksInHour), (int)(Core.TickCount / ticksInHour),
TcpServer.Instances.Count - 1, // Shame if you modify this! TcpServer.Instances.Count - 1, // Shame if you modify this!

View file

@ -19,7 +19,7 @@ namespace Server.SkillHandlers
SkillInfo.Table[(int)SkillName.Tracking].Callback = OnUse; SkillInfo.Table[(int)SkillName.Tracking].Callback = OnUse;
} }
public static void QuestArrow(NetState state, CircularBufferReader reader, ref int packetLength) public static void QuestArrow(NetState state, CircularBufferReader reader, int packetLength)
{ {
if (state.Mobile is PlayerMobile from) if (state.Mobile is PlayerMobile from)
{ {