From 2697c934cdb207c9b45c272ec0bcd6fd48fd7b0a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Aug 2017 16:44:41 +1000 Subject: [PATCH] Fix /whonick returning 'player not online' when multiple people matched the given nickname. --- MCGalaxy/Commands/Bots/CmdBotAI.cs | 2 +- MCGalaxy/Commands/Information/CmdWhoNick.cs | 15 +++++++++++---- MCGalaxy/CorePlugin/NotesPlugin.cs | 2 +- MCGalaxy/Player/Player.cs | 3 --- MCGalaxy/Player/PlayerInfo.cs | 19 ------------------- MCGalaxy/Server/Server.Fields.cs | 2 +- MCGalaxy/Server/Server.cs | 2 -- 7 files changed, 14 insertions(+), 31 deletions(-) diff --git a/MCGalaxy/Commands/Bots/CmdBotAI.cs b/MCGalaxy/Commands/Bots/CmdBotAI.cs index e875377a2..951a983eb 100644 --- a/MCGalaxy/Commands/Bots/CmdBotAI.cs +++ b/MCGalaxy/Commands/Bots/CmdBotAI.cs @@ -99,7 +99,7 @@ namespace MCGalaxy.Commands.Bots{ Player.Message(p, "Created new bot AI: &b" + ai); using (StreamWriter w = new StreamWriter("bots/" + ai)) w.WriteLine("#Version 2"); - } else if (instructions[0] != "#Version 2") { + } else if (!instructions[0].CaselessEq("#Version 2")) { Player.Message(p, "File found is out-of-date. Overwriting"); File.Delete("bots/" + ai); using (StreamWriter w = new StreamWriter("bots/" + ai)) diff --git a/MCGalaxy/Commands/Information/CmdWhoNick.cs b/MCGalaxy/Commands/Information/CmdWhoNick.cs index 8d83a63a3..ac6863da0 100644 --- a/MCGalaxy/Commands/Information/CmdWhoNick.cs +++ b/MCGalaxy/Commands/Information/CmdWhoNick.cs @@ -28,11 +28,18 @@ namespace MCGalaxy.Commands.Info { public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } - Player nick = PlayerInfo.FindNick(p, message); - if (nick == null) { - Player.Message(p, "The player is not online."); return; - } + Player nick = FindNick(p, message); + + if (nick == null) return; Player.Message(p, "This player's real username is " + nick.name); + } + + static Player FindNick(Player p, string nick) { + nick = Colors.Strip(nick); + Player[] players = PlayerInfo.Online.Items; + int matches = 0; + return Matcher.Find(p, nick, out matches, players, pl => Entities.CanSee(p, pl), + pl => Colors.Strip(pl.DisplayName), "online player nicks"); } public override void Help(Player p) { diff --git a/MCGalaxy/CorePlugin/NotesPlugin.cs b/MCGalaxy/CorePlugin/NotesPlugin.cs index 1966b4b9a..394885fa4 100644 --- a/MCGalaxy/CorePlugin/NotesPlugin.cs +++ b/MCGalaxy/CorePlugin/NotesPlugin.cs @@ -46,7 +46,7 @@ namespace MCGalaxy.Core { case ModActionType.Warned: AddNote(action, "W"); break; case ModActionType.Ban: - string banType = action.Duration.Ticks == 0 ? "B" : "T"; + string banType = action.Duration.Ticks != 0 ? "T" : "B"; AddNote(action, banType); break; } } diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index d584ef78b..47b01c181 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -378,9 +378,6 @@ namespace MCGalaxy { [Obsolete("Use PlayerInfo.FindExact(name)")] public static Player FindExact(string name) { return PlayerInfo.FindExact(name); } - [Obsolete("Use PlayerInfo.FindNick(name)")] - public static Player FindNick(string name) { return PlayerInfo.FindNick(null, name); } - unsafe static byte NextFreeId() { byte* used = stackalloc byte[256]; for (int i = 0; i < 256; i++) diff --git a/MCGalaxy/Player/PlayerInfo.cs b/MCGalaxy/Player/PlayerInfo.cs index ba252cb07..6b5257264 100644 --- a/MCGalaxy/Player/PlayerInfo.cs +++ b/MCGalaxy/Player/PlayerInfo.cs @@ -25,8 +25,6 @@ namespace MCGalaxy { /// Array of all currently online players. /// Note this field is highly volatile, you should cache references to the items array. public static VolatileArray Online = new VolatileArray(true); - [Obsolete("Use PlayerInfo.Online.Items")] - public static List players; public static Group GetGroup(string name) { return Group.GroupIn(name); } @@ -89,23 +87,6 @@ namespace MCGalaxy { } return null; } - - public static Player FindNick(Player p, string nick) { - nick = Colors.Strip(nick); - Player[] players = PlayerInfo.Online.Items; - Player match = null; int matches = 0; - - foreach (Player pl in players) { - if (!Entities.CanSee(p, pl)) continue; - string name = Colors.Strip(pl.DisplayName); - - if (name.CaselessEq(nick)) return pl; - if (name.CaselessContains(nick)) { - match = pl; matches++; - } - } - return matches == 1 ? match : null; - } /// Retrieves from the database the player data for the player diff --git a/MCGalaxy/Server/Server.Fields.cs b/MCGalaxy/Server/Server.Fields.cs index 98689e8d9..7edf156d8 100644 --- a/MCGalaxy/Server/Server.Fields.cs +++ b/MCGalaxy/Server/Server.Fields.cs @@ -36,7 +36,7 @@ namespace MCGalaxy { public static IRCBot IRC; public static Thread locationChecker; - public static DateTime StartTime, StartTimeLocal; + public static DateTime StartTime; public static PlayerExtList AutoloadMaps; public static PlayerMetaList RankInfo = new PlayerMetaList("text/rankinfo.txt"); diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index e973ffefa..cfd009251 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -76,12 +76,10 @@ namespace MCGalaxy { #pragma warning disable 0618 Player.players = PlayerInfo.Online.list; - PlayerInfo.players = PlayerInfo.Online.list; Server.levels = LevelInfo.Loaded.list; #pragma warning restore 0618 StartTime = DateTime.UtcNow; - StartTimeLocal = StartTime.ToLocalTime(); shuttingDown = false; Logger.Log(LogType.SystemActivity, "Starting Server"); ServicePointManager.Expect100Continue = false;