A high-performance Go library for handling Counter-Strike 2 Game State Integration (GSI) with type-safe event handling and real-time game data processing.
- Type-safe Event System: Subscribe to specific game events with compile-time type safety
- Real-time Game Data: Process live game state updates from CS2
- HTTP Server: Built-in HTTP server using Go 1.22+ ServeMux for handling GSI requests
- Comprehensive Game Models: Complete data structures for all CS2 game state information
- Configurable: Customizable server settings, round limits, and logging levels
- Production Ready: Proper error handling, validation, and security measures
go get github.com/nescabir/go-cs2-gsi
package main
import (
"log/slog"
cs2gsi "github.com/nescabir/go-cs2-gsi"
"github.com/nescabir/go-cs2-gsi/models"
)
func main() {
// Create GSI instance with default configuration
gsi := cs2gsi.New(cs2gsi.NewConfig())
// Subscribe to events
cs2gsi.Subscribe(cs2gsi.Mvp, func(event cs2gsi.Event[*models.Player]) {
fmt.Printf("MVP: %s with %d kills (%d HS)\n",
event.Data.Name, event.Data.State.Round_kills, event.Data.State.Round_killhs)
})
cs2gsi.Subscribe(cs2gsi.RoundEnd, func(event cs2gsi.Event[*models.Score]) {
fmt.Printf("Round ended! Winner: %s\n", event.Data.Winner.Name)
})
// Start the server
if err := gsi.Listen(); err != nil {
log.Fatal(err)
}
}
The library provides flexible configuration options:
config := cs2gsi.Config{
ServerAddr: ":3000", // HTTP server address ex: 127.0.0.1:3000, localhost:4242
RegulationMaxRounds: 13, // Max rounds in regulation
OvertimeMaxRounds: 3, // Max rounds in overtime
LogLevel: slog.LevelInfo, // Logging level
}
gsi := cs2gsi.New(config)
The library provides type-safe events for all major game occurrences:
Data
- Raw game state updatesRoundEnd
- Round completion with winner informationMatchEnd
- Match completion
-
Mvp
- MVP player selection -
MIRV needed (Not implemented)
Kill
- Player kills with detailed weapon and damage infoHurt
- Player damage events
FreezetimeStart/End
- Freeze time beginning/endingIntermissionStart/End
- Intermission periodsTimeoutStart/End
- Team timeouts
BombPlantStart/Stop
- Bomb planting initiation/cancellationBombPlanted
- Bomb successfully plantedBombDefused
- Bomb defusedBombExploded
- Bomb explosionDefuseStart/End
- Defuse initiation/completion
-
Copy the configuration template:
Copy the configuration template to your game's cfg folder (
steamapps/common/Counter-Strike Global Offensive/game/core/cfg/
) -
Configure the GSI file:
- Update the
uri
to match your server address - Modify the
token
for authentication (No token validation yet) - Enable/disable specific data feeds as needed
- Update the
-
Start your Go application and launch CS2
The library provides comprehensive data structures for all CS2 game information:
- Steam ID, name, clan, team
- Health, armor, money, equipment
- Position, weapons, match statistics
- Activity status
- Map information and phase
- Round details and outcomes
- Team scores and statistics
- Bomb state and position
- Grenade positions and effects
- Round history and outcomes
- Player damage tracking
- Weapon information and states
- Observer data
// Subscribe to multiple events
cs2gsi.Subscribe(cs2gsi.BombPlanted, func(event cs2gsi.Event[*models.Player]) {
fmt.Printf("Bomb planted by %s at site %s\n",
event.Data.Name,
event.Data.Team.Side)
})
cs2gsi.Subscribe(cs2gsi.Mvp, func(event cs2gsi.Event[*models.Player]) {
fmt.Printf("MVP: %s with %d kills (%d headshots)\n",
event.Data.Name,
event.Data.State.Round_kills,
event.Data.State.Round_killhs)
})
gsi := cs2gsi.New(cs2gsi.Config{
ServerAddr: ":3000",
LogLevel: slog.LevelDebug,
})
if err := gsi.Listen(); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
config := cs2gsi.Config{
ServerAddr: ":8080",
RegulationMaxRounds: 30, // Custom round limit
OvertimeMaxRounds: 6, // Custom overtime limit
LogLevel: slog.LevelWarn,
}
gsi := cs2gsi.New(config)
- Built with Go 1.24+ for optimal performance
- Efficient memory management with pre-allocated slices
- Type-safe event system with minimal overhead
- Concurrent event handling with proper synchronization
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- osztenkurden's NodeJS implementation for the data processing which I heavly relied on
- Valve Corporation for the CS2 Game State Integration API
- The Go community for excellent tooling and libraries
Note: This library requires Counter-Strike 2 to be running with Game State Integration enabled. Make sure to properly configure the GSI file in your CS2 installation.