private static void CloseHandlerInternal() { if (!LocalVars.PrintHelp) { if (GlobalVars.ProcessID != 0) { if (LocalFuncs.ProcessExists(GlobalVars.ProcessID)) { Process proc = Process.GetProcessById(GlobalVars.ProcessID); proc.Kill(); } } if (!LocalVars.OverrideINI) { WriteConfigValues(); } if (GlobalVars.RequestToOutputInfo) { GlobalFuncs.FixedFileDelete(GlobalPaths.BasePath + "\\" + GlobalVars.ServerInfoFileName); } } Environment.Exit(-1); }
public static void Main(string[] args) { _handler += new EventHandler(CloseHandler); SetConsoleCtrlHandler(_handler, true); var config = new NLog.Config.LoggingConfiguration(); var logfile = new NLog.Targets.FileTarget("logfile") { FileName = GlobalPaths.ConfigDir + "\\CMD-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" }; config.AddRuleForAllLevels(logfile); LogManager.Configuration = config; LoadCMDArgs(args); if (!LocalVars.PrintHelp) { GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName, true, GlobalPaths.RootPathLauncher + "\\Novetus.exe"); GlobalFuncs.TurnOffInitialSequence(); Console.Title = "Novetus " + GlobalVars.ProgramInformation.Version + " CMD"; GlobalFuncs.ConsolePrint("NovetusCMD version " + GlobalVars.ProgramInformation.Version + " loaded.", 1); GlobalFuncs.ConsolePrint("Novetus path: " + GlobalPaths.BasePath, 1); GlobalFuncs.ConsolePrint("NovetusCMD is now loading main server configurations from the INI file.", 5); if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName)) { GlobalFuncs.ConsolePrint("WARNING 2 - " + GlobalPaths.ConfigName + " not found. Creating one with default values.", 5); WriteConfigValues(); } ReadConfigValues(true); LoadOverrideINIArgs(args); InitUPnP(); GlobalFuncs.ConsolePrint("Launching a " + GlobalVars.UserConfiguration.SelectedClient + " server on " + GlobalVars.UserConfiguration.Map + " with " + GlobalVars.UserConfiguration.PlayerLimit + " players.", 1); switch (LocalVars.DebugMode) { case true: GlobalFuncs.CreateTXT(); break; case false: default: StartServer(LocalVars.StartInNo3D); break; } } else { LocalFuncs.CommandInfo(); } Console.ReadKey(); }
static void ProgramClose(object sender, EventArgs e) { if (GlobalVars.ProcessID != 0) { if (LocalFuncs.ProcessExists(GlobalVars.ProcessID)) { Process proc = Process.GetProcessById(GlobalVars.ProcessID); proc.Kill(); } } if (!LocalVars.OverrideINI) { WriteConfigValues(); } Application.Exit(); }
public static void Main(string[] args) { var config = new NLog.Config.LoggingConfiguration(); var logfile = new NLog.Targets.FileTarget("logfile") { FileName = GlobalPaths.ConfigDir + "\\CMD-log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".log" }; config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile); LogManager.Configuration = config; //https://stackify.com/csharp-catch-all-exceptions/ AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => { Logger log = LogManager.GetCurrentClassLogger(); log.Error("EXEPTION THROWN: " + (!string.IsNullOrWhiteSpace(eventArgs.Exception.Message) ? eventArgs.Exception.Message : "N/A")); log.Error("EXCEPTION INFO: " + (eventArgs.Exception != null ? eventArgs.Exception.ToString() : "N/A")); log.Error("INNER EXCEPTION: " + (eventArgs.Exception.InnerException != null ? eventArgs.Exception.InnerException.ToString() : "N/A")); log.Error("STACK TRACE: " + (!string.IsNullOrWhiteSpace(eventArgs.Exception.StackTrace) ? eventArgs.Exception.StackTrace : "N/A")); log.Error("TARGET SITE: " + (eventArgs.Exception.TargetSite != null ? eventArgs.Exception.TargetSite.ToString() : "N/A")); log.Error("FOOTPRINTS: " + (!string.IsNullOrWhiteSpace(eventArgs.Exception.GetExceptionFootprints()) ? eventArgs.Exception.GetExceptionFootprints() : "N/A")); }; LoadCMDArgs(args); if (!LocalVars.PrintHelp) { GlobalFuncs.ReadInfoFile(GlobalPaths.ConfigDir + "\\" + GlobalPaths.InfoName, true); Console.Title = "Novetus " + GlobalVars.ProgramInformation.Version + " CMD"; GlobalFuncs.ConsolePrint("NovetusCMD version " + GlobalVars.ProgramInformation.Version + " loaded.", 1); GlobalFuncs.ConsolePrint("Novetus path: " + GlobalPaths.BasePath, 1); GlobalFuncs.ConsolePrint("NovetusCMD is now loading main server configurations from the INI file.", 5); if (!File.Exists(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ConfigName)) { GlobalFuncs.ConsolePrint("WARNING 2 - " + GlobalPaths.ConfigName + " not found. Creating one with default values.", 5); WriteConfigValues(); } ReadConfigValues(true); LoadOverrideINIArgs(args); InitUPnP(); if (GlobalVars.UserConfiguration.WebServer) { StartWebServer(); } AppDomain.CurrentDomain.ProcessExit += new EventHandler(ProgramClose); GlobalFuncs.ConsolePrint("Launching a " + GlobalVars.UserConfiguration.SelectedClient + " server on " + GlobalVars.UserConfiguration.Map + " with " + GlobalVars.UserConfiguration.PlayerLimit + " players.", 1); switch (LocalVars.DebugMode) { case true: GlobalFuncs.CreateTXT(); break; case false: default: StartServer(LocalVars.StartInNo3D); break; } } else { LocalFuncs.CommandInfo(); } Console.ReadKey(); }