Team-Silver-Sphere / SquadJS

Squad Server Script Framework
Boost Software License 1.0
167 stars 127 forks source link

update: getNextMap to work with v8 #361

Closed IgnisAlienus closed 5 months ago

IgnisAlienus commented 5 months ago
[SquadServer][1] Failed to update layer information. TypeError: Cannot read properties of null (reading '1')
at SquadRcon.getNextMap (file:///home/container/squad-server/rcon.js:129:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SquadServer.updateLayerInformation (file:///home/container/squad-server/index.js:452:23)

V8 Updates some RCON Commands it seems

async getNextMap() {
    const response = await this.execute('ShowNextMap');
    const match = response.match(/^Next level is (.*), layer is (.*)/);
    return {
      level: match[1] !== '' ? match[1] : null,
      layer: match[2] !== 'To be voted' ? match[2] : null
    };
  }

the new response from ShowNextMap is Next map is not defined Therefore match ends up being null which broke the return values.

Updated to this seems to work for me so far:

  async getNextMap() {
    const response = await this.execute('ShowNextMap');
    const match = response.match(/^Next level is (.*), layer is (.*)/);
    return {
      level: match ? (match[1] !== '' ? match[1] : null) : null,
      layer: match ? (match[2] !== 'To be voted' ? match[2] : null) : null
    };
  }
werewolfboy13 commented 5 months ago

@IgnisAlienus can you do another change here for me on this PR?

werewolfboy13 commented 5 months ago

https://github.com/Team-Silver-Sphere/SquadJS/blob/de8219d2630fbfd07b355771e1b22853723edd8c/package.json#L3

Can you bump this to "version": "4.1.0",