Resources and packages
A SixL game mode is made of packages: folders of JavaScript. There are two kinds. Server packages run on the server. Client packages run on every player's computer; the server gives them to players when they join.
Both kinds use the mp object (SixL is the same object) with the server and client API reference that ships with the server (typings in the types folder). Events are listed in Events; a complete small package is in Examples.
Folder layout
<server folder>/
server.json
node/
packages/
my-mode/
index.js a server package
other-package/
index.js
client_packages/
index.js the one entry of the client scripts
my-mode/
client.js files that index.js loads
ui/
hud.html pages and other files for players
In the Windows archive the node and client_packages folders are in the archive's root. In the Linux container setup the two folders are packages/ and client_packages/ next to compose.yml. The folder names come from node.scriptsPath (its packages subfolder) and resources.sourceDir in server.json.
Server packages
- Every folder in
packagesthat contains anindex.jsis a package. The server loads each one once at start, withrequire, and printsloading package <name>to the log. A folder withoutindex.jsis skipped. - The built-in package named
sixlprovides thempAPI; it is never loaded as yours. Do not use that name. - The loading order of packages is not defined: do not make one package depend on another having loaded first. When every package has loaded, the
packagesLoadedevent is raised. mpandSixLare global. A server script is an ordinary Node.js script: it can split itself into files withrequire('./file')and use Node.js modules.- A package is read when the server starts. To change a server script, restart the server.
- If a package throws while it loads, the script host reports the error and stops, and so does the server.
npm modules in a server package
A server package can use npm modules (a database driver, a validation library and so on). Install them into the package's own folder, so node_modules sits next to its index.js:
node/packages/my-mode/
index.js
package.json
node_modules/
- Windows archive. The archive's
node\node.exe(Node.js 26) runs your packages but comes without npm. Install the modules with your own Node.js and npm: open a terminal innode\packages\my-modeand runnpm install <module>. Thenrequire('<module>')in your package finds it. - Linux container. The packages folder is mounted read-only into the container, and the image has no npm. Install on the host, in
packages/my-mode, the same way. - Modules with compiled add-ons (those that build a
.nodefile when installed) must be built for the server's platform and Node.js version: Node.js 26, Windows x64 for the archive, Linux x64 (glibc) for the container. For the container, install them inside a matching image, for exampledocker run --rm -v ./packages/my-mode:/w -w /w node:26-bookworm-slim npm install. Modules written in JavaScript only work from any install. - Writing files. In the container the packages folder is read-only, and so is the rest of the file system apart from
/tmpand the log volume. A module or a mode that writes files (a SQLite database, a cache) needs a writable folder: add a volume of your own tocompose.ymland write there. A database server that the mode reaches over the network works from both the archive and the container. - Keep
node_modulesinside the package folder: every folder ofpackagesthat has anindex.jsis loaded as a package, and a module installed at another level can be picked up by other packages too.
Editor support: the typings
The archive's types folder holds the typings of the API: types/server for server scripts and types/client for client scripts. They give your editor completion, the descriptions of every member and a check of your calls. The server and the client both have a global mp with different members, so each side gets its own project file.
For server packages written in JavaScript, put a jsconfig.json into the node folder:
{
"compilerOptions": { "target": "ES2022", "module": "commonjs", "checkJs": true, "noEmit": true, "types": [] },
"include": ["packages/**/*.js", "../types/server/*.d.ts"]
}
For client scripts, put one into client_packages:
{
"compilerOptions": { "target": "ES2022", "module": "commonjs", "checkJs": true, "noEmit": true, "types": [] },
"include": ["**/*.js", "../types/client/**/*.d.ts"]
}
Open the server folder in Visual Studio Code: a misspelt member is underlined (for example player.outputChatBoxx is reported with a hint to outputChatBox). checkJs turns the check on; leave it out if you want completion only. For TypeScript, tsconfig.example.json at the archive's root is the starting point for server packages (node/packages/**/*.ts); compile to JavaScript before you start the server, which loads index.js files only.
To try a mode, run it on your own server on this computer (see Make your own server) and join it with "Connect by address".
Client packages
- The client scripts are the files in
client_packages(resources.sourceDir). The player's game runs onlyclient_packages/index.js. Anything else must be loaded from it withrequire('./name/file.js')orrequire('./name')(which findsname/index.js). - Pages for
mp.browsers.new('package://<folder>/<file>.html')and any other files a page needs go into the same folder tree. Apackage://address names the folder first:package://my-mode/ui/hud.htmlisclient_packages/my-mode/ui/hud.html. - The client API is smaller than the server's. Check the client API reference for what exists.
How players receive client scripts
- The server builds
client_packagesinto its build folder when it starts (resources.buildDir), and again a moment after any file inclient_packageschanges (resources.watch). - Before the first join, the player's game asks the server for the list of files with their SHA-256 hashes and sizes.
- Each player keeps a separate folder of downloaded files for each server. A file that is already there with the same size and hash is not downloaded again. A file that is new or changed (a different hash) is downloaded. A file that is no longer in the list is deleted from the player's folder.
- Every downloaded file is checked against its hash, and all files are checked once more before the scripts start. A file that does not match stops the join: nothing runs and the player does not enter the server.
- The scripts start only after everything is in place, so a handler registered while the scripts load is always ready before the player is.
What this means for you:
- Changing, adding or removing a client file changes the list. Players who are already connected keep running the files they have; they get the new files the next time they join.
- Only changed files are downloaded, so keep large assets in files of their own instead of inside one big script.
- An external download host is not supported.
Limits and file names
- The server leaves out, with a warning in the log: symbolic links and junctions, files with a name a player's game would refuse, files over
resources.maxFileBytes(32 MiB by default), and files beyondresources.maxFiles(5000 by default). - The player's game refuses the whole list, and does not join, if a single file is over 64 MiB, the total is over 512 MiB, there are more than 5000 files, or a path is invalid.
- A valid path is relative, uses
/, has at most 240 characters, and has no.., no empty or.part, no\, no:, none of< > " | ? *, no control characters, no Windows device name (con,nul,com1...), and no part that ends with a dot or a space. - Files outside
client_packagesare never read.
What a client script can and cannot do
A client script runs in an isolated environment, not in Node.js. What you can use:
- the language itself (modern JavaScript,
Math,JSON,Date,Promise,Intland the other standard objects); mpandSixL;console(log,info,warn,error, ...: the text goes to the game's log);setTimeout,setInterval,clearTimeout,clearInterval,queueMicrotask;performance.now()(whole milliseconds);URL,URLSearchParams,TextEncoder,TextDecoder,structuredClone;requireof your own files only:./fileand../fileinsideclient_packages, with or without.js,.jsonfiles too, and a folder with anindex.js.
What is not there, and what you must not rely on:
- No Node.js: no
process,Buffer,global,moduleof Node, and no built-in modules (fs,net,http,child_process, ...).require('fs')fails. - No
requireof a name that is not a relative path of your own files, and norequireof a file outsideclient_packages. Paths with\or a drive letter are refused. - No dynamic
import(); it is refused. - No
eval, nonew Function(...)and no WebAssembly: code cannot be built from text. - No network and no files: there is no
fetch,XMLHttpRequestorWebSocket, and a script cannot read or write files of the player's computer or start programs. To talk to the server usemp.events.callRemoteandmp.events.callRemoteProc. - Dates and times use the UTC time zone, whatever the player's computer uses.
- A thrown error is reported to the log (the
uncaughtExceptionevent is raised) and the runtime keeps running; the file names in error messages look likeresource://client_packages/<file>.
Pages opened with mp.browsers.new are web pages in the overlay and have their own rules: they load package:// addresses from your client resources, or https:// addresses from the internet (the owner of such a host then sees the player's IP address); other address schemes do not load.
A player can turn on «Server pages only from the server itself» in the launcher's settings (off by default). Then a page reaches only package:// and your server's own address, the one the player connected to (an IP address if they connected by IP, not a domain name of the same server): any other host fails to load, for the page itself, its frames, images, scripts, fetch, WebSocket and redirects alike, and the page gets the usual load failure. Keep the pages your mode needs in your client resources, or on your server's address, and they work for every player.
Talking between server and client
- Server to client:
player.call('name', ...args); the client receives it withmp.events.add('name', (...args) => {}).mp.players.callsends to everyone. - Client to server:
mp.events.callRemote('name', ...args); the server receives it withmp.events.add('name', (player, ...args) => {}). Arguments must be JSON-serialisable. - Procedures that return a value: the server registers
mp.events.addProc('name', (player, ...args) => result)and the client callsawait mp.events.callRemoteProc('name', ...args)(it fails after 10 seconds without an answer); the server can call the client's procedures withplayer.callProc. - Encrypted only with a key and a current client. The game traffic between a player and your server after the join,
player.call,callRemoteandcallRemoteProcincluded, is encrypted and protected against changes when your server has its key (serverKeyPath, see Player logins) and the player's client supports it (voice is never encrypted). Otherwise (a server without a kept key, an older client, a player who joined plain) it crosses the network unencrypted: anyone on the network path (a shared Wi-Fi, an internet provider) can read it, and an attacker on the path can change it.requireEncryptedSessionsin the server's settings turns older clients away. Even so, do not send passwords, keys or other secrets this way: a login of your own with a password typed into a page and sent withcallRemoteis readable on the way. Use the player's SixL login instead (player.login,player.lobbyId, see Player logins), and keep secrets on the server.