From 09fe254f17e25d3f570dce1edc8cf4960d37012e Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 25 May 2021 18:34:33 -0700 Subject: [PATCH] Change TSPlayer.FindByNameOrID to keep searching Currently, the TSPlayer FindbyNameOrID method aborts if it finds an "exact match" based on this criteria: 1. If the player ID is on the server, it must be the thing we're looking for. Therefore, return that. 2. If the case sensitive "exact match" is on the server that isn't an ID, that must be what we're looking for. Therefore, return that. 3. Just yolo and downcase everything and return any number of matching players next. This commit changes the behavior because some players have been joining servers with ambiguous names, like `1`. In the current system, this player is difficult to query because they're an "ID" and therefore an exact match will be returned even if a player name exists that matches the criteria. This also alleviates the issue of a case exact match falling down the same trap. It's ambiguous enough in all of these situations that an admin should just be using a player ID instead.` --- CHANGELOG.md | 1 + TShockAPI/TSPlayer.cs | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 246db4f5..c9369eea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed torchgod settings to include whether or not torchgod has been fought by the player before and respect `usingBiomeTorches` setting. (@Quinci135) * Fixed /worldmode not synchronising data to players after updating the world state (@bartico6, @Arthri) * Added `OnSendNetData` hook to TSAPI, which enables developers to intercept traffic being sent from the server to clients. (@Stealownz) +* Changed `TSPlayer.FindByNameOrID` so that it will continue searching for players and return a list of many players whem ambiguous matches exist in all cases. Specifically, this avoids a scenario where a griefer names themselves `1` and is difficult to enact justice on, because their name will not be found by the matching system used to kick players. (@hakusaro, @Onusai) ## TShock 4.5.3 * Added permissions for using Teleportation Potions, Magic Conch, and Demon Conch. (@drunderscore) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 8b20dfd3..12fb2d69 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -92,7 +92,7 @@ namespace TShockAPI TSPlayer player = TShock.Players[plrID]; if (player != null && player.Active) { - return new List { player }; + found.Add(player); } } @@ -101,9 +101,6 @@ namespace TShockAPI { if (player != null) { - // Must be an EXACT match - if (player.Name == plr) - return new List { player }; if (player.Name.ToLower().StartsWith(plrLower)) found.Add(player); }