Skip to content

Commit

Permalink
Add FogOfWar plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Smyth committed Apr 7, 2021
1 parent 29fc06e commit fa31300
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,23 @@ Grafana:
<pre><code>false</code></pre></li></ul>
</details>

<details>
<summary>FogOfWar</summary>
<h2>FogOfWar</h2>
<p>The <code>FogOfWar</code> plugin can be used to automate setting fog of war mode.</p>
<h3>Options</h3>
<ul><li><h4>mode</h4>
<h6>Description</h6>
<p>Fog of war mode to set.</p>
<h6>Default</h6>
<pre><code>1</code></pre></li>
<li><h4>delay</h4>
<h6>Description</h6>
<p>Delay before setting fog of war mode.</p>
<h6>Default</h6>
<pre><code>10000</code></pre></li></ul>
</details>

<details>
<summary>IntervalledBroadcasts</summary>
<h2>IntervalledBroadcasts</h2>
Expand Down
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
"color": 16761867,
"disableSCBL": false
},
{
"plugin": "FogOfWar",
"enabled": false,
"mode": 1,
"delay": 10000
},
{
"plugin": "IntervalledBroadcasts",
"enabled": false,
Expand Down
46 changes: 46 additions & 0 deletions squad-server/plugins/fog-of-war.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import BasePlugin from './base-plugin.js';

export default class FogOfWar extends BasePlugin {
static get description() {
return 'The <code>FogOfWar</code> 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);
}
}
4 changes: 4 additions & 0 deletions squad-server/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down

0 comments on commit fa31300

Please sign in to comment.