From 521283c36b6d00b40fe5e02d133f0e45f5ff20b3 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 31 Dec 2017 01:13:33 -0700 Subject: [PATCH] Migrate calls from Players.Length to ActivePlayers As pointed out by @QuiCM, TShock.Players is actually an array and not a smarter collection, so length will return the total collection size and not the active players. An earlier commit was added that gives TSPlayer an ICollection that contains only active players. This is now the basis of determining the number of active players on the server. --- TShockAPI/Commands.cs | 2 +- TShockAPI/StatTracker.cs | 2 +- TShockAPI/TShock.cs | 4 ++-- TShockAPI/Utils.cs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2faa71bc..92264b3b 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4819,7 +4819,7 @@ namespace TShockAPI return; } - args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Players.Length, TShock.Config.MaxSlots); + args.Player.SendSuccessMessage("Online Players ({0}/{1})", TSPlayer.ActivePlayers.Count, TShock.Config.MaxSlots); var players = new List(); diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 0d1d2b6c..1063d70d 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -144,7 +144,7 @@ namespace TShockAPI return new JsonData() { port = Terraria.Netplay.ListenPort, - currentPlayers = TShock.Players.Length, + currentPlayers = TSPlayer.ActivePlayers.Count, maxPlayers = TShock.Config.MaxSlots, systemRam = GetTotalSystemRam(ServerApi.RunningMono), version = TShock.VersionNum.ToString(), diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 26594077..cb617166 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1621,7 +1621,7 @@ namespace TShockAPI if (Config.EnableGeoIP && TShock.Geo != null) { Log.Info("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP, - player.Group.Name, player.Country, TShock.Players.Length, + player.Group.Name, player.Country, TSPlayer.ActivePlayers.Count, TShock.Config.MaxSlots); if (!player.SilentJoinInProgress) Utils.Broadcast(string.Format("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow); @@ -1629,7 +1629,7 @@ namespace TShockAPI else { Log.Info("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP, - player.Group.Name, TShock.Players.Length, TShock.Config.MaxSlots); + player.Group.Name, TSPlayer.ActivePlayers.Count, TShock.Config.MaxSlots); if (!player.SilentJoinInProgress) Utils.Broadcast(player.Name + " has joined.", Color.Yellow); } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index fc550600..c8012c74 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1108,7 +1108,7 @@ namespace TShockAPI } else { - invasionSize = 100 + (TShock.Config.InvasionMultiplier * TShock.Players.Length); + invasionSize = 100 + (TShock.Config.InvasionMultiplier * TSPlayer.ActivePlayers.Count); } // Order matters @@ -1147,7 +1147,7 @@ namespace TShockAPI { Console.Title = string.Format("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})", !string.IsNullOrWhiteSpace(TShock.Config.ServerName) ? TShock.Config.ServerName + " - " : "", - empty ? 0 : TShock.Players.Length, + empty ? 0 : TSPlayer.ActivePlayers.Count, TShock.Config.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum); }