mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
feat: Satisfactory add lightweight query (#652)
* feat: add lightweight query * docs: update CHANGELOG
This commit is contained in:
parent
899a39a393
commit
5b1da1ad71
2 changed files with 28 additions and 12 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
## 5.X.Y
|
## 5.X.Y
|
||||||
* Feat: Replaced `punycode` package usage with `url.domainToASCII` (#630).
|
* Feat: Replaced `punycode` package usage with `url.domainToASCII` (#630).
|
||||||
* Feat: World of Padman (2007) - Added support (#636)
|
* Feat: World of Padman (2007) - Added support (#636)
|
||||||
* Feat: Satisfactory - Added support (By @Smidy13 #645)
|
* Feat: Satisfactory - Added support (By @Smidy13 #645, #652)
|
||||||
* Feat: Update Soldat protocol (#642)
|
* Feat: Update Soldat protocol (#642)
|
||||||
* Feat: TOXIKK (2016) - Added support (#641)
|
* Feat: TOXIKK (2016) - Added support (#641)
|
||||||
* Feat: Renegade X (2014) - Added support (#643)
|
* Feat: Renegade X (2014) - Added support (#643)
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,27 @@ export default class satisfactory extends Core {
|
||||||
|
|
||||||
// Don't use the tcp ping probing
|
// Don't use the tcp ping probing
|
||||||
this.usedTcp = true
|
this.usedTcp = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async run (state) {
|
async run (state) {
|
||||||
|
const packet = Buffer.from([0xD5, 0xF6, 0, 1, 5, 5, 5, 5, 5, 5, 5, 5, 1])
|
||||||
|
const response = await this.udpSend(packet, packet => {
|
||||||
|
const reader = this.reader(packet)
|
||||||
|
const header = reader.part(4)
|
||||||
|
if (header.equals(Buffer.from([0xD5, 0xF6, 1, 2]))) return
|
||||||
|
reader.skip(8) // skip the cookie
|
||||||
|
return reader
|
||||||
|
})
|
||||||
|
|
||||||
|
state.raw.serverState = response.int(1)
|
||||||
|
state.version = response.int(4).toString()
|
||||||
|
state.raw.serverFlags = response.int(8)
|
||||||
|
|
||||||
|
const subStatesCount = response.int(1)
|
||||||
|
response.skip(subStatesCount * 3)
|
||||||
|
|
||||||
|
const nameLength = response.int(2)
|
||||||
|
state.name = response.part(nameLength).toString('utf-8')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get information about the Satisfactory game server, you need to first obtain a client authenticationToken.
|
* To get information about the Satisfactory game server, you need to first obtain a client authenticationToken.
|
||||||
|
|
@ -27,7 +44,7 @@ export default class satisfactory extends Core {
|
||||||
function: 'QueryServerState'
|
function: 'QueryServerState'
|
||||||
}
|
}
|
||||||
|
|
||||||
let headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,25 +55,24 @@ export default class satisfactory extends Core {
|
||||||
*/
|
*/
|
||||||
if (!this.options.rejectUnauthorized) this.options.rejectUnauthorized = false
|
if (!this.options.rejectUnauthorized) this.options.rejectUnauthorized = false
|
||||||
|
|
||||||
let tokenRequestResponse = await this.queryInfo(tokenRequestJson, headers)
|
const tokenRequestResponse = await this.queryInfo(tokenRequestJson, headers)
|
||||||
|
|
||||||
headers.Authorization = `Bearer ${tokenRequestResponse.data.authenticationToken}`
|
const { data: queryResponse } = await this.queryInfo(queryJson, {
|
||||||
|
...headers,
|
||||||
let queryResponse = await this.queryInfo(queryJson, headers)
|
Authorization: `Bearer ${tokenRequestResponse.data.authenticationToken}`
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Satisfactory API cannot pull Server Name at the moment, see QA and vote for fix here
|
* Satisfactory API cannot pull Server Name at the moment, see QA and vote for fix here
|
||||||
* https://questions.satisfactorygame.com/post/66ebebad772a987f4a8b9ef8
|
* https://questions.satisfactorygame.com/post/66ebebad772a987f4a8b9ef8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
state.numplayers = queryResponse.data.serverGameState.numConnectedPlayers
|
state.numplayers = queryResponse.serverGameState.numConnectedPlayers
|
||||||
state.maxplayers = queryResponse.data.serverGameState.playerLimit
|
state.maxplayers = queryResponse.serverGameState.playerLimit
|
||||||
state.raw = queryResponse
|
state.raw.http = queryResponse
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async queryInfo (json, headers) {
|
async queryInfo (json, headers) {
|
||||||
|
|
||||||
const url = `https://${this.options.host}:${this.options.port}/api/v1/`
|
const url = `https://${this.options.host}:${this.options.port}/api/v1/`
|
||||||
|
|
||||||
this.logger.debug(`POST: ${url}`)
|
this.logger.debug(`POST: ${url}`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue