Unity SDK
One C# file in Assets/, for any Unity platform.
Install
curl -o Assets/Warden/WardenClient.cs --create-dirs https://wardenauth.dev/packages/csharp/1.1.0/WardenClient.csRun in your Unity project folder (Unity 2021.3+). The HWID comes from SystemInfo.deviceUniqueIdentifier.
- Or drop the file into
Assets/Warden/by hand. The device ID works on every platform Unity builds for. - The example adds a
WardenLogincomponent you can put on any GameObject. Awaits resume on Unity's main thread.
The URL includes the version, and released versions never change, so a pinned install keeps working. See the changelog for older versions.
Quickstart
Replace the placeholders with your app's values from its Overview in the dashboard, where the Add Warden to your project card shows this snippet with your credentials already filled in. The application ID and public key are safe to ship; never put your seller key in client code.
using UnityEngine;
using Warden;
public class WardenLogin : MonoBehaviour
{
private WardenClient _app;
private async void Start()
{
_app = new WardenClient("YOUR_APP_ID",
"YOUR_PUBLIC_KEY",
"1.0", "https://wardenauth.dev/api/v1");
await _app.InitAsync();
}
public async void SignIn(string key)
{
try
{
var user = await _app.LicenseAsync(key);
Debug.Log($"Welcome {user.Username}!");
}
catch (WardenException ex) { Debug.LogError(ex.Message); }
}
private void OnDestroy() => _app?.Dispose();
}Example project
A complete program with the usual loader menu (login, register, upgrade, key-only login) that prints the user's details. It bundles the SDK, so it runs without installing anything. Fill in the Application credentials block and put your code where it says Your application code goes here.
- Edit
- Assets/Warden/Examples/WardenLogin.cs
- Run
- Copy Assets/ into your project
- Needs
- Unity 2021.3+
API
Every method maps to one call of the client API. Each response is checked against your public key, timestamp and nonce before the SDK uses it.
| Method | What it does |
|---|---|
| await app.InitAsync(…) | Start a session. Call this first. |
| await app.LoginAsync(…) | Log in with a username and password. |
| await app.RegisterAsync(…) | Create an account by redeeming a license key. |
| await app.LicenseAsync(…) | Log in with just a license key. |
| await app.UpgradeAsync(…) | Redeem another key on an existing account. |
| await app.CheckAsync(…) | Whether the session is still logged in. |
| await app.CheckBlacklistAsync(…) | Whether this machine's IP or HWID is blacklisted. |
| await app.VarAsync(…) | Read a global variable. |
| await app.GetVarAsync(…) | Read one of the user's variables. |
| await app.SetVarAsync(…) | Write one of the user's variables. |
| await app.FileAsync(…) | Download a file into memory. |
| await app.WebhookAsync(…) | Call one of your webhooks through the server. |
| await app.LogAsync(…) | Send a log line to your dashboard. |
| await app.BanAsync(…) | Ban the current user (e.g. after detecting a debugger). |
| await app.FetchOnlineAsync(…) | Usernames with a logged-in session. |
| await app.FetchStatsAsync(…) | User, online and key counts. |
| await app.ChatGetAsync(…) | The last 50 messages in a channel. |
| await app.ChatSendAsync(…) | Post to a channel. |
| await app.LogoutAsync(…) | End the session. |
Errors
Failures throw WardenException; e.Response holds the server's reply when it rejected the request.
Rejected responses, including a bad signature, a stale timestamp or a replayed nonce, fail the same way, so a spoofed server can't log anyone in. See verifying responses, and protecting your app for what a signature check can and can't stop.