Overview
TheIAutoRef interface defines the contract for an automated referee bot that manages a specific match lifecycle. This interface is implemented by both the Qualifiers and Elimination stage automations, providing a consistent API for lifecycle management and communication.
Interface Definition
Methods
StartAsync()
Initializes the connection to Bancho and joins the match lobby. Signature:- Loads match data from the database
- Validates referee and team/player information
- Establishes IRC connection to Bancho
- Creates tournament lobby
- Initializes lobby settings
StopAsync()
Gracefully stops the automation, saves the state to the database, and parts the channel. Signature:- Persists match state to database
- Saves picked/banned maps (Elimination) or MP link ID (both)
- Closes the multiplayer lobby with
!mp close - Disconnects from Bancho IRC
SendMessageFromDiscord()
Proxies a message from a Discord channel to the Bancho IRC lobby. Signature:content(string): The raw message content to send to the IRC lobby
- Forwards Discord messages to the active Bancho lobby channel
- Enables bi-directional communication between Discord and IRC
- Used by the Discord bot to relay referee commands and player messages
Implementation Overview
Common Components
BothAutoRefEliminationStage and AutoRefQualifiersStage share the following implementation patterns:
- BanchoSharp Integration: Uses
IBanchoClientfor IRC communication - Database Context: Loads match data via Entity Framework (
ModelsContext) - State Machines: Implement finite state machines to control match flow
- Panic Protocol: Support
!panicand>panic_overfor emergency override - Message Callback: Relay IRC messages to Discord via
Action<string, string>delegate
Constructor Pattern
Both implementations use a consistent constructor:matchId: Database identifier for the match/roomrefDisplayName: Referee’s display name for IRC authenticationmsgCallback: Callback function to relay messages to Discord (matchId, message)
Implementations
AutoRefEliminationStage
Handles Head-to-Head matches with:- Pick/Ban phases
- Best-of-N win conditions
- Tiebreaker enforcement
- Timeout management
- Double ban rounds
AutoRefQualifiersStage
Handles Qualifier lobbies with:- Linear map pool iteration
- Timer-based flow control
- Multi-player room management
- Automatic map progression