-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
165 lines (141 loc) · 7.18 KB
/
Program.cs
File metadata and controls
165 lines (141 loc) · 7.18 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Blaze2SDK;
using BlazeCommon;
using NLog;
using NLog.Layouts;
using Tdf;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using Zamboni.Components.Blaze;
using Zamboni.Components.NHL10;
using Zamboni.Api;
namespace Zamboni;
//((ip.src == 127.0.0.1) && (ip.dst == 127.0.0.1)) && tcp.port == 42100 || tcp.port == 13337 || tcp.port == 8999 || tcp.port == 9946 || tcp.port == 17502 || tcp.port == 17501 || tcp.port == 17500 || tcp.port == 17499
// (ip.dst == 192.168.100.178 && ip.src == 192.168.1.79) || (ip.src == 192.168.100.178 && ip.dst == 192.168.1.79)
//tcp.port == 8999 || tcp.port == 9946 || tcp.port == 17502 || tcp.port == 17501 || tcp.port == 17500 || tcp.port == 17499 || udp.port == 8999 || udp.port == 9946 || udp.port == 17502 || udp.port == 17501 || udp.port == 17500 || udp.port == 17499
//tcp.port == 17499 || udp.port == 17499 || tcp.port == 3659|| udp.port == 3659
// tcp.port == 17499 || udp.port == 17499 || tcp.port == 3659 || udp.port == 3659 || tcp.port == 17500 || udp.port == 17500 || tcp.port == 17501 || udp.port == 17501 || tcp.port == 17502 || udp.port == 17502 || tcp.port == 17503 || udp.port == 17503
internal class Program
{
public const string Name = "NHL 10";
public const int RedirectorPort = 42100;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static ZamboniConfig ZamboniConfig;
public static Database Database;
private static readonly string PublicIp = new HttpClient().GetStringAsync("https://checkip.amazonaws.com/").GetAwaiter().GetResult().Trim();
public static string GameServerIp;
private static async Task Main(string[] args)
{
InitConfig();
StartLogger();
InitDatabase();
GameServerIp = ZamboniConfig.GameServerIp.Equals("auto") ? PublicIp : ZamboniConfig.GameServerIp;
var tasks = new List<Task>();
tasks.Add(Task.Run(StartCommandListener));
tasks.Add(StartCoreServer());
tasks.Add(new Api.Api().StartAsync());
if (ZamboniConfig.HostRedirectorInstance) tasks.Add(StartRedirectorServer());
await Task.WhenAll(tasks);
}
private static void StartLogger()
{
var logLevel = LogLevel.FromString(ZamboniConfig.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);
});
}
private static void InitConfig()
{
const string configFile = "zamboni-config.yml";
var deserializer = new DeserializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.Build();
var serializer = new SerializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.Build();
if (!File.Exists(configFile))
{
ZamboniConfig = new ZamboniConfig();
var yaml = serializer.Serialize(ZamboniConfig);
var comments = "# GameServerIp: 'auto' = automatically detect public IP or specify a manual IP address, where GameServer is run on\n" +
"# GameServerPort: Port for GameServer to listen on. (Redirector server lives on " + RedirectorPort + ", clients request there)\n" +
"# LogLevel: Valid values: Trace, Debug, Info, Warn, Error, Fatal, Off.\n" +
"# DatabaseConnectionString: Connection string to PostgreSQL, for saving data. (Not required)\n\n";
File.WriteAllText(configFile, comments + yaml);
Logger.Warn("Config file created: " + configFile);
return;
}
var yamlText = File.ReadAllText(configFile);
ZamboniConfig = deserializer.Deserialize<ZamboniConfig>(yamlText);
}
private static void InitDatabase()
{
Database = new Database();
}
private static async Task StartRedirectorServer()
{
var redirector = Blaze2.CreateBlazeServer("RedirectorServer", new IPEndPoint(IPAddress.Any, RedirectorPort));
redirector.AddComponent<RedirectorComponent>();
await redirector.Start(-1).ConfigureAwait(false);
}
private static async Task StartCoreServer()
{
var tdfFactory = new TdfFactory();
var config = new BlazeServerConfiguration("CoreServer", new IPEndPoint(IPAddress.Any, ZamboniConfig.GameServerPort), tdfFactory.CreateLegacyEncoder(), tdfFactory.CreateLegacyDecoder());
var core = new ZamboniCoreServer(config);
core.AddComponent<UtilComponent>();
core.AddComponent<AuthenticationComponent>();
core.AddComponent<UserSessionsComponent>();
core.AddComponent<MessagingComponent>();
core.AddComponent<CensusDataComponent>();
core.AddComponent<RoomsComponent>();
core.AddComponent<LeagueComponent>();
core.AddComponent<ClubsComponent>();
core.AddComponent<StatsComponent>();
core.AddComponent<GameManager>();
core.AddComponent<GameReportingComponent>();
core.AddComponent<DynamicMessagingComponent>(); // Seems to be NHL10 Specific Components
core.AddComponent<OSDKSettingsComponent>(); // Seems to be NHL10 Specific Components
await core.Start(-1).ConfigureAwait(false);
}
private static void StartCommandListener()
{
Logger.Info("Type 'help' or 'status'.");
while (true)
{
var input = ReadLine.Read();
if (string.IsNullOrWhiteSpace(input))
continue;
switch (input.Trim().ToLowerInvariant())
{
case "help":
Logger.Warn("Available commands: help, status");
break;
case "status":
Logger.Info(Name);
Logger.Info("Server running on ip: " + GameServerIp + " (" + PublicIp + ")");
Logger.Info("GameServerPort port: " + ZamboniConfig.GameServerPort);
Logger.Info("Redirector port: " + RedirectorPort);
Logger.Info("Online Players: " + ServerManager.GetServerPlayers().Count);
foreach (var serverPlayer in ServerManager.GetServerPlayers()) Logger.Info(serverPlayer.UserIdentification.mName);
Logger.Info("Queued Total Players: " + ServerManager.GetQueuedPlayers().Count);
foreach (var queuedPlayer in ServerManager.GetQueuedPlayers()) Logger.Info(queuedPlayer.ServerPlayer.UserIdentification.mName);
Logger.Info("Server Games: " + ServerManager.GetServerGames().Count);
foreach (var serverGame in ServerManager.GetServerGames()) Logger.Info(serverGame);
break;
default:
Logger.Info($"Unknown command: {input}");
break;
}
}
}
}