https://github.com/koczadly/csgo-gsi
A Java library for Counter-Strike: Global Offensive's game state integration
https://github.com/koczadly/csgo-gsi
api counter-strike counter-strike-global-offensive csgo game game-state-integration gsi integration java state valve
Last synced: 5 months ago
JSON representation
A Java library for Counter-Strike: Global Offensive's game state integration
- Host: GitHub
- URL: https://github.com/koczadly/csgo-gsi
- Owner: koczadly
- License: mit
- Created: 2019-04-25T17:30:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-27T20:16:49.000Z (about 3 years ago)
- Last Synced: 2025-10-28T04:28:05.767Z (8 months ago)
- Topics: api, counter-strike, counter-strike-global-offensive, csgo, game, game-state-integration, gsi, integration, java, state, valve
- Language: Java
- Homepage:
- Size: 565 KB
- Stars: 32
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```xml
uk.oczadly.karl
csgo-gsi
1.6.0
```
### Documentation
The latest Javadoc pages can be [viewed online through Javadoc.io](https://www.javadoc.io/doc/uk.oczadly.karl/csgo-gsi).
### 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`](https://www.javadoc.io/doc/uk.oczadly.karl/csgo-gsi/latest/uk/oczadly/karl/csgsi/config/GSIConfig.html)
class. The example below demonstrates how to use this utility:
```java
// 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
```text
"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`](https://www.javadoc.io/doc/uk.oczadly.karl/csgo-gsi/latest/uk/oczadly/karl/csgsi/GSIServer.html)
object must be created, and an instance which implements [`GSIListener`](https://www.javadoc.io/doc/uk.oczadly.karl/csgo-gsi/latest/uk/oczadly/karl/csgsi/GSIListener.html)
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.
```java
// 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.