mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
feat(games/satisfactory): pass optional token, make http query not required (#653)
* feat: let the user provide a token to skip PasswordlessLogin * feat: make querying the HTTP api not required * docs: add to changelog, note query priority * fix: passing rejectUnauthorized as arg made it string, ignoring its value
This commit is contained in:
parent
5b1da1ad71
commit
f5899fd54d
4 changed files with 33 additions and 21 deletions
|
|
@ -28,22 +28,15 @@ export default class satisfactory extends Core {
|
|||
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.
|
||||
* https://satisfactory.wiki.gg/wiki/Dedicated_servers/HTTPS_API
|
||||
*/
|
||||
|
||||
const tokenRequestJson = {
|
||||
function: 'PasswordlessLogin',
|
||||
data: {
|
||||
MinimumPrivilegeLevel: 'Client'
|
||||
}
|
||||
}
|
||||
|
||||
const queryJson = {
|
||||
function: 'QueryServerState'
|
||||
try {
|
||||
await this.doHttpApiQueries(state)
|
||||
} catch (e) {
|
||||
this.logger.debug('HTTP API query failed.')
|
||||
this.logger.debug(e)
|
||||
}
|
||||
}
|
||||
|
||||
async doHttpApiQueries (state) {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
|
@ -55,11 +48,26 @@ export default class satisfactory extends Core {
|
|||
*/
|
||||
if (!this.options.rejectUnauthorized) this.options.rejectUnauthorized = false
|
||||
|
||||
const tokenRequestResponse = await this.queryInfo(tokenRequestJson, headers)
|
||||
let token = this.options.token
|
||||
if (!token) {
|
||||
const tokenRequestJson = {
|
||||
function: 'PasswordlessLogin',
|
||||
data: {
|
||||
MinimumPrivilegeLevel: 'Client'
|
||||
}
|
||||
}
|
||||
|
||||
const { data: queryResponse } = await this.queryInfo(queryJson, {
|
||||
const response = await this.queryInfo(tokenRequestJson, headers)
|
||||
token = response.authenticationToken
|
||||
}
|
||||
|
||||
const queryJson = {
|
||||
function: 'QueryServerState'
|
||||
}
|
||||
|
||||
const queryResponse = await this.queryInfo(queryJson, {
|
||||
...headers,
|
||||
Authorization: `Bearer ${tokenRequestResponse.data.authenticationToken}`
|
||||
Authorization: `Bearer ${token}`
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
@ -92,7 +100,7 @@ export default class satisfactory extends Core {
|
|||
if (response.data == null) {
|
||||
throw new Error('Unable to retrieve data from server')
|
||||
} else {
|
||||
return response
|
||||
return response.data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue