Provies a RESTful API for reading and writing data to a live Stationeers game.
Requires BepInEx 5.0.1 or later.
- Install BepInEx in the Stationeers steam folder.
- Launch the game, reach the main menu, then quit back out.
- In the steam folder, there should now be a folder BepInEx/Plugins
- Create a folder
StationeersWebApi
in the BepInEx/Plugins folder. - Extract the release zip file to this folder.
This mod has been tested against Stationeers 0.2.4889.
Make HTTP requests to your server's port.
Expect responses to be application/json
Create a file called config.json
inside the stationeers-StationeersWebApi
folder under BepInEx/Plugins
.
This file should be a json object with the following properties.
enabled
(bool): Specify whether the mod should be enabled or disabled. Set totrue
to enable.port
(number): The port to use. Defaults to your server's game port.passwordAuthentication
: Settings for unsecure plaintext password authentication.enabled
: Set to true to enable this authentication mechanism.password
: The password to require.
jwtSecret
(string, optional): The encryption key to encode the user's login token. If unset, a random key will be used.- Note: Set this if you want to remember logins across server restarts.
Currently, only HTTP is supported. This is an unsecure protocol, so the authentication mechanism is vulnurable to man in the middle attacks.
HTTPS support has been abandoned for the time being as Stationeers is now on a unity version that is incompatible with the previous secure web request library being used.
Authentication controls how the mod determines who is and is not allowed to execute commands on the server. Multiple authentication mechanisms can be enabled at the same time and used concurrently.
If neither password nor steam authentication is enabled, the server will allow anonymous users access without any authentication. This is not a discrete mode, but instead only applies when no other mode is available.
Password authentication accepts a plaintext (unsecured) password. At the moment, there is only support for one password, and it will grant access to all api endpoints.
To enable password authentication, set the configuration optionpasswordAuthentication.enabled
to true
, and set your password in passwordAuthentication.password
.
To login with a password, make a request to /api/login/password?password=foobar
, where foobar
is the configured password.
For all authentication methods that require a login, the user must log in using the appropriate endpoint. On a successful login, the mod will return a login token under the authorization
property.
This token must be sent with all requests in one of two ways:
- In an
Authorization
cookie. - In an
Authorization
header, in the formBearer <token>
.
Failure to send this token, or sending an invalid token, will result in the command being rejected.
These tokens uniquely identify your user to the system, and connect your login with your future requests. They are valid for 1 hour, after which you must log in again.
These tokens are encrypted. By default, the encryption key is randomly generated each time the server starts up. You may choose to use a persistent key by specifying the jwtSecret
configuration property. However, if a third party obtains this key, they will be able to generate forged login requests and bypass security. It is recommended that this parameter remains empty so a random encrpytion key will be used every server restart.
For additional security, tokens are bound to the ip address of the client when the token was issued. If the client's ip changes, they will need to login again. This is to provide a small amount of protection against the case where a token is intercepted by a malacious third party, as can happen when using the http protocol.
Gets the general server status.
Gets game and server settings.
name
(string, optional): Sets the server name.password
(string, optional): Sets the server passwordmaxPlayers
(int, optional): Sets the max players allowed on the server.startingCondition
(string, optional): Sets the starting condition for new players.respawnCondition
(string, optional): Sets the respawn condition for new players.
Gets an array of valid starting conditions on this server.
Gets an array of valid respawn conditions on this server.
Gets a list of all players on the server
Kick a player from the server. steamId must be a steamId of a player on the server.
reason
(string, optional): The reason message for the kick. Can be empty.
Bans a player from the server. steamId should be a valid steamId, but the player does not have to be on the server. If they are on the server, they will be kicked.
hours
(int): The number of hours to ban the player for.reason
(string, optional): The reason message for the ban. Can be empty.
Gets an array of all things.
prefabName
(optional): Only return things with the given prefab name.prefabHash
(optional): Only return things with the given prefab hash.
Gets a thing by its id.
Change properties of a thing.
customName
(string, optional): Change the labeler-given name of a device.accessState
(int, optional): Set the bitmask of allowed access card colors.
Gets an array of all device things.
Queries devices.
Each body property takes an array of values, using OR
logic. A device will match if it matches any item
in the list.
By default, all body properties are treated with OR
logic. That is, if a device matches any of the properties,
it will be included. This can be changed to AND
logic by setting matchIntersection
to true, which will include a device only if it matches at least one value for every given body property.
referenceIds
(string array, optional): An array of reference ids to filter by.prefabNames
(string array, optional): An array of prefab names to filter by.prefabHashes
(int array, optional): An array of prefab hashes to filter by.displayNames
(string array, optional): An array of display names to filter by.dataNetworkIds
(string array, optional): An array of data network ids to filter by.matchIntersection
(boolean, optional): Whether to require an intersection of all filters per device.
prefabName
(optional): Only return devices with the given prefab name.prefabHash
(optional): Only return devices with the given prefab hash.
Gets a device by reference id.
Change properties of a device.
customName
(string, optional): Change the labeler-given name of a device.accessState
(int, optional): Set the bitmask of allowed access card colors.
Gets all readable logic values for a device.
Gets a readable logic value by logic type.
Writes a writable logic value by logic type.
value
(number): The value to write to the logic type.
Gets all cable networks
Gets a cable network by its reference id
Gets all devices in a cable network
Queries devices on the given cable network.
Each body property takes an array of values, using OR
logic. A device will match if it matches any item
in the list.
By default, all body properties are treated with OR
logic. That is, if a device matches any of the properties,
it will be included. This can be changed to AND
logic by setting matchIntersection
to true, which will include a device only if it matches at least one value for every given body property.
referenceIds
(string array, optional): An array of reference ids to filter by.prefabNames
(string array, optional): An array of prefab names to filter by.prefabHashes
(int array, optional): An array of prefab hashes to filter by.displayNames
(string array, optional): An array of display names to filter by.dataNetworkIds
(string array, optional): An array of data network ids to filter by.matchIntersection
(boolean, optional): Whether to require an intersection of all filters per device.
Gets an array of all item things.
Gets an array of all atmosphere cells.
Gets an array of all pipe networks.
Save the game
Gets a dictionary of IC10 instructions.
Gets a dictionary of possible logic slot types.
Gets a dictionary of possible logic types.
For any GET request NOT in the /api/ folder, content will be served from the web-content
folder of the plugin's folder.
For exact paths, the file will be returned if it exists. If the path is a directory, an index.htm
or index.html
file in that directory will be returned if it exists, or a directory listing will be used as a fallback.
This mod can be compiled using the .net SDK tools. Visual studio will do nicely, but any text editor will do as long as the .net sdk is installed.
This mod makes use of both nuget dependencies, and takes dependencies on game files.
To properly work with this mod, the GameDir
environment variable must be set to your stationeers game directory. Without this, the project
will not build. You should set this env var in the terminal that launches VSCode or Visual Studio in order to get proper intellisense support.
This project loads its dependencies from the Stationeers directory directly. To tell the project what directory to use, set the StationeersGameDir
environment variable to your stationeers folder.
Assuming you have installed the .net sdk properly, the project can be built with dotnet build
from the command line.
The compiled output will be dropped into the BepInEx plugins directory under the StationeersWebApi folder.