public Client(
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<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.
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.
public Task<PlayerUnbanResponse> UnbanPlayerAsync(int playerId, CancellationToken ct = default)
Unbans a previously banned player. Requires private API token.
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".
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,
int maxPlayers = 4,
string? password = null,
bool hostSwitch = false,
bool canLeaveRoom = true,
T? rules = null,
T? playerData = null,
CancellationToken ct = default)
Creates a new game room for multiplayer sessions with typed rules support, host switching, and player data. Max players: 2-16.
public Task<RoomListResponse<T>> GetRoomsAsync<T>(string? search = null, int? limit = null, CancellationToken ct = default)
Retrieves a list of all available game rooms with typed rules support. Supports search and limit parameters (limit: 1-50).
public Task<RoomJoinResponse> JoinRoomAsync(
string gamePlayerToken,
string roomId,
string? password = null,
T? playerData = null,
CancellationToken ct = default)
Joins an existing game room with optional password and player data.
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<SuccessResponse> StopRoomAsync(
string playerToken,
CancellationToken ct = default)
Stops the current game room (Host Only). Completely removes the room and all associated data.
public Task<RoomKickResponse> KickPlayerAsync(
string playerToken,
int playerId,
CancellationToken ct = default)
Kicks a player from the game room (Host Only). Cannot kick yourself.
public Task<SuccessResponse> UpdateRoomPasswordAsync(
string playerToken,
string? password = null,
CancellationToken ct = default)
Updates the room password (Host Only). Use empty string to remove password.
public Task<ActionSubmitResponse> SubmitActionAsync<T>(string playerToken,
SubmitAction<T> request,
CancellationToken ct = default)
Submits a game action to specific targets (host, all, others, or specific 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,
PollUpdates request,
CancellationToken ct = default)
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.
public Realtime(string realtimeWebSocketUrl = "wss://realtime.michitai.com")
Initializes the realtime WebSocket client with optional custom server URL.
public static async Task<TokenResponse> GetTokenAsync(
Client client,
string playerToken
)
Static method to generate a realtime authentication token using the API client.
public async Task<bool> ConnectAsync(string realtimeToken)
Connects to the WebSocket server using the realtime token. Returns true if successful, false if failed.
public async Task SendAsync<T>(
ERoomTargetPlayer target,
string command,
T? data = null,
int[]? targetIds = null
)
Sends a message to specific targets (host, all, others, or specific player IDs) with optional data.
public async Task DisconnectAsync()
Disconnects from the WebSocket server and cleans up resources.
public event Action<string, object, SenderInfo>? OnReceive;
public event Action? OnConnected;
OnReceive: Fired when a message is received from the server. OnConnected: Fired when WebSocket connection is established.
public Task<MatchmakingListResponse<T>> GetMatchmakingLobbiesAsync<T>(string? search = null, int? limit = null, CancellationToken ct = default)
Lists all available matchmaking lobbies with typed rules support. Supports search and limit parameters (limit: 1-50).
public Task<MatchmakingCreateResponse> CreateMatchmakingLobbyAsync<T>(string gamePlayerToken,
string matchmakingName,
int maxPlayers = 4,
bool strictFull = false,
bool joinByRequests = false,
bool hostSwitch = false,
bool canLeaveRoom = true,
string? password = null,
T? rules = null,
T? playerData = null,
CancellationToken ct = default)
Creates a new matchmaking lobby with name, optional password, typed rules support, host switching, and player data. Max players: 2-16.
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<SuccessResponse> StopMatchmakingAsync(
string gamePlayerToken,
CancellationToken ct = default)
Stops matchmaking lobby (Host Only). Cannot be called after game has started.
public Task<MatchmakingKickResponse> KickPlayerAsync(
string playerToken,
int playerId,
CancellationToken ct = default)
Kicks a player from matchmaking lobby (Host Only). Cannot kick yourself or after matchmaking has started.
public Task<SuccessResponse> UpdateMatchmakingPasswordAsync(
string playerToken,
string? password = null,
CancellationToken ct = default)
Updates the matchmaking password (Host Only). Cannot change password after matchmaking has started. Use empty string to remove password.
public Task<LeaderboardResponse<T>> GetLeaderboardAsync<T>(string[] sortBy, int limit = 10, CancellationToken ct = default)
Gets ranked leaderboard with configurable sorting, limit (1-100), 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
}