-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (72 loc) · 2.52 KB
/
Copy pathProgram.cs
File metadata and controls
86 lines (72 loc) · 2.52 KB
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
83
84
85
86
using NLog;
using NLog.Layouts;
namespace ZamboniDedicated;
internal static class Program
{
private static LogLevel _loglevel = LogLevel.Info;
private const int DefaultTicksPerSecond = 30;
private const int DefaultMaxClients = 12;
private const int DefaultPort = 6767;
static void Main(string[] args)
{
var port = DefaultPort;
var ticksPerSecond = DefaultTicksPerSecond;
var maxClients = DefaultMaxClients;
if (args.Length > 0)
{
if (!int.TryParse(args[0], out ticksPerSecond) || ticksPerSecond <= 0)
{
Console.WriteLine($"ERROR: tick rate must be a positive number, got '{args[0]}'");
return;
}
}
if (args.Length > 1)
{
if (!int.TryParse(args[1], out maxClients) || maxClients <= 0)
{
Console.WriteLine($"ERROR: max players must be a positive number, got '{args[1]}'");
return;
}
}
if (args.Length > 2)
{
if (!int.TryParse(args[2], out port) || port is < 1 or > 65535)
{
Console.WriteLine($"ERROR: port is not valid, got '{args[2]}'");
return;
}
}
if (args.Length > 3)
{
if (!int.TryParse(args[3], out var intLoglevel) || intLoglevel is < 0 or > 6)
{
Console.WriteLine($"ERROR: LogLevel must be 0-6, got '{args[3]}'");
return;
}
_loglevel = LogLevel.FromOrdinal(intLoglevel);
}
StartLogger();
var server = new Dedicated(ticksPerSecond, maxClients, port);
var shutdownComplete = new ManualResetEventSlim(false);
server.Stopped += _ => shutdownComplete.Set();
server.Start();
Console.CancelKeyPress += (_, e) =>
{
e.Cancel = true;
server.Stop();
};
shutdownComplete.Wait();
Console.WriteLine("Shutting down...");
}
public static void StartLogger()
{
var logLevel = _loglevel;
var layout = new SimpleLayout("[${longdate}][${callsite-filename:includeSourcePath=false}(${callsite-linenumber})][${level:uppercase=true}]: ${message:withexception=true}");
LogManager.Setup().LoadConfiguration(builder =>
{
builder.ForLogger().FilterMinLevel(logLevel)
.WriteToConsole(layout)
.WriteToFile("logs/server-${shortdate}.log", layout);
});
}
}