Main SDK class for Unity multiplayer functionality
public Client(string apiToken, string apiPrivateToken, string baseUrl = "https://api.michitai.com/api",
ILogger logger = null, HttpClient httpClient = null, bool useUnityFormat = true)
Initializes the SDK with API tokens and optional Unity formatting.
Methods for player registration, authentication, and lifecycle management
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 JsonUtility 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<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(string playerToken, CancellationToken ct = default)
Sends a heartbeat to maintain the player's connection. Call every 30-60 seconds to prevent timeout.
public Task<PlayerLogoutResponse> LogoutPlayerAsync(string playerToken, CancellationToken ct = default)
Logs out the current player and invalidates their session. Updates last logout timestamp.
public Task<PlayerListResponse> GetAllPlayers(CancellationToken ct = default)
Lists all registered players. Requires private API token. Useful for admin dashboards.
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".
Methods for managing global and player-specific game data
public Task<GameDataResponse<T>> GetGameData<T>(CancellationToken ct = default)
Retrieves global game data with generic type support. Data is automatically deserialized using JsonUtility.
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 player-specific data with generic type support. Requires player authentication.
public Task<SuccessResponse> UpdatePlayerData<T>(string playerToken, T data, CancellationToken ct = default)
Updates player-specific data with generic type support. Requires player authentication.
Methods for server time synchronization
public Task<ServerTimeResponse> GetServerTime(CancellationToken ct = default)
Retrieves current server time in UTC and readable formats.
public Task<ServerTimeWithOffsetResponse> GetServerTimeWithOffset(int utcOffset, CancellationToken ct = default)
Retrieves server time with specified UTC offset. Useful for time synchronization.
Methods for creating and managing game rooms
public Task<RoomCreateResponse> CreateRoomAsync<T>(string playerToken, 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 with optional password, host switching, player data and rules. The creating player becomes the host. Max players: 2-16.
public Task<RoomListResponse<T>> GetRoomsAsync<T>(string search = "", int limit = 20, CancellationToken ct = default)
Retrieves all available game rooms with typed rules support. Useful for server browser. Supports search and limit parameters (limit: 1-50).
public Task<RoomJoinResponse> JoinRoomAsync(string playerToken, string roomId, string password = null, T playerData = null, CancellationToken ct = default)
Joins an existing room with password and player data. Password required for private rooms.
public Task<RoomPlayersResponse> GetRoomPlayersAsync(string playerToken, CancellationToken ct = default)
Lists all players in the current room with heartbeat status.
public Task<RoomLeaveResponse> LeaveRoomAsync(string playerToken, CancellationToken ct = default)
Leaves the current room and updates player status.
public Task<HeartbeatResponse> SendRoomHeartbeatAsync(string playerToken, CancellationToken ct = default)
Sends heartbeat to maintain room connection. Call every 30-60 seconds while in room.
public Task<CurrentRoomResponse> GetCurrentRoomAsync(string playerToken, CancellationToken ct = default)
Gets comprehensive room state including player lists and pending actions.
public Task<SuccessResponse> StopRoomAsync(string playerToken, CancellationToken ct = default)
Stops current game room (Host Only). Completely removes 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, CancellationToken ct = default)
Updates the room password (Host Only). Use empty string to remove password.
Methods for submitting and processing game actions
public Task<ActionSubmitResponse> SubmitActionAsync<T>(string playerToken, SubmitAction<T> request, CancellationToken ct = default)
Submits an action to specific targets (host, all, others, or specific players) with typed request data.
public Task<ActionPollResponse> PollActionsAsync(string playerToken, CancellationToken ct = default)
Polls for completed actions from other players. Call periodically to check for new actions.
public Task<ActionPendingResponse<T>> GetPendingActionsAsync<T>(string playerToken, CancellationToken ct = default)
Gets actions awaiting processing by the current player with typed request data.
public Task<ActionCompleteResponse> CompleteActionAsync<T>(string actionId, string playerToken, ActionComplete<T> request, CancellationToken ct = default)
Marks an action as completed with processing results using typed response data.
Methods for data synchronization between players
public Task<UpdatePlayersResponse> UpdatePlayersAsync<T>(string playerToken, UpdatePlayers<T> request, CancellationToken ct = default)
Sends updates to specific players or all players. Uses typed UpdatePlayers parameter.
public Task<PollUpdatesResponse> PollUpdatesAsync(string playerToken, PollUpdates request, CancellationToken ct = default)
Polls for updates from specific source players. Use PollUpdates request object to specify from_players, from_players_ids, and lastUpdate.
WebSocket connections for live multiplayer gameplay
public Realtime(string realtimeWebSocketUrl = "wss://realtime.michitai.com")
Initializes realtime WebSocket client with optional custom server URL. Default: wss://realtime.michitai.com
public static async Task<TokenResponse> GetTokenAsync(
Client client,
string playerToken
)
Static method to generate realtime authentication token using API client.
public async Task<bool> ConnectAsync(string realtimeToken)
Connects to WebSocket server using realtime token. Returns true if successful, false if failed. Includes connection state protection.
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. Uses JsonUtility for serialization.
public async Task DisconnectAsync()
Disconnects from WebSocket server and cleans up resources. Automatically called in OnDestroy.
public event Action<string, string, SenderInfo> OnReceive;
public event Action OnConnected;
OnConnected: Fired when WebSocket connection is established. OnReceive: Fired when a message is received from server with command, data, and sender information.
Methods for matchmaking lobby management and game start
public Task<MatchmakingListResponse> GetMatchmakingLobbiesAsync(string search = "", int limit = 20, CancellationToken ct = default)
Lists all available matchmaking lobbies. Useful for lobby browser functionality. Supports search and limit parameters (limit: 1-50).
public Task<MatchmakingCreateResponse> CreateMatchmakingLobbyAsync<T>(string playerToken, 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. The creating player becomes the host. Max players: 2-16.
public Task<MatchmakingJoinRequestResponse> RequestToJoinMatchmakingAsync(string playerToken, string matchmakingId, CancellationToken ct = default)
Requests to join a lobby that requires host approval. Returns request ID for tracking.
public Task<MatchmakingPermissionResponse> RespondToJoinRequestAsync(string playerToken, string requestId, MatchmakingRequestAction action, CancellationToken ct = default)
Responds to a join request (approve/reject). Only the lobby host can call this.
public Task<MatchmakingRequestStatusResponse> CheckJoinRequestStatusAsync(string playerToken, string requestId, CancellationToken ct = default)
Checks the status of a join request. Useful for tracking approval/rejection status.
public Task<MatchmakingCurrentResponse<T>> GetCurrentMatchmakingStatusAsync<T>(string playerToken, CancellationToken ct = default)
Gets comprehensive lobby state with typed rules including player status and pending requests.
public Task<MatchmakingDirectJoinResponse> JoinMatchmakingDirectlyAsync(string playerToken, string matchmakingId, CancellationToken ct = default)
Joins a matchmaking lobby directly. Only works if lobby allows direct join.
public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(string playerToken, CancellationToken ct = default)
Leaves the current matchmaking lobby and updates player status.
public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(string playerToken, CancellationToken ct = default)
Lists all players in the current matchmaking lobby. Useful for displaying player lists.
public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(string playerToken, CancellationToken ct = default)
Sends heartbeat to maintain lobby connection. Call every 30-60 seconds while in lobby.
public Task<MatchmakingRemoveResponse> RemoveMatchmakingLobbyAsync(string playerToken, CancellationToken ct = default)
Removes the matchmaking lobby and kicks all players. Only the lobby host can call this.
public Task<MatchmakingStartResponse> StartGameFromMatchmakingAsync(string playerToken, CancellationToken ct = default)
Starts a game from matchmaking lobby. Transfers all players to a new game room.
public Task<SuccessResponse> StopMatchmakingAsync(string playerToken, 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, CancellationToken ct = default)
Updates the matchmaking password (Host Only). Cannot change password after matchmaking has started. Use empty string to remove password.
Methods for competitive rankings and player statistics
public Task<LeaderboardResponse<T>> GetLeaderboardAsync<T>(string[] sortBy, int limit = 10, CancellationToken ct = default)
Retrieves ranked players with configurable sorting criteria, limit (1-100), and typed player data support.