SquadJS is a scripting framework, designed for Squad servers, that aims to handle all communication and data collection to and from the servers. Using SquadJS as the base to any of your scripting projects allows you to easily write complex plugins without having to worry about the hassle of RCON or log parsing. However, for your convenience SquadJS comes shipped with multiple plugins already built for you allowing you to experience the power of SquadJS right away.
SquadJS relies on being able to access the Squad server log directory in order to parse logs live to collect information. Thus, SquadJS must be hosted on the same server box as your Squad server or be connected to your Squad server via FTP.
SquadJS can be configured via a JSON configuration file which, by default, is located in the SquadJS and is named [config.json](https://github.com/Thomas-Smyth/SquadJS/blob/master/config.json).
The config file needs to be valid JSON syntax. If an error is thrown saying the config cannot be parsed then try putting the config into a JSON syntax checker (there's plenty to choose from that can be found via Google).
*`id` - An integer ID to uniquely identify the server.
*`host` - The IP of the server.
*`queryPort` - The query port of the server.
*`rconPort` - The RCON port of the server.
*`rconPassword` - The RCON password of the server.
*`logReaderMode` - `tail` will read from a local log file. `ftp` will read from a remote log file using the FTP protocol.
*`logDir` - The folder where your Squad logs are saved. Most likely will be `C:/servers/squad_server/SquadGame/Saved/Logs`.
*`ftp:port` - The FTP port of the server. Only required for `ftp``logReaderMode`.
*`ftp:user` - The FTP user of the server. Only required for `ftp``logReaderMode`.
*`ftp:password` - The FTP password of the server. Only required for `ftp``logReaderMode`.
*`adminLists` - Sources for identifying an admins on the server.
---
</details>
<details>
<summary>Connectors</summary>
## Connector Configuration
Connectors allow SquadJS to communicate with external resources.
```json
"connectors": {
"discord": "Discord Login Token",
},
```
Connectors should be named, for example the above is named `discord`, and should have the associated config against it. Configs can be specified by name in plugin options. Should a connector not be needed by any plugin then the default values can be left or you can remove it from your config file.
See below for more details on connectors and their associated config.
##### Squad Layer Filter
Connects to a filtered list of Squad layers and filters them either by an "initial filter" or an "active filter" that depends on current server information, e.g. player count.
*`type` - The type of filter builder to use. `filter` will depend on this type.
-`buildPoolFromFilter` - Builds the Squad layers list from a list of filters. An example `filter` with default values for this type is show above.
-`whitelistedLayers` - List of layers to consider.
-`blacklistLayers` - List of layers to not consider.
-`whitelistedMaps` - List of maps to consider.
-`blacklistedMaps` - List of maps to not consider.
-`whitelistedGamemodes` - List of gamemodes to consider.
-`blacklistedGamemodes` - List of gamemodes to not consider.
-`flagCountMin` - Minimum number of flags the layer may have.
-`flagCountMax` - Maximum number of flags the layer may have.
-`hasCommander` - Layer must/most not have a commander. `null` for either.
-`hasTanks` - Layer must/most not have a tanks. `null` for either.
-`hasHelicopters` - Layer must/most not have a helicopters. `null` for either.
-`buildPoolFromFile` - Builds the Squad layers list from a Squad layer config file. `filter` should be the filename of the config file.
-`buildPoolFromLayerNames` - Builds the Squad layers list from a list of layers. `filter` should be a list of layers, e.g. `"filter": ["Sumari AAS v1", "Fool's Road AAS v1"]`.
*`filter` - Described above.
*`activeLayerFilter` - Filters layers live as server information updates, e.g. if the player count exceeds a certain amount a layer may no longer be in the filter.
-`historyResetTime` - After this number of miliseconds the layer history is no longer considered.
-`layerHistoryTolerance` - A layer can only be played again after this number of layers.
-`mapHistoryTolerance` - A map can only be played again after this number of layers.
-`gamemodeHistoryTolerance` - A gamemode can only be played again after this number of layers. Gamemodes can be specified individually inside the object. If they are not listed then the filter is not applied.
-`gamemodeRepetitiveTolerance` - A gamemode can only be played this number of times in a row. Gamemodes can be specified individually inside the object. If they are not listed then the filter is not applied.
-`playerCountComplianceEnabled` - Filter layers by player count.
-`factionComplianceEnabled` - Filter layers so that a team cannot play the same faction twice in a row.
-`factionHistoryTolerance` - A faction can only be played again after this number of layers. Factions can be specified individually inside the object. If they are not listed then the filter is not applied.
-`factionRepetitiveTolerance` - A faction can only be played this number of times in a row. Factions can be specified individually inside the object. If they are not listed then the filter is not applied.
##### Discord
Connects to Discord via `discord.js`.
```json
"discord": "Discord Login Token",
```
Requires a Discord bot login token.
##### Databases
SquadJS uses [Sequelize](https://sequelize.org/) to connect and use a wide range of SQL databases.
The connector should be configured using any of Sequelize's single argument configuration options.
<p>The <code>ChatCommands</code> plugin can be configured to make chat commands that broadcast or warn the caller with present messages.</p>
<h3>Options</h3>
<h4>commands</h4>
<h6>Description</h6>
<p>An array of objects containing the following properties: <ul><li><code>command</code> - The command that initiates the message.</li><li><code>type</code> - Either <code>warn</code> or <code>broadcast</code>.</li><li><code>response</code> - The message to respond with.</li><li><code>ignoreChats</code> - A list of chats to ignore the commands in. Use this to limit it to admins.</li></ul></p>
<p>The <code>mysql-log</code> plugin will log various server statistics and events to a database. This is great for server performance monitoring and/or player stat tracking.
Grafana (NOT YET WORKING WITH V2):
* [Grafana](https://grafana.com/) is a cool way of viewing server statistics stored in the database.
* Install Grafana.
* Add your database as a datasource named <code>SquadJS</code>.
* Import the [SquadJS Dashboard](https://github.com/Thomas-Smyth/SquadJS/blob/master/plugins/mysql-log/SquadJS-Dashboard.json) to get a preconfigured MySQL only Grafana dashboard.
<p>The <code>DiscordAdminRequest</code> plugin will ping admins in a Discord channel when a player requests an admin via the <code>!admin</code> command in in-game chat.</p>
<p><ul><li>Dictionary of roles and a list of the permissions they are allowed to use.<li>If dictionary is empty (<code>{}</code>) permissions will be disabled</li><li>A list of available RCON commands can be found here <a>https://squad.gamepedia.com/Server_Administration#Admin_Console_Commands</a>.</ul></p>
<p>The <code>DiscordSubSystemRestarter</code> plugin allows you to manually restart SquadJS subsystems in case an issues arises with them.<ul><li><code>!squadjs restartsubsystem rcon</code></li><li><code>!squadjs restartsubsystem logparser</code></li></ul></p>
<p>The <code>SeedingMode</code> plugin broadcasts seeding rule messages to players at regular intervals when the server is below a specified player count. It can also be configured to display "Live" messages when the server goes live.</p>
<h3>Options</h3>
<h4>interval</h4>
<h6>Description</h6>
<p>Frequency of seeding messages in milliseconds.</p>
<p>The <code>TeamRandomizer</code> can be used to randomize teams. It's great for destroying clan stacks or for social events. It can be run by typing, by default, <code>!randomize</code> into in-game admin chat</p>
Some of the information SquadJS collects from Squad servers was never intended or designed to be collected. As a result, it is impossible for any framework to collect the same information with 100% accuracy. SquadJS aims to get as close as possible to that figure, however, it acknowledges that this is not possible in some specific scenarios.
Below is a list of scenarios we know may cause some information to be inaccurate:
* Use of Realtime Server and Player Information - We update server and player information periodically every 30 seconds (by default) or when we know that it requires an update. As a result, some information about the server or players may be up to 30 seconds out of date.
- The current state of players will be lost. For example, if a player was wounded prior to the bot starting and then is revived/gives up after the bot is started information regarding who originally wounded them will not be known.
- The accurate collection of some server log events will not occur. SquadJS collects players' "suffix" name, i.e. their Steam name without the clan tag added via the game settings, when they join the server and uses this to identify them in certain logs that do not include their full name. As a result, for players connecting prior to SquadJS starting some log events associated with their actions will show the player as `null`. We aim to implement a solution to attempt to recover players' suffix names when this occurs, but the accuracy of correctly identifying players will be decreased.
* Duplicated Player Names - If two or more players have the same name or suffix name (see above) then SquadJS will be unable to identify them in the logs. When this occurs event logs will show the player as `null`. Be on the watch for groups of players who try to abuse this in order to TK or complete other malicious actions without being detected by SquadJS plugins.
## Credits
SquadJS would not be possible without the support of so many individuals and organisations. My thanks goes out to: