fix: require hat select before ready up #1037
Merged
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.
Fixes #963
Changes
PlayerSlot
is now (sort of) a state machine, starting outEmpty
then progressing throughSelectingPlayer
andSelectingHat
until becomingReady
SelectingHat
andReady
states for simplicity<
and>
show around the thing being selected (player/hat), brackets now don't show when ready*.ftl
files so that they are treated as text for diffs and not binary filesRUSTSEC-2024-0370
proc-macro-error is unmaintained (see related bones issue and the advisory)This also fixes a bug I was seeing on
main
where another player in a LAN lobby pressing A/D would behave as if everyone pressed A/D, e.g. pressing D to select the next skin would change to the next skin in both slots.Rationale for the rough state machine:
Previously there were 3 states for a player slot: Empty, SelectingPlayer, and Ready + SelectingHat. This state was maintained by two booleans,
active
andconfirmed
, which tell you whether the slot is not empty and whether the player has readied-up respectively. Together they represent the 3 states as: (active/confirmed
)false/false
,true/false
andtrue/true
; withfalse/true
being an invalid state.Now that there are four states to the ready-up process, one way of implementing this is to add a third boolean, but this introduces 3 more invalid states. Let's say the boolean is called
selectedPlayer
, these are the possible boolean combinations and the states they represent (active/selectedPlayer/confirmed
):The implementation I opted for is a simple state machine. While it added a lot more code to some areas of this module I found it made reasoning about some sections much easier. It also made explicit certain edge cases in the
handle_match_setup_messages
system where e.g the client could theoretically receive a confirmation message from a peer when it had not yet received any player selection messages. A warning log is now generated in the unlikely case this occurs.