diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index f7d3247a5..d82f10e29 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5363,7 +5363,7 @@ private static void ListConnectedPlayers(CommandArgs args) foreach (TSPlayer ply in TShock.Players) { - if (ply != null && ply.Active) + if (ply != null && ply.Active && ply.FinishedHandshake) { if (displayIdsRequested) if (ply.Account != null) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b736a5123..8f70fd2ca 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2726,6 +2726,8 @@ private static bool HandleSpawn(GetDataHandlerArgs args) short numberOfDeathsPVP = args.Data.ReadInt16(); PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte(); + args.Player.FinishedHandshake = true; + if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context)) return true; @@ -2762,6 +2764,7 @@ private static bool HandleSpawn(GetDataHandlerArgs args) args.Player.Dead = true; else args.Player.Dead = false; + return false; } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index c9194c368..cb66649a6 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -351,6 +351,9 @@ public int RespawnTimer /// Determines if the player is disabled for not clearing their trash. A re-login is the only way to reset this. public bool IsDisabledPendingTrashRemoval; + /// Determines if the player has finished the handshake (Sent all necessary packets for connection, such as Request World Data, Spawn Player, etc). A normal client would do all of this no problem. + public bool FinishedHandshake = false; + /// Checks to see if active throttling is happening on events by Bouncer. Rejects repeated events by malicious clients in a short window. /// If the player is currently being throttled by Bouncer, or not. public bool IsBouncerThrottled() diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index fae533ea7..8b6319b47 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -63,7 +63,7 @@ public class TShock : TerrariaPlugin /// VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info. public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; /// VersionCodename - The version codename is displayed when the server starts. Inspired by software codenames conventions. - public static readonly string VersionCodename = "Intensity"; + public static readonly string VersionCodename = "East"; /// SavePath - This is the path TShock saves its data in. This path is relative to the TerrariaServer.exe (not in ServerPlugins). public static string SavePath = "tshock"; @@ -1366,6 +1366,8 @@ private void OnConnect(ConnectEventArgs args) } } } + + Bans.CheckBan(player); Players[args.Who] = player; } @@ -1387,7 +1389,8 @@ private void OnJoin(JoinEventArgs args) return; } - Bans.CheckBan(player); + if (Bans.CheckBan(player)) + return; } /// OnLeave - Called when a player leaves the server. @@ -1427,7 +1430,7 @@ private void OnLeave(LeaveEventArgs args) if (tsplr.ReceivedInfo) { - if (!tsplr.SilentKickInProgress && tsplr.State >= 3) + if (!tsplr.SilentKickInProgress && tsplr.State >= 3 && tsplr.FinishedHandshake) //The player has left, do not broadcast any clients exploiting the behaviour of not spawning their player. Utils.Broadcast(GetString("{0} has left.", tsplr.Name), Color.Yellow); Log.Info(GetString("{0} disconnected.", tsplr.Name)); @@ -1448,6 +1451,9 @@ private void OnLeave(LeaveEventArgs args) } } + + tsplr.FinishedHandshake = false; + // Fire the OnPlayerLogout hook too, if the player was logged in and they have a TSPlayer object. if (tsplr.IsLoggedIn) { @@ -1477,6 +1483,12 @@ private void OnChat(ServerChatEventArgs args) return; } + if (!tsplr.FinishedHandshake) + { + args.Handled = true; + return; + } + if (args.Text.Length > 500) { tsplr.Kick(GetString("Crash attempt via long chat packet."), true); @@ -1693,14 +1705,14 @@ private void OnGreetPlayer(GreetPlayerEventArgs args) Log.Info(GetString("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP, player.Group.Name, player.Country, TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots)); - if (!player.SilentJoinInProgress) + if (!player.SilentJoinInProgress && player.FinishedHandshake) Utils.Broadcast(GetString("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow); } else { Log.Info(GetString("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP, player.Group.Name, TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots)); - if (!player.SilentJoinInProgress) + if (!player.SilentJoinInProgress && player.FinishedHandshake) Utils.Broadcast(GetString("{0} has joined.", player.Name), Color.Yellow); } diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 41bc03ff8..1395d5f88 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -18,7 +18,7 @@ Also, be sure to release on github with the exact assembly version tag as below so that the update manager works correctly (via the Github releases api and mimic) --> - 5.2.1 + 5.2.2 TShock for Terraria Pryaxis & TShock Contributors TShockAPI diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 3b9c0286b..613e7a8a4 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -183,7 +183,7 @@ public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null) /// The number of active players on the server. public int GetActivePlayerCount() { - return TShock.Players.Count(p => null != p && p.Active); + return TShock.Players.Count(p => null != p && p.Active && p.FinishedHandshake); } //Random should not be generated in a method diff --git a/docs/changelog.md b/docs/changelog.md index 490a6b0af..afcfc727e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,6 +78,8 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes +* Added a variable for handshake (True upon spawn player), clients no longer notify others of their presence and cant chat if this is never set to true. (@ohayo) +* Fixed a security issue with how bans are handled on join. (@ohayo) * Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) * Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005) * Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939)