English
Sign in

Plugin tools

cs_plugin comes in the server and tools package (the dedicated server and the authors' tools, a download apart from the game), on Linux and Windows. It makes, checks, tests, packs and installs plugins.

cs_plugin new <name> [--template plugin|mod|native|shop] [--dir DIR]
cs_plugin check <folder> [--no-types]
cs_plugin keygen [--key FILE]
cs_plugin pack <folder> [-o FILE] [--key FILE]
cs_plugin info <file.csplug>
cs_plugin install <file.csplug|file.csmod> [--user DIR | --to PLUGINS] [--trust KEY] [--force]
cs_plugin search [TEXT]
cs_plugin install <name> [--user DIR | --to PLUGINS] [--force]
cs_plugin test <folder> [--filter TEXT] [--map NAME] [--port N] [--content DIR]
cs_plugin preview <folder> [COMMANDS] [--map NAME] [--game PATH]
                        [--timeout SECONDS] [--keep] [--verbose]

Making a plugin

cs_plugin new jumps makes the folder jumps/ from a template:

The Luau templates also have .vscode/settings.json for the luau-lsp extension. It points to the API's types (data/plugin_sdk/cs.d.luau and client.d.luau), so VS Code completes and checks the plugin's code.

A plugin is loaded from the server's plugins/ folder: the user folder's plugins/<name>/ (on Linux, ~/.local/share/Classic Strike/classic/plugins), or data/plugins/. While developing, the plugin's folder can be there directly, and plugin reload <name> loads it again.

Checking

cs_plugin check <folder> checks what the server would refuse or warn about, without a server:

It exits with 1 when there are errors. Warnings do not fail it.

Testing

cs_plugin test <folder> runs the plugin's tests: every .luau file in its tests/ folder. It starts a dedicated server (headless, on --map, default de_dust2, port --port, default 27035) in a temporary user folder with the plugin, the plugins it depends on that sit next to it (the game's own are enabled by name), and the test runner, which has the plugin's lang/ too (a test reads its texts with cs.t, a client with no language gets English). Each case runs in turn; the tool prints its result and exits with 0 when all passed. --filter runs the cases whose name holds that text. --keep leaves the temporary folder (the server's and clients' output are in user/plugin_data/cs_test/), and --verbose shows the server's output.

local test = require("test")

test.case("welcomes who joins", function(t)
	local alice = t:client("Alice", { team = "t" })
	alice:expect_text("Welcome, Alice.")
end)

test.case("the ban command", function(t)
	local admin = t:client("Boss", { admin = true })
	local victim = t:client("Victim")
	admin:send("ban Victim 5 testing")
	victim:expect_text("Banned for 5 minute(s)")
	t:equal(t:import("banned")(victim.player.id), true)
end, { timeout = 60 })

A case is a function that gets the context t. It runs in a coroutine, so its waits leave the server running: everything else happens meanwhile. A case fails on the first check that fails, on an error, or when it lasts more than its timeout (default 30 s). The failure shows the test's file and line. The clients and bots a case made leave when it ends.

t:wait(seconds), t:frame()Waits that long, or one server frame.
t:wait_until(fn, [seconds], [what])Waits until fn() returns a value (not nil or false) and returns it.
t:event(name, [accept], [seconds])Waits for the event; accept(e) sees each one while it is valid and returns a value to take it.
t:command(line)A line in the server console.
t:output(text, [seconds])Waits for a line of the server's output that holds the text, after the last one matched, and returns it.
t:client(name, [options])A scripted player (cs_netclient) that joins (its name keeps letters, digits, spaces, _, -, .; anything else becomes _): team (t, ct, spectator), class, admin (every right in admins.toml), fps (its frames and commands a second, default 250). Returns once it is on a team (the one asked, or another the plugin chose).
client:send(command), client:say(text)What the player types in the console or the chat.
client:input(action)Its input, as cs_netclient scripts write it: hold attack, release all, look 0 90, move 250 0, aim 0.
client:expect_text(text, [seconds])Waits for a line the player received (chat, console, centre text, menus) that holds the text.
client:saw(text), client:leave()Whether such a line arrived (not waiting); the player leaves.
client.playerIts Player on the server.
t:bots(count, [team])Adds bots and returns them once they are in (the test server keeps bots with no player on a team: bot_join_after_player 0).
t:import(name, [plugin])An export of the plugin under test (or another).
t:check(value, [message]), t:equal(a, b, [message]), t:near(a, b, [tolerance], [message]), t:fail(message)Checks.

Waits default to 10 seconds. A map whose bot mesh the game has not made yet makes the first bot wait while it is made (the tool reuses the game's meshes when it finds them). The types are in data/plugin_sdk/test.luau, so cs_plugin check and luau-lsp check the tests too. tools/plugin_harness_test.sh tests the tool itself, on Linux and Windows.

Packing and installing

A .csplug is a plugin's folder in one file, signed by its author:

  1. cs_plugin keygen makes the author's key (Ed25519, the same kind as the players' identities), kept as plugin_author.key next to the user folder. Keep it: updates of a plugin must be signed with the same key.
  2. cs_plugin pack <folder> checks the plugin and then packs it into <name>-<version>.csplug. A plugin with errors is not packed. The package takes every file of the folder except hidden ones (starting with .), build* folders and other packages. The files are compressed with zstd, and the manifest lists each one with its SHA-256.
  3. cs_plugin install <file> installs the plugin. The package's signature, every file's hash and every path are checked first: a path outside the plugin's folder is refused.
    • The plugin is unpacked beside the others and then moved into place in one step, so a failed install leaves the old version as it was.
    • plugins/authors.toml keeps the key that first installed each plugin. An update signed by another key is refused unless --force is given.
    • --trust KEY accepts the package only when it is signed by that public key (hex, as keygen and info print it).

cs_plugin info <file> shows a package's name, version, author key and files once its signature checks.

A native module runs without a sandbox. Installing it does not make the server load it: the server's admin allows it in plugins/natives.toml.

The format

"CSPLUG" 0 1                     magic and version (8 bytes)
u32 size, manifest (TOML)        name, version, author, author_key,
                                 [[files]] path, size, sha256
u64 size, u64 packed size        the files' bytes one after another
packed bytes                     zstd
signature (64 bytes)             Ed25519, of everything before it

Numbers are little-endian. The signature is made with the key named in the manifest, so it proves that the package was not changed since it was packed and that it comes from whoever holds that key.

Game modules

A folder with a module.toml is a game module (docs/modules.md), and the same commands handle it: check checks its manifest and libraries, pack makes <id>-<version>.csmod, and install puts it in the user folder's modules/ (authors.toml there). A .csmod starts with "CSMOD" 0 0 1 and carries one more signature right after the manifest, of "CSMOD-MANIFEST" (with its zero byte) and the manifest: installing keeps the manifest and that signature beside the module, and the game checks them, and every file's hash, each time it loads it.

The catalogue

cs_plugin search [TEXT] lists the catalogue's plugins and modes: ours, and the community's that players published in the game's workshop and staff reviewed. cs_plugin install <name> installs or updates one. The download is checked against the listing and the key it lists (ours, or its author's), and an update is taken only with the key that installed it (plugin catalogue).

The documentation

The reference (docs/plugins_reference.md), the types (data/plugin_sdk/cs.d.luau), the native header (data/plugin_sdk/native/cs_plugin.h), and these guides as HTML (data/plugin_sdk/docs/, in the server and tools package) are generated from native/game/src/plugins/api.toml by tools/gen_plugin_api.py. --check fails when any of them is stale.

Previewing

cs_plugin preview <folder> [COMMANDS] checks the plugin and opens the game on a game of your own (cs_office, or --map), alone, with the plugin loaded from its folder and development mode on: saving one of its files loads it again. You join the Counter-Terrorists, and COMMANDS (a ;-list, such as buy or the plugin's own command) are typed for you, so the window you work on opens by itself:

cs_plugin preview shop buy

The plugin's folder name, the map and COMMANDS go into the game's command line between double quotes, so they may not hold what a shell reads there (" $ ` \ on Linux, " % on Windows) nor a line's end: the preview refuses them.

The game is the one --game names (its launcher or its folder), else CS_GAME, else the installer's folder (~/Games/ClassicStrike; %LOCALAPPDATA%\Programs\Classic Strike on Windows). The plugin's folder is linked, not copied; on Windows a link needs developer mode, and without it the plugin is copied and saving does not reload it.

Development mode

plugin_dev 1 in the server console turns development mode on. It is a setting of the plugin host, so it exists only on servers with plugins.

Profiling

plugin prof prints, for each plugin and event, the handler calls and their time per server frame since plugin prof reset, and its timers' (cs.after, cs.every). plugin prof <plugin> lists that plugin's handlers and repeating timers one by one, slowest first, each with the file and line where its function starts:

jumps: 1520 frames, 2 handlers called
  frame                main.luau:31                  1520 calls     3.10 us/call      3.1 us/frame
  player_move          main.luau:12                 18240 calls     0.42 us/call      5.0 us/frame

Debugging

The server is its own debugger: in development mode, plugin debug <port> listens on that TCP port of this machine only (127.0.0.1) and speaks the Debug Adapter Protocol, so VS Code, or any client of the protocol, attaches to it directly. plugin debug off stops it.

With VS Code, install the small extension in data/plugin_sdk/vscode/ (its README says how). Then add this configuration to the plugin's .vscode/launch.json and start it:

{ "type": "classic-strike", "request": "attach", "name": "Attach to the server's plugins", "port": 27050 }

Checked by tools/plugin_debug_test.py.