Unity (C#) SDK — Players

Player Management

Methods for player registration, authentication, and lifecycle management

RegisterPlayer

public Task<PlayerRegisterResponse> RegisterPlayer<T>(string name, T playerData = null, CancellationToken ct = default)

Registers a new player with optional custom data. Uses generic type for player data with JsonUtility serialization.

RegisterPlayerWithSteam

public static Task<PlayerRegisterResponse> RegisterPlayerWithSteam<T>(Client client, string steamTicket, string steamIdentity = null, string name = null, T playerData = null, string playerToken = null, bool restore = false, CancellationToken ct = default)

Registers or logs in a player via a hex-encoded Steam auth ticket from ISteamUser::GetAuthTicketForWebApi. Requires Steam enabled for the project in the API cabinet. The ticket is single-use — request a fresh one for every login. First call creates the account; afterwards it signs the player in by SteamID. Response includes steam_id.

// Hex-encode the ticket bytes from GetAuthTicketForWebApi
var reg = await Players.RegisterPlayerWithSteam<PlayerData>(client, ticketHex, "michitai");
playerToken = reg.private_key;

RegisterPlayerWithGoogle

public static Task<PlayerRegisterResponse> RegisterPlayerWithGoogle<T>(Client client, string googleAuthCode, string googleIntegrityToken = null, string name = null, T playerData = null, string playerToken = null, bool restore = false, CancellationToken ct = default)

Registers or logs in via a Google Play Games server auth code. Pass restore: true only after the player explicitly confirms a deletion-restore prompt; the fresh provider credential can recover the account even after a reinstall.

AuthenticatePlayer

public Task<PlayerAuthResponse<T>> AuthenticatePlayer<T>(string playerToken, CancellationToken ct = default)

Authenticates a player using their private token. Returns player information with typed data support.

SendPlayerHeartbeatAsync

public Task<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(string playerToken, CancellationToken ct = default)

Sends a heartbeat to maintain the player's connection. Call every 30-60 seconds to prevent timeout.

LogoutPlayerAsync

public Task<PlayerLogoutResponse> LogoutPlayerAsync(string playerToken, CancellationToken ct = default)

Logs out the current player and invalidates their session. Updates last logout timestamp.

GetAllPlayers

public Task<PlayerListResponse> GetAllPlayers(CancellationToken ct = default)

Lists all registered players. Requires private API token. Useful for admin dashboards.

RenamePlayerAsync

public Task<PlayerRenameResponse> RenamePlayerAsync(string playerToken, string newName, CancellationToken ct = default)

Renames a player to a new name. Validates name length (2-50 characters) and requires player authentication.

DeleteAccountAsync

public static Task<PlayerDeleteResponse> DeleteAccountAsync(Client client, string playerToken, CancellationToken ct = default)

Schedules player-initiated account deletion. The account freezes immediately and is purged after the 30-day grace window unless restored. Keep the player credential during the window; the response includes deletion_pending and purge_after.

RestoreAccountAsync

public static Task<PlayerRestoreResponse> RestoreAccountAsync(Client client, string playerToken, CancellationToken ct = default)

Cancels a pending deletion. This must be an explicit player action, never an automatic login or background retry. Provider-linked accounts can also restore after reinstall by signing in with the provider and restore set after confirmation.

BanPlayerAsync

public Task<PlayerBanResponse> BanPlayerAsync(int playerId, EBanTime banDuration, string banReason = null, CancellationToken ct = default)

Bans a player from the game with specified duration (Hour, Day, Week, Month, Quarter, Year, Forever) and optional reason. Requires private API token.

UnbanPlayerAsync

public Task<PlayerUnbanResponse> UnbanPlayerAsync(int playerId, CancellationToken ct = default)

Unbans a previously banned player. Requires private API token.

IsBanned

public static bool IsBanned(ApiResponse response)

Checks if an API response indicates the player is banned. Returns true if the error message contains "You are banned".

Sessions, tokens and name rules

Register creates the player and returns the token your game stores and presents as X-Game-Player-Token. Login re-opens the session on a later run; heartbeat keeps the player marked online while they play; logout ends the session cleanly. Rotate issues a fresh credential and invalidates the old one — call it any time a token may have leaked.

Registration and rename validate the display name server-side against your game's name rules — allowed scripts, case policy and symbols, edited in the cabinet — plus the profanity screen. A rejected name comes back as a fielded error you can show the player instead of guessing why it failed.

  • Players register with just a display name — identity is the returned token, so store it like a credential.
  • Admin calls — list, ban and unban — use the API token pair. Never ship the private token in a client build.
  • Each player also carries a JSON data record — stats, loadouts, progression — that leaderboards rank server-side.
  • SDK methods are async Tasks — await them inside your own async methods, or continue on the main thread when the result touches scene objects. The managed HttpClient transport works in both Mono and IL2CPP builds.