fix: add state machine validation and fix vote/captain disconnect handling#136
Open
fix: add state machine validation and fix vote/captain disconnect handling#136
Conversation
… disconnect Add allowed-transitions dictionary to MatchManager.UpdateMapStatus so illegal state jumps (e.g. Finished -> Live) are rejected with a warning. Fix CaptainSystem.RemoveCaptain to allow captain removal during knife round in addition to warmup. Replace hardcoded captain vote count of 2 in VoteSystem.CheckVotes with the dynamic expectedVoteCount so a single remaining captain can resolve a vote when the other disconnects. Remove stray extra semicolon in GetExpectedVoteCount.
SendSurrender() in GameEnd.cs calls UpdateMapStatus(Finished) after a surrender, so Surrendered cannot be a terminal state. Without this, the surrender flow silently fails to mark the map as Finished.
When a player disconnects, their vote was persisting in active votes while GetExpectedVoteCount excluded them, causing inconsistent tallies. Now cleans up votes from surrender, pause, resume, and restore systems.
Move the allowed-transition guard above CheckForBackupRestore so illegal transitions are rejected before any side effects run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_allowedTransitionsdictionary toMatchManagerthat defines legaleMapStatustransitions.UpdateMapStatusnow rejects and logs illegal transitions (e.g.Finished -> Live,Paused -> Kniferound skip) instead of silently accepting any status change.CaptainSystem.RemoveCaptaincondition from!match.IsWarmup()to!(match.IsWarmup() || match.IsKnife())so captains can be properly removed/reassigned during the knife round.2inVoteSystem.CheckVotescaptain-only path with the dynamicexpectedVoteCountfromGetExpectedVoteCount(). When a captain disconnects and only 1 remains, a single captain's vote now resolves the vote instead of deadlocking. Also remove a stray extra semicolon inGetExpectedVoteCount.Test plan