Cleanup /shutdown.

This commit is contained in:
UnknownShadow200 2016-06-23 19:53:41 +10:00
parent a890e91d74
commit c6d79ac32d
4 changed files with 104 additions and 107 deletions

View File

@ -44,8 +44,8 @@ namespace MCGalaxy.Commands {
int i = 0; int i = 0;
foreach (DataRow row in Inbox.Rows) { 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, "{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") { } else if (parts[0] == "del" || parts[0] == "delete") {
int num = -1; int num = -1;

View File

@ -16,7 +16,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -31,38 +31,46 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
int secTime = 10; int secTime = 10;
bool shutdown = true; bool shutdown = message != "cancel";
string file = "stopShutdown"; Server.abortShutdown = false;
if (File.Exists(file)) { File.Delete(file); }
if (message == "") { message = "Server is going to shutdown in " + secTime + " seconds"; } if (message == "") {
else message = "Server is going to shutdown in " + secTime + " seconds";
{ } else if (message == "cancel") {
if (message == "cancel") { File.Create(file).Close(); shutdown = false; message = "Shutdown cancelled"; } Server.abortShutdown = true; message = "Shutdown cancelled";
else } else {
{ string[] args = message.SplitSpaces(2);
if (!message.StartsWith("0")) if (int.TryParse(args[0], out secTime)) {
{ message = args.Length > 1 ? args[1] : message;
string[] split = message.Split(' '); } else {
bool isNumber = false; secTime = 10;
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; }
} }
} }
if (shutdown)
{ if (secTime <= 0) {
Player.GlobalMessage("%4" + message); 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 (!Server.abortShutdown) {
MCGalaxy.Gui.App.ExitProgram(false);
} else {
Server.abortShutdown = false; Log("Shutdown cancelled");
}
}
static void Log(string message) {
Player.GlobalMessage("&4" + message);
Server.s.Log(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 (!File.Exists(file)) { MCGalaxy.Gui.App.ExitProgram(false); return; }
else { File.Delete(file); Player.GlobalMessage("Shutdown cancelled"); Server.s.Log("Shutdown cancelled"); return; }
}
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -14,7 +14,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands.Building { namespace MCGalaxy.Commands.Building {
public sealed class CmdMode : Command { public sealed class CmdMode : Command {
public override string name { get { return "mode"; } } public override string name { get { return "mode"; } }
@ -24,22 +24,17 @@ namespace MCGalaxy.Commands.Building {
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdMode() { } public CmdMode() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (message == "") {
if (message == "") if (p.modeType != 0) {
{ Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize());
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; p.modeType = 0;
} else {
Help(p);
} }
else return;
{
Help(p); return;
} }
}
else
{
byte b = Block.Byte(message); byte b = Block.Byte(message);
if (b == Block.Zero) { Player.Message(p, "Could not find block given."); return; } 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 (b == Block.air) { Player.Message(p, "Cannot use Air Mode."); return; }
@ -48,23 +43,18 @@ namespace MCGalaxy.Commands.Building {
|| b == Block.nuketnt || b == Block.tntexplosion)) { || b == Block.nuketnt || b == Block.tntexplosion)) {
Player.Message(p, "Tnt usage is not allowed at the moment"); return; Player.Message(p, "Tnt usage is not allowed at the moment"); return;
} }
if (!p.allowTnt && b == Block.fire) { 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; 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 (!Block.canPlace(p, b)) { Player.Message(p, "Cannot place this block at your rank."); return; }
if (p.modeType == b) if (p.modeType == b) {
{ Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize());
Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &cOFF");
p.modeType = 0; p.modeType = 0;
} } else {
else
{
p.modeType = b; p.modeType = b;
Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &aON"); Player.Message(p, "&b{0} %Smode: &aON", Block.Name(p.modeType).Capitalize());
}
} }
} }

View File

@ -365,8 +365,7 @@ namespace MCGalaxy
public static bool flipHead = false; public static bool flipHead = false;
public static bool shuttingDown = false; public static bool shuttingDown = false, restarting = false, abortShutdown = false;
public static bool restarting = false;
//hackrank stuff //hackrank stuff
[ConfigBool("kick-on-hackrank", "Other", null, true)] [ConfigBool("kick-on-hackrank", "Other", null, true)]