C#
Your game server reaches /server/v1 through the C# server client: the NuGet package
Rudder.Server and one file rudder server generate --lang csharp writes from a release. It
targets .NET Standard 2.1 and has no dependencies.
Install
Section titled “Install”dotnet add package Rudder.Server --source https://hub.rudder.build/api/packages/rudder/nuget --api-key <token>The token is that of your Rudder account (Settings → Applications).
Generate the client
Section titled “Generate the client”In the repository of the game server, where rudder project use chose the project:
rudder server generate --lang csharp --output src/RudderServer.g.cs --namespace Game \ --game-address https://api.rudder.build [--environment staging|prod]The client follows a release, not the draft. A module gets a class and a property named after it
(stores, Stores), a method per function, the functions marked server included, and the
types of their arguments and results. Every method names the player first. Generate it again
when a release changes a function or a type.
using Game;using RudderServer;
var rudder = new RudderServer(new ServerOptions{ ServerKey = Environment.GetEnvironmentVariable("RUDDER_SERVER_KEY")!,});
var environment = await rudder.Server.Environment();var purchase = await rudder.Shop.Buy(playerId, new Shop.BuyArguments { Offer = "pumpkin-pack" });
await rudder.Server.SetPlayerProfile(playerId, new Profile { Nickname = "Ada", Avatar = "https://example.com/ada.png" });await rudder.Server.BanPlayer(playerId, new Ban { Until = DateTimeOffset.Parse("2026-12-01T00:00:00Z"), Reason = "cheating" });await rudder.Server.UnbanPlayer(playerId);The generated RudderServer contains the core Server and a module each: the profile, the ban
and the environment live on rudder.Server, the functions of a module on rudder.<Module>.
- Environment.
Environment()answersstagingorprod, the environment of the server key. The header of the generated file names the environment it was generated from. - Calls. A mutation sends an
Idempotency-Key, generated for each call unlessnew MutationOptions { IdempotencyKey = ... }is passed. A banned player is refused to the game client only. - Errors. A refused call throws
RudderExceptionwithCode,MessageandStatus. - Retries. A request that got no answer or the answer
try_againis sent again after theRetry-Afterit gave or a short backoff, at most five times, with the same key. 429 is not retried. - Cancel. Every method takes a
CancellationToken.