node-gamedig/protocols/geneshift.js
Pedro Ivo Hudson a7c3b5474c
feat: Add version as a top level field (#532)
* add top level version on existing entries

* start adding version on new protocols WIP

* add version to more games

* more games with version

* add more games

* more version

* even more games with version

* add 'delete state.raw.version'

* fix delete version

* Update CHANGELOG.md

* add version in Results.js

* more games

* add new game

* more games

* add version on README

* add new game

* other game

* new game

* add unreal2 version

* add ventrilo version

* add eldewrito eldewrito

* add beammp version

* fix starmade version

* add new version in samp protocol

* docs: tweak the changelog line a bit

---------

Co-authored-by: CosminPerRam <cosmin.p@live.com>
2024-02-24 20:46:40 +02:00

47 lines
1.3 KiB
JavaScript

import Core from './core.js'
export default class geneshift extends Core {
async run (state) {
await this.tcpPing()
const body = await this.request({
url: 'http://geneshift.net/game/receiveLobby.php'
})
const split = body.split('<br/>')
let found = null
for (const line of split) {
const fields = line.split('::')
const ip = fields[2]
const port = fields[3]
if (ip === this.options.address && parseInt(port) === this.options.port) {
found = fields
break
}
}
if (found === null) {
throw new Error('Server not found in list')
}
state.raw.countrycode = found[0]
state.raw.country = found[1]
state.name = found[4]
state.map = found[5]
state.numplayers = parseInt(found[6])
state.maxplayers = parseInt(found[7])
// fields[8] is unknown?
state.raw.rules = found[9]
state.raw.gamemode = parseInt(found[10])
state.raw.gangsters = parseInt(found[11])
state.raw.cashrate = parseInt(found[12])
state.raw.missions = !!parseInt(found[13])
state.raw.vehicles = !!parseInt(found[14])
state.raw.customweapons = !!parseInt(found[15])
state.raw.friendlyfire = !!parseInt(found[16])
state.raw.mercs = !!parseInt(found[17])
// fields[18] is unknown? listen server?
state.version = found[19]
}
}