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:
CosminPerRam 2024-10-16 22:40:06 +03:00 committed by GitHub
parent 5b1da1ad71
commit f5899fd54d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 21 deletions

View file

@ -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, #652) * Feat: Satisfactory - Added support (By @Smidy13 #645, #652, #653)
* 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)

View file

@ -521,8 +521,12 @@ Palworld support can be unstable, the devs mention the api is currently experime
To query Palworld servers, the `RESTAPIEnabled` setting must be `True` in the configuration file, and you need to pass the `username` (currently always `admin`) and the `adminpassword` (from the server config) as the `password` parameter. To query Palworld servers, the `RESTAPIEnabled` setting must be `True` in the configuration file, and you need to pass the `username` (currently always `admin`) and the `adminpassword` (from the server config) as the `password` parameter.
### <a name="satisfactory"></a>Satisfactory ### <a name="satisfactory"></a>Satisfactory
Satisfactory servers unless specified use self-signed certificates for the HTTPS API. If you are using a self-signed certificate you will need to set the `rejectUnauthorized` flag in options to `false` in order to connect. Satisfactory servers unless specified use self-signed certificates for the HTTPS API. If you are using proper-signed certificates you will need to set the `rejectUnauthorized` flag in options to `true` to ensure a secured query.
For more information on setting a user certificate refer to the [Satisfactory Dedicated server/HTTPS API wiki documentation](https://satisfactory.wiki.gg/wiki/Dedicated_servers/HTTPS_API). For more information on setting a user certificate refer to the [Satisfactory Dedicated server/HTTPS API wiki documentation](https://satisfactory.wiki.gg/wiki/Dedicated_servers/HTTPS_API).
One can also provide an authentication token via the `token` option to skip the `PasswordlessLogin` query.
The query is done via the lightweight query option but also safely tries to utilize the HTTP one.
### <a name="soldat"></a>Soldat ### <a name="soldat"></a>Soldat
Requires `Allow_Download` and `Logging` to be `1` in the server config. Requires `Allow_Download` and `Logging` to be `1` in the server config.

View file

@ -6,7 +6,7 @@ import Minimist from 'minimist'
import { GameDig } from './../lib/index.js' import { GameDig } from './../lib/index.js'
const argv = Minimist(process.argv.slice(2), { const argv = Minimist(process.argv.slice(2), {
boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules', 'requestPlayers', 'requestRulesRequired', 'requestPlayersRequired', 'stripColors', 'portCache', 'noBreadthOrder', 'checkOldIDs'], boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules', 'requestPlayers', 'requestRulesRequired', 'requestPlayersRequired', 'stripColors', 'portCache', 'noBreadthOrder', 'checkOldIDs', 'rejectUnauthorized'],
string: ['guildId', 'serverId', 'listenUdpPort', 'ipFamily', 'token'], string: ['guildId', 'serverId', 'listenUdpPort', 'ipFamily', 'token'],
default: { default: {
stripColors: true, stripColors: true,

View file

@ -28,22 +28,15 @@ export default class satisfactory extends Core {
const nameLength = response.int(2) const nameLength = response.int(2)
state.name = response.part(nameLength).toString('utf-8') state.name = response.part(nameLength).toString('utf-8')
/** try {
* To get information about the Satisfactory game server, you need to first obtain a client authenticationToken. await this.doHttpApiQueries(state)
* https://satisfactory.wiki.gg/wiki/Dedicated_servers/HTTPS_API } catch (e) {
*/ this.logger.debug('HTTP API query failed.')
this.logger.debug(e)
const tokenRequestJson = {
function: 'PasswordlessLogin',
data: {
MinimumPrivilegeLevel: 'Client'
}
}
const queryJson = {
function: 'QueryServerState'
} }
}
async doHttpApiQueries (state) {
const headers = { const headers = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
@ -55,11 +48,26 @@ export default class satisfactory extends Core {
*/ */
if (!this.options.rejectUnauthorized) this.options.rejectUnauthorized = false 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, ...headers,
Authorization: `Bearer ${tokenRequestResponse.data.authenticationToken}` Authorization: `Bearer ${token}`
}) })
/** /**
@ -92,7 +100,7 @@ export default class satisfactory extends Core {
if (response.data == null) { if (response.data == null) {
throw new Error('Unable to retrieve data from server') throw new Error('Unable to retrieve data from server')
} else { } else {
return response return response.data
} }
} }
} }