C++ SDK — Players

Player Management

registerPlayer
template<typename T = nlohmann::json>
static PlayerRegisterResponse registerPlayer(
    Client& client,
    const std::string& name,
    const std::optional<T>& playerData = std::nullopt
)

Registers a new player with optional custom data. Uses template type for player data with nlohmann::json serialization.

registerPlayerWithSteam
template<typename T = nlohmann::json>
static PlayerRegisterResponse registerPlayerWithSteam(
    Client& client,
    const std::string& steamTicket,
    const std::optional<std::string>& steamIdentity = std::nullopt,
    const std::optional<std::string>& name = std::nullopt,
    const std::optional<T>& playerData = std::nullopt
)

Registers or logs in a player via a hex-encoded Steam auth ticket from ISteamUser::GetAuthTicketForWebApi (single-use — request a fresh ticket each login). Requires Steam enabled for the project in the API cabinet; the account persists via SteamID.

Mint the ticket with michitai::multiplayer::steam::SteamTicket (Steam/SteamTicket.h) — a thin wrapper over the real Steamworks SDK: steam_api64.lib at link time, steam_api64.dll + steam_appid.txt beside the exe. See the MICHITAI_STEAM demo in examples/Game.cpp.

authenticatePlayer
template<typename T = nlohmann::json>
static PlayerAuthResponse<T> authenticatePlayer(
    Client& client,
    const std::string& playerToken
)

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

getAllPlayers
static PlayerListResponse getAllPlayers(Client& client)

Retrieves a list of all players (requires private API token).

sendPlayerHeartbeat
static PlayerHeartbeatResponse sendPlayerHeartbeat(
    Client& client,
    const std::string& playerToken
)

Updates player heartbeat to maintain online status.

logoutPlayer
static PlayerLogoutResponse logoutPlayer(
    Client& client,
    const std::string& playerToken
)

Logs out a player and updates their last logout timestamp.

renamePlayer
static PlayerRenameResponse renamePlayer(
    Client& client,
    const std::string& playerToken,
    const std::string& newName
)

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

banPlayer
static PlayerBanResponse banPlayer(
    Client& client,
    int playerId,
    EBanTime banDuration,
    const std::optional<std::string>& banReason = std::nullopt
)

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

unbanPlayer
static PlayerUnbanResponse unbanPlayer(
    Client& client,
    int playerId
)

Unbans a previously banned player. Requires private API token.

isBanned
static bool isBanned(const ApiResponse& response)

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