From 4fe6fd5178ed1cc09b16897970b904cb3945d238 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 1 May 2017 23:23:26 +1000 Subject: [PATCH] Doing ban/rank of an offline player, but forgetting the + at the end, should autocomplete that +. --- MCGalaxy/Commands/Information/CmdWhois.cs | 2 +- MCGalaxy/Commands/Information/WhoInfo.cs | 4 +-- MCGalaxy/Commands/Moderation/ModActionCmd.cs | 2 +- MCGalaxy/Network/Packets/Packet.CPE.cs | 4 +-- MCGalaxy/Network/Packets/Packet.cs | 2 +- MCGalaxy/Server/Tasks/InitTasks.cs | 2 +- MCGalaxy/util/Extensions/StringExts.cs | 26 ++++++++++++++++---- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/MCGalaxy/Commands/Information/CmdWhois.cs b/MCGalaxy/Commands/Information/CmdWhois.cs index 96856b2be..774b0a3dd 100644 --- a/MCGalaxy/Commands/Information/CmdWhois.cs +++ b/MCGalaxy/Commands/Information/CmdWhois.cs @@ -84,7 +84,7 @@ namespace MCGalaxy.Commands { string prefix = data.Title == "" ? "" : color + "[" + data.TitleColor + data.Title + color + "] "; WhoInfo info = new WhoInfo(); - info.FullName = prefix + color + data.Name.TrimEnd('+'); + info.FullName = prefix + color + data.Name.RemoveLastPlus(); info.Name = data.Name; info.Group = group; info.Money = data.Money; info.Deaths = data.Deaths; diff --git a/MCGalaxy/Commands/Information/WhoInfo.cs b/MCGalaxy/Commands/Information/WhoInfo.cs index f6446022c..ea4ae8bd7 100644 --- a/MCGalaxy/Commands/Information/WhoInfo.cs +++ b/MCGalaxy/Commands/Information/WhoInfo.cs @@ -75,9 +75,9 @@ namespace MCGalaxy.Commands { } } - if (Server.Devs.CaselessContains(who.Name.TrimEnd('+'))) + if (Server.Devs.CaselessContains(who.Name.RemoveLastPlus())) Player.Message(p, " Player is an &9{0} Developer", Server.SoftwareName); - if (Server.Mods.CaselessContains(who.Name.TrimEnd('+'))) + if (Server.Mods.CaselessContains(who.Name.RemoveLastPlus())) Player.Message(p, " Player is an &9{0} Moderator", Server.SoftwareName); if (Server.server_owner.CaselessEq(who.Name)) Player.Message(p, " Player is the &cServer owner"); diff --git a/MCGalaxy/Commands/Moderation/ModActionCmd.cs b/MCGalaxy/Commands/Moderation/ModActionCmd.cs index becb6d954..7993b49e3 100644 --- a/MCGalaxy/Commands/Moderation/ModActionCmd.cs +++ b/MCGalaxy/Commands/Moderation/ModActionCmd.cs @@ -127,7 +127,7 @@ namespace MCGalaxy.Commands.Moderation { if (confirmed != null) reason = confirmed; if (match != null) { - if (match.CaselessEq(name)) return match; + if (match.RemoveLastPlus().CaselessEq(name.RemoveLastPlus())) return match; // Not an exact match, may be wanting to ban a non-existent account Player.Message(p, "1 player matches \"{0}\": {1}", name, match); } diff --git a/MCGalaxy/Network/Packets/Packet.CPE.cs b/MCGalaxy/Network/Packets/Packet.CPE.cs index 8479a0415..aebad14fb 100644 --- a/MCGalaxy/Network/Packets/Packet.CPE.cs +++ b/MCGalaxy/Network/Packets/Packet.CPE.cs @@ -201,8 +201,8 @@ namespace MCGalaxy.Network { byte[] buffer = new byte[138 + (extPos ? 6 : 0)]; buffer[0] = Opcode.CpeExtAddEntity2; buffer[1] = id; - NetUtils.Write(displayName.TrimEnd('+'), buffer, 2, hasCP437); - NetUtils.Write(skinName.TrimEnd('+'), buffer, 66, hasCP437); + NetUtils.Write(displayName.RemoveLastPlus(), buffer, 2, hasCP437); + NetUtils.Write(skinName.RemoveLastPlus(), buffer, 66, hasCP437); int offset = NetUtils.WritePos(pos, buffer, 130, extPos); buffer[130 + offset] = rot.RotY; diff --git a/MCGalaxy/Network/Packets/Packet.cs b/MCGalaxy/Network/Packets/Packet.cs index 33ebdbb0a..a112507d5 100644 --- a/MCGalaxy/Network/Packets/Packet.cs +++ b/MCGalaxy/Network/Packets/Packet.cs @@ -54,7 +54,7 @@ namespace MCGalaxy.Network { byte[] buffer = new byte[74 + (extPos ? 6 : 0)]; buffer[0] = Opcode.AddEntity; buffer[1] = id; - NetUtils.Write(name.TrimEnd('+'), buffer, 2, hasCP437); + NetUtils.Write(name.RemoveLastPlus(), buffer, 2, hasCP437); int offset = NetUtils.WritePos(pos, buffer, 66, extPos); buffer[66 + offset] = rot.RotY; diff --git a/MCGalaxy/Server/Tasks/InitTasks.cs b/MCGalaxy/Server/Tasks/InitTasks.cs index 32f2bf41c..d143e7e4c 100644 --- a/MCGalaxy/Server/Tasks/InitTasks.cs +++ b/MCGalaxy/Server/Tasks/InitTasks.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Tasks { string type = line.Split(':')[0].ToLower(); List list = (type == "devs") ? Server.Devs : (type == "mods") ? Server.Mods : null; foreach (string name in line.Split(':')[1].Split()) - list.Add(name.TrimEnd('+')); + list.Add(name.RemoveLastPlus()); } } } catch (Exception e) { diff --git a/MCGalaxy/util/Extensions/StringExts.cs b/MCGalaxy/util/Extensions/StringExts.cs index 06185b4e5..2a6544e9d 100644 --- a/MCGalaxy/util/Extensions/StringExts.cs +++ b/MCGalaxy/util/Extensions/StringExts.cs @@ -21,16 +21,25 @@ namespace MCGalaxy { public static class StringExts { + /// Sets the first character of the input string touppercase. public static string Capitalize(this string str) { - if (String.IsNullOrEmpty(str)) - return String.Empty; + if (String.IsNullOrEmpty(str)) return str; char[] a = str.ToCharArray(); a[0] = char.ToUpper(a[0]); return new string(a); } + /// Removes an ending + from an account name. + public static string RemoveLastPlus(this string str) { + if (String.IsNullOrEmpty(str)) return str; + + if (str[str.Length - 1] != '+') return str; + return str.Substring(0, str.Length - 1); + } + + /// Converts a string consisting of code page 437 indices into unicode. public static string Cp437ToUnicode(this string str) { if (str == null || str.Length == 0 || !HasSpecial(str)) return str; @@ -39,7 +48,9 @@ namespace MCGalaxy { c[i] = Cp437ToUnicode(str[i]); return new String(c); } - + + /// Converts a unicode string into a string consisting of code page 437 indices. + /// Unicode characters not in code page 437 are converted to '?'. public static string UnicodeToCp437(this string str) { if (str == null || str.Length == 0 || !HasSpecial(str)) return str; @@ -49,6 +60,7 @@ namespace MCGalaxy { return new String(c); } + /// Modifies the characters of a string consisting of code page 437 indices into unicode. public unsafe static void Cp437ToUnicodeInPlace(this string str) { fixed (char* ptr = str) { for (int i = 0; i < str.Length; i++) { @@ -56,7 +68,9 @@ namespace MCGalaxy { } } } - + + /// Modifies the characters of a unicode string into code page 437 indices. + /// Unicode characters not in code page 437 are replaced with '?'. public static unsafe void UnicodeToCp437InPlace(this string str) { fixed (char* ptr = str) { for (int i = 0; i < str.Length; i++) { @@ -66,6 +80,7 @@ namespace MCGalaxy { } + /// Converts a code page 437 indice into unicode. public static char Cp437ToUnicode(this char c) { if (c < 0x20) { return FullCP437Handler.ControlCharReplacements[c]; @@ -76,7 +91,8 @@ namespace MCGalaxy { } return '?'; } - + + /// Converts a unicode character into a code page 437 indice. public static char UnicodeToCp437(this char c) { int cpIndex = 0; if (c >= ' ' && c <= '~') {