public GameSDK(
string apiToken,
string apiPrivateToken,
string baseUrl = "https://api.michitai.com/api",
ILogger? logger = null
)
Initializes the SDK with API tokens and optional custom base URL.
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 System.Text.Json serialization.
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.
public Task<PlayerListResponse> GetAllPlayers(CancellationToken ct = default)
Retrieves a list of all players (requires private API token).
public Task<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(string playerToken, CancellationToken ct = default)
Updates player heartbeat to maintain online status.
public Task<PlayerLogoutResponse> LogoutPlayerAsync(string playerToken, CancellationToken ct = default)
Logs out a player and updates their last logout timestamp.
public Task<GameDataResponse<T>> GetGameData<T>(CancellationToken ct = default)
Retrieves global game data with System.Text.Json compatible nested objects.
public Task<SuccessResponse> UpdateGameData<T>(T data, CancellationToken ct = default)
Updates global game data (requires private API token). Uses generic type for type safety.
public Task<PlayerDataResponse<T>> GetPlayerData<T>(string playerToken, CancellationToken ct = default)
Retrieves a specific player's data using their authentication token with typed support.
public Task<SuccessResponse> UpdatePlayerData<T>(string playerToken, T data, CancellationToken ct = default)
Updates a specific player's data like level, score, and inventory with generic type support.
public Task<ServerTimeResponse> GetServerTime()
Retrieves current server time in multiple formats including UTC timestamp.
public Task<ServerTimeWithOffsetResponse> GetServerTimeWithOffset(
int utcOffset
)
Retrieves server time with specified UTC offset adjustment.
public Task<RoomCreateResponse> CreateRoomAsync<T>(string gamePlayerToken,
string roomName,
string? password = null,
int maxPlayers = 4,
T? rules = null,
CancellationToken ct = default)
Creates a new game room for multiplayer sessions with typed rules support.
public Task<RoomListResponse<T>> GetRoomsAsync<T>(CancellationToken ct = default)
Retrieves a list of all available game rooms with typed rules support.
public Task<RoomJoinResponse> JoinRoomAsync(
string gamePlayerToken,
string roomId,
string? password = null,
CancellationToken ct = default)
Joins an existing game room with optional password.
public Task<RoomLeaveResponse> LeaveRoomAsync(
string gamePlayerToken,
CancellationToken ct = default)
Leaves the current game room.
public Task<RoomPlayersResponse> GetRoomPlayersAsync(
string gamePlayerToken,
CancellationToken ct = default)
Retrieves a list of all players in the current room.
public Task<HeartbeatResponse> SendHeartbeatAsync(
string gamePlayerToken,
CancellationToken ct = default)
Sends heartbeat to maintain connection in game room.
public Task<CurrentRoomResponse<T>> GetCurrentRoomAsync<T>(
string playerToken,
CancellationToken ct = default)
Gets comprehensive room state including player lists and pending actions with typed support.
public Task<ActionSubmitResponse> SubmitActionAsync<T>(string gamePlayerToken,
string actionType,
T? requestData = null,
CancellationToken ct = default)
Submits a game action for processing by other players with typed request data.
public Task<ActionPollResponse<T>> PollActionsAsync<T>(string gamePlayerToken, CancellationToken ct = default)
Polls for completed actions from other players with typed response data.
public Task<ActionPendingResponse<T>> GetPendingActionsAsync<T>(string gamePlayerToken, CancellationToken ct = default)
Retrieves a list of pending actions that need to be processed with typed request data.
public Task<ActionCompleteResponse> CompleteActionAsync<T>(string actionId,
string gamePlayerToken,
ActionComplete<T> request,
CancellationToken ct = default)
Marks an action as completed with response data using typed ActionComplete parameter.
public Task<UpdatePlayersResponse> UpdatePlayersAsync<T>(string gamePlayerToken,
UpdatePlayers<T> request,
CancellationToken ct = default)
Sends updates to specific players or all players in the room with typed data support.
public Task<PollUpdatesResponse<T>> PollUpdatesAsync<T>(string gamePlayerToken,
string? lastUpdateId = null,
CancellationToken ct = default)
Polls for updates from other players with optional incremental polling and typed data.
public Task<MatchmakingListResponse<T>> GetMatchmakingLobbiesAsync<T>(CancellationToken ct = default)
Lists all available matchmaking lobbies with typed rules support.
public Task<MatchmakingCreateResponse> CreateMatchmakingLobbyAsync<T>(string gamePlayerToken,
int maxPlayers = 4,
bool strictFull = false,
bool joinByRequests = false,
T? rules = null,
CancellationToken ct = default)
Creates a new matchmaking lobby with typed rules support and configurable settings.
public Task<MatchmakingJoinRequestResponse> RequestToJoinMatchmakingAsync(
string gamePlayerToken,
string matchmakingId,
CancellationToken ct = default)
Requests to join a matchmaking lobby that requires host approval.
public Task<MatchmakingPermissionResponse> RespondToJoinRequestAsync(
string gamePlayerToken,
string requestId,
MatchmakingRequestAction action,
CancellationToken ct = default)
Host responds to a join request (approve or reject).
public Task<MatchmakingRequestStatusResponse> CheckJoinRequestStatusAsync(
string gamePlayerToken,
string requestId,
CancellationToken ct = default)
Checks the status of a join request.
public Task<MatchmakingCurrentResponse<T>> GetCurrentMatchmakingStatusAsync<T>(string gamePlayerToken, CancellationToken ct = default)
Gets the current player's matchmaking status and lobby information with typed rules.
public Task<MatchmakingDirectJoinResponse> JoinMatchmakingDirectlyAsync(
string gamePlayerToken,
string matchmakingId,
CancellationToken ct = default)
Joins a matchmaking lobby directly (only works if lobby doesn't require approval).
public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(
string gamePlayerToken,
CancellationToken ct = default)
Leaves the current matchmaking lobby.
public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(
string gamePlayerToken,
CancellationToken ct = default)
Gets all players in the current matchmaking lobby.
public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(
string gamePlayerToken,
CancellationToken ct = default)
Sends heartbeat to maintain connection in matchmaking lobby.
public Task<MatchmakingRemoveResponse> RemoveMatchmakingLobbyAsync(
string gamePlayerToken,
CancellationToken ct = default)
Removes the matchmaking lobby (host only).
public Task<MatchmakingStartResponse> StartGameFromMatchmakingAsync(
string gamePlayerToken,
CancellationToken ct = default)
Starts a game from matchmaking lobby (host only).
public Task<LeaderboardResponse<T>> GetLeaderboardAsync<T>(string[] sortBy, int limit = 10, CancellationToken ct = default)
Gets ranked leaderboard with configurable sorting, limit, and typed player data support.
Example Usage:
// Sort by level, then score
var response = await sdk.GetLeaderboardAsync<PlayerData>(
new[] { "level", "score" },
10
);
foreach (var entry in response.Leaderboard) {
Console.WriteLine($"#{entry.Rank} - {entry.Player_name}");
// Access typed player data: entry.PlayerData
}