mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-08 22:59:29 -04:00
Initial work on implementing TextColors CPE extension.
This commit is contained in:
parent
a649e1eeeb
commit
ec19f0166a
@ -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":
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
/// <summary> Gets a color from a char. </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -136,6 +136,7 @@
|
||||
<Compile Include="Commands\Building\CmdWrite.cs" />
|
||||
<Compile Include="Commands\building\DrawCmd.cs" />
|
||||
<Compile Include="Commands\building\ReplaceCmd.cs" />
|
||||
<Compile Include="Commands\Chat\Class1.cs" />
|
||||
<Compile Include="Commands\Chat\CmdAdminChat.cs" />
|
||||
<Compile Include="Commands\Chat\CmdChatRoom.cs" />
|
||||
<Compile Include="Commands\Chat\CmdGcaccept.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;
|
||||
}
|
||||
}
|
||||
|
@ -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<string> extensions = new List<string>();
|
||||
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user