CSGO GSI

Java library for retrieving game state information from Counter-Strike: Global Offensive

License

License

GroupId

GroupId

uk.oczadly.karl
ArtifactId

ArtifactId

csgo-gsi
Last Version

Last Version

1.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

CSGO GSI
Java library for retrieving game state information from Counter-Strike: Global Offensive
Project URL

Project URL

https://github.com/koczadly/csgo-gsi
Source Code Management

Source Code Management

http://github.com/koczadly/csgo-gsi/tree/master

Download csgo-gsi

How to add to project

<!-- https://jarcasting.com/artifacts/uk.oczadly.karl/csgo-gsi/ -->
<dependency>
    <groupId>uk.oczadly.karl</groupId>
    <artifactId>csgo-gsi</artifactId>
    <version>1.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/uk.oczadly.karl/csgo-gsi/
implementation 'uk.oczadly.karl:csgo-gsi:1.6.0'
// https://jarcasting.com/artifacts/uk.oczadly.karl/csgo-gsi/
implementation ("uk.oczadly.karl:csgo-gsi:1.6.0")
'uk.oczadly.karl:csgo-gsi:jar:1.6.0'
<dependency org="uk.oczadly.karl" name="csgo-gsi" rev="1.6.0">
  <artifact name="csgo-gsi" type="jar" />
</dependency>
@Grapes(
@Grab(group='uk.oczadly.karl', module='csgo-gsi', version='1.6.0')
)
libraryDependencies += "uk.oczadly.karl" % "csgo-gsi" % "1.6.0"
[uk.oczadly.karl/csgo-gsi "1.6.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.code.gson : gson jar 2.8.6
org.slf4j : slf4j-api jar 1.7.30
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

CSGO-GSI

About

A Java library for retrieving real-time game information and statistics from Counter-Strike: Global Offensive using the built-in game state integration service.

Features

This library provides access to 3 main features:

  • Automated location of the game's installation directory
  • The creation and deletion of game state service configurations
  • A server which listens for updates and parses the game state data

Usage

Maven

This project is hosted on Maven Central. To import this library, add the following dependency into your pom.xml:

<dependency>
    <groupId>uk.oczadly.karl</groupId>
    <artifactId>csgo-gsi</artifactId>
    <version>1.6.0</version>
</dependency>

Documentation

The latest Javadoc pages can be viewed online through Javadoc.io.

Configuration generation

Creating the game state configuration file for the game client is an easy and automated process. This can be accomplished using the provided GSIConfig class. The example below demonstrates how to use this utility:

// Build the configuration for our service
GSIConfig config = new GSIConfig()
        .setLocalURI(1337)  // Server on localhost:1337
        .setTimeoutPeriod(1.0)
        .setBufferPeriod(0.5)
        .withAuthToken("password", "Q79v5tcxVQ8u")
        .withAllDataComponents();  // Or specify which using withDataComponents(...)

try {
    // Automatically locates the game directory and creates the configuration file
    Path output = config.writeFile("test_service");
    System.out.println("Written config file: " + output);
} catch (GameNotFoundException e) {
    // Either CSGO or Steam installation directory could not be located
    System.err.println("Couldn't locate CSGO installation: " + e.getMessage());
} catch (IOException e) {
    System.err.println("Couldn't write to configuration file.");
}
Click to view data written to the file gamestate_integration_test_service.cfg
"Sample test service" {
    "uri"     "http://localhost:1337"
    "timeout" "1.0"
    "buffer"  "0.5"
    "auth" {
        "password" "Q79v5tcxVQ8u"
    }
    "data" {
        "map_round_wins"         "1"
        "map"                    "1"
        "player_id"              "1"
        "player_match_stats"     "1"
        "player_state"           "1"
        "player_weapons"         "1"
        "player_position"        "1"
        "provider"               "1"
        "round"                  "1"
        "allgrenades"            "1"
        "allplayers_id"          "1"
        "allplayers_match_stats" "1"
        "allplayers_position"    "1"
        "allplayers_state"       "1"
        "allplayers_weapons"     "1"
        "bomb"                   "1"
        "phase_countdowns"       "1"
    }
}

Listening for state information

To listen for new game state information, a GSIServer object must be created, and an instance which implements GSIListener must be registered to the server object. The example below demonstrates a basic listener which prints the client's Steam ID and current map name (if in a game) to the console.

// Create a new listener (using a lambda for this example)
GSIListener listener = (state, context) -> {
    // Access state information with the 'state' object...
    System.out.println("New state from game client address " + context.getAddress().getHostAddress());
    
    state.getProvider().ifPresent(provider -> {
        System.out.println("Client SteamID: " + provider.getClientSteamId());
    });
    state.getMap().ifPresent(map -> {
        System.out.println("Current map: " + map.getName());
    });
};

// Configure server
GSIServer server = new GSIServer.Builder(1337)        // Port 1337, on all network interfaces
        .requireAuthToken("password", "Q79v5tcxVQ8u") // Require the specified password
        .registerListener(listener)                   // Alternatively, you can call this dynamically on the GSIServer
        .build();

// Start server
try {
    server.start(); // Start the server (runs in a separate thread)
    System.out.println("Server started. Listening for state data...");
} catch (IOException e) {
    System.err.println("Couldn't start server.");
}

Accessing the diagnostics page

If not disabled (using the GSIServer builder), you can access the server as a standard webpage, revealing information about the server and the game state information being received.

Sample output screenshot

Development

If you experience a bug or think the library is missing some functionality, please submit an issue or pull request.

Versions

Version
1.6.0
1.5.0
1.4.2
1.4.1
1.4.0
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.0
1.1.1
1.1.0
1.0.4
1.0.3
1.0.2