From ea02a24cbd8670b68849b18f71af14424aea90ac Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 15 Feb 2016 13:00:20 +1100 Subject: [PATCH] Remove pointless CommandHasBadColourCodes which never really worked properly. --- Commands/CPE/CmdCustomColors.cs | 3 ++- Commands/other/CmdSay.cs | 24 +++++++----------------- IRC/ForgeBot.cs | 3 --- Network/Player.Networking.cs | 10 +++++++--- Player/Player.cs | 30 ------------------------------ Server/Colors.cs | 9 ++++++--- 6 files changed, 22 insertions(+), 57 deletions(-) diff --git a/Commands/CPE/CmdCustomColors.cs b/Commands/CPE/CmdCustomColors.cs index 576682d93..c617c4a15 100644 --- a/Commands/CPE/CmdCustomColors.cs +++ b/Commands/CPE/CmdCustomColors.cs @@ -73,10 +73,11 @@ namespace MCGalaxy.Commands { "custom color with the name \"" + name + "\"."); return; } - char fallback = args[3][0]; + char fallback = args[3][0]; if (!Colors.IsStandardColor(fallback)) { Player.SendMessage(p, fallback + " must be a standard color code."); return; } + if (fallback >= 'A' && fallback <= 'F') fallback += ' '; string hex = args[4]; if (hex.Length > 0 && hex[0] == '#') diff --git a/Commands/other/CmdSay.cs b/Commands/other/CmdSay.cs index c415f8671..f0a6da24c 100644 --- a/Commands/other/CmdSay.cs +++ b/Commands/other/CmdSay.cs @@ -15,10 +15,10 @@ or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. */ -namespace MCGalaxy.Commands -{ - public sealed class CmdSay : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdSay : Command { + public override string name { get { return "say"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } @@ -26,25 +26,15 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdSay() { } - public override void Use(Player p, string message) - { + public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - //for (int i = 0; i < 10; i++) - // message = message.Replace("%" + i, "&" + i); - //for (char c = 'a'; c <= 'f'; c++) - // message = message.Replace("%" + c, "&" + c); message = Colors.EscapeColors(message); Player.GlobalMessage(message); - - for (int i = 0; i < 10; i++) - message = message.Replace("&" + i, ""); - for (char c = 'a'; c <= 'f'; c++) - message = message.Replace("&" + c, ""); Server.IRC.Say(message); } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/say - broadcasts a global message to everyone in the server."); } } diff --git a/IRC/ForgeBot.cs b/IRC/ForgeBot.cs index 7050623ba..5eb7d3643 100644 --- a/IRC/ForgeBot.cs +++ b/IRC/ForgeBot.cs @@ -269,9 +269,6 @@ namespace MCGalaxy { if (banCmd.Contains(cmdName)) { error = "You are not allowed to use this command from IRC."; return false; } - if (Player.CommandHasBadColourCodes(null, message)) { - error = "Your command had invalid color codes."; return false; - } return true; } diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index ba483538d..57ab04030 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -188,9 +188,13 @@ namespace MCGalaxy { if (colorParse) { for (int i = 0; i < 128; i++) { - if (Colors.IsStandardColor((char)i)) continue; - CustomColor col = Colors.ExtColors[i]; - + if (Colors.IsStandardColor((char)i)) { + if (i >= 'A' && i <= 'F') // WoM does not work with uppercase color codes. + sb.Replace("&" + (char)i, "&" + (char)(i + ' ')); + continue; + } + + CustomColor col = Colors.ExtColors[i]; if (col.Undefined) { sb.Replace("&" + (char)i, ""); continue; } diff --git a/Player/Player.cs b/Player/Player.cs index 7b4c6d618..13ea2f8f2 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -477,36 +477,6 @@ namespace MCGalaxy { }); } - public static bool CommandHasBadColourCodes(Player who, string message) { - string[] checkmessagesplit = message.Split(' '); - bool lastendwithcolour = false; - foreach ( string s in checkmessagesplit ) { - s.Trim(); - if ( s.StartsWith("%") ) { - if ( lastendwithcolour ) { - if ( who != null ) { - who.SendMessage("Sorry, Your colour codes in this command were invalid (You cannot use 2 colour codes next to each other"); - who.SendMessage("Command failed."); - Server.s.Log(who.name + " attempted to send a command with invalid colours codes (2 colour codes were next to each other)!"); - Chat.GlobalMessageOps(who.color + who.DisplayName + " " + Server.DefaultColor + " attempted to send a command with invalid colours codes (2 colour codes were next to each other)!"); - } - return true; - } - else if ( s.Length == 2 ) { - lastendwithcolour = true; - } - } - if ( s.TrimEnd(Server.ColourCodesNoPercent).EndsWith("%") ) { - lastendwithcolour = true; - } - else { - lastendwithcolour = false; - } - - } - return false; - } - public static List Last50Chat = new List(); public static void GlobalMessage(string message) { GlobalMessage(message, false); diff --git a/Server/Colors.cs b/Server/Colors.cs index 8d6a468b8..d8db41722 100644 --- a/Server/Colors.cs +++ b/Server/Colors.cs @@ -142,8 +142,7 @@ namespace MCGalaxy { } public static string EscapeColors(string value) { - if (value.IndexOf('%') == -1) - return value; + if (value.IndexOf('%') == -1) return value; char[] chars = new char[value.Length]; for (int i = 0; i < value.Length; i++ ) { @@ -163,7 +162,11 @@ namespace MCGalaxy { } public static bool MapColor(ref char color) { - if (IsStandardColor(color)) return true; + if (IsStandardColor(color)) { + if (color >= 'A' && color <= 'F') color += ' '; + return true; + } + if (color == 's' || color == 'S') { color = Server.DefaultColor[1]; return true; } if (color == 'h' || color == 'H') { color = 'e'; return true; } if (color == 't' || color == 'T') { color = 'a'; return true; }