# Adding Servers

### Example Code

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { RCEManager, RCEIntent } from "rce.js";

const rce = new RCEManager();
const success = await rce.addServer({
    identifier: "my-solo-duo-trio-3x",
    rcon: {
        host: "127.0.0.1",
        port: 1234,
        password: "testing123"
    },
    state: ["trio", "3x"],
    intents: [RCEIntent.ServerInfo, RCEIntent.PlayerList],
    intentTimers: {
        [RCEIntent.ServerInfo]: 30_000,
        [RCEIntent.PlayerList]: 45_000
    },
    reconnection: {
        enabled: true,
        interval: 10_000, // 10 seconds
        maxAttempts: -1 // unlimited
    },
});
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const { default: RCEManager, RCEIntent } = require("rce.js");

const rce = new RCEManager();

const success = await rce.addServer({
    identifier: "my-solo-duo-trio-3x",
    rcon: {
        host: "127.0.0.1",
        port: 1234,
        password: "testing123"
    },
    state: ["trio", "3x"],
    intents: [RCEIntent.ServerInfo, RCEIntent.PlayerList],
    intentTimers: {
        [RCEIntent.ServerInfo]: 30_000,
        [RCEIntent.PlayerList]: 45_000
    },
    reconnection: {
        enabled: true,
        interval: 10_000, // 10 seconds
        maxAttempts: -1 // unlimited
    },
});
```

{% endtab %}
{% endtabs %}

***

### Server Options

Below is a brief explanation of each option when defining new server(s).

<details>

<summary>Identifier</summary>

The identifier is a unique string which allows rce.js to identify the correct server(s) events are being received for or commands are being sent to. We suggest using a UUID for this!

**Type**: String

**Required**: Yes

</details>

<details>

<summary>RCON</summary>

The RCON information to connect to the rust server, including IP address, RCON port and RCON password.

**Type:** { host: String, port: Number, password: String }

**Required:** Yes

</details>

<details>

<summary>State</summary>

The state is an array of anything you wish to implement. For example, you can add "pvp" in your state array and check later in your code is the state array includes "pvp" to make your application behave differently if the server is a PvP-only server. You can use the state for anything.

**Type**: Any\[]

**Required**: Yes

**Default:** \[]

</details>

<details>

<summary>Reconnection</summary>

If your server disconnects for any reason, enabling this will attempt reconnecting in intervals.

**Type:** { enabled: Boolean, interval: Number, maxAttempts: Number }

**Required:** No

</details>

<details>

<summary>Intents</summary>

Define a list of intents, this could include periodically fetching key information, or enabling caching of key information.

**RCEIntent.ServerInfo** - enables periodic "serverinfo" command fetching and caching

**RCEIntent.PlayerList** - enables periodic "playerlist" command fetching and caching

**RCEIntent.Frequencies** - enables periodic "rf.listboardcasters" command fetching and caching

**RCEIntent.Gibs** - enables periodic gib-related fetching and caching to emit RCEEvent.EventStart when the patrol helicopter or bradley APC is destroyed

**RCEIntent.Kits** - enables periodic "kit list" and "kit info" command fetching and caching

**RCEIntent.CustomZones** - enables periodic "zones.listcustomzones" and "zones.customzoneinfo" command fetching and caching

**RCEIntent.Teams** - add a "team" object onto the IPlayer interface

**RCEIntent.RoleInfo** - add a "role" object onto the IPlayer interface

**Type:** RCEIntent\[]

**Required:** No

</details>

<details>

<summary>Intent Timers</summary>

Set specific interval timers on each data fetching intent instead of using default timer values.

**Type**: Record\<RCEIntent, number>

**Required:** No

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rcejs.gitbook.io/rcejs/getting-started/adding-servers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
