Remove Utils.ActivePlayers

Duplicated what an array already stored and told us, but added code and
was obscure. It predated TSPlayers existing.
This commit is contained in:
Lucas Nicodemus 2017-12-26 21:14:16 -07:00
parent 9648e9ac0c
commit b613fdcda6
6 changed files with 11 additions and 19 deletions

View file

@ -66,6 +66,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Fix stack hack detection being inconsistent between two different check points. Moved `TShock.HackedInventory` to `TSPlayer.HasHackedItemStacks`. Added `GetDataHandlers.GetDataHandledEventArgs` which is where most hooks will inherit from in the future. (@hakusaro) * Fix stack hack detection being inconsistent between two different check points. Moved `TShock.HackedInventory` to `TSPlayer.HasHackedItemStacks`. Added `GetDataHandlers.GetDataHandledEventArgs` which is where most hooks will inherit from in the future. (@hakusaro)
* All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro) * All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro)
* Replaced `Utils.FindPlayer` with `TSPlayer.FindByNameOrID` to more appropriately be object orientated. (@hakusaro) * Replaced `Utils.FindPlayer` with `TSPlayer.FindByNameOrID` to more appropriately be object orientated. (@hakusaro)
* Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro)
## TShock 4.3.25 ## TShock 4.3.25
* Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6.

View file

@ -4818,7 +4818,7 @@ namespace TShockAPI
return; return;
} }
args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots); args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Players.Length, TShock.Config.MaxSlots);
PaginationTools.SendPage( PaginationTools.SendPage(
args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(TShock.Utils.GetPlayers(displayIdsRequested)), args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(TShock.Utils.GetPlayers(displayIdsRequested)),
new PaginationTools.Settings new PaginationTools.Settings

View file

@ -1946,7 +1946,7 @@ namespace TShockAPI
if (OnGetSection(args.Player, args.Data, args.Data.ReadInt32(), args.Data.ReadInt32())) if (OnGetSection(args.Player, args.Data, args.Data.ReadInt32(), args.Data.ReadInt32()))
return true; return true;
if (TShock.Utils.ActivePlayers() + 1 > TShock.Config.MaxSlots && if (TShock.Players.Length + 1 > TShock.Config.MaxSlots &&
!args.Player.HasPermission(Permissions.reservedslot)) !args.Player.HasPermission(Permissions.reservedslot))
{ {
TShock.Utils.ForceKick(args.Player, TShock.Config.ServerFullReason, true); TShock.Utils.ForceKick(args.Player, TShock.Config.ServerFullReason, true);

View file

@ -144,7 +144,7 @@ namespace TShockAPI
return new JsonData() return new JsonData()
{ {
port = Terraria.Netplay.ListenPort, port = Terraria.Netplay.ListenPort,
currentPlayers = TShock.Utils.ActivePlayers(), currentPlayers = TShock.Players.Length,
maxPlayers = TShock.Config.MaxSlots, maxPlayers = TShock.Config.MaxSlots,
systemRam = GetTotalSystemRam(ServerApi.RunningMono), systemRam = GetTotalSystemRam(ServerApi.RunningMono),
version = TShock.VersionNum.ToString(), version = TShock.VersionNum.ToString(),

View file

@ -1243,7 +1243,7 @@ namespace TShockAPI
var player = new TSPlayer(args.Who); var player = new TSPlayer(args.Who);
if (Utils.ActivePlayers() + 1 > Config.MaxSlots + Config.ReservedSlots) if (TShock.Players.Length + 1 > Config.MaxSlots + Config.ReservedSlots)
{ {
Utils.ForceKick(player, Config.ServerFullNoReservedReason, true, false); Utils.ForceKick(player, Config.ServerFullNoReservedReason, true, false);
args.Handled = true; args.Handled = true;
@ -1402,7 +1402,7 @@ namespace TShockAPI
} }
// The last player will leave after this hook is executed. // The last player will leave after this hook is executed.
if (Utils.ActivePlayers() == 1) if (TShock.Players.Length == 1)
{ {
if (Config.SaveWorldOnLastPlayerExit) if (Config.SaveWorldOnLastPlayerExit)
SaveManager.Instance.SaveWorld(); SaveManager.Instance.SaveWorld();
@ -1623,7 +1623,7 @@ namespace TShockAPI
if (Config.EnableGeoIP && TShock.Geo != null) if (Config.EnableGeoIP && TShock.Geo != null)
{ {
Log.Info("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP, Log.Info("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP,
player.Group.Name, player.Country, TShock.Utils.ActivePlayers(), player.Group.Name, player.Country, TShock.Players.Length,
TShock.Config.MaxSlots); TShock.Config.MaxSlots);
if (!player.SilentJoinInProgress) if (!player.SilentJoinInProgress)
Utils.Broadcast(string.Format("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow); Utils.Broadcast(string.Format("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow);
@ -1631,7 +1631,7 @@ namespace TShockAPI
else else
{ {
Log.Info("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP, Log.Info("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP,
player.Group.Name, TShock.Utils.ActivePlayers(), TShock.Config.MaxSlots); player.Group.Name, TShock.Players.Length, TShock.Config.MaxSlots);
if (!player.SilentJoinInProgress) if (!player.SilentJoinInProgress)
Utils.Broadcast(player.Name + " has joined.", Color.Yellow); Utils.Broadcast(player.Name + " has joined.", Color.Yellow);
} }

View file

@ -201,15 +201,6 @@ namespace TShockAPI
} }
} }
/// <summary>
/// Gets the number of active players on the server.
/// </summary>
/// <returns>The number of active players on the server.</returns>
public int ActivePlayers()
{
return Main.player.Where(p => null != p && p.active).Count();
}
//Random should not be generated in a method //Random should not be generated in a method
Random r = new Random(); Random r = new Random();
@ -1433,7 +1424,7 @@ namespace TShockAPI
} }
else else
{ {
invasionSize = 100 + (TShock.Config.InvasionMultiplier * ActivePlayers()); invasionSize = 100 + (TShock.Config.InvasionMultiplier * TShock.Players.Length);
} }
// Order matters // Order matters
@ -1467,12 +1458,12 @@ namespace TShockAPI
} }
/// <summary>Updates the console title with some pertinent information.</summary> /// <summary>Updates the console title with some pertinent information.</summary>
/// <param name="empty">If the server is empty; determines if we should use Utils.ActivePlayers() for player count or 0.</param> /// <param name="empty">If the server is empty; determines if we should use TShock.Players.Length for player count or 0.</param>
internal void SetConsoleTitle(bool empty) internal void SetConsoleTitle(bool empty)
{ {
Console.Title = string.Format("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})", Console.Title = string.Format("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})",
!string.IsNullOrWhiteSpace(TShock.Config.ServerName) ? TShock.Config.ServerName + " - " : "", !string.IsNullOrWhiteSpace(TShock.Config.ServerName) ? TShock.Config.ServerName + " - " : "",
empty ? 0 : ActivePlayers(), empty ? 0 : TShock.Players.Length,
TShock.Config.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum); TShock.Config.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum);
} }