Skip to content

Server Scripting

Server resources can be written in C#, JavaScript or Go. Native C++ modules are available for low-level extensions.

The complete server JS API reference is Server JavaScript API.

Resource Types

TypeRuntimeUse
csharpVarion.SDKGamemode and gameplay logic
jsVarion Node hostServer scripts and shared JS workflows
goVarion Go hostServer-side Go logic
noneNo server runtimeClient-only resource

A JS resource does not need modules = [ "js-module" ]: the server starts the Node host for every resource with type = "js" and a non-empty main.

Events

Server resources can receive player events and emit events to clients. In JS the first argument to onClient is a Player proxy, not a numeric id.

csharp
varion.OnPlayerConnect += player => varion.Log($"connect {player.Id}");
player.Emit("chat:addMessage", "Welcome");
javascript
varion.onClient('chat:message', (player, message) => {
  player.emit('chat:addMessage', message);
});

RPC

Use RPC for request/response flows.

csharp
varion.OnClientRpc("server:ping", (player, args) => new { pong = true });
javascript
varion.onRpc('server:ping', async (player) => ({ pong: true }));

Resources

Each resource has its own resource.toml. Resource startup order is controlled by the resources list in server.toml and by optional dependencies in resource.toml. The [config] table is read synchronously with varion.getResourceConfig() (no await).

For the complete list of varion methods, see Server JavaScript API.

Varion Multiplayer Platform