Multiplayer API Logo

Multiplayer API

C++ SDK for
Multiplayer Games

C++ SDK

C++ SDK Download

View on GitHub
Repository

C++ API Documentation

Client

Constructor
Client(
    const std::string& apiToken,
    const std::string& apiPrivateToken,
    const std::string& baseUrl = "https://api.michitai.com/api",
    std::shared_ptr<ILogger> logger = nullptr
)

Initializes the SDK with API tokens and optional custom base URL and logger.

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.

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".

Game Data

getGameData
template<typename T = nlohmann::json>
static GameDataResponse<T> getGameData(Client& client)

Retrieves global game data with nlohmann::json compatible nested objects.

updateGameData
template<typename T>
static SuccessResponse updateGameData(Client& client, const T& data)

Updates global game data (requires private API token). Uses template type for type safety.

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

Retrieves a specific player's data using their authentication token with typed support.

updatePlayerData
template<typename T>
static SuccessResponse updatePlayerData(
    Client& client,
    const std::string& playerToken,
    const T& data
)

Updates a specific player's data like level, score, and inventory with template type support.

Time Management

getServerTime
static ServerTimeResponse getServerTime(Client& client)

Retrieves current server time in multiple formats including UTC timestamp.

getServerTimeWithOffset
static ServerTimeWithOffsetResponse getServerTimeWithOffset(
    Client& client,
    int utcOffset
)

Retrieves server time with specified UTC offset adjustment.

Room Management

createRoom
template<typename TPlayerData = nlohmann::json, typename TRules = nlohmann::json>
static RoomCreateResponse createRoom(
    Client& client,
    const std::string& playerToken,
    const std::string& roomName,
    int maxPlayers = 4,
    const std::optional<std::string>& password = std::nullopt,
    bool hostSwitch = false,
    bool canLeaveRoom = true,
    const std::optional<TPlayerData>& playerData = std::nullopt,
    const std::optional<TRules>& rules = std::nullopt
)

Creates a new game room for multiplayer sessions with typed rules support, host switching, and player data. Max players: 2-16.

getRooms
template<typename T = nlohmann::json>
static RoomListResponse<T> getRooms(
    Client& client,
    const std::optional<std::string>& search = std::nullopt,
    const std::optional<int>& limit = std::nullopt
)

Retrieves a list of all available game rooms with typed rules support. Supports search and limit parameters (limit: 1-50).

joinRoom
template<typename T = nlohmann::json>
static RoomJoinResponse joinRoom(
    Client& client,
    const std::string& playerToken,
    const std::string& roomId,
    const std::optional<std::string>& password = std::nullopt,
    const std::optional<T>& playerData = std::nullopt
)

Joins an existing game room with optional password and player data.

leaveRoom
static RoomLeaveResponse leaveRoom(
    Client& client,
    const std::string& playerToken
)

Leaves the current game room.

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

Retrieves a list of all players in the current room.

sendRoomHeartbeat
static HeartbeatResponse sendRoomHeartbeat(
    Client& client,
    const std::string& playerToken
)

Sends heartbeat to maintain connection in game room.

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

Gets comprehensive room state including player lists and pending actions with typed support.

stopRoom
static SuccessResponse stopRoom(
    Client& client,
    const std::string& playerToken
)

Stops the current game room (Host Only). Completely removes the room and all associated data.

kickPlayer
static RoomKickResponse kickPlayer(
    Client& client,
    const std::string& playerToken,
    int playerId
)

Kicks a player from the game room (Host Only). Cannot kick yourself.

updateRoomPassword
static SuccessResponse updateRoomPassword(
    Client& client,
    const std::string& playerToken,
    const std::optional<std::string>& password = std::nullopt
)

Updates the room password (Host Only). Use nullopt to remove password.

Room Actions

submitAction
template<typename T = nlohmann::json>
static ActionSubmitResponse submitAction(
    Client& client,
    const std::string& playerToken,
    const SubmitAction<T>& request
)

Submits a game action to specific targets (host, all, others, or specific players) with typed request data.

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

Polls for completed actions from other players with typed response data.

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

Retrieves a list of pending actions that need to be processed with typed request data.

completeAction
template<typename T = nlohmann::json>
static ActionCompleteResponse completeAction(
    Client& client,
    const std::string& actionId,
    const std::string& playerToken,
    const ActionComplete<T>& request
)

Marks an action as completed with response data using typed ActionComplete parameter.

Room Updates

updatePlayers
template<typename T = nlohmann::json>
static UpdatePlayersResponse updatePlayers(
    Client& client,
    const std::string& playerToken,
    const UpdatePlayers<T>& request
)

Sends updates to specific players or all players in the room with typed data support.

pollUpdates
template<typename T = nlohmann::json>
static PollUpdatesResponse<T> pollUpdates(
    Client& client,
    const std::string& playerToken,
    const PollUpdates& request
)

Polls for updates from specific source players with typed data support. Use PollUpdates request object to specify from_players, from_players_ids, and last_update.

Realtime

getToken (Static)
static TokenResponse getToken(
    Client& client,
    const std::string& playerToken
)

Static method to generate a realtime authentication token using the API client.

buildWebSocketUrl (Static)
static std::string buildWebSocketUrl(
    const RealtimeServerInfo& serverInfo,
    const std::string& token,
    const std::string& clientType = "json"
)

Constructs a WebSocket URL from server info and token. Full WebSocket implementation requires additional dependencies (e.g., websocketpp, uWebSockets).

Matchmaking

getMatchmakingLobbies
template<typename T = nlohmann::json>
static MatchmakingListResponse<T> getMatchmakingLobbies(
    Client& client,
    const std::optional<std::string>& search = std::nullopt,
    const std::optional<int>& limit = std::nullopt
)

Lists all available matchmaking lobbies with typed rules support. Supports search and limit parameters (limit: 1-50).

createMatchmakingLobby
template<typename TPlayerData = nlohmann::json, typename TRules = nlohmann::json>
static MatchmakingCreateResponse createMatchmakingLobby(
    Client& client,
    const std::string& playerToken,
    const std::string& matchmakingName,
    int maxPlayers = 4,
    bool strictFull = false,
    bool joinByRequests = false,
    bool hostSwitch = false,
    bool canLeaveRoom = true,
    bool realtimeRoom = false,
    const std::optional<std::string>& password = std::nullopt,
    const std::optional<TPlayerData>& playerData = std::nullopt,
    const std::optional<TRules>& rules = std::nullopt
)

Creates a new matchmaking lobby with name, optional password, typed rules support, host switching, and player data. Max players: 2-16.

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

Gets the current player's matchmaking status and lobby information with typed rules.

joinMatchmakingDirectly
template<typename T = nlohmann::json>
static MatchmakingDirectJoinResponse joinMatchmakingDirectly(
    Client& client,
    const std::string& playerToken,
    const std::string& matchmakingId,
    const std::optional<T>& playerData = std::nullopt
)

Joins a matchmaking lobby directly (only works if lobby doesn't require approval).

leaveMatchmaking
static MatchmakingLeaveResponse leaveMatchmaking(
    Client& client,
    const std::string& playerToken
)

Leaves the current matchmaking lobby.

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

Gets all players in the current matchmaking lobby.

sendMatchmakingHeartbeat
static MatchmakingHeartbeatResponse sendMatchmakingHeartbeat(
    Client& client,
    const std::string& playerToken
)

Sends heartbeat to maintain connection in matchmaking lobby.

removeMatchmakingLobby
static MatchmakingRemoveResponse removeMatchmakingLobby(
    Client& client,
    const std::string& playerToken
)

Removes the matchmaking lobby (host only).

startGameFromMatchmaking
static MatchmakingStartResponse startGameFromMatchmaking(
    Client& client,
    const std::string& playerToken
)

Starts a game from matchmaking lobby (host only).

stopMatchmaking
static SuccessResponse stopMatchmaking(
    Client& client,
    const std::string& playerToken
)

Stops matchmaking lobby (Host Only). Cannot be called after game has started.

kickPlayer
static MatchmakingKickResponse kickPlayer(
    Client& client,
    const std::string& playerToken,
    int playerId
)

Kicks a player from matchmaking lobby (Host Only). Cannot kick yourself or after matchmaking has started.

updateMatchmakingPassword
static SuccessResponse updateMatchmakingPassword(
    Client& client,
    const std::string& playerToken,
    const std::optional<std::string>& password = std::nullopt
)

Updates the matchmaking password (Host Only). Cannot change password after matchmaking has started. Use nullopt to remove password.

Leaderboard

getLeaderboard
template<typename T = nlohmann::json>
static LeaderboardResponse<T> getLeaderboard(
    Client& client,
    const std::vector<std::string>& sortBy,
    int limit = 10
)

Gets ranked leaderboard with configurable sorting, limit (1-100), and typed player data support.

Example Usage:

// Sort by level, then score
auto response = Leaderboard::getLeaderboard<PlayerData>(
    client, 
    {"level", "score"}, 
    10
);

for (const auto& entry : response.leaderboard) {
    std::cout << "#" << entry.rank << " - " << entry.playerName << std::endl;
    // Access typed player data: entry.playerData
}