/// <summary> /// Timers the elapsed. /// </summary> /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param> /// <returns>Task.</returns> private async Task _timer_Elapsed(ElapsedEventArgs e) { await Task.Run(async() => { if (_settings.Update.AnnounceTwitch) { _twitchMessageService.SendMessage(_twitchMessages.TwitchServerUptimeMessage.Replace("@hours", _settings.General.RestartServerAfterHours.ToString())); } if (_settings.Update.AnnounceTwitch) { await _discordMessageService.SendMessage(_discordMessages.DiscordServerUptimeMessage.Replace("@hours", _settings.General.RestartServerAfterHours.ToString())); } if (_settings.Update.AnnounceRCon) { await _rconMessageService.SendMessage(_rconMessages.RconServerUptimeMessage.Replace("@hours", _settings.General.RestartServerAfterHours.ToString())); } await Task.Delay(TimeSpan.FromMinutes(5)); await _steamCmdService.KillAtlas(); if (_settings.Update.AnnounceTwitch) { _twitchMessageService.SendMessage(_twitchMessages.TwitchServerRestartingMessage); } if (_settings.Update.AnnounceTwitch) { await _discordMessageService.SendMessage(_discordMessages.DiscordServerRestartingMessage); } _steamCmdService.StartAtlasServer(); }); }
/// <summary> /// Timers the elapsed. /// </summary> /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param> /// <returns>Task.</returns> private async Task _timer_Elapsed(System.Timers.ElapsedEventArgs e) { _checkGameRunningTimer?.Dispose(); if (!_steamCmdService.IsSteamCmdInstalled()) { _logger.LogError("Could not find SteamCMD - we need it to perform the update. Aborting"); return; } _logger.LogInformation("Performing Update Check"); (bool Result, string Version)updateCheck = await _steamCmdService.DetectUpdate(); if (updateCheck.Result) { if (_settings.Update.AnnounceTwitch) { string twitchMessage = _twitchMessages.TwitchUpdateMessage.Replace("@version", $"{updateCheck.Version}").Replace(AnnounceBefore, $"{_settings.Update.AnnounceMinutesBefore}{MinutesPluralisation()}"); _twitchMessageService.SendMessage(twitchMessage); } if (_settings.Update.AnnounceTwitch) { string discordMessage = _discordMessages.DiscordUpdateMessage.Replace("@version", $"{updateCheck.Version}").Replace(AnnounceBefore, $"{_settings.Update.AnnounceMinutesBefore}{MinutesPluralisation()}"); await _discordMessageService.SendMessage(discordMessage); } if (_settings.Update.AnnounceRCon) { string rconMessage = _rconMessages.RconUpdateMessage.Replace("@version", $"{updateCheck.Version}").Replace(AnnounceBefore, $"{_settings.Update.AnnounceMinutesBefore}{MinutesPluralisation()}"); await _rconMessageService.SendMessage(rconMessage); } await Task.Delay(TimeSpan.FromMinutes(_settings.Update.AnnounceMinutesBefore)); _logger.LogInformation("Updating..."); bool updateResult = await _steamCmdService.KillAtlas(); if (!updateResult) { _logger.LogInformation("Update process has failed to stop the running server."); return; } _steamCmdService.InstallAndUpdateAtlasServer(); bool result = _steamCmdService.StartAtlasServer(); if (result) { if (_settings.Update.AnnounceTwitch) { _twitchMessageService.SendMessage(_twitchMessages.TwitchServerRestartingMessage); } if (_settings.Update.AnnounceTwitch) { await _discordMessageService.SendMessage(_discordMessages.DiscordServerRestartingMessage); } } _logger.LogInformation("Server Has Started Back Up."); } if (_settings.General.ShouldRestartAtlasOnNotRunning) { SetupServerProcessMonitor(); } }