From 27b3b0950d64d0ce0657dd35cb54602f85618c28 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 28 Feb 2017 23:15:20 +1100 Subject: [PATCH] cleanup --- MCGalaxy/Chat/ChatTokens.cs | 6 +++--- MCGalaxy/Chat/Colors.cs | 12 ++---------- MCGalaxy/Chat/ProfanityFilter.cs | 6 +++--- MCGalaxy/Network/Packets/Packet.CPE.cs | 20 ++++++++++++++------ MCGalaxy/Player/Player.CPE.cs | 5 +++-- MCGalaxy/util/IO/Paths.cs | 7 ++++--- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/MCGalaxy/Chat/ChatTokens.cs b/MCGalaxy/Chat/ChatTokens.cs index 3e97e82df..7d6144ceb 100644 --- a/MCGalaxy/Chat/ChatTokens.cs +++ b/MCGalaxy/Chat/ChatTokens.cs @@ -84,8 +84,8 @@ namespace MCGalaxy { public static Dictionary CustomTokens = new Dictionary(); internal static void LoadCustom() { CustomTokens.Clear(); - if (File.Exists("text/custom$s.txt")) { - using (StreamReader r = new StreamReader("text/custom$s.txt")) { + if (File.Exists(Paths.CustomTokensFile)) { + using (StreamReader r = new StreamReader(Paths.CustomTokensFile)) { string line; while ((line = r.ReadLine()) != null) { if (line.StartsWith("//")) continue; @@ -96,7 +96,7 @@ namespace MCGalaxy { } } else { Server.s.Log("custom$s.txt does not exist, creating"); - using (StreamWriter w = new StreamWriter("text/custom$s.txt")) { + using (StreamWriter w = new StreamWriter(Paths.CustomTokensFile)) { w.WriteLine("// This is used to create custom $s"); w.WriteLine("// If you start the line with a // it wont be used"); w.WriteLine("// It should be formatted like this:"); diff --git a/MCGalaxy/Chat/Colors.cs b/MCGalaxy/Chat/Colors.cs index ece77586e..35867e81b 100644 --- a/MCGalaxy/Chat/Colors.cs +++ b/MCGalaxy/Chat/Colors.cs @@ -228,19 +228,11 @@ namespace MCGalaxy { Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (!p.HasCpeExt(CpeExt.TextColors)) continue; - SendSetTextColor(p, col); + p.Send(Packet.SetTextColor(col)); } SaveExtColors(); } - - internal static void SendSetTextColor(Player p, CustomColor col) { - byte[] buffer = new byte[6]; - buffer[0] = Opcode.CpeSetTextColor; - buffer[1] = col.R; buffer[2] = col.G; buffer[3] = col.B; buffer[4] = col.A; - buffer[5] = (byte)col.Code; - p.Send(buffer); - } - + internal static void SaveExtColors() { using (StreamWriter w = new StreamWriter(Paths.CustomColorsFile)) { foreach (CustomColor col in ExtColors) { diff --git a/MCGalaxy/Chat/ProfanityFilter.cs b/MCGalaxy/Chat/ProfanityFilter.cs index 139cd906c..06eda56a3 100644 --- a/MCGalaxy/Chat/ProfanityFilter.cs +++ b/MCGalaxy/Chat/ProfanityFilter.cs @@ -66,15 +66,15 @@ namespace MCGalaxy { } static void LoadBadWords() { - if (!File.Exists("text/badwords.txt")) { + if (!File.Exists(Paths.BadWordsFile)) { // No file exists yet, so let's create one StringBuilder sb = new StringBuilder(); sb.AppendLine("# This file contains a list of bad words to remove via the profanity filter"); sb.AppendLine("# Each bad word should be on a new line all by itself"); - File.WriteAllText("text/badwords.txt", sb.ToString()); + File.WriteAllText(Paths.BadWordsFile, sb.ToString()); } - string[] lines = File.ReadAllLines("text/badwords.txt"); + string[] lines = File.ReadAllLines(Paths.BadWordsFile); // Run the badwords through the reducer to ensure things like Ls become Is and everything is lowercase filters = new List(); foreach (string line in lines) { diff --git a/MCGalaxy/Network/Packets/Packet.CPE.cs b/MCGalaxy/Network/Packets/Packet.CPE.cs index 14f05e87f..686f6762c 100644 --- a/MCGalaxy/Network/Packets/Packet.CPE.cs +++ b/MCGalaxy/Network/Packets/Packet.CPE.cs @@ -53,7 +53,7 @@ namespace MCGalaxy { } public static byte[] TextHotKey(string label, string input, int keycode, - byte mods, bool hasCP437) { + byte mods, bool hasCP437) { byte[] buffer = new byte[134]; buffer[0] = Opcode.CpeSetTextHotkey; NetUtils.Write(label, buffer, 1, hasCP437); @@ -62,8 +62,8 @@ namespace MCGalaxy { buffer[133] = mods; return buffer; } - - public static byte[] ExtAddEntity(byte id, string name, string displayname, bool hasCP437) { + + public static byte[] ExtAddEntity(byte id, string name, string displayname, bool hasCP437) { byte[] buffer = new byte[130]; buffer[0] = Opcode.CpeExtAddEntity; buffer[1] = id; @@ -73,7 +73,7 @@ namespace MCGalaxy { } public static byte[] ExtAddPlayerName(byte id, string listName, string displayName, - string grp, byte grpRank, bool hasCP437) { + string grp, byte grpRank, bool hasCP437) { byte[] buffer = new byte[196]; buffer[0] = Opcode.CpeExtAddPlayerName; NetUtils.WriteI16(id, buffer, 1); @@ -151,7 +151,7 @@ namespace MCGalaxy { } public static byte[] MapAppearance(string url, byte side, byte edge, int sideLevel, - bool hasCP437) { + bool hasCP437) { byte[] buffer = new byte[69]; WriteMapAppearance(buffer, url, side, edge, sideLevel, hasCP437); return buffer; @@ -167,7 +167,7 @@ namespace MCGalaxy { } static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge, - int sideLevel, bool hasCP437) { + int sideLevel, bool hasCP437) { buffer[0] = Opcode.CpeEnvSetMapApperance; NetUtils.Write(url, buffer, 1, hasCP437); buffer[65] = side; @@ -210,6 +210,14 @@ namespace MCGalaxy { buffer[137] = roty; return buffer; } + + public static byte[] SetTextColor(CustomColor col) { + byte[] buffer = new byte[6]; + buffer[0] = Opcode.CpeSetTextColor; + buffer[1] = col.R; buffer[2] = col.G; buffer[3] = col.B; buffer[4] = col.A; + buffer[5] = (byte)col.Code; + return buffer; + } public static byte[] EnvMapUrl(string url, bool hasCP437) { diff --git a/MCGalaxy/Player/Player.CPE.cs b/MCGalaxy/Player/Player.CPE.cs index 1ba578d44..c0a715070 100644 --- a/MCGalaxy/Player/Player.CPE.cs +++ b/MCGalaxy/Player/Player.CPE.cs @@ -82,8 +82,9 @@ namespace MCGalaxy { for (int i = 0; i < Colors.ExtColors.Length; i++) { if (Colors.ExtColors[i].Undefined) continue; - Colors.SendSetTextColor(this, Colors.ExtColors[i]); - } break; + Send(Packet.SetTextColor(Colors.ExtColors[i])); + } + break; case CpeExt.BulkBlockUpdate: BulkBlockUpdate = version; break; case CpeExt.EnvMapAspect: diff --git a/MCGalaxy/util/IO/Paths.cs b/MCGalaxy/util/IO/Paths.cs index 552aeae91..085e8b5b8 100644 --- a/MCGalaxy/util/IO/Paths.cs +++ b/MCGalaxy/util/IO/Paths.cs @@ -16,9 +16,6 @@ permissions and limitations under the Licenses. */ using System; -using System.Collections.Generic; -using System.IO; -using System.Text; namespace MCGalaxy { @@ -29,5 +26,9 @@ namespace MCGalaxy { public const string BlockPermsFile = "properties/block.properties"; public const string TempRanksFile = "text/tempranks.txt"; + + public const string CustomTokensFile = "text/custom$s.txt"; + + public const string BadWordsFile = "text/badwords.txt"; } }