public static void Crash(Exception Ex, bool StopServer = false) { string crash = "<-=================- C R A S H -=================->"; if (Server.Properties.GetProperty("console-colors") == Config.SWITCH_ON) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine(Environment.NewLine + crash); Data.SendToLog("Detected server crash", Data.Log_Critical); Console.WriteLine(" * " + Ex.ToString()); Console.WriteLine(" * Source: " + Ex.Source); Console.WriteLine(crash + Environment.NewLine); if (Server.Properties.GetProperty("console-colors") == Config.SWITCH_ON) { Console.ForegroundColor = ConsoleColor.White; } if (StopServer) { Server.ServerStop(); } if (Server.Properties.GetProperty("save-crashes") == Config.SWITCH_ON) { string dt = DateTime.Now.ToShortDateString().Replace('.', '-') + "_" + DateTime.Now.ToLongTimeString().Replace(':', '-'); File.AppendAllText("crashdump_" + dt + ".txt", Ex.ToString()); } }
public static string HandleCommand(string[] Args, string ownerName = "Console") { events.ConsoleCommandEvent ev = new events.ConsoleCommandEvent(Args); events.Events.CallEvent(ev); if (ev.Cancelled) { return(ev.Metadata); } switch (Args[0]) { case "?": case "help": ShowHelpText(); return(string.Join(", ", HelpCommandLines)); case "exit": Server.Exit(); return(Strings.From("cmd.closing")); case "stop": Server.ServerStop(); return(Strings.From("cmd.closing")); case "resume": Server.ServerResume(); return(Strings.From("cmd.resumed")); case "online": Data.SendToLog("Online: " + Server.GetOnlinePlayers().Length.ToString()); foreach (player.Player p in Server.GetOnlinePlayers()) { Data.SendToLog("- " + p.ToString()); } return(string.Join(", ", Server.GetOnlinePlayersStr())); case "ban": if (Args.Length < 2) { return(Strings.From("cmd.badargument")); } string ValidIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; Regex r = new Regex(ValidIpAddressRegex, RegexOptions.IgnoreCase | RegexOptions.Singleline); if (r.Match(Args[1]).Success) { player.control.Ban.BanIP(Args[1], ownerName); } else { player.control.Ban.BanByName(Args[1], ownerName); } return("ok"); case "pardon": if (Args.Length < 2) { return(Strings.From("cmd.badargument")); } ValidIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; r = new Regex(ValidIpAddressRegex, RegexOptions.IgnoreCase | RegexOptions.Singleline); if (r.Match(Args[1]).Success) { player.control.Ban.PardonIP(Args[1], ownerName); } else { player.control.Ban.PardonByName(Args[1], ownerName); } return("ok"); case "ip": string ip = "(server) " + Server.GetFullAddress(); if (Args.Length > 1 && Server.GetPlayer(Args[1]) != null) { ip = Server.GetPlayer(Args[1]).Connection.Address; } Data.SendToLog("IP = " + ip); return("IP = " + ip); default: Data.SendToLog(Strings.From("command.unknown"), Data.Log_Warning); return(Strings.From("command.unknown")); } }