mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
feat: Add support for AltvMP (#588)
* feat: Add Minetest support using serverlist * Allow for connect to be assigned, * Add serverId to the string args * Add altvmp implementation * Added altv to games. * Add changelog entry * Update CHANGELOG.md with state.connect
This commit is contained in:
parent
38229cde3b
commit
bdb819d0f8
7 changed files with 88 additions and 3 deletions
63
protocols/altvmp.js
Normal file
63
protocols/altvmp.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import Core from './core.js'
|
||||
|
||||
export default class altvmp extends Core {
|
||||
constructor() {
|
||||
super()
|
||||
this.usedTcp = true
|
||||
}
|
||||
|
||||
async getServerFromMasterList() {
|
||||
const targetID = `${this.options.host}:${this.options.port}`
|
||||
|
||||
const results = await this.request({
|
||||
url: 'https://api.alt-mp.com/servers',
|
||||
responseType: 'json'
|
||||
})
|
||||
|
||||
if (results == null) {
|
||||
throw new Error('Unable to retrieve master server list')
|
||||
}
|
||||
|
||||
const serverInfo = results.find((server) => {
|
||||
// If the server uses a CDN, there could be occasional paths in the address, so we are checking for them.
|
||||
// If the server does not use a CDN, there will be no paths in the address and direct comparison will work.
|
||||
const address = server.useCdn
|
||||
? server.address
|
||||
: server.address.replace(/(https?:\/\/)?\/?/g, '')
|
||||
return address === targetID
|
||||
})
|
||||
|
||||
return serverInfo
|
||||
}
|
||||
|
||||
async getServerById(targetID) {
|
||||
const serverInfo = await this.request({
|
||||
url: `https://api.alt-mp.com/servers/${targetID}`,
|
||||
responseType: 'json'
|
||||
})
|
||||
|
||||
if (serverInfo == null) {
|
||||
throw new Error('Unable to retrieve server info')
|
||||
}
|
||||
|
||||
return serverInfo
|
||||
}
|
||||
|
||||
async run(state) {
|
||||
const serverInfo = this.options.serverId
|
||||
? await this.getServerById(this.options.serverId)
|
||||
: await this.getServerFromMasterList()
|
||||
|
||||
if (!serverInfo) {
|
||||
throw new Error('No server info was found.')
|
||||
}
|
||||
|
||||
state.name = serverInfo.name
|
||||
state.numplayers = serverInfo.playersCount
|
||||
state.maxplayers = serverInfo.maxPlayersCount
|
||||
state.password = serverInfo.passworded
|
||||
state.version = serverInfo.version
|
||||
state.connect = `altv://${serverInfo.address}`
|
||||
state.raw = serverInfo
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ export default class Core extends EventEmitter {
|
|||
state.queryPort = options.port
|
||||
// because lots of servers prefix with spaces to try to appear first
|
||||
state.name = (state.name || '').trim()
|
||||
state.connect = `${state.gameHost || options.host || options.address}:${state.gamePort || options.port}`
|
||||
state.connect = state.connect || `${state.gameHost || options.host || options.address}:${state.gamePort || options.port}`
|
||||
state.ping = this.shortestRTT
|
||||
|
||||
delete state.gameHost
|
||||
|
|
|
|||
|
|
@ -59,11 +59,12 @@ import dayz from './dayz.js'
|
|||
import theisleevrima from './theisleevrima.js'
|
||||
import ragemp from './ragemp.js'
|
||||
import xonotic from './xonotic.js'
|
||||
import altvmp from './altvmp.js'
|
||||
|
||||
export {
|
||||
armagetron, ase, asa, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, epic, factorio, farmingsimulator, ffow,
|
||||
fivem, gamespy1, gamespy2, gamespy3, geneshift, goldsrc, gtasao, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft,
|
||||
minecraftbedrock, minecraftvanilla, minetest, mumble, mumbleping, nadeo, openttd, palworld, quake1, quake2, quake3, rfactor, ragemp, samp,
|
||||
savage2, starmade, starsiege, teamspeak2, teamspeak3, terraria, tribes1, tribes1master, unreal2, ut3, valve,
|
||||
vcmp, ventrilo, warsow, eldewrito, beammpmaster, beammp, dayz, theisleevrima, xonotic
|
||||
vcmp, ventrilo, warsow, eldewrito, beammpmaster, beammp, dayz, theisleevrima, xonotic, altvmp
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue