Overview
AutoRefEliminationStage handles the automated refereeing logic for Elimination/Versus matches. It implements a complex state machine to manage picks, bans, timeouts, and scoring for Best-of-N tournaments.
Namespace: ss.Internal.Management.Server.AutoRef
Class Definition
State Machine
State Enum
State Descriptions
| State | Description |
|---|---|
Idle | System waiting for referee input or configuration |
BanPhaseStart | Determines which team bans first |
WaitingForBanRed | Red team’s turn to ban a map |
WaitingForBanBlue | Blue team’s turn to ban a map |
PickPhaseStart | Determines which team picks first |
SecondBanPhaseStart | Mid-match ban phase (for double ban rounds) |
WaitingForPickRed | Red team’s turn to pick a map |
WaitingForPickBlue | Blue team’s turn to pick a map |
WaitingForStart | Map loaded, waiting for players to ready up |
Playing | Map in progress, waiting for results |
MatchFinished | One team has reached the win condition |
OnTimeout | Tactical timeout active |
MatchOnHold | Panic mode - automation paused |
State Transition Diagram
Key Methods
StartAsync()
Initializes the match and connects to Bancho.- Loads
MatchRoomfrom database bymatchId - Validates referee credentials
- Loads red/blue team information
- Loads round configuration (BestOf, BanRounds, MapPool)
- Connects to Bancho IRC
- Creates tournament lobby
StopAsync()
Saves match state and closes the lobby.MpLinkId: osu! match IDPickedMaps: List of picked maps with team colorsBannedMaps: List of banned maps with team colorsEndTime: UTC timestamp
HandleIrcMessage()
Core event loop that drives the state machine.- Parse IRC messages from BanchoBot and players
- Extract scores using regex:
^(.*) finished playing \(Score: (\d+), - Detect match completion
- Handle
!panicemergency protocol - Process admin commands (prefix:
>) - Drive state transitions via
TryStateChange()
ExecuteAdminCommand()
Processes referee commands.| Command | Syntax | Description |
|---|---|---|
>invite | >invite | Invites both teams to the lobby |
>finish | >finish | Closes the lobby |
>maps | >maps | Shows picks, bans, and available maps |
>setmap | >setmap [slot] | Manually sets a map (requires Idle state) |
>timeout | >timeout | Triggers a referee timeout |
>start | >start | Engages automation |
>stop | >stop | Stops automation |
>firstpick | >firstpick [red/blue] | Sets which team picks first |
>firstban | >firstban [red/blue] | Sets which team bans first |
ProcessFinalScores()
Aggregates player scores and determines the point winner.- Sums scores for each team from
currentMapScoresdictionary - Increments
matchScore[0](red) ormatchScore[1](blue) - Announces winner in lobby
- Displays current match score (e.g., “TeamA 3 - 2 TeamB | Best of 7”)
- Clears score dictionary for next map
IsMapAvailable()
Validates if a map can be picked or banned.- Must exist in the round’s
MapPool - Must not be in
BannedMaps - Must not be in
PickedMaps - Cannot be the Tiebreaker (
TB1)
TryStateChange()
The state machine brain - evaluates current state and transitions.- Ban Phase: Alternates between teams, enforces
BanRoundscount - Pick Phase: Alternates picks, validates map availability
- Stolen Picks: If timer expires, opponent gets to pick
- Double Ban Rounds: Triggers second ban phase after 4 maps (if configured)
- Tiebreaker: Automatically picked when both teams reach match point
- Win Condition: Checks if team reached
(BestOf - 1) / 2 + 1points
Score Processing
The system uses regex to extract scores from BanchoBot messages:Pick/Ban Validation
Players type map slots in chat (e.g.,NM1, HD2):
- State Check: Must be in correct
WaitingForPickRed/BlueorWaitingForBanRed/Blue - Sender Validation: Message must come from the active team’s player
- Map Validation: Checked via
IsMapAvailable() - Add to List: Appended to
pickedMapsorbannedMapswith team color - State Transition: Moves to next phase or opponent’s turn
Timeout System
Players can request timeouts by typing!timeout:
- One timeout per team per match
- Only available during pick/ban/waiting states
- 120-second countdown
- Returns to previous state when countdown finishes
Panic Protocol
Emergency override system: Trigger: Anyone types!panic
>panic_over
Double Ban Rounds
For rounds configured withBanRounds == 2 and BanMode == SpanishShowdown:
- Initial ban phase (2 bans per team)
- Pick phase (4 maps played)
- Second ban phase (2 more bans per team)
- Continue picking remaining maps