From fa31300c28329fc91ccc579c16854230c233bfc3 Mon Sep 17 00:00:00 2001 From: Thomas Smyth Date: Wed, 7 Apr 2021 16:48:00 +0100 Subject: [PATCH] Add FogOfWar plugin --- README.md | 17 +++++++++++ config.json | 6 ++++ squad-server/plugins/fog-of-war.js | 46 ++++++++++++++++++++++++++++++ squad-server/rcon.js | 4 +++ 4 files changed, 73 insertions(+) create mode 100644 squad-server/plugins/fog-of-war.js diff --git a/README.md b/README.md index a65d81d..71f066d 100644 --- a/README.md +++ b/README.md @@ -733,6 +733,23 @@ Grafana:
false
+
+ FogOfWar +

FogOfWar

+

The FogOfWar plugin can be used to automate setting fog of war mode.

+

Options

+ +
+
IntervalledBroadcasts

IntervalledBroadcasts

diff --git a/config.json b/config.json index ff36905..13cd482 100644 --- a/config.json +++ b/config.json @@ -174,6 +174,12 @@ "color": 16761867, "disableSCBL": false }, + { + "plugin": "FogOfWar", + "enabled": false, + "mode": 1, + "delay": 10000 + }, { "plugin": "IntervalledBroadcasts", "enabled": false, diff --git a/squad-server/plugins/fog-of-war.js b/squad-server/plugins/fog-of-war.js new file mode 100644 index 0000000..2db5728 --- /dev/null +++ b/squad-server/plugins/fog-of-war.js @@ -0,0 +1,46 @@ +import BasePlugin from './base-plugin.js'; + +export default class FogOfWar extends BasePlugin { + static get description() { + return 'The FogOfWar plugin can be used to automate setting fog of war mode.'; + } + + static get defaultEnabled() { + return false; + } + + static get optionsSpecification() { + return { + mode: { + required: false, + description: 'Fog of war mode to set.', + default: 1 + }, + delay: { + required: false, + description: 'Delay before setting fog of war mode.', + default: 10 * 1000 + } + }; + } + + constructor(server, options, connectors) { + super(server, options, connectors); + + this.onNewGame = this.onNewGame.bind(this); + } + + async mount() { + this.server.on('NEW_GAME', this.onNewGame); + } + + async unmount() { + this.server.removeEventListener('NEW_GAME', this.onNewGame); + } + + async onNewGame() { + setTimeout(() => { + this.server.rcon.setFogOfWar(this.options.mode); + }, this.options.delay); + } +} diff --git a/squad-server/rcon.js b/squad-server/rcon.js index b73dbde..66ac46c 100644 --- a/squad-server/rcon.js +++ b/squad-server/rcon.js @@ -173,6 +173,10 @@ export default class SquadRcon extends Rcon { await this.execute(`AdminBroadcast ${message}`); } + async setFogOfWar(mode) { + await this.execute(`AdminSetFogOfWar ${mode}`); + } + async warn(steamID, message) { await this.execute(`AdminWarn "${steamID}" ${message}`); }