-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.cs
82 lines (68 loc) · 3.73 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Net;
using LanPlayServer.Stats;
using LanPlayServer.Utils;
using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading;
namespace LanPlayServer
{
static class Program
{
private static readonly IPAddress Host = IPAddress.Parse(Environment.GetEnvironmentVariable("LDN_HOST") ?? "0.0.0.0");
private static readonly int Port = int.Parse(Environment.GetEnvironmentVariable("LDN_PORT") ?? "30456");
private static readonly string GamelistPath = Environment.GetEnvironmentVariable("LDN_GAMELIST_PATH") ?? "gamelist.json";
private static readonly string RedisSocketPath = Environment.GetEnvironmentVariable("LDN_REDIS_SOCKET") ?? "";
private static readonly string RedisHost = Environment.GetEnvironmentVariable("LDN_REDIS_HOST") ?? "127.0.0.1";
private static readonly int RedisPort = int.Parse(Environment.GetEnvironmentVariable("LDN_REDIS_PORT") ?? "6379");
private static readonly ManualResetEventSlim StopEvent = new();
private static LdnServer _ldnServer;
static void Main()
{
Console.CancelKeyPress += (_, _) => StopEvent.Set();
PosixSignalRegistration.Create(PosixSignal.SIGINT, _ => StopEvent.Set());
PosixSignalRegistration.Create(PosixSignal.SIGHUP, _ => StopEvent.Set());
PosixSignalRegistration.Create(PosixSignal.SIGQUIT, _ => StopEvent.Set());
PosixSignalRegistration.Create(PosixSignal.SIGTERM, _ => StopEvent.Set());
Console.WriteLine();
Console.WriteLine( "__________ __ .__ .____ .___ ");
Console.WriteLine(@"\______ \ ___.__. __ __ |__||__| ____ ___ ___ | | __| _/ ____ ");
Console.WriteLine(@" | _/< | || | \ | || | / \ \ \/ / | | / __ | / \ ");
Console.WriteLine(@" | | \ \___ || | / | || || | \ > < | |___ / /_/ | | | \");
Console.WriteLine(@" |____|_ / / ____||____/ /\__| ||__||___| //__/\_ \ |_______ \\____ | |___| /");
Console.WriteLine(@" \/ \/ \______| \/ \/ \/ \/ \/ ");
Console.WriteLine();
Console.WriteLine( "_________________________________________________________________________________");
Console.WriteLine();
Console.WriteLine("- Information");
Console.Write($"\tReading '{GamelistPath}'...");
GameList.Initialize(File.ReadAllText(GamelistPath));
Console.WriteLine(" Done!");
_ldnServer = new(Host, Port);
Console.Write($"\tLdnServer (port: {Port}) starting...");
_ldnServer.Start();
Console.WriteLine(" Done!");
bool usingUnixSocket = !string.IsNullOrWhiteSpace(RedisSocketPath);
EndPoint redisEndpoint;
if (usingUnixSocket)
{
redisEndpoint = new UnixDomainSocketEndPoint(RedisSocketPath);
}
else
{
if (!IPAddress.TryParse(RedisHost, out IPAddress ipAddress))
{
ipAddress = Dns.GetHostEntry(RedisHost!).AddressList[0];
}
redisEndpoint = new IPEndPoint(ipAddress, RedisPort);
}
Console.Write($"\tRedis analytics starting (using unix socket: {usingUnixSocket})...");
StatsDumper.Start(redisEndpoint);
Console.WriteLine(" Done!");
StopEvent.Wait();
StatsDumper.Stop();
_ldnServer.Dispose();
}
}
}