public HeartBeatAgent(IPEndPoint remote, HeartBeatServer server, GameServerStorage storage, Action disposeServer) { this.remote = remote; this.server = server; this.storage = storage; this.disposeServer = disposeServer; AddedAt = DateTime.UtcNow; Console.WriteLine("Created HeartBeatAgent for {0}", remote); }
static async Task Main(string[] args) { CompositeResolver.RegisterAndSetAsDefault( ImmutableCollectionResolver.Instance, StandardResolver.Instance ); var cts = new CancellationTokenSource(); AssemblyLoadContext.Default.Unloading += ctx => { cts.Cancel(); }; Console.CancelKeyPress += (sender, cce) => { cce.Cancel = true; cts.Cancel(); }; var storageFile = new FileInfo(StorageFilePath); Console.WriteLine("Starting"); using (var gameServerStorage = await ReadGameServerStorage(storageFile, cts.Token)) using (var udpServer = new HeartBeatServer(new IPEndPoint(IPAddress.Any, HeartBeatServerPort), gameServerStorage)) using (var tcpServer = new MasterServer(gameServerStorage)) { udpServer.Listen(); var masterTask = tcpServer.Listen(new IPEndPoint(IPAddress.Any, MasterServerPort), cts.Token); Console.WriteLine("Started"); cts.Token.WaitHandle.WaitOne(); Console.WriteLine("Shutting down"); var saveTask = gameServerStorage.Save(new CancellationTokenSource(500).Token); await Task.WhenAll(masterTask, saveTask); } }