diff --git a/src/FiveStack.Events/PlayerDisconnected.cs b/src/FiveStack.Events/PlayerDisconnected.cs index 620848e..f7580a6 100644 --- a/src/FiveStack.Events/PlayerDisconnected.cs +++ b/src/FiveStack.Events/PlayerDisconnected.cs @@ -49,6 +49,11 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo match.captainSystem.RemoveCaptain(@event.Userid); } + _surrenderSystem.surrenderingVote?.RemovePlayerVote(player.SteamID); + _timeoutSystem.pauseVote?.RemovePlayerVote(player.SteamID); + _timeoutSystem.resumeVote?.RemovePlayerVote(player.SteamID); + _gameBackupRounds.restoreRoundVote?.RemovePlayerVote(player.SteamID); + if (match.IsInProgress()) { if (match.IsFreezePeriod()) diff --git a/src/FiveStack.Services/CaptainSystem.cs b/src/FiveStack.Services/CaptainSystem.cs index 5659a89..bdacd84 100644 --- a/src/FiveStack.Services/CaptainSystem.cs +++ b/src/FiveStack.Services/CaptainSystem.cs @@ -75,7 +75,7 @@ public void RemoveCaptain(CCSPlayerController player) if ( match == null - || !match.IsWarmup() + || !(match.IsWarmup() || match.IsKnife()) || team == CsTeam.None || team == CsTeam.Spectator || _captains[team] == null diff --git a/src/FiveStack.Services/MatchManager.cs b/src/FiveStack.Services/MatchManager.cs index 8581dac..fb4b1a5 100644 --- a/src/FiveStack.Services/MatchManager.cs +++ b/src/FiveStack.Services/MatchManager.cs @@ -16,6 +16,76 @@ namespace FiveStack; public class MatchManager { + private static readonly Dictionary> _allowedTransitions = + new() + { + { + eMapStatus.Unknown, + new HashSet + { + eMapStatus.Scheduled, + eMapStatus.Warmup, + eMapStatus.Knife, + eMapStatus.Live, + eMapStatus.Paused, + eMapStatus.Overtime, + eMapStatus.Finished, + eMapStatus.Surrendered, + eMapStatus.UploadingDemo, + } + }, + { eMapStatus.Scheduled, new HashSet { eMapStatus.Warmup } }, + { + eMapStatus.Warmup, + new HashSet + { + eMapStatus.Knife, + eMapStatus.Live, + eMapStatus.Paused, + } + }, + { + eMapStatus.Knife, + new HashSet { eMapStatus.Live, eMapStatus.Paused } + }, + { + eMapStatus.Live, + new HashSet + { + eMapStatus.Paused, + eMapStatus.Finished, + eMapStatus.Overtime, + eMapStatus.Surrendered, + eMapStatus.UploadingDemo, + } + }, + { + eMapStatus.Overtime, + new HashSet + { + eMapStatus.Paused, + eMapStatus.Finished, + eMapStatus.Surrendered, + eMapStatus.UploadingDemo, + } + }, + { + eMapStatus.Paused, + new HashSet + { + eMapStatus.Live, + eMapStatus.Warmup, + eMapStatus.Overtime, + eMapStatus.Knife, + eMapStatus.Finished, + eMapStatus.Surrendered, + } + }, + { eMapStatus.UploadingDemo, new HashSet { eMapStatus.Finished } }, + { eMapStatus.Finished, new HashSet() }, + { eMapStatus.Surrendered, new HashSet { eMapStatus.Finished } }, + }; + private MatchData? _matchData; private eMapStatus _currentMapStatus = eMapStatus.Unknown; private Timer? _resumeMessageTimer; @@ -265,6 +335,18 @@ public void UpdateMapStatus(eMapStatus status, Guid? winningLineupId = null) _logger.LogInformation($"Update Map Status {_currentMapStatus} -> {status}"); + if ( + _currentMapStatus != eMapStatus.Unknown + && _allowedTransitions.TryGetValue(_currentMapStatus, out var allowed) + && !allowed.Contains(status) + ) + { + _logger.LogWarning( + $"Illegal map status transition {_currentMapStatus} -> {status}, ignoring" + ); + return; + } + if (_currentMapStatus == eMapStatus.Unknown) { _backUpManagement.CheckForBackupRestore(); diff --git a/src/FiveStack.Services/VoteSystem.cs b/src/FiveStack.Services/VoteSystem.cs index 68b4175..868de9f 100644 --- a/src/FiveStack.Services/VoteSystem.cs +++ b/src/FiveStack.Services/VoteSystem.cs @@ -319,7 +319,7 @@ private void CheckVotes(bool fail = false) if (IsCaptainVoteOnly()) { - if (_votes.Count < 2) + if (_votes.Count < expectedVoteCount) { if (fail) { @@ -328,7 +328,7 @@ private void CheckVotes(bool fail = false) return; } - if (totalYesVotes >= 2) + if (totalYesVotes >= Math.Ceiling(expectedVoteCount / 2.0)) { VoteSuccess(); return; @@ -367,7 +367,6 @@ private int GetExpectedVoteCount() .Where(player => { return CanVote(player); - ; }) .ToList();