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;
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;

View File

@ -16,7 +16,7 @@
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,38 +31,46 @@ 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);
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 (!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);
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) {

View File

@ -14,7 +14,7 @@
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"; } }
@ -24,22 +24,17 @@ namespace MCGalaxy.Commands.Building {
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");
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);
}
else
{
Help(p); return;
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; }
@ -48,23 +43,18 @@ namespace MCGalaxy.Commands.Building {
|| 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.modeType == b)
{
Player.Message(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &cOFF");
if (p.modeType == b) {
Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize());
p.modeType = 0;
}
else
{
} 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");
}
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 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)]