diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index cb66649a..cb418b0e 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -2102,6 +2102,28 @@ namespace TShockAPI SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time); } + + /// + /// 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); + } + //Todo: Separate this into a few functions. SendTo, SendToAll, etc /// /// Sends data to the player. @@ -2119,6 +2141,12 @@ namespace TShockAPI if (RealPlayer && !ConnectionAlive) return; + if (!NecessaryPacket(msgType) && !FinishedHandshake) + return; + + if (msgType == PacketTypes.WorldInfo && State < 3) //If the player has requested the world data, their state will be 3. + return; + NetMessage.SendData((int)msgType, Index, -1, text == null ? null : NetworkText.FromLiteral(text), number, number2, number3, number4, number5); } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 061d05fa..64f23ec3 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1494,6 +1494,7 @@ namespace TShockAPI if (!tsplr.FinishedHandshake) { + tsplr.Kick(GetString("Your client didn't finish the handshake."), true); args.Handled = true; return; }