MultiplayerHost 1.5.0
dotnet add package MultiplayerHost --version 1.5.0
NuGet\Install-Package MultiplayerHost -Version 1.5.0
<PackageReference Include="MultiplayerHost" Version="1.5.0" />
<PackageVersion Include="MultiplayerHost" Version="1.5.0" />
<PackageReference Include="MultiplayerHost" />
paket add MultiplayerHost --version 1.5.0
#r "nuget: MultiplayerHost, 1.5.0"
#:package MultiplayerHost@1.5.0
#addin nuget:?package=MultiplayerHost&version=1.5.0
#tool nuget:?package=MultiplayerHost&version=1.5.0
Multiplayer Host
Overview
The Multiplayer Host is a class library helping game developers implementing multiplayer game servers. It exposes a Server component that streamlines message handling, message buffering, user state handling and invoking the game implementation layer. The Server component does not contain any game specific logic. Game developers deal with the game logic by implementing several interfaces invoked by the server component.
The goal of this project is to create a framework for streamlining the game backend development.
High level architecture
Multiplayer Host implements
- abstract User class and user management
- main game loop
- message dispatcher loop
- client message double buffering (accepts new incoming messages simultaneously with turn processing)
- server message buffering
- dedicated background threads for the main loop and message dispatcher
- public IServer api supporting basic server operations, queuing client messages and creating response messages
Multiplayer Host does not implement
- a real game - although a minimalistic reference game (server and client) is provided for test purposes
- any kind of game specific logic
- any kind of client connectivity
- any kind of data storage
- anything related to game clients
Components
The server requires external components providing the following interfaces:
IConnectionManager, providing client connection management and message sending/receivingIRepository, providing game persistenceITurnProcessor, providing the game logic- in addition the host implements the
IServerto be used by other components to control and communicate with the server
Turn processing
The server uses the ITurnProcessor interface to invoke game specific logic. The turn processors methods are invoked in the following order:
ITurnProcessor.ProcessClientMessage(User user, in ClientMessage message);invoked once for every received client messageITurnProcessor.ProcessUserTurn(User user, int elapsedMilliseconds);invoked once per turn for every user (both online and offline)ITurnProcessor.OnTurnComplete();invoked once per turn after all messages and users have been processed
Runtime and lifecycle expectations
- Configure the server context before calling
Start(). Start()loads the active users, raises the startup callbacks, and then begins the background main loop and dispatcher loop.StopAsync()is the preferred shutdown API. The compatibilityStop()wrapper blocks until the asynchronous shutdown completes.ITurnProcessorcallbacks run on the server background loop, so implementations should avoid blocking work and keep their own shared state thread-safe.- Outbound server messages are timestamped with UTC ticks, and dispatcher shutdown drains queued outbound messages before the stop operation completes.
- Dirty users are persisted on the host save interval (currently 5 seconds) rather than on every turn.
Message contracts
ClientMessageandServerMessagepayloads are owned by the game implementation and should be treated as non-null application data.ServerMessage.Targetsis interpreted together withTargetKind; use an empty target array when broadcasting to all users.- Message timestamps should use UTC-based values when the game implementation sets them.
Quickstart
- create a game specific user entity inheriting from
MultiplayerHost.Domain.User
public class Player : User
{
public int Diamond { get; internal set; }
public int Gold { get; internal set; }
public int Reputation { get; internal set; }
...
}
- implement the three mandatory interfaces:
IConnectionManager,IRepositoryandITurnProcessor. Note: for testing purposes a single class could implement all of them. When dealing with users inside your game logic, make sure to cast the provided User instance into your specific user entity class. The server will only use the IRepository interface to save the user state. If you need to persist additional state you must implement it as part of your game logic. - Implement client messages and corresponding parsers/handlers, define server messages and specify their payload format
- obtain an IServer reference, grab the context and provide the interface implementations
IServer server;
var context = server.Context;
context.Configure(repository, connMngr, turnProcessor, turnTimeMillis: 50);
// optionally subscribe for initial game setup: context.Server.OnBeforeServerStart += OnServerStart;
- start the server
await server.Start();
- The server starts invoking the turn processing logic
- stop the server gracefully when the host application shuts down
await server.StopAsync();
- You also need a client capable of exchanging messages with your IConnectionManager implementation
Note: The multiplayer game server is easiest to be used with a DI container. Consult the reference game server project how to setup DI in a console application.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.0 | 81 | 4/19/2026 |
| 1.4.1 | 331 | 8/29/2025 |
| 1.4.0 | 277 | 8/24/2025 |
| 1.3.0 | 384 | 3/8/2025 |
| 1.2.8 | 949 | 1/22/2022 |
| 1.2.7 | 725 | 10/24/2021 |
| 1.2.2-release0001-0012 | 477 | 10/24/2021 |
| 1.2.1-release0001-0011 | 475 | 10/24/2021 |
| 1.2.1-release0001-0009 | 434 | 10/24/2021 |
| 1.2.0-release0001-0010 | 517 | 10/24/2021 |
| 1.0.4-release0001-0001 | 387 | 10/13/2021 |
| 1.0.0-release0001-0073 | 392 | 10/13/2021 |
| 1.0.0-release0001-0070 | 466 | 3/13/2021 |
| 1.0.0-release0001-0009 | 482 | 10/24/2021 |
| 1.0.0-release0001-0008 | 463 | 10/13/2021 |
| 1.0.0-release0001-0006 | 410 | 10/13/2021 |
| 0.3.1-release0001 | 464 | 10/24/2021 |