Rust Game Server Client SDK

This is the Rust version of the Agones Game Server Client SDK.

Check the Client SDK Documentation for more details on each of the SDK functions and how to run the SDK locally.

Download

Download the source directly from GitHub .

Prerequisites

  • CMake >= 3.8.0
  • Rust >= 1.19.0
  • Go (>=1.7)

The SDK needs the above for building to gRPC-rs.

Usage

Add this crate to dependencies section in your Cargo.toml. Specify a directory where this README.md is located to the path.

[dependencies]
agones = { path = "../agones/sdks/rust" }

Add extern crate agones to your crate root.

To begin working with the SDK, create an instance of it. This function blocks until connection and handshake are made.

let sdk = agones::Sdk::new()?;

To send a health check ping call sdk.health().

if sdk.health().is_ok() {
    println!("Health ping sent");
}

To mark the game session as ready call sdk.ready().

sdk.ready()?;

To mark the game server as reserved for a period of time, call sdk.reserve(duration).

sdk.reserve(Duration::new(5, 0))?;

To mark that the game session is completed and the game server should be shut down call sdk.shutdown().

if sdk.shutdown().is_err() {
    println!("Could not run Shutdown");
}

To set a Label on the backing GameServer call sdk.set_label(key, value).

sdk.set_label("test-label", "test-value")?;

To set an Annotation on the backing GameServer call sdk.set_annotation(key, value).

sdk.set_annotation("test-annotation", "test value")?;

To get details of the backing GameServer call sdk.get_gameserver().

The function will return an instance of agones::types::GameServer including GameServer configuration info.

let gameserver = sdk.get_gameserver()?;

To get updates on the backing GameServer as they happen, call sdk.watch_gameserver(|gameserver| {...}).

This will call the passed closure synchronously (this is a blocking function, so you may want to run it in its own thread) whenever the backing GameServer is updated.

sdk.watch_gameserver(|gameserver| {
    println!("GameServer Update, name: {}", gameserver.object_meta.unwrap().name);
    println!("GameServer Update, state: {}", gameserver.status.unwrap().state);
})?;

For more information, please read the SDK Overview, check out agones sdk implementation and also look at the Rust example .