dreamteam-hq/brigid/dotnet-gameserver-hosting

Claude Code and agent skill by dreamteam-hq/brigid

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

.NET Generic Host patterns for headless game servers — BackgroundService tick loops, DI patterns, graceful shutdown, WebSocket hosting

Install

npx vskill@latest install dreamteam-hq/brigid/dotnet-gameserver-hosting

SKILL.md

The same SKILL.md was published earlier as dreamteam-hq/brigid/dotnet-gameserver-hosting.

.NET Game Server Hosting

Domain knowledge for .NET Generic Host patterns specific to headless game servers. NO MCP servers.

1. Generic Host for Games

Use WebApplication.CreateBuilder() + AddHostedService<T>() for background game logic. WebSocket endpoint handles client connections. Wire everything through DI.

This project's pattern: MapHub as singleton (owns all map state), SocketHandler as singleton (manages WebSocket connections), BackgroundService subclasses drive server-controlled entities (patrols, spawns, world ticks).

csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<MapHub>();
builder.Services.AddSingleton<SocketHandler>();
builder.Services.AddHostedService<GameLoopService>();
builder.Services.AddHostedService<PatrolService>();

2. BackgroundService Tick Loop

ExecuteAsync with while (!stoppingToken.IsCancellationRequested). Use Task.Delay for tick cadence. Never spin-wait. Pass CancellationToken on every await. For physics-rate ticks: Stopwatch + sleep to maintain consistent tick rate regardless of work duration.

csharp
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var sw = Stopwatch.StartNew();
while (!stoppingToken.IsCancellationRequested)
{
var tickStart = sw.ElapsedMilliseconds;
await DoTick(stoppingToken);
var elapsed = sw.ElapsedMilliseconds - tickStart;
var delay = Math.Max(0, TickIntervalMs - elapsed);
await Task.Delay((int)delay, stoppingToken);
}
}

3. DI Registration Patterns

  • AddSingleton for game state (MapHub, ConnectionService) — one instance, shared across all services
  • AddHostedService for background loops — started/stopped by the host
  • Inject via constructor

This project: MapHub registered as both concrete type and IMapHub interface for shared instance.

csharp
builder.Services.AddSingleton<MapHub>();
builder.Services.AddSingleton<IMapHub>(sp => sp.GetRequiredService<MapHub>());

4. WebSocket Hosting

app.UseWebSockets() + app.Map("/ws", handler.ProcessSocket). SocketHandler manages per-connection lifecycle. Each connection gets a ConnectedUser with an Outgoing channel. Use BoundedChannel with FullMode.DropOldest to prevent slow clients from blocking the server.

csharp
var channel = Channel.CreateBounded<ServerMessage>(
new BoundedChannelOptions(64) { FullMode = BoundedChannelFullMode.DropOldest });

Two tasks per connection: one reads from WebSocket, one writes from the channel. When either completes, the connection tears down.

5. Graceful Shutdown

ApplicationStopping token triggers shutdown sequence. BackgroundService.StopAsync called by the host. Drain player connections: send disconnect message, wait for outgoing channels to flush, close WebSockets with CloseAsync, timeout after 5s if clients don't disconnect cleanly.

csharp
lifetime.ApplicationStopping.Register(() =>
{
_ = connectionService.DisconnectAllAsync(TimeSpan.FromSeconds(5));
});

6. Health Checks

app.MapHealthChecks("/health") for container orchestration. Checks: can accept WebSocket connections, game loop is ticking (last tick within tolerance), memory pressure acceptable. Readiness probe: accepting new players? Liveness probe: process responsive?

7. Configuration

appsettings.json for tuning (tick rate, max players, patrol parameters). IOptions<T> pattern. Environment variable overrides for containers. This project today: all consts in code — move to config when there is more than one tunable per concern.

json
{ "GameServer": { "TickRateMs": 100, "MaxPlayers": 50, "PatrolSpeedMultiplier": 1.0 } }

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dreamteam-hq/brigid/dotnet-gameserver-hosting/badge)](https://verified-skill.com/skills/dreamteam-hq/brigid/dotnet-gameserver-hosting)

Something wrong with this skill or its page? Tell us.