Skip to Content
GameLink plugin

GameLink add-ons

How to write a game server plugin that adds its own action to GameLink, sends its own events to the site and shows players a menu: fully on CS2, partly on SA-MP and Minecraft.

By the end you will have a CounterStrikeSharp plugin that adds the example.crate action to GameLink. The site module from Game servers queues a crate for a player, your plugin hands it out, and when the player opens it the site receives an example.crate_opened event. The connection to the site, signing, the queue and retries stay with GameLink: your plugin only registers a handler.

Only the CS2 plugin offers the full set, on all three of its platforms. On SA-MP the gamemode declares its own actions, and on Minecraft another plugin can send events and data but cannot add actions. What the other games offer is listed under Other games.

Minimal example

Reference FluteConnect.Api.dll from the CS2 plugin release (addons/counterstrikesharp/shared/FluteConnect.Api/) and do not ship it with your plugin. The server must hold one copy: a copy next to your CounterStrikeSharp plugin becomes a different IFluteConnect type, and your plugin will not find GameLink.

ExampleCrates.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="CounterStrikeSharp.API" Version="1.0.369" ExcludeAssets="runtime" PrivateAssets="all" />
    <Reference Include="FluteConnect.Api">
      <HintPath>lib/FluteConnect.Api.dll</HintPath>
      <Private>false</Private>
    </Reference>
  </ItemGroup>
</Project>
Plugin.cs
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Capabilities;
using FluteConnect.Api;
using Microsoft.Extensions.Logging;

namespace ExampleCrates;

[MinimumApiVersion(369)]
public sealed class Plugin : BasePlugin
{
    public override string ModuleName => "ExampleCrates";
    public override string ModuleVersion => "1.0.0";

    private IFluteConnect? _flute;
    private readonly Dictionary<ulong, int> _crates = new();

    public override void Load(bool hotReload)
    {
        AddCommand("css_opencrate", "Open a crate from the site", (caller, _) =>
        {
            if (caller is { IsValid: true, IsBot: false, AuthorizedSteamID: { } sid }) Open(sid.SteamId64, caller.PlayerName);
        });
        RegisterListener<Listeners.OnMapStart>(_ => Attach());
        if (hotReload) Attach();
    }

    public override void OnAllPluginsLoaded(bool hotReload) => Attach();

    public override void Unload(bool hotReload) => _flute?.Unregister(ModuleName);

    private void Attach()
    {
        try
        {
            var api = new PluginCapability<IFluteConnect>(FluteApi.Capability).Get()
                ?? throw new InvalidOperationException("the capability is empty");
            if (ReferenceEquals(api, _flute)) return;
            _flute = api;
            api.RegisterAction(ModuleName, "example.crate", Give);
        }
        catch (Exception ex)
        {
            _flute = null;
            Logger.LogError("FluteCS2Connect is not loaded: {Error}", ex.Message);
        }
    }

    private ActionResult Give(ActionCall call)
    {
        if (call.Online is null) return ActionResult.Offline();
        if (!int.TryParse(call.Arg("crate"), out var grant)) return ActionResult.InvalidArgs;

        _crates[call.Online.SteamId] = grant;
        _flute?.Reply(call.Online.SteamId, "{green}A crate is waiting for you: !opencrate");

        return ActionResult.Done;
    }

    private void Open(ulong steamId, string name)
    {
        if (!_crates.Remove(steamId, out var grant)) return;
        _flute?.SendEvent("example.crate_opened", steamId, name, new Dictionary<string, object?> { ["crate"] = grant });
    }
}

The crates live in memory here and are lost on restart: a real plugin keeps them in its own database or file. Once the plugin loads, css_flute_status lists ExampleCrates on the Extensions: … line, and example.crate joins the list of actions GameLink reports to the site.

How it works

GameLink keeps one connection to the site per server. Your plugin takes its local API and uses it to register actions, send events and subscribe to data. Every call except SendEvent and GetPlayerAsync is made on the game thread, and every handler is called on the game thread too.

The action name shows up in capabilities.actions with the next sync. The site uses that list to decide whether the action can run on this server: while your plugin is not loaded, the site module sees No and does not sell what the server cannot deliver. The first plugin to register a name owns it. RegisterAction returns false when another plugin already took the name or when it is built in (player.kick, message.player, menu.refresh, raw and others).

The handler's answer goes back to the site as an acknowledgement. Done closes the delivery. Offline() (deferred: player_offline) puts it back in the queue without using up an attempt, and RetryIn tells the site how many seconds to wait before sending it again. The reasons invalid_args, unsupported_action and expired are final. Any other failed reason is retried by the site until the attempts run out (3 by default). An exception thrown by the handler counts as failed with the exception text.

Delivery is at least once, but GameLink remembers an executed id for 24 hours and answers a repeat with done without calling your handler. It does not remember a non-final failed: that command comes back and runs again.

GameLink can reload on its own, and then it is a new object. That is why the example takes the API again on every map start and registers the action again when the object has changed. Unregister(ModuleName) on unload removes everything the plugin registered.

Other CS2 platforms

SwiftlyS2 and Metamod use the same contract. Only the way you get the API differs.

Plugin.cs
public override void UseSharedInterface(IInterfaceManager interfaceManager)
{
    _flute = interfaceManager.HasSharedInterface(FluteApi.SharedInterface)
        ? interfaceManager.GetSharedInterface<IFluteConnect>(FluteApi.SharedInterface)
        : null;
    _flute?.RegisterAction("ExampleCrates", "example.crate", Give);
}

SwiftlyS2 calls UseSharedInterface again whenever a plugin loads or unloads, so the action is registered again on its own. For Metamod, flute_api.h is in connect/metamod/include/ of the plugin repository. JSON crosses that interface as text (args_json, data_json), and steam_id is 0 when there is no player.

Reference

Call (IFluteConnect)What it does
RegisterAction(owner, name, handler)an action the site may send. false when the name is taken
SendEvent(type, steamId, name, data)an event for the site. GameLink assigns the id, batches and resends. Safe from any thread
OnSyncData(owner, key, handler)data.<key> of a sync answer whenever it changed
SetMetric(key, value)a number or string in metrics of every sync, null removes it
SetPlayerExtra(owner, ns, provider)players[].extra.<ns> for each player, null means "nothing to report"
GetPlayerAsync(steamId)the player's card from the site, cached for a minute. Safe from any thread
SetGroups(owner, server, player)the groups your plugin can grant, for the server and for a player
Match, Playersthe current match (null before the first map) and the players as the next sync will report them
ShowMenu(steamId, title, options, onSelect)a menu drawn by GameLink. onSelect gets the option's key
Reply(steamId, text)a chat line with the GameLink prefix, {green}-style tags work
Unregister(owner)removes everything the plugin registered
ActionResultWhat the site sees
Donethe delivery is done
Offline()deferred: player_offline, the delivery goes back to the queue: until the player joins if the action requires them online, otherwise after RetryIn seconds
InvalidArgs, Unsupporteda final refusal, no retries
Failed("reason")a refusal the site retries unless the reason is final

Prefix your own event type with your module's name (example.crate_opened), up to 64 characters. On the site a GameLinkEventReceived listener picks it up. A site module puts data for OnSyncData into the sync through LINK_SYNC_CONTRIBUTOR and adds an in-game menu entry through LINK_MENU_CONTRIBUTOR: the menu is built on the site, and the plugin API has no way to add entries to it.

Other games

GameWhat your own plugin can do
SA-MP and open.mpits own action, events, login through the gamemode's accounts and sanctions through flute_link.inc. Details in Gamemode integration
Minecraft (Paper, Folia)FluteLinkAPI from ServicesManager: events, your own player data in the sync, charging the site balance, a local queue of console commands, the FluteLinkSyncEvent and PlayerLinkedEvent events. You cannot register your own site action
CS 1.6 (AMX Mod X)the flutecms_cs16_bridge include: checking and managing chat and voice blocks, the player's roles and flags, the match id, the OnFluteReady, OnFluteAccessLoaded and OnFluteCommsChanged forwards. No actions or events of your own
SourceMod gamesonly the FluteConnect_GetMatchId native from flute_connect.inc
Rust, Garry's Mod, FiveM and RedM, Minecraft modsno API for other plugins yet

Where there is no action of your own, the site can send a console command with the raw action if the server owner turned it on.

Common mistakes

What you seeCause
FluteCS2Connect is not loaded in your plugin's log although it is loadedyour plugin ships its own copy of FluteConnect.Api.dll. Delete it and keep Private at false
the site reports unsupported_action: example.crateyour plugin is not loaded, RegisterAction returned false, or the action was not registered again after GameLink reloaded
RegisterAction returns falsethe name is built in or another plugin took it. Prefix it with your module's name
an item is handed out twicethe handler gave part of it and returned a non-final failed. Hand out everything or nothing in one call
the server stalls on a deliverythe handler waits for the network or a database on the game thread. Answer fast and move slow work off the thread

See also

On this page