From 0e1f67efbaa3164f52b47a26dd8f45a507c41edf Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 10 Apr 2016 15:09:13 +1000 Subject: [PATCH] Ignore colour codes for /whonick. --- Commands/Information/CmdWhoNick.cs | 53 ++++++++++++++---------------- Player/Player.cs | 2 +- Player/PlayerInfo.cs | 16 +++++---- Server/Colors.cs | 4 +-- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/Commands/Information/CmdWhoNick.cs b/Commands/Information/CmdWhoNick.cs index 6f70860a3..d1ba146f8 100644 --- a/Commands/Information/CmdWhoNick.cs +++ b/Commands/Information/CmdWhoNick.cs @@ -1,26 +1,26 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. */ using System.Data; using MCGalaxy.SQL; -namespace MCGalaxy.Commands -{ - public sealed class CmdWhoNick : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdWhoNick : Command { + public override string name { get { return "whonick"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Information; } } @@ -28,19 +28,16 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public CmdWhoNick() { } - public override void Use(Player p, string message) - { + public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - if (PlayerInfo.FindNick(message) == null) - { - Player.SendMessage(p, "The player is not online."); - return; + Player nick = PlayerInfo.FindNick(p, message); + if (nick == null) { + Player.SendMessage(p, "The player is not online."); return; } - Player.SendMessage(p, "This player's real username is " + PlayerInfo.FindNick(message).name); + Player.SendMessage(p, "This player's real username is " + nick.name); } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/whonick - Displays player's real username"); } } diff --git a/Player/Player.cs b/Player/Player.cs index 9ce08e10c..9eb11d09a 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -672,7 +672,7 @@ catch { }*/ public static Player FindExact(string name) { return PlayerInfo.FindExact(name); } [Obsolete("Use PlayerInfo.FindNick(name)")] - public static Player FindNick(string name) { return PlayerInfo.FindNick(name); } + public static Player FindNick(string name) { return PlayerInfo.FindNick(null, name); } static byte FreeId() { /* diff --git a/Player/PlayerInfo.cs b/Player/PlayerInfo.cs index 3e02d7208..88eec3a36 100644 --- a/Player/PlayerInfo.cs +++ b/Player/PlayerInfo.cs @@ -94,14 +94,18 @@ namespace MCGalaxy { return null; } - public static Player FindNick(string nick) { - Player[] players = PlayerInfo.Online.Items; + public static Player FindNick(Player p, string nick) { + nick = Colors.StripColours(nick); + Player[] players = PlayerInfo.Online.Items; Player match = null; int matches = 0; - foreach (Player p in players) { - if (p.DisplayName.Equals(nick, comp)) return p; - if (p.DisplayName.IndexOf(nick, comp) >= 0) { - match = p; matches++; + foreach (Player pl in players) { + if (!Player.CanSee(p, pl)) continue; + string name = Colors.StripColours(nick); + + if (name.Equals(nick, comp)) return pl; + if (name.IndexOf(nick, comp) >= 0) { + match = pl; matches++; } } return matches == 1 ? match : null; diff --git a/Server/Colors.cs b/Server/Colors.cs index 584ab32c6..bf1c7a36d 100644 --- a/Server/Colors.cs +++ b/Server/Colors.cs @@ -177,14 +177,14 @@ namespace MCGalaxy { } public static string StripColours(string value) { - if (value.IndexOf('%') == -1) + if (value.IndexOf('%') == -1 && value.IndexOf('&') == -1) return value; char[] output = new char[value.Length]; int usedChars = 0; for (int i = 0; i < value.Length; i++) { char token = value[i]; - if( token == '%' ) { + if( token == '%' || token == '&' ) { i++; // Skip over the following colour code. } else { output[usedChars++] = token;