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
|
|
@ -27,7 +27,7 @@ namespace Server.Engines.Chat
|
|||
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;
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ namespace Server.Engines.Chat
|
|||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ namespace Server.Engines.MLQuests.Gumps
|
|||
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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Server.Engines.UltimaStore
|
|||
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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Server.Items
|
|||
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;
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ namespace Server.Items
|
|||
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;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ namespace Server.Items
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace Server.Network
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Server.Engines.Mahjong
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Server.Network
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ namespace Server.Network
|
|||
}
|
||||
else
|
||||
{
|
||||
Delays[0x03] = 5; // Speech
|
||||
Delays[0xAD] = 5; // Speech
|
||||
Delays[0x03] = 25; // Speech
|
||||
Delays[0xAD] = 25; // Speech
|
||||
Delays[0x75] = 500; // Rename request
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ namespace Server.Network
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Core.TickCount < ns.GetPacketDelay(packetID) + Delays[packetID])
|
||||
if (Core.TickCount < ns.GetPacketTime(packetID) + Delays[packetID])
|
||||
{
|
||||
drop = true;
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1766,7 +1766,7 @@ namespace Server.Multis
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
@ -83,21 +83,21 @@ namespace Server.Network
|
|||
|
||||
if (!span.SequenceEqual(_token))
|
||||
{
|
||||
ns.Disconnect("Invalid token sent for ConnectUO");
|
||||
state.Disconnect("Invalid token sent for ConnectUO");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ns.LogInfo($"ConnectUO (v{version}) is requesting stats.");
|
||||
state.LogInfo($"ConnectUO (v{version}) is requesting stats.");
|
||||
if (version > ConnectUOProtocolVersion)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
ns.SendServerPollInfo();
|
||||
state.SendServerPollInfo();
|
||||
}
|
||||
|
||||
public static void SendServerPollInfo(this NetState ns)
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ namespace Server.Network
|
|||
public static void Register(int cmd, bool ingame, OnPacketReceive 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;
|
||||
|
||||
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;
|
||||
var party = Party.Get(from);
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace Server.Network
|
|||
{
|
||||
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();
|
||||
|
||||
PacketHandler ph = cmd >= 0 && cmd < packetHandlers.Length ? packetHandlers[cmd] : null;
|
||||
PacketHandler ph = packetHandlers[cmd];
|
||||
|
||||
if (ph == null)
|
||||
{
|
||||
|
|
@ -43,7 +43,7 @@ namespace Server.Network
|
|||
}
|
||||
else
|
||||
{
|
||||
ph.OnReceive(state, reader, ref packetLength);
|
||||
ph.OnReceive(state, reader, packetLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
TcpServer.Instances.Count - 1, // Shame if you modify this!
|
||||
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;
|
||||
ns.SendExtendedShardStats(
|
||||
state.SendExtendedShardStats(
|
||||
ServerList.ServerName,
|
||||
(int)(Core.TickCount / ticksInHour),
|
||||
TcpServer.Instances.Count - 1, // Shame if you modify this!
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Server.SkillHandlers
|
|||
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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue