2021-07-07 13:36:25 +02:00
|
|
|
|
using System;
|
2021-12-10 11:31:36 +01:00
|
|
|
|
using System.Diagnostics;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
using System.IO;
|
2021-12-10 11:31:36 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
namespace RageCoop.Server
|
2021-07-07 13:36:25 +02:00
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2021-12-08 13:45:00 +01:00
|
|
|
|
public static bool ReadyToStop = false;
|
2022-06-22 08:58:36 +08:00
|
|
|
|
public static Core.Logger Logger;
|
2021-07-07 13:36:25 +02:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2022-06-22 08:58:36 +08:00
|
|
|
|
Logger=new Core.Logger()
|
2022-05-31 19:35:01 -08:00
|
|
|
|
{
|
|
|
|
|
LogPath="RageCoop.Server.log",
|
|
|
|
|
UseConsole=true,
|
|
|
|
|
};
|
2021-07-07 13:36:25 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-12-10 11:31:36 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
new Thread(async () =>
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
2022-04-06 02:18:24 +02:00
|
|
|
|
Console.Title = string.Format("RAGECOOP [{0,5:P2}] [{1:F}MB]", await GetCpuUsageForProcess(), Process.GetCurrentProcess().PrivateMemorySize64 * 0.000001);
|
2021-12-10 11:31:36 +01:00
|
|
|
|
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
} while (true);
|
|
|
|
|
}).Start();
|
|
|
|
|
#else
|
2022-04-06 02:18:24 +02:00
|
|
|
|
Console.Title = "RAGECOOP";
|
2021-12-10 11:31:36 +01:00
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
|
2021-12-08 13:45:00 +01:00
|
|
|
|
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.SpecialKey == ConsoleSpecialKey.ControlC)
|
|
|
|
|
{
|
2022-06-22 10:03:45 +08:00
|
|
|
|
if (!ReadyToStop)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
ReadyToStop = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Environment.Exit(1);
|
|
|
|
|
}
|
2021-12-08 13:45:00 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-07 13:36:25 +02:00
|
|
|
|
_ = new Server();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2022-06-21 18:13:30 +08:00
|
|
|
|
Logger.Error(e);
|
|
|
|
|
Logger.Error($"Fatal error occurred, server shutting down.");
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-10 11:31:36 +01:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
private static async Task<double> GetCpuUsageForProcess()
|
|
|
|
|
{
|
|
|
|
|
DateTime startTime = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
TimeSpan startCpuUsage = Process.GetCurrentProcess().TotalProcessorTime;
|
|
|
|
|
await Task.Delay(500);
|
|
|
|
|
|
|
|
|
|
DateTime endTime = DateTime.UtcNow;
|
|
|
|
|
TimeSpan endCpuUsage = Process.GetCurrentProcess().TotalProcessorTime;
|
|
|
|
|
double cpuUsedMs = (endCpuUsage - startCpuUsage).TotalMilliseconds;
|
|
|
|
|
double totalMsPassed = (endTime - startTime).TotalMilliseconds;
|
|
|
|
|
double cpuUsageTotal = cpuUsedMs / (Environment.ProcessorCount * totalMsPassed);
|
|
|
|
|
return cpuUsageTotal * 100;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-07-07 13:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|