mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
feat: Add Grand Theft Auto V - RAGE MP support (#576)
* feat: Add Grand Theft Auto V - RAGE MP support * Add changelog entry * Change ID for RageMP to gta5r * Rename to be RageMP * Revert prettier changing * to - * Add notes to ragemp. * Update CHANGELOG.md
This commit is contained in:
parent
ce29238428
commit
cfd5614353
5 changed files with 68 additions and 1 deletions
49
protocols/ragemp.js
Normal file
49
protocols/ragemp.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import Core from './core.js'
|
||||
|
||||
export default class ragemp extends Core {
|
||||
constructor() {
|
||||
super()
|
||||
this.usedTcp = true
|
||||
}
|
||||
|
||||
async run(state) {
|
||||
const results = await this.request({
|
||||
url: 'https://cdn.rage.mp/master/v2/',
|
||||
responseType: 'json'
|
||||
})
|
||||
|
||||
if (results == null) {
|
||||
throw new Error('Unable to retrieve master server list')
|
||||
}
|
||||
|
||||
const targetID = `${this.options.host}:${this.options.port}`
|
||||
|
||||
let serverResult = null
|
||||
let serverInfo = null
|
||||
|
||||
for (const entry of results) {
|
||||
if (entry.id === targetID) {
|
||||
serverResult = entry
|
||||
serverInfo = entry.servers.at(0)
|
||||
break
|
||||
}
|
||||
|
||||
for (const serverEntry of entry.servers) {
|
||||
if (serverEntry.id === targetID) {
|
||||
serverResult = entry
|
||||
serverInfo = serverEntry
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (serverInfo == null) {
|
||||
throw new Error('Server not found in master server list.')
|
||||
}
|
||||
|
||||
state.name = serverInfo.name
|
||||
state.numplayers = serverInfo.players.amount
|
||||
state.maxplayers = serverInfo.players.max
|
||||
state.raw = serverResult
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue