Game SDKs
Guide version 1.10.0
Rust 1.3.0
Download inspacy-game-sdk-1.3.0.crateSHA-256 · 50e1212c66d7f4c2e8a6ae4375f1582417cc303bd8b363424923150ff0a97dee
Rust 1.2.0
Download inspacy-game-sdk-1.2.0.crateSHA-256 · 3b5e7e1a30315bea1d6ac3b9af7347354c96faae001727c30d83078cc241448f
Rust 1.1.0
Download inspacy-game-sdk-1.1.0.crateSHA-256 · 1d5a2095fe0fadfd2c5906018996b7df59fa78608de31836fa0c3ae7e2f3b397
Function reference
Use Rust 1.88 or newer, Tokio and system TLS on Windows, Linux or macOS. Linux builds use OpenSSL development headers and pkg-config. In a new binary project extract the .crate under vendor, then copy vendor/inspacy-game-sdk-1.1.0/examples/game.rs to src/main.rs. Set INSPACY_ORIGIN and INSPACY_GAME_ID. Login also reads INSPACY_CLIENT_ID and INSPACY_REDIRECT_URI. Open the printed URL and enter the complete callback URL on stdin. Membership reads INSPACY_ACCESS_TOKEN. Integrated packaged launch uses Windows x64.
- GameService::new · GameService::with_timeout
- Create the connection for an API origin. Reuse it when constructing clients for the same store.
- GameOAuth::new · begin · LoginAttempt::authorization_url · complete
- Start sign-in with the game’s public client ID and registered callback. Open the returned URL in the system browser, then give the full callback URL to the same login attempt to get tokens.
- GameOAuth::refresh · revoke
- Request offline access during sign-in if the game needs to renew a session. Refresh using the saved refresh token, keep its replacement in protected storage and revoke a token on sign-out.
- PlayerClient::new · me
- Use the player’s game access token and the game ID. Read the scoped subject, entitlement, owned content and expansions, beta, membership and accumulated seconds.
- PlayerClient::membership
- Read active and the paid-through time for this game. Recheck at expiry before enabling a paid benefit.
- PlayerClient::beta
- Read the beta state, program ID and expiry for this player. Enable beta content only while the decision is active.
- PlayerClient::start · heartbeat · end
- Start one session UUID at sequence 0. Send increasing heartbeats about every 30 seconds and an end event on exit. Retry an uncertain write with the identical session, sequence and event.
- PublisherClient::new · player
- On your backend, use a game-bound publisher key and the subject returned by sign-in or ticket redemption to read that player’s current game access.
- PublisherClient::unlock
- Award a published achievement code on your trusted backend. Use a credential with achievement access. Repeating the same game, subject and code returns the original award time.
- PublisherClient::redeem
- Exchange a single-use packaged-launch ticket on the publisher backend. Read the scoped subject and preview flag. Start a fresh launch after a spent ticket or an uncertain redemption.
- ServerReporter::new · report
- Use the named server’s reporter key. Persist a new, increasing generation on restart and increase sequence for each observation. Report zero players when going offline.
- inspacy_game_sdk::windows::receive
- On Windows, call this at startup with the pinned game ID, trusted store roots and the build’s ownership policy. Read the optional ticket or signed beta decision from the verified launch. Environment delivery uses the registered variable.
- GameService::cancel_on
- Run an SDK operation with a cancellation signal. An interrupted write may have reached the service.
- Error.kind · status · retry_after
- Inspect the error category, HTTP status when available, and retry delay. On rate limiting, wait for the indicated delay. Check the outcome of a write before retrying.
# Cargo.toml
[dependencies]
inspacy-game-sdk = { version = "=1.1.0", path = "vendor/inspacy-game-sdk-1.1.0" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }use inspacy_game_sdk::{GameService, PlayerClient};
use std::{env, error::Error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let store = GameService::new(&env::var("INSPACY_ORIGIN")?)?;
let game = env::var("INSPACY_GAME_ID")?.parse()?;
let player = PlayerClient::new(store, game, &env::var("INSPACY_ACCESS_TOKEN")?)?;
let access = player.me().await?;
println!("entitled={} seconds={}", access.entitled, access.total_seconds);
Ok(())
}Expected result
The player read uses INSPACY_ORIGIN, INSPACY_GAME_ID and INSPACY_ACCESS_TOKEN from a session for this game. Its result describes this player’s entitlement and accumulated playtime. Open the operation topics for write examples.
If something goes wrong
If a player read returns 401 or 403, check the token’s lifetime and that the game ID matches its session. Keep the publisher key on your backend and the reporter key on its named server.
Rust 1.0.0
Download inspacy-game-sdk-1.0.0.crateSHA-256 · 0a799cbf496d2eccb881f66295d1f2aad4798a0c860e5ad9875a15908a56bbdf
Choose a language and run a player example
Use an SDK inside a game or on its server to work with a signed-in player. Pick your language to see the exact functions, installation instructions and examples shipped for that release.
Steps
- Choose a language tab and download the published package. Compare the file’s SHA-256 with the value beside the download, then follow Install the SDK in that tab.
- For your first session, open Sign in a player and follow the callback registration steps. For an existing session, set INSPACY_ORIGIN, INSPACY_GAME_ID and INSPACY_ACCESS_TOKEN to the API origin, numeric game ID and that game’s player token.
- Open Function reference. Run its player read in the project you installed, or run the player example supplied in the archive. Check the entitlement and total seconds for the signed-in player. A new player can have zero seconds.
Example
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_sdk_docs",
"arguments": {}
}
}Expected result
All five language guides offer SDK 1.3.0 with paginated game friends for players and publisher backends.
If something goes wrong
For an unknown selector, return to the published language, version and topic index.
C# function referenceC function referenceC++ function referenceJavaScript function referenceRust function referenceWhich client should make this call?
The runtime has three callers. A player signs in to a particular game. Your backend holds the game’s publisher key. Each dedicated server has a reporter key tied to that server. Use the function reference for the spelling in your language.
- GET /api/store/game-runtime/v1/{gameId}/me
- Player. Read the scoped player identifier (subject), entitlement, content and expansion IDs, beta, membership and total seconds.
- GET /api/store/game-runtime/v1/{gameId}/me/beta
- Player. Read the beta program, current state and expiry after a key is redeemed.
- GET /api/store/game-runtime/v1/{gameId}/me/membership
- Player. Read active, asOf and validUntil before offering a monthly benefit.
- POST /api/store/game-runtime/v1/{gameId}/playtime/{sessionId}/events
- Player. Record start, heartbeat and end for one session. The receipt gives the updated total and identifies preview play.
- GET /api/store/game-access/v1/{gameId}/players/{subject}
- Publisher backend. Look up access for the authenticated player using the game-scoped subject.
- POST /api/store/achievements/v1/unlocks
- Publisher backend. Report an achievement code for a player. A credential may be authorized to report for a delegated expansion.
- POST /api/store/tickets/v1/redeem
- Publisher backend. Redeem the packaged game’s one-use ticket to establish your own session. Inspect the returned game, build, subject and purpose.
- POST /api/store/server-reports/v1/{gameId}/{serverId}
- Dedicated server. Publish its online status, player count and optional capacity. The receipt identifies the generation and sequence accepted.
- GET /api/store/game-runtime/v1/{gameId}/rankings
- Player. List published categories for this game.
- GET /api/store/game-runtime/v1/{gameId}/rankings/{category}/standings
- Player. Page through standings using the returned cursor and read your own rank.
- POST /api/store/rankings/v1/scores
- Publisher backend with score permission. Submit one player’s integer score with its saved request UUID.
- POST /api/moderation/game-reports/v1/{gameId}
- Player. Report another player in this game with a saved request UUID.
- POST /api/moderation/game-reports/v1/{gameId}/server
- Publisher backend with report permission. Submit a game-conduct report and optional evidence.
- GET /api/moderation/game-reports/v1/{gameId}/server/{reportId}
- Publisher backend with report permission. Read the state and outcome of a report submitted by your game.
- POST /api/store/game-bans/v1/{gameId}
- Publisher backend with ban permission. Ban a player from this game with a saved command UUID.
- GET /api/store/game-access/v1/{gameId}/players/{subject}/ban
- Publisher backend. Check the player’s current ban when starting a session and at least every five minutes.
Sign in from a browser or standalone game
Register a public client for this game, then use the player’s system browser and S256 PKCE.
Before you start
- Register the exact HTTPS callback in the game credential settings. For the runnable native sample, register http://127.0.0.1:48241/inspacy/callback and copy the new public client ID.
Steps
- Generate fresh state and a PKCE verifier for each attempt. Open the issuer’s /connect/authorize with response_type=code, scope=openid game.player and the S256 challenge. Browser clients use their own registered HTTPS callback.
- Compare the returned state, then post the code, verifier, client ID and original callback to /connect/token. Send the access token to this game’s runtime /me route. The sample keeps tokens in memory.
- Read expansionGameIds, betaAccess, membership and totalSeconds. A publisher service resolves the pairwise subject for that game. The dedicated server has its own separate reporting credential.
Example
python game-session.py --origin "$INSPACY_API_ORIGIN" --client "$GAME_CLIENT_ID" --game 42Expected result
The response contains this game’s decisions for the signed-in player. An empty collection of expansions is valid.
If something goes wrong
After a callback change, revoked authorization, spent code or mismatched audience, start a new authorization with the current client ID.
Download game-session.pyReport a dedicated server’s status
Players can see the status and current player count of named servers on the game page.
Before you start
- Create an active server record and issue its reporter credential from the game’s settings. Keep the secret on that server.
Steps
- Send an initial observation on startup. Use a persisted increasing generation for each process restart and increase the sequence within that generation.
- Send fresh online observations while running. When possible send one final offline observation. Retry a lost response with the identical generation and sequence.
Example
curl --fail-with-body -X POST "$INSPACY_API_ORIGIN/api/store/server-reports/v1/42/7" -H "X-Api-Key: $SERVER_REPORTER_KEY" -H "Content-Type: application/json" --data '{"generation":1,"sequence":0,"online":true,"players":0,"capacity":24}'Expected result
A fresh online report can show zero players. After 90 seconds without a fresh observation the listing shows a stale status.
If something goes wrong
On 429 honor Retry-After. When a key is rotated, install the replacement on its assigned server.
Submit scores and read standings
List the published categories with a game player session. Set INSPACY_RANKING_CATEGORY to a category code. The standings include the player’s own place, even outside the current page. Private profiles have no public name. A tie shares a rank.
Steps
- In the publisher’s game editor, publish a category and issue a backend credential with score permission.
- Submit a score from the backend example, then use the player example to read the same category.
Example
inspacy docs sdk --language javascript --version 1.3.0 --topic rankings --locale enExpected result
Select your language for its sample commands and function names.
If something goes wrong
On your backend, set INSPACY_PUBLISHER_KEY to a game credential with score permission, INSPACY_SUBJECT to the retail player subject, INSPACY_SCORE to the integer score and INSPACY_REQUEST_ID to a UUID saved with this submission. The receipt gives the best score. Retry a lost response with identical values and UUID. A changed submission under that UUID returns 409.
Report a player
Set INSPACY_REPORTED_SUBJECT to another player’s retail subject for this game and INSPACY_REQUEST_ID to a saved UUID. The game player session identifies the reporter. The receipt gives an opaque report ID and its state. A backend with report permission can also submit evidence and check its own case by INSPACY_REPORT_ID.
Steps
- Sign in through the game client and run the player report example with a second participant’s retail subject.
- For a server-originated case, run the publisher report example with report permission. Save its receipt and request the status with the same game credential.
Example
inspacy docs sdk --language javascript --version 1.3.0 --topic reports --locale enExpected result
Select your language for its sample commands and function names.
If something goes wrong
Set INSPACY_REPORT_REASON to the applicable reason and supply INSPACY_REPORT_EXPLANATION for other. Retry identical inputs after an uncertain response. Respect Retry-After on 429. If the store returns moderation_unavailable, use the support channel in the store.
Manage game bans
Run the publisher example on your server with a game credential that has ban permission. Set INSPACY_SUBJECT, your own INSPACY_BAN_REASON and a saved UUID in INSPACY_COMMAND_ID. The ban applies only to this player in this game. Only Inspacy staff may remove it. Players can contest it through their account.
Steps
- Issue a game credential with ban permission and store it on your backend.
- Run the ban example with your own reason code. Read player-ban again after staff have reviewed a removal request.
Example
inspacy docs sdk --language javascript --version 1.3.0 --topic game-bans --locale enExpected result
Select your language for its sample commands and function names.
If something goes wrong
After a lost reply, repeat the same command with the original ID. Check player-ban when starting each server session and at least every five minutes thereafter. An active ban returns game_banned at store enforcement points. A replay after staff removal returns the removed state.