From fa3c1442741e291c17df08db93da3aa5422c6a82 Mon Sep 17 00:00:00 2001 From: ohayo Date: Tue, 4 Feb 2025 11:28:09 +1000 Subject: [PATCH] Add necessary packets to a static hashset for further performance boosts title --- TShockAPI/TSPlayer.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index cb418b0e..6569ef01 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -2102,27 +2102,26 @@ namespace TShockAPI SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time); } + /// + /// The list of necessary packets to make sure gets through to the player upon connection (before they finish the handshake). + /// + private static readonly HashSet NecessaryPackets = new() + { + PacketTypes.ContinueConnecting, + PacketTypes.WorldInfo, + PacketTypes.Status, + PacketTypes.Disconnect, + PacketTypes.TileFrameSection, + PacketTypes.TileSendSection, + PacketTypes.PlayerSpawnSelf + }; /// /// Determines if an outgoing packet is necessary to send to a player before they have finished the connection handshake. /// /// The packet type to check against the necessary list. - /// - private bool NecessaryPacket(PacketTypes msgType) - { - List ConnectionPackets = new List() - { - PacketTypes.ContinueConnecting, - PacketTypes.WorldInfo, - PacketTypes.Status, - PacketTypes.Disconnect, - PacketTypes.TileFrameSection, - PacketTypes.TileSendSection, - PacketTypes.PlayerSpawnSelf - }; - - return ConnectionPackets.Contains(msgType); - } + /// Whether the packet is necessary for connection or not + private bool NecessaryPacket(PacketTypes msgType) => NecessaryPackets.Contains(msgType); //Todo: Separate this into a few functions. SendTo, SendToAll, etc ///