Skip to main content

Overview

The Match class is the central data model that orchestrates all match-related data, including teams, players, rounds, timeouts, and event processing. Each match instance represents a single game session and manages the lifecycle from match start to completion.

Match Class

export class Match {
  // Identification
  public matchId: string = "";
  public groupCode: string;
  public groupSecret: string;
  public organizationId: string = "";
  public isRegistered: boolean = false;
  
  // Match State
  public isRunning: boolean = false;
  public roundNumber: number = 0;
  public roundPhase: string = "LOBBY";
  public eventNumber: number = 1;
  
  // Teams and Players
  private teams: Team[] = [];
  private map: string = "Loading";
  
  // Game Configuration
  private matchType: "bomb" | "swift" | string = "bomb";
  private switchRound: number = 13;
  private firstOtRound: number = 25;
  
  // Round State
  private roundTimeoutTime?: number;
  private wasTimeout: boolean = false;
  private agentSelectStartTime?: number;
  
  // Spike State
  private spikeState: SpikeStates;
  private spikeDetonationTime?: number;
  private attackersWon: boolean = false;
  
  // Timeout Management
  private timeoutState: TimeoutStates;
  private timeoutEndTimeout: any;
  private timeoutRemainingLoop: any;
  private timeoutGracePeriodPassed: boolean = false;
  
  // Tools and Configuration
  private tools: ToolsData;
  private showAliveKDA: boolean = false;
  
  // Replay and Logging
  private replayLog: ReplayLogging;
  private hasEnteredOvertime: boolean = false;
  private orgIsSupporter: boolean = false;
}

Properties

matchId
string
Unique identifier for the match received from the game client.
groupCode
string
Unique code that identifies the match session for client connections.
groupSecret
string
12-character alphanumeric secret for secure match access. Auto-generated.
isRunning
boolean
default:"false"
Indicates whether the match is currently active.
roundNumber
number
default:"0"
Current round number (1-indexed).
roundPhase
string
default:"LOBBY"
Current phase of the round.
eventNumber
number
default:"1"
Incremental counter for tracking events throughout the match.
teams
Team[]
Array containing exactly two team instances (left and right).
map
string
default:"Loading"
Current map name (translated from internal names).
matchType
string
default:"bomb"
Game mode type.

Constructor

constructor(data: IAuthenticationData)
Initializes a new match with authentication data from the observer client.
data
IAuthenticationData
required
Authentication payload containing:

Core Methods

receiveMatchSpecificData

async receiveMatchSpecificData(data: IAuthedData | IAuthedAuxData): Promise<void>
Processes incoming event data from observer and auxiliary clients. This is the primary data ingestion method.
data
IAuthedData | IAuthedAuxData
required
Authenticated event data with type discriminator.
Behavior:
  • Routes data to appropriate team/player instances
  • Updates match state based on event type
  • Increments eventNumber after processing
  • Writes all events to replay log
  • Manages database sync for registered matches

setAuxDisconnected

public setAuxDisconnected(playerId: string): void
Marks auxiliary data sources as disconnected for a specific player.

State Interfaces

SpikeStates

export interface SpikeStates {
  planted: boolean;
  detonated: boolean;
  defused: boolean;
}
planted
boolean
Whether the spike has been planted this round.
detonated
boolean
Whether the spike has detonated.
defused
boolean
Whether the spike has been defused.

TimeoutStates

export interface TimeoutStates {
  techPause: boolean;
  leftTeam: boolean;
  rightTeam: boolean;
  timeRemaining: number;
}
techPause
boolean
Whether a technical pause is active (not team-initiated).
leftTeam
boolean
Whether the left team has an active timeout.
rightTeam
boolean
Whether the right team has an active timeout.
timeRemaining
number
Seconds remaining in the current timeout.

Lifecycle Events

Match Start

When MATCH_START is received:
  1. Sets isRunning = true
  2. Stores the match ID
  3. Registers with database (if backend enabled)
  4. Initializes stats tracking (for supporters)

Round Transitions

On shopping phase:
  1. Processes previous round results
  2. Resets spike states
  3. Handles side switches (round 13 and OT rounds)
  4. Grants overtime timeouts
  5. Updates database

Match End

When game_end is received:
  1. Sets isRunning = false
  2. Clears timeout timers
  3. Removes match from controller
  4. Completes database record
  5. Triggers stats processing (for supporters)

Example Usage

// Match is created on authentication
const authData: IAuthenticationData = {
  type: DataTypes.AUTH,
  clientVersion: "1.0.0",
  obsName: "Observer1",
  key: "auth-key",
  groupCode: "ABC123",
  leftTeam: {
    name: "Team Alpha",
    tricode: "ALP",
    url: "https://example.com/alpha.png",
    attackStart: true
  },
  rightTeam: {
    name: "Team Beta",
    tricode: "BTA",
    url: "https://example.com/beta.png",
    attackStart: false
  },
  toolsData: new ToolsData()
};

const match = new Match(authData);

// Process incoming events
await match.receiveMatchSpecificData({
  obsName: "Observer1",
  groupCode: "ABC123",
  type: DataTypes.MATCH_START,
  timestamp: Date.now(),
  data: "match-uuid-12345"
});

await match.receiveMatchSpecificData({
  obsName: "Observer1",
  groupCode: "ABC123",
  type: DataTypes.ROUND_INFO,
  timestamp: Date.now(),
  data: {
    roundNumber: 1,
    roundPhase: "shopping"
  }
});

Internal Mechanisms

Build docs developers (and LLMs) love