64 lines
2.1 KiB
C#
Raw Normal View History

2021-07-07 13:36:25 +02:00
using System;
using System.Diagnostics;
2021-07-07 13:36:25 +02:00
using System.IO;
using System.Threading;
using System.Threading.Tasks;
2022-07-10 16:13:08 +08:00
using RageCoop.Core;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Server
2021-07-07 13:36:25 +02:00
{
class Program
{
2022-06-27 15:35:23 +08:00
private static bool Stopping = false;
2021-07-07 13:36:25 +02:00
static void Main(string[] args)
{
2022-07-10 16:13:08 +08:00
var mainLogger= new Logger()
2022-05-31 19:35:01 -08:00
{
LogPath="RageCoop.Server.log",
UseConsole=true,
2022-07-10 16:13:08 +08:00
Name="Server"
2022-05-31 19:35:01 -08:00
};
2021-07-07 13:36:25 +02:00
try
{
2022-04-06 02:18:24 +02:00
Console.Title = "RAGECOOP";
2022-06-27 15:35:23 +08:00
var setting = Util.Read<ServerSettings>("Settings.xml");
#if DEBUG
setting.LogLevel=0;
#endif
2022-06-27 15:35:23 +08:00
var server = new Server(setting, mainLogger);
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
{
2022-06-27 15:35:23 +08:00
mainLogger.Info("Initiating shutdown sequence...");
mainLogger.Info("Press Ctrl+C again to commence an emergency shutdown.");
if (e.SpecialKey == ConsoleSpecialKey.ControlC)
{
2022-06-27 15:35:23 +08:00
if (!Stopping)
2022-06-22 10:03:45 +08:00
{
e.Cancel = true;
2022-06-27 15:35:23 +08:00
Stopping = true;
server.Stop();
mainLogger.Info("Server stopped.");
mainLogger.Dispose();
Thread.Sleep(3000);
2022-06-22 10:03:45 +08:00
}
else
{
2022-06-27 15:35:23 +08:00
mainLogger.Flush();
2022-06-22 10:03:45 +08:00
Environment.Exit(1);
}
}
};
2022-06-27 15:35:23 +08:00
server.Start();
mainLogger?.Info("Please use CTRL + C if you want to stop the server!");
2021-07-07 13:36:25 +02:00
}
catch (Exception e)
{
mainLogger.Error(e);
mainLogger.Error($"Fatal error occurred, server shutting down.");
2022-06-27 15:35:23 +08:00
mainLogger.Flush();
Thread.Sleep(5000);
Environment.Exit(1);
2021-07-07 13:36:25 +02:00
}
}
}
}