Multiplayer API Logo

Multiplayer API

.NET SDK for
Modern C# Applications

Modern .NET SDK with System.Text.Json support. Async/await patterns, full serialization, and seamless integration with your C# projects.

.NET-Specific Features

Built for modern C# development

Async/Await

Modern async/await patterns with Task-based operations for responsive applications.

System.Text.Json

Full serialization support with System.Text.Json for modern .NET applications.

Type Safe

Strong typing with generics, nullable reference types, and comprehensive error handling.

.NET SDK

Complete System.Text.Json SDK for C# developers

.NET SDK Download

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.

Async/Await Ready

Modern async/await patterns with Task-based operations

System.Text.Json

Full serialization support with modern .NET JSON library

Type Safe

Strong typing with generics and nullable reference types

Multiplayer Ready

Complete player management and matchmaking system

Game Rooms

Real-time room management with actions and updates

Leaderboards

Competitive rankings and player statistics

View on GitHub
Full Repository
Quick Installation Guide
1
Download & Add SDK
  1. Click "Download .NET SDK" button
  2. Save SDK.cs
  3. In Visual Studio: Project → Add Existing Item
  4. Select the downloaded SDK file
  5. Verify file appears in Solution Explorer

Tip: Create a "Models" folder to organize your files

2
Setup Project
  1. Create new C# Console Application
  2. Name it "MultiplayerDemo" or similar
  3. Ensure .NET 6.0 or later is selected
  4. Add System.Text.Json NuGet package
  5. Add SDK.cs to your project

Tip: Use .NET CLI: dotnet add package System.Text.Json

3
Configure & Initialize
  1. Get your API token from dashboard
  2. Set token in SDK constructor (Api Token)
  3. Get your private API token for player operations
  4. Set private token in SDK constructor (Private Api Token)
  5. Download example code for reference
  6. Copy example to Program.cs
  7. Replace YOUR_API_TOKEN and YOUR_PRIVATE_API_TOKEN with actual tokens

Tip: Store tokens in appsettings.json for production

Testing Your Setup
  1. Build the project (Ctrl+Shift+B)
  2. Run the application (F5)
  3. Check Console for SDK initialization
  4. Verify API calls work (test with RegisterPlayer)
  5. Monitor async operations with await
Production Checklist
  • Secure API tokens (use configuration files)
  • Enable proper error handling and logging
  • Test on target .NET versions
  • Handle network timeouts gracefully
  • Implement proper async/await patterns
Common Issues & Solutions

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

50+
API Methods
25+
Response Classes
100%
System.Text.Json
Async
Task-Based

.NET API Documentation

Complete System.Text.Json-compatible API documentation

GameSDK

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.

Constructor
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.

Player Management

RegisterPlayer
public Task<PlayerRegisterResponse> RegisterPlayer(
    string name, 
    object playerData
)

Registers a new player and returns their ID and private key for authentication.

AuthenticatePlayer
public Task<PlayerAuthResponse> AuthenticatePlayer(
    string playerToken
)

Authenticates a player using their private token and returns player information.

GetAllPlayers
public Task<PlayerListResponse> GetAllPlayers()

Retrieves a list of all players (requires private API token).

SendPlayerHeartbeatAsync
public Task<PlayerHeartbeatResponse> SendPlayerHeartbeatAsync(
    string gamePlayerToken
)

Updates player heartbeat to maintain online status.

LogoutPlayerAsync
public Task<PlayerLogoutResponse> LogoutPlayerAsync(
    string gamePlayerToken
)

Logs out a player and updates their last logout timestamp.

Game Data

GetGameData
public Task<GameDataResponse> GetGameData()

Retrieves global game data with System.Text.Json compatible nested objects.

UpdateGameData
public Task<SuccessResponse> UpdateGameData(
    object data
)

Updates global game data (requires private API token).

GetPlayerData
public Task<PlayerDataResponse> GetPlayerData(
    string playerToken
)

Retrieves a specific player's data using their authentication token.

UpdatePlayerData
public Task<SuccessResponse> UpdatePlayerData(
    string playerToken, 
    object data
)

Updates a specific player's data like level, score, and inventory.

Time Management

GetServerTime
public Task<ServerTimeResponse> GetServerTime()

Retrieves current server time in multiple formats including UTC timestamp.

GetServerTimeWithOffset
public Task<ServerTimeWithOffsetResponse> GetServerTimeWithOffset(
    int utcOffset
)

Retrieves server time with specified UTC offset adjustment.

Room Management

CreateRoomAsync
public Task<RoomCreateResponse> CreateRoomAsync(
    string gamePlayerToken,
    string roomName,
    string? password = null,
    int maxPlayers = 4
)

Creates a new game room for real-time multiplayer sessions.

GetRoomsAsync
public Task<RoomListResponse> GetRoomsAsync()

Retrieves a list of all available game rooms.

JoinRoomAsync
public Task<RoomJoinResponse> JoinRoomAsync(
    string gamePlayerToken,
    string roomId,
    string? password = null
)

Joins an existing game room with optional password.

LeaveRoomAsync
public Task<RoomLeaveResponse> LeaveRoomAsync(
    string gamePlayerToken
)

Leaves the current game room.

GetRoomPlayersAsync
public Task<RoomPlayersResponse> GetRoomPlayersAsync(
    string gamePlayerToken
)

Retrieves a list of all players in the current room.

SendHeartbeatAsync
public Task<HeartbeatResponse> SendHeartbeatAsync(
    string gamePlayerToken
)

Sends heartbeat to maintain connection in game room.

Room Actions

SubmitActionAsync
public Task<ActionSubmitResponse> SubmitActionAsync(
    string gamePlayerToken,
    string actionType,
    object requestData
)

Submits a game action for processing by other players.

PollActionsAsync
public Task<ActionPollResponse> PollActionsAsync(
    string gamePlayerToken
)

Polls for completed actions from other players.

GetPendingActionsAsync
public Task<ActionPendingResponse> GetPendingActionsAsync(
    string gamePlayerToken
)

Retrieves a list of pending actions that need to be processed.

CompleteActionAsync
public Task<ActionCompleteResponse> CompleteActionAsync(
    string actionId,
    string gamePlayerToken,
    ActionCompleteRequest request
)

Marks an action as completed with response data.

Room Updates

SendUpdateAsync
public Task<UpdateSendResponse> SendUpdateAsync(
    string gamePlayerToken,
    string targetPlayerIds,
    string type,
    object dataJson
)

Sends updates to specific players or all players in the room.

PollUpdatesAsync
public Task<UpdatePollResponse> PollUpdatesAsync(
    string gamePlayerToken,
    string? lastUpdateId = null
)

Polls for updates from other players with optional incremental polling.

Matchmaking

ListMatchmakingAsync
public Task<MatchmakingListResponse> ListMatchmakingAsync()

Lists all available matchmaking lobbies.

CreateMatchmakingAsync
public Task<MatchmakingCreateResponse> CreateMatchmakingAsync(
    string gamePlayerToken,
    int maxPlayers,
    bool strictFull,
    bool joinByRequests,
    object? extraJsonString = null
)

Creates a new matchmaking lobby with configurable settings.

RequestJoinMatchmakingAsync
public Task<MatchmakingJoinRequestResponse> RequestJoinMatchmakingAsync(
    string gamePlayerToken,
    string matchmakingId
)

Requests to join a matchmaking lobby that requires host approval.

RespondToJoinRequestAsync
public Task<MatchmakingJoinRequestResponse> RespondToJoinRequestAsync(
    string requestId,
    MatchmakingRequestAction action
)

Host responds to a join request (approve or reject).

CheckRequestStatusAsync
public Task<MatchmakingJoinRequestStatusResponse> CheckRequestStatusAsync(
    string requestId
)

Checks the status of a join request.

GetCurrentMatchmakingStatusAsync
public Task<MatchmakingCurrentStatusResponse> GetCurrentMatchmakingStatusAsync(
    string gamePlayerToken
)

Gets the current player's matchmaking status and lobby information.

JoinMatchmakingAsync
public Task<MatchmakingDirectJoinResponse> JoinMatchmakingAsync(
    string gamePlayerToken,
    string matchmakingId
)

Joins a matchmaking lobby directly (only works if lobby doesn't require approval).

LeaveMatchmakingAsync
public Task<MatchmakingLeaveResponse> LeaveMatchmakingAsync(
    string gamePlayerToken
)

Leaves the current matchmaking lobby.

GetMatchmakingPlayersAsync
public Task<MatchmakingPlayersResponse> GetMatchmakingPlayersAsync(
    string gamePlayerToken
)

Gets all players in the current matchmaking lobby.

SendMatchmakingHeartbeatAsync
public Task<MatchmakingHeartbeatResponse> SendMatchmakingHeartbeatAsync(
    string gamePlayerToken
)

Sends heartbeat to maintain connection in matchmaking lobby.

RemoveMatchmakingAsync
public Task<MatchmakingRemoveResponse> RemoveMatchmakingAsync(
    string gamePlayerToken
)

Removes the matchmaking lobby (host only).

StartMatchmakingAsync
public Task<MatchmakingStartResponse> StartMatchmakingAsync(
    string gamePlayerToken
)

Starts a game from matchmaking lobby (host only).

Leaderboard

GetLeaderboardAsync
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}");
}

HTTP Communication

Send (Internal)
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:

  • Automatic authentication with API tokens
  • System.Text.Json serialization/deserialization
  • Comprehensive error handling and logging
  • HTTP client management and timeout handling
  • Response validation and ApiException throwing
Url (Internal)
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}");
JsonSerializerOptions (Internal)
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
{
    PropertyNameCaseInsensitive = true,
    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

System.Text.Json configuration for case-insensitive deserialization and null handling.

Response Classes

IApiResponse

Base interface for all API responses with Success and Error properties.

PlayerRegisterResponse

Contains player registration results with ID and private key.

PlayerAuthResponse

Contains player authentication information and data.

GameDataResponse

Contains global game data with nested objects.

RoomCreateResponse

Contains room creation results with room ID.

LeaderboardResponse

Contains ranked leaderboard data and statistics.

ApiException

Custom exception for API errors with response details.

System.Text.Json Compatibility

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.