---
title: Resources and packages
description: How a SixL server loads its scripts, the folder layout of server and client packages, how players receive client scripts, and the rules of the client script sandbox.
---

# 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](events.md); a complete small package is in [Examples](examples.md).

## 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-config.md).

## Server packages

- Every folder in `packages` that contains an `index.js` is a package. The server loads each one once at start, with `require`, and prints `loading package <name>` to the log. A folder without `index.js` is skipped.
- The built-in package named `sixl` provides the `mp` API; 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 `packagesLoaded` event is raised.
- `mp` and `SixL` are global. A server script is an ordinary Node.js script: it can split itself into files with `require('./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 in `node\packages\my-mode` and run `npm install <module>`. Then `require('<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 `.node` file 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 example `docker 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 `/tmp` and 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 to `compose.yml` and write there. A database server that the mode reaches over the network works from both the archive and the container.
- Keep `node_modules` inside the package folder: every folder of `packages` that has an `index.js` is 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:

```json
{
  "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`:

```json
{
  "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](server.md)) 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 **only** `client_packages/index.js`. Anything else must be loaded from it with `require('./name/file.js')` or `require('./name')` (which finds `name/index.js`).
- Pages for `mp.browsers.new('package://<folder>/<file>.html')` and any other files a page needs go into the same folder tree. A `package://` address names the folder first: `package://my-mode/ui/hud.html` is `client_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

1. The server builds `client_packages` into its build folder when it starts (`resources.buildDir`), and again a moment after any file in `client_packages` changes (`resources.watch`).
2. Before the first join, the player's game asks the server for the list of files with their SHA-256 hashes and sizes.
3. 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.
4. 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.
5. 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 beyond `resources.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_packages` are 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`, `Intl` and the other standard objects);
- `mp` and `SixL`;
- `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`;
- `require` of **your own files** only: `./file` and `../file` inside `client_packages`, with or without `.js`, `.json` files too, and a folder with an `index.js`.

What is not there, and what you must not rely on:

- No Node.js: no `process`, `Buffer`, `global`, `module` of Node, and no built-in modules (`fs`, `net`, `http`, `child_process`, ...). `require('fs')` fails.
- No `require` of a name that is not a relative path of your own files, and no `require` of a file outside `client_packages`. Paths with `\` or a drive letter are refused.
- No dynamic `import()`; it is refused.
- No `eval`, no `new Function(...)` and no WebAssembly: code cannot be built from text.
- No network and no files: there is no `fetch`, `XMLHttpRequest` or `WebSocket`, and a script cannot read or write files of the player's computer or start programs. To talk to the server use `mp.events.callRemote` and `mp.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 `uncaughtException` event is raised) and the runtime keeps running; the file names in error messages look like `resource://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 with `mp.events.add('name', (...args) => {})`. `mp.players.call` sends to everyone.
- Client to server: `mp.events.callRemote('name', ...args)`; the server receives it with `mp.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 calls `await mp.events.callRemoteProc('name', ...args)` (it fails after 10 seconds without an answer); the server can call the client's procedures with `player.callProc`.
- **Encrypted only with a key and a current client.** The game traffic between a player and your server after the join, `player.call`, `callRemote` and `callRemoteProc` included, is encrypted and protected against changes when your server has its key (`serverKeyPath`, see [Player logins](server-config.md#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. `requireEncryptedSessions` in [the server's settings](server-config.md) 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 with `callRemote` is readable on the way. Use the player's SixL login instead (`player.login`, `player.lobbyId`, see [Player logins](server-config.md#player-logins)), and keep secrets on the server.
