From c6d79ac32dc852f3328c5cf27b48ab4caa40a501 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 23 Jun 2016 19:53:41 +1000 Subject: [PATCH] Cleanup /shutdown. --- Commands/Chat/CmdInbox.cs | 2 +- Commands/Moderation/CmdShutdown.cs | 104 ++++++++++++++++------------- Commands/building/CmdMode.cs | 102 +++++++++++++--------------- Server/Server.cs | 3 +- 4 files changed, 104 insertions(+), 107 deletions(-) diff --git a/Commands/Chat/CmdInbox.cs b/Commands/Chat/CmdInbox.cs index 76733d291..15ec2bd44 100644 --- a/Commands/Chat/CmdInbox.cs +++ b/Commands/Chat/CmdInbox.cs @@ -44,8 +44,8 @@ namespace MCGalaxy.Commands { int i = 0; foreach (DataRow row in Inbox.Rows) { Player.Message(p, "{0}: From &5{1} %Sat &a{2}:", i, row["PlayerFrom"], row["TimeSent"]); i++; - Player.Message(p, row["Contents"].ToString()); } + Player.Message(p, "Use %T/inbox [number] %Sto read the contents of that message."); } } else if (parts[0] == "del" || parts[0] == "delete") { int num = -1; diff --git a/Commands/Moderation/CmdShutdown.cs b/Commands/Moderation/CmdShutdown.cs index 64e81105f..98a071fcc 100644 --- a/Commands/Moderation/CmdShutdown.cs +++ b/Commands/Moderation/CmdShutdown.cs @@ -1,22 +1,22 @@ /* - Copyright 2011 MCForge - - Written by jordanneil23 with alot of help from TheMusiKid. - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ + Copyright 2011 MCForge + + Written by jordanneil23 with alot of help from TheMusiKid. + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ using System; using System.IO; using System.Threading; @@ -31,43 +31,51 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { int secTime = 10; - bool shutdown = true; - string file = "stopShutdown"; - if (File.Exists(file)) { File.Delete(file); } - if (message == "") { message = "Server is going to shutdown in " + secTime + " seconds"; } - else - { - if (message == "cancel") { File.Create(file).Close(); shutdown = false; message = "Shutdown cancelled"; } - else - { - if (!message.StartsWith("0")) - { - string[] split = message.Split(' '); - bool isNumber = false; - try { secTime = Convert.ToInt32(split[0]); isNumber = true; } - catch { secTime = 10; isNumber = false; } - if (split.Length > 1) { if (isNumber) { message = message.Substring(1 + split[0].Length); } } - } - else { Player.Message(p, "Countdown time cannot be zero"); return; } + bool shutdown = message != "cancel"; + Server.abortShutdown = false; + + if (message == "") { + message = "Server is going to shutdown in " + secTime + " seconds"; + } else if (message == "cancel") { + Server.abortShutdown = true; message = "Shutdown cancelled"; + } else { + string[] args = message.SplitSpaces(2); + if (int.TryParse(args[0], out secTime)) { + message = args.Length > 1 ? args[1] : message; + } else { + secTime = 10; } } - if (shutdown) - { - Player.GlobalMessage("%4" + message); - Server.s.Log(message); - for (int t = secTime; t > 0; t = t - 1) - { - if (!File.Exists(file)) { Player.GlobalMessage("%4Server shutdown in " + t + " seconds"); Server.s.Log("Server shutdown in " + t + " seconds"); Thread.Sleep(1000); } - else { File.Delete(file); Player.GlobalMessage("Shutdown cancelled"); Server.s.Log("Shutdown cancelled"); return; } + + if (secTime <= 0) { + Player.Message(p, "Countdown time must be greater than zero"); return; + } + if (!shutdown) return; + + Log(message); + for (int t = secTime; t > 0; t--) { + if (!Server.abortShutdown) { + Log("Server shutdown in " + t + " seconds"); Thread.Sleep(1000); + } else { + Server.abortShutdown = false; Log("Shutdown cancelled"); return; } - if (!File.Exists(file)) { MCGalaxy.Gui.App.ExitProgram(false); return; } - else { File.Delete(file); Player.GlobalMessage("Shutdown cancelled"); Server.s.Log("Shutdown cancelled"); return; } + } + + if (!Server.abortShutdown) { + MCGalaxy.Gui.App.ExitProgram(false); + } else { + Server.abortShutdown = false; Log("Shutdown cancelled"); } } - public override void Help(Player p) { + static void Log(string message) { + Player.GlobalMessage("&4" + message); + Server.s.Log(message); + } + + public override void Help(Player p) { Player.Message(p, "%T/shutdown [time] [message]"); - Player.Message(p, "%HShuts the server down"); + Player.Message(p, "%HShuts the server down"); } } } diff --git a/Commands/building/CmdMode.cs b/Commands/building/CmdMode.cs index da2bc4c38..5a5844fdf 100644 --- a/Commands/building/CmdMode.cs +++ b/Commands/building/CmdMode.cs @@ -14,64 +14,54 @@ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. -*/ + */ namespace MCGalaxy.Commands.Building { - public sealed class CmdMode : Command { - public override string name { get { return "mode"; } } - public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Building; } } - public override bool museumUsable { get { return false; } } - public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public CmdMode() { } + public sealed class CmdMode : Command { + public override string name { get { return "mode"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Building; } } + public override bool museumUsable { get { return false; } } + public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } + public CmdMode() { } - public override void Use(Player p, string message) - { - if (message == "") - { - if (p.modeType != 0) - { - Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &cOFF"); - p.modeType = 0; - } - else - { - Help(p); return; - } - } - else - { - byte b = Block.Byte(message); - if (b == Block.Zero) { Player.Message(p, "Could not find block given."); return; } - if (b == Block.air) { Player.Message(p, "Cannot use Air Mode."); return; } + public override void Use(Player p, string message) { + if (message == "") { + if (p.modeType != 0) { + Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize()); + p.modeType = 0; + } else { + Help(p); + } + return; + } + + byte b = Block.Byte(message); + if (b == Block.Zero) { Player.Message(p, "Could not find block given."); return; } + if (b == Block.air) { Player.Message(p, "Cannot use Air Mode."); return; } - if (!p.allowTnt && (b == Block.tnt || b == Block.bigtnt || b == Block.smalltnt - || b == Block.nuketnt || b == Block.tntexplosion)) { - Player.Message(p, "Tnt usage is not allowed at the moment"); return; - } + if (!p.allowTnt && (b == Block.tnt || b == Block.bigtnt || b == Block.smalltnt + || b == Block.nuketnt || b == Block.tntexplosion)) { + Player.Message(p, "Tnt usage is not allowed at the moment"); return; + } + if (!p.allowTnt && b == Block.fire) { + Player.Message(p, "Tnt usage is not allowed at the moment, fire is a lighter for tnt and is also disabled"); return; + } + + if (!Block.canPlace(p, b)) { Player.Message(p, "Cannot place this block at your rank."); return; } - if (!p.allowTnt && b == Block.fire) { - Player.Message(p, "Tnt usage is not allowed at the moment, fire is a lighter for tnt and is also disabled"); return; - } - - if (!Block.canPlace(p, b)) { Player.Message(p, "Cannot place this block at your rank."); return; } - - if (p.modeType == b) - { - Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &cOFF"); - p.modeType = 0; - } - else - { - p.modeType = b; - Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &aON"); - } - } - } - - public override void Help(Player p) { - Player.Message(p, "%T/mode [block]"); - Player.Message(p, "%HMakes every block placed into [block]."); - Player.Message(p, "%H/[block] also works"); - } - } + if (p.modeType == b) { + Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize()); + p.modeType = 0; + } else { + p.modeType = b; + Player.Message(p, "&b{0} %Smode: &aON", Block.Name(p.modeType).Capitalize()); + } + } + + public override void Help(Player p) { + Player.Message(p, "%T/mode [block]"); + Player.Message(p, "%HMakes every block placed into [block]."); + Player.Message(p, "%H/[block] also works"); + } + } } diff --git a/Server/Server.cs b/Server/Server.cs index 3d99497e3..74e50f352 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -365,8 +365,7 @@ namespace MCGalaxy public static bool flipHead = false; - public static bool shuttingDown = false; - public static bool restarting = false; + public static bool shuttingDown = false, restarting = false, abortShutdown = false; //hackrank stuff [ConfigBool("kick-on-hackrank", "Other", null, true)]