Skip to main content

Overview

The IAutoRef 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

namespace ss.Internal.Management.Server.AutoRef;

public interface IAutoRef
{
    Task StartAsync();
    Task StopAsync();
    Task SendMessageFromDiscord(string content);
}

Methods

StartAsync()

Initializes the connection to Bancho and joins the match lobby. Signature:
Task StartAsync()
Behavior:
  • Loads match data from the database
  • Validates referee and team/player information
  • Establishes IRC connection to Bancho
  • Creates tournament lobby
  • Initializes lobby settings
Usage:
var autoRef = new AutoRefEliminationStage(matchId, refName, callback);
await autoRef.StartAsync();

StopAsync()

Gracefully stops the automation, saves the state to the database, and parts the channel. Signature:
Task StopAsync()
Behavior:
  • 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
Usage:
await autoRef.StopAsync();

SendMessageFromDiscord()

Proxies a message from a Discord channel to the Bancho IRC lobby. Signature:
Task SendMessageFromDiscord(string content)
Parameters:
  • content (string): The raw message content to send to the IRC lobby
Behavior:
  • 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
Usage:
await autoRef.SendMessageFromDiscord("!mp settings");

Implementation Overview

Common Components

Both AutoRefEliminationStage and AutoRefQualifiersStage share the following implementation patterns:
  1. BanchoSharp Integration: Uses IBanchoClient for IRC communication
  2. Database Context: Loads match data via Entity Framework (ModelsContext)
  3. State Machines: Implement finite state machines to control match flow
  4. Panic Protocol: Support !panic and >panic_over for emergency override
  5. Message Callback: Relay IRC messages to Discord via Action<string, string> delegate

Constructor Pattern

Both implementations use a consistent constructor:
public AutoRefEliminationStage(
    string matchId, 
    string refDisplayName, 
    Action<string, string> msgCallback)
Parameters:
  • matchId: Database identifier for the match/room
  • refDisplayName: Referee’s display name for IRC authentication
  • msgCallback: 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
See Elimination Automaton for details.

AutoRefQualifiersStage

Handles Qualifier lobbies with:
  • Linear map pool iteration
  • Timer-based flow control
  • Multi-player room management
  • Automatic map progression
See Qualifiers Automaton for details.

Build docs developers (and LLMs) love