From 269897366632132e8a4975a188fe8db8ff1ff39e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 17 Dec 2016 09:54:49 +1100 Subject: [PATCH] Core: Fix global.json.bak never actually being saved. (Thanks CookieNetwork) --- MCGalaxy/Blocks/BlockDefinitions.cs | 6 ++++-- MCGalaxy/Commands/Chat/CmdGlobalCLS.cs | 4 +++- MCGalaxy/Commands/Chat/CmdPlayerCLS.cs | 5 +++-- MCGalaxy/Commands/Moderation/ModActionCmd.cs | 17 +++++++++-------- MCGalaxy/Network/Packet.cs | 9 +++++++++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index fc64cfa0c..264df5d01 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -124,8 +124,10 @@ namespace MCGalaxy { GlobalProps[i] = new BlockProps((byte)i); try { - if (File.Exists(GlobalPath) && File.Exists(GlobalBackupPath)) { - File.Delete(GlobalBackupPath); + if (File.Exists(GlobalPath)) { + if (File.Exists(GlobalBackupPath)) { + File.Delete(GlobalBackupPath); + } File.Copy(GlobalPath, GlobalBackupPath); } } catch (Exception ex) { diff --git a/MCGalaxy/Commands/Chat/CmdGlobalCLS.cs b/MCGalaxy/Commands/Chat/CmdGlobalCLS.cs index 449a5d976..eb97ebb3b 100644 --- a/MCGalaxy/Commands/Chat/CmdGlobalCLS.cs +++ b/MCGalaxy/Commands/Chat/CmdGlobalCLS.cs @@ -26,7 +26,9 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { Player[] players = PlayerInfo.Online.Items; for (int i = 0; i < 20; i++) { - foreach (Player pl in players) pl.SendBlankMessage(); + foreach (Player pl in players) { + pl.Send(Packet.BlankMessage()); + } } Chat.MessageAll("%4Global Chat Cleared."); } diff --git a/MCGalaxy/Commands/Chat/CmdPlayerCLS.cs b/MCGalaxy/Commands/Chat/CmdPlayerCLS.cs index a7ffba949..796190385 100644 --- a/MCGalaxy/Commands/Chat/CmdPlayerCLS.cs +++ b/MCGalaxy/Commands/Chat/CmdPlayerCLS.cs @@ -24,8 +24,9 @@ namespace MCGalaxy.Commands { public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override void Use(Player p, string message) { - for (int i = 0; i < 20; i++) - p.SendBlankMessage(); + for (int i = 0; i < 20; i++) { + p.Send(Packet.BlankMessage()); + } Player.Message(p, "%4Chat cleared."); } diff --git a/MCGalaxy/Commands/Moderation/ModActionCmd.cs b/MCGalaxy/Commands/Moderation/ModActionCmd.cs index 4ac6f1456..1b34257fa 100644 --- a/MCGalaxy/Commands/Moderation/ModActionCmd.cs +++ b/MCGalaxy/Commands/Moderation/ModActionCmd.cs @@ -46,12 +46,12 @@ namespace MCGalaxy.Commands.Moderation { List rules = CP437Reader.ReadAllLines("text/rules.txt"); foreach (string rule in rules) - AddRule(rule, sections); + ParseRule(rule, sections); return sections; } - static void AddRule(string rule, Dictionary sections) { - int num = -1; + static void ParseRule(string rule, Dictionary sections) { + int ruleNum = -1; rule = Colors.StripColors(rule); for (int i = 0; i < rule.Length; i++) { @@ -60,13 +60,14 @@ namespace MCGalaxy.Commands.Moderation { bool isLetter = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); if (!isNumber && !isLetter) continue; // Found start of a word, but didn't find a number - assume this is a non-numbered rule - if (isLetter && num == -1) return; + if (isLetter && ruleNum == -1) return; - if (isNumber) { // 1) Do not do X - if (num == -1) num = 0; - num *= 10; num += (c - '0'); + if (isNumber) { // e.g. line is: 1) Do not do X + if (ruleNum == -1) ruleNum = 0; + ruleNum *= 10; + ruleNum += (c - '0'); } else { - sections[num] = rule.Substring(i); + sections[ruleNum] = rule.Substring(i); return; } } diff --git a/MCGalaxy/Network/Packet.cs b/MCGalaxy/Network/Packet.cs index 6db7531b0..c38b57a4f 100644 --- a/MCGalaxy/Network/Packet.cs +++ b/MCGalaxy/Network/Packet.cs @@ -39,6 +39,15 @@ namespace MCGalaxy { return buffer; } + public static byte[] BlankMessage() { + byte[] buffer = new byte[66]; + buffer[0] = Opcode.Message; + + for (int i = 2; i < buffer.Length; i++) + buffer[i] = (byte)' '; + return buffer; + } + public static byte[] UserType(Player p) { byte[] buffer = new byte[2]; buffer[0] = Opcode.SetPermission;