Modern .NET SDK with System.Text.Json support. Async/await patterns, full serialization, and seamless integration with your C# projects.
Built for modern C# development
Modern async/await patterns with Task-based operations for responsive applications.
Full serialization support with System.Text.Json for modern .NET applications.
Strong typing with generics, nullable reference types, and comprehensive error handling.
Complete System.Text.Json SDK for C# developers
Modern .NET SDK with System.Text.Json support designed specifically for C# developers. Includes comprehensive multiplayer functionality with async/await patterns, authentication, and full serialization capabilities for modern applications.
Modern async/await patterns with Task-based operations
Full serialization support with modern .NET JSON library
Strong typing with generics and nullable reference types
Complete player management and matchmaking system
Real-time room management with actions and updates
Competitive rankings and player statistics
SDK.csTip: Create a "Models" folder to organize your files
Tip: Use .NET CLI: dotnet add package System.Text.Json
YOUR_API_TOKEN and YOUR_PRIVATE_API_TOKEN with actual tokensTip: Store tokens in appsettings.json for production
Compilation Errors:
Ensure .NET 6.0+ and System.Text.Json package installed
API Timeouts:
Check internet connection and API token validity
Json Serialization:
Use [JsonPropertyName] attributes for proper mapping
Async Issues:
Use await properly and mark methods as async Task
Complete System.Text.Json-compatible API documentation
Main SDK class for interacting with the MICHITAI Game API. Handles authentication, player management, game rooms, matchmaking, and actions using modern async/await patterns with System.Text.Json serialization.
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(
string name,
object playerData
)
Registers a new player and returns their ID and private key for authentication.
public Task<PlayerAuthResponse> AuthenticatePlayer(
string playerToken
)
Authenticates a player using their private token and returns player information.
public Task<PlayerListResponse> GetAllPlayers()
Retrieves a list of all players (requires private API token).
public Task<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(
string gamePlayerToken
)
Updates player heartbeat to maintain online status.
public Task<PlayerLogoutResponse> LogoutPlayerAsync(
string gamePlayerToken
)
Logs out a player and updates their last logout timestamp.
public Task<GameDataResponse> GetGameData()
Retrieves global game data with System.Text.Json compatible nested objects.
public Task<SuccessResponse> UpdateGameData(
object data
)
Updates global game data (requires private API token).
public Task<PlayerDataResponse> GetPlayerData(
string playerToken
)
Retrieves a specific player's data using their authentication token.
public Task<SuccessResponse> UpdatePlayerData(
string playerToken,
object data
)
Updates a specific player's data like level, score, and inventory.
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(
string gamePlayerToken,
string roomName,
string? password = null,
int maxPlayers = 4
)
Creates a new game room for real-time multiplayer sessions.
public Task<RoomListResponse> GetRoomsAsync()
Retrieves a list of all available game rooms.
public Task<RoomJoinResponse> JoinRoomAsync(
string gamePlayerToken,
string roomId,
string? password = null
)
Joins an existing game room with optional password.
public Task<RoomLeaveResponse> LeaveRoomAsync(
string gamePlayerToken
)
Leaves the current game room.
public Task<RoomPlayersResponse> GetRoomPlayersAsync(
string gamePlayerToken
)
Retrieves a list of all players in the current room.
public Task<HeartbeatResponse> SendHeartbeatAsync(
string gamePlayerToken
)
Sends heartbeat to maintain connection in game room.
public Task<ActionSubmitResponse> SubmitActionAsync(
string gamePlayerToken,
string actionType,
object requestData
)
Submits a game action for processing by other players.
public Task<ActionPollResponse> PollActionsAsync(
string gamePlayerToken
)
Polls for completed actions from other players.
public Task<ActionPendingResponse> GetPendingActionsAsync(
string gamePlayerToken
)
Retrieves a list of pending actions that need to be processed.
public Task<ActionCompleteResponse> CompleteActionAsync(
string actionId,
string gamePlayerToken,
ActionCompleteRequest request
)
Marks an action as completed with response data.
public Task<UpdateSendResponse> SendUpdateAsync(
string gamePlayerToken,
string targetPlayerIds,
string type,
object dataJson
)
Sends updates to specific players or all players in the room.
public Task<UpdatePollResponse> PollUpdatesAsync(
string gamePlayerToken,
string? lastUpdateId = null
)
Polls for updates from other players with optional incremental polling.
public Task<MatchmakingListResponse> ListMatchmakingAsync()
Lists all available matchmaking lobbies.
public Task<MatchmakingCreateResponse> CreateMatchmakingAsync(
string gamePlayerToken,
int maxPlayers,
bool strictFull,
bool joinByRequests,
object? extraJsonString = null
)
Creates a new matchmaking lobby with configurable settings.
public Task<MatchmakingJoinRequestResponse> RequestJoinMatchmakingAsync(
string gamePlayerToken,
string matchmakingId
)
Requests to join a matchmaking lobby that requires host approval.
public Task<MatchmakingJoinRequestResponse> RespondToJoinRequestAsync(
string requestId,
MatchmakingRequestAction action
)
Host responds to a join request (approve or reject).
public Task<MatchmakingJoinRequestStatusResponse> CheckRequestStatusAsync(
string requestId
)
Checks the status of a join request.
public Task<MatchmakingCurrentStatusResponse> GetCurrentMatchmakingStatusAsync(
string gamePlayerToken
)
Gets the current player's matchmaking status and lobby information.
public Task<MatchmakingDirectJoinResponse> JoinMatchmakingAsync(
string gamePlayerToken,
string matchmakingId
)
Joins a matchmaking lobby directly (only works if lobby doesn't require approval).
public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(
string gamePlayerToken
)
Leaves the current matchmaking lobby.
public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(
string gamePlayerToken
)
Gets all players in the current matchmaking lobby.
public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(
string gamePlayerToken
)
Sends heartbeat to maintain connection in matchmaking lobby.
public Task<MatchmakingRemoveResponse> RemoveMatchmakingAsync(
string gamePlayerToken
)
Removes the matchmaking lobby (host only).
public Task<MatchmakingStartResponse> StartMatchmakingAsync(
string gamePlayerToken
)
Starts a game from matchmaking lobby (host only).
public Task<LeaderboardResponse> GetLeaderboardAsync(
string[] sortBy,
int limit = 10
)
Gets ranked leaderboard with configurable sorting and limit.
Example Usage:
// Sort by level, then score
var response = await sdk.GetLeaderboardAsync(
new[] { "level", "score" },
10
);
foreach (var entry in response.Leaderboard) {
Console.WriteLine($"#{entry.Rank} - {entry.Player_name}");
}
private async Task<T> Send<T>(
HttpMethod method,
string url,
object? body = null
) where T : class
Internal method for sending HTTP requests and deserializing System.Text.Json responses.
Features:
private string Url(
string endpoint,
string extra = ""
)
Constructs URLs with authentication tokens and query parameters.
Example:
// Generates: https://api.michitai.com/api/game_players.php/list?api_token=TOKEN&api_private_token=PRIVATE_TOKEN
var url = Url("game_players.php/list", "&api_private_token={_apiPrivateToken}");
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
System.Text.Json configuration for case-insensitive deserialization and null handling.
Base interface for all API responses with Success and Error properties.
Contains player registration results with ID and private key.
Contains player authentication information and data.
Contains global game data with nested objects.
Contains room creation results with room ID.
Contains ranked leaderboard data and statistics.
Custom exception for API errors with response details.
All response classes are designed for System.Text.Json serialization with proper property naming, nullable reference types, and case-insensitive deserialization for modern .NET applications.