private async Task InitializeServers() { var config = ConfigHandler.Configuration(); int successServers = 0; Exception lastException = null; async Task Init(ServerConfiguration Conf) { try { // todo: this might not always be an IW4MServer var ServerInstance = _serverInstanceFactory.CreateServer(Conf, this) as IW4MServer; using (LogContext.PushProperty("Server", ServerInstance.ToString())) { _logger.LogInformation("Beginning server communication initialization"); await ServerInstance.Initialize(); _servers.Add(ServerInstance); Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_MONITORING_TEXT"].FormatExt(ServerInstance.Hostname.StripColors())); _logger.LogInformation("Finishing initialization and now monitoring [{server}]", ServerInstance.Hostname, ServerInstance.ToString()); } // add the start event for this server var e = new GameEvent() { Type = EventType.Start, Data = $"{ServerInstance.GameName} started", Owner = ServerInstance }; AddEvent(e); successServers++; } catch (ServerException e) { Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNFIXABLE"].FormatExt($"[{Conf.IPAddress}:{Conf.Port}]")); using (LogContext.PushProperty("Server", $"{Conf.IPAddress}:{Conf.Port}")) { _logger.LogError(e, "Unexpected exception occurred during initialization"); } lastException = e; } } await Task.WhenAll(config.Servers.Select(c => Init(c)).ToArray()); if (successServers == 0) { throw lastException; } if (successServers != config.Servers.Length) { if (!Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_START_WITH_ERRORS"])) { throw lastException; } } }
private async Task InitializeServers() { var config = ConfigHandler.Configuration(); int successServers = 0; Exception lastException = null; async Task Init(ServerConfiguration Conf) { try { // todo: this might not always be an IW4MServer var ServerInstance = _serverInstanceFactory.CreateServer(Conf, this) as IW4MServer; await ServerInstance.Initialize(); _servers.Add(ServerInstance); Logger.WriteVerbose(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_MONITORING_TEXT"].FormatExt(ServerInstance.Hostname)); // add the start event for this server var e = new GameEvent() { Type = GameEvent.EventType.Start, Data = $"{ServerInstance.GameName} started", Owner = ServerInstance }; AddEvent(e); successServers++; } catch (ServerException e) { Logger.WriteError(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_UNFIXABLE"].FormatExt($"[{Conf.IPAddress}:{Conf.Port}]")); if (e.GetType() == typeof(DvarException)) { Logger.WriteDebug($"{e.Message} {(e.GetType() == typeof(DvarException) ? $"({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})" : "")}"); } lastException = e; } } await Task.WhenAll(config.Servers.Select(c => Init(c)).ToArray()); if (successServers == 0) { throw lastException; } if (successServers != config.Servers.Length) { if (!Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_START_WITH_ERRORS"])) { throw lastException; } } }