diff --git a/PugSharp.Match/Match.cs b/PugSharp.Match/Match.cs index 6cff0201..7b17d4bd 100644 --- a/PugSharp.Match/Match.cs +++ b/PugSharp.Match/Match.cs @@ -514,41 +514,51 @@ private void TryCompleteMatch() private async Task CompleteMatchAsync() { - _CsServer.StopDemoRecording(); + try + { + _CsServer.StopDemoRecording(); - var delay = 15; + var delay = 15; - if (_CsServer.GetConvar("tv_enable") || _CsServer.GetConvar("tv_enable1")) - { - // TV Delay in s - var tvDelaySeconds = Math.Max(_CsServer.GetConvar("tv_delay"), _CsServer.GetConvar("tv_delay1")); - _Logger.LogInformation("Waiting for sourceTV. Delay: {delay}s + 15s", tvDelaySeconds); - delay += tvDelaySeconds; - } + if (_CsServer.GetConvar("tv_enable") || _CsServer.GetConvar("tv_enable1")) + { + // TV Delay in s + var tvDelaySeconds = Math.Max(_CsServer.GetConvar("tv_delay"), _CsServer.GetConvar("tv_delay1")); + _Logger.LogInformation("Waiting for sourceTV. Delay: {delay}s + 15s", tvDelaySeconds); + delay += tvDelaySeconds; + } - var seriesResultParams = new SeriesResultParams(MatchInfo.Config.MatchId, MatchInfo.MatchMaps.GroupBy(x => x.Winner).MaxBy(x => x.Count())!.Key!.TeamConfig.Name, Forfeit: true, (uint)delay * 1100, MatchInfo.MatchMaps.Count(x => x.Team1Points > x.Team2Points), MatchInfo.MatchMaps.Count(x => x.Team2Points > x.Team1Points)); - var finalize = _ApiProvider.FinalizeAsync(seriesResultParams, CancellationToken.None); + var seriesResultParams = new SeriesResultParams(MatchInfo.Config.MatchId, MatchInfo.MatchMaps.GroupBy(x => x.Winner).MaxBy(x => x.Count())!.Key!.TeamConfig.Name, Forfeit: true, (uint)delay * 1100, MatchInfo.MatchMaps.Count(x => x.Team1Points > x.Team2Points), MatchInfo.MatchMaps.Count(x => x.Team2Points > x.Team1Points)); + var finalize = _ApiProvider.FinalizeAsync(seriesResultParams, CancellationToken.None); - while (delay > 0) - { - _Logger.LogInformation("Waiting for sourceTV. Remaining Delay: {delay}s", delay); - var delayLoopTime = Math.Min(_TimeBetweenDelayMessages, delay); - await Task.Delay(TimeSpan.FromSeconds(delayLoopTime)).ConfigureAwait(false); - delay -= delayLoopTime; - } + while (delay > 0) + { + _Logger.LogInformation("Waiting for sourceTV. Remaining Delay: {delay}s", delay); + var delayLoopTime = Math.Min(_TimeBetweenDelayMessages, delay); + await Task.Delay(TimeSpan.FromSeconds(delayLoopTime)).ConfigureAwait(false); + delay -= delayLoopTime; + } - await finalize.ConfigureAwait(false); + await finalize.ConfigureAwait(false); - if (_DemoUploader != null) - { - await _DemoUploader.UploadDemoAsync(MatchInfo.DemoFile, CancellationToken.None).ConfigureAwait(false); - } + if (_DemoUploader != null) + { + await _DemoUploader.UploadDemoAsync(MatchInfo.DemoFile, CancellationToken.None).ConfigureAwait(false); + } - DoForAll(AllMatchPlayers.ToList(), p => p.Player.Kick()); + DoForAll(AllMatchPlayers.ToList(), p => p.Player.Kick()); - await _ApiProvider.FreeServerAsync(CancellationToken.None).ConfigureAwait(false); + await _ApiProvider.FreeServerAsync(CancellationToken.None).ConfigureAwait(false); - MatchFinalized?.Invoke(this, new MatchFinalizedEventArgs()); + } + catch (Exception ex) + { + _Logger.LogError(ex, "Unexpected error during finalize."); + } + finally + { + MatchFinalized?.Invoke(this, new MatchFinalizedEventArgs()); + } } private void MatchLive()