diff --git a/Commands/Economy/CmdEconomy.cs b/Commands/Economy/CmdEconomy.cs index 5e114b3a8..4707a6aa4 100644 --- a/Commands/Economy/CmdEconomy.cs +++ b/Commands/Economy/CmdEconomy.cs @@ -57,14 +57,11 @@ namespace MCGalaxy.Commands { if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this)) { switch (par1) { case "apply": - if (p != null) { - if (p.name == Server.server_owner) { - Economy.Load(); - Player.SendMessage(p, "%aApplied changes"); - } else Player.SendMessage(p, "%cThis command is only usable by the server owner: %6" + Server.server_owner); - } else { //console fix + if (p == null || p.name == Server.server_owner) { Economy.Load(); Player.SendMessage(p, "%aApplied changes"); + } else { + Player.SendMessage(p, "%cThis command is only usable by the server owner: %6" + Server.server_owner); } return; case "maps": diff --git a/Commands/World/CmdEnvironment.cs b/Commands/World/CmdEnvironment.cs index f5abf3887..8d8573f3b 100644 --- a/Commands/World/CmdEnvironment.cs +++ b/Commands/World/CmdEnvironment.cs @@ -282,11 +282,8 @@ namespace MCGalaxy.Commands { static bool IsValidHex(string hex) { for (int i = 0; i < hex.Length; i++) { - char ch = hex[i]; - if (ch < '0' || ch > '9' && ch < 'A' || ch > 'F' && - ch < 'a' || ch > 'f') { + if (!Chat.IsStandardColor(hex[i])) return false; - } } return true; } diff --git a/GUI/ColoredTextBox.cs b/GUI/ColoredTextBox.cs index b43a42835..99ff1b560 100644 --- a/GUI/ColoredTextBox.cs +++ b/GUI/ColoredTextBox.cs @@ -172,7 +172,7 @@ namespace MCGalaxy.Gui.Components { string split = messagesSplit[i]; if ( String.IsNullOrEmpty(split.Trim()) ) continue; - Color? color = GetDimColorFromChar(split[0]); + Color? color = GetColor(split[0]); Append(color != null ? split.Substring(1) : split, color ?? foreColor, BackColor); } @@ -373,7 +373,7 @@ namespace MCGalaxy.Gui.Components { #endregion /// Gets a color from a char. - public static Color? GetDimColorFromChar( char c ) { + public static Color? GetColor( char c ) { Chat.Map( ref c ); switch ( c ) { case '0': return Color.Black; @@ -392,9 +392,10 @@ namespace MCGalaxy.Gui.Components { case 'd': return Color.FromArgb( 255, 225, 34, 225 ); case 'e': return Color.FromArgb( 255, 225, 225, 34 ); case 'f': return Color.Black; - default: return null; + default: + char fallback = Chat.GetFallback(c); + return fallback == '\0' ? null : GetColor(fallback); } } - } } diff --git a/GUI/Program.cs b/GUI/Program.cs index c9d60fa87..3917abab0 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -174,12 +174,9 @@ namespace MCGalaxy_.Gui } } - private static ConsoleColor GetColor(char c) - { + private static ConsoleColor GetColor(char c) { Chat.Map(ref c); - switch (c) - { - case 'e': return ConsoleColor.Yellow; + switch (c) { case '0': return ConsoleColor.Black; case '1': return ConsoleColor.DarkBlue; case '2': return ConsoleColor.DarkGreen; @@ -190,13 +187,15 @@ namespace MCGalaxy_.Gui case '6': return ConsoleColor.DarkYellow; case '8': return ConsoleColor.DarkGray; case '9': return ConsoleColor.Blue; - case 'a': return ConsoleColor.Green; - case 'b': return ConsoleColor.Cyan; - case 'c': return ConsoleColor.Red; - case 'd': return ConsoleColor.Magenta; - //Dont need f, it will default to white. + case 'a': case 'A': return ConsoleColor.Green; + case 'b': case 'B': return ConsoleColor.Cyan; + case 'c': case 'C': return ConsoleColor.Red; + case 'd': case 'D': return ConsoleColor.Magenta; + case 'e': case 'E': return ConsoleColor.Yellow; + case 'f': case 'F': return ConsoleColor.White; default: - return ConsoleColor.White; + char fallback = Chat.GetFallback(c); + return fallback == '\0' ? ConsoleColor.White : GetColor(fallback); } } @@ -542,7 +541,7 @@ namespace MCGalaxy_.Gui catch (Exception e) { Server.ErrorLog(e); } } - static public void ExitProgram(bool AutoRestart) + public static void ExitProgram(bool AutoRestart) { Server.restarting = AutoRestart; Server.shuttingDown = true; @@ -591,7 +590,7 @@ namespace MCGalaxy_.Gui })).Start(); } - static public void saveAll(bool restarting) + public static void saveAll(bool restarting) { try { diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index f223547be..a079a8d2a 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -136,6 +136,7 @@ + diff --git a/Network/Opcode.cs b/Network/Opcode.cs index cfb40353d..cd71bab65 100644 --- a/Network/Opcode.cs +++ b/Network/Opcode.cs @@ -60,5 +60,7 @@ namespace MCGalaxy { public const byte CpeDefineBlock = 35; public const byte CpeRemoveBlockDefinition = 36; public const byte CpeDefineBlockExt = 37; + public const byte CpeBulkBlockUpdate = 38; + public const byte CpeSetTextColor = 39; } } diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index 920884636..79f6c7834 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -74,7 +74,7 @@ namespace MCGalaxy { } } - public bool hasCpe = false, hasCustomBlocks = false, finishedLogin = false; + public bool hasCpe = false, hasCustomBlocks = false, hasTextColors, finishedLogin = false; public string appName; public int extensionCount; public List extensions = new List(); @@ -218,15 +218,14 @@ namespace MCGalaxy { message = Chat.EscapeColours(message); StringBuilder sb = new StringBuilder(message); - if (colorParse) { - // Begin fix to replace all invalid color codes typed in console or chat with "." - for ( char ch = '\0'; ch <= '/'; ch++ ) // Characters that cause clients to disconnect - sb.Replace("&" + ch, String.Empty); - for ( char ch = ':'; ch <= '`'; ch++ ) // Characters that cause clients to disconnect - sb.Replace("&" + ch, String.Empty); - for ( char ch = 'g'; ch <= '\u007F'; ch++ ) // Characters that cause clients to disconnect - sb.Replace("&" + ch, String.Empty); - // End fix + if (colorParse) { + for (int i = 0; i < 128; i++) { + if (Chat.IsStandardColor((char)i)) continue; + CustomColor col = Chat.ExtColors[i]; + + if (col.Fallback == '\0' || !hasTextColors) + sb.Replace("&" + (char)i, ""); + } } Chat.ApplyDollarTokens(sb, this, colorParse); diff --git a/Player/Chat.cs b/Player/Chat.cs index 4301258c8..050e94781 100644 --- a/Player/Chat.cs +++ b/Player/Chat.cs @@ -13,6 +13,7 @@ or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. */ using System; +using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; @@ -118,7 +119,7 @@ namespace MCGalaxy { } } - public static bool IsValidColor(char c) { + public static bool IsStandardColor(char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } @@ -144,15 +145,21 @@ namespace MCGalaxy { } public static bool Map(ref char color) { - if (IsValidColor(color)) return true; + if (IsStandardColor(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; } if (color == 'i' || color == 'I') { color = Server.IRCColour[1]; return true; } if (color == 'g' || color == 'G') { color = Server.GlobalChatColor[1]; return true; } if (color == 'r' || color == 'R') { color = 'f'; return true; } - return false; + + return GetFallback(color) != '\0'; } + public static CustomColor[] ExtColors = new CustomColor[256]; + + public static char GetFallback(char c) { + return (int)c >= 256 ? '\0' : ExtColors[c].Fallback; + } public static string StripColours(string value) { if (value.IndexOf('%') == -1) @@ -304,4 +311,9 @@ namespace MCGalaxy { Player.SendMessage(who, "&9[>] " + fullName + ": &f" + message); } } + + public struct CustomColor { + public char Code, Fallback; + public byte R, G, B, A; + } } diff --git a/Player/Player.CPE.cs b/Player/Player.CPE.cs index 5f55aac9f..dacb8d8d6 100644 --- a/Player/Player.CPE.cs +++ b/Player/Player.CPE.cs @@ -40,6 +40,7 @@ namespace MCGalaxy public int FullCP437 = 0; public int BlockDefinitions = 0; public int BlockDefinitionsExt = 0; + public int TextColors = 0; public void AddExtension(string Extension, int version) { @@ -132,6 +133,9 @@ namespace MCGalaxy BlockDefinitions = version; break; case CpeExt.BlockDefinitionsExt: BlockDefinitionsExt = version; break; + case CpeExt.TextColors: + hasTextColors = true; + TextColors = version; break; } } @@ -249,5 +253,6 @@ namespace MCGalaxy public const string FullCP437 = "FullCP437"; public const string BlockDefinitions = "BlockDefinitions"; public const string BlockDefinitionsExt = "BlockDefinitionsExt"; + public const string TextColors = "TextColors"; } } \ No newline at end of file diff --git a/Server/Color.cs b/Server/Color.cs index e0e7f7970..603f7d42c 100644 --- a/Server/Color.cs +++ b/Server/Color.cs @@ -121,6 +121,12 @@ namespace MCGalaxy { input = Chat.EscapeColours(input); StringBuilder sb = new StringBuilder(input); + for (int i = 0; i < 128; i++) { + CustomColor col = Chat.ExtColors[i]; + if (col.Fallback == '\0') continue; + sb.Replace("&" + col.Code, "&" + col.Fallback); + } + foreach (var kvp in ircColors) sb.Replace(kvp.Key, kvp.Value); return sb.ToString();