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.
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.
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.
static PlayerListResponse getAllPlayers(Client& client)
Retrieves a list of all players (requires private API token).
static PlayerHeartbeatResponse sendPlayerHeartbeat(
Client& client,
const std::string& playerToken
)
Updates player heartbeat to maintain online status.
static PlayerLogoutResponse logoutPlayer(
Client& client,
const std::string& playerToken
)
Logs out a player and updates their last logout timestamp.
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.
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.
static PlayerUnbanResponse unbanPlayer(
Client& client,
int playerId
)
Unbans a previously banned player. Requires private API token.
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".
template<typename T = nlohmann::json>
static GameDataResponse<T> getGameData(Client& client)
Retrieves global game data with nlohmann::json compatible nested objects.
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.
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.
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.
static ServerTimeResponse getServerTime(Client& client)
Retrieves current server time in multiple formats including UTC timestamp.
static ServerTimeWithOffsetResponse getServerTimeWithOffset(
Client& client,
int utcOffset
)
Retrieves server time with specified UTC offset adjustment.
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.
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).
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.
static RoomLeaveResponse leaveRoom(
Client& client,
const std::string& playerToken
)
Leaves the current game room.
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.
static HeartbeatResponse sendRoomHeartbeat(
Client& client,
const std::string& playerToken
)
Sends heartbeat to maintain connection in game room.
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.
static SuccessResponse stopRoom(
Client& client,
const std::string& playerToken
)
Stops the current game room (Host Only). Completely removes the room and all associated data.
static RoomKickResponse kickPlayer(
Client& client,
const std::string& playerToken,
int playerId
)
Kicks a player from the game room (Host Only). Cannot kick yourself.
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.
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.
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.
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.
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.
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.
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.
static TokenResponse getToken(
Client& client,
const std::string& playerToken
)
Static method to generate a realtime authentication token using the API client.
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).
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).
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.
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.
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).
static MatchmakingLeaveResponse leaveMatchmaking(
Client& client,
const std::string& playerToken
)
Leaves the current matchmaking lobby.
template<typename T = nlohmann::json>
static MatchmakingPlayersResponse<T> getMatchmakingPlayers(
Client& client,
const std::string& playerToken
)
Gets all players in the current matchmaking lobby.
static MatchmakingHeartbeatResponse sendMatchmakingHeartbeat(
Client& client,
const std::string& playerToken
)
Sends heartbeat to maintain connection in matchmaking lobby.
static MatchmakingRemoveResponse removeMatchmakingLobby(
Client& client,
const std::string& playerToken
)
Removes the matchmaking lobby (host only).
static MatchmakingStartResponse startGameFromMatchmaking(
Client& client,
const std::string& playerToken
)
Starts a game from matchmaking lobby (host only).
static SuccessResponse stopMatchmaking(
Client& client,
const std::string& playerToken
)
Stops matchmaking lobby (Host Only). Cannot be called after game has started.
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.
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.
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
}