Compare commits

...

7 Commits

Author SHA1 Message Date
Pedro Ivo Hudson e7bc452332
Merge a4790bbfaa into ee5baaff13 2024-04-10 09:00:59 +02:00
CosminPerRam ee5baaff13
feat: add palworld new new query implementation (#560)
* feat: add initial first working query

* feat: map serverInfo data

* feat: add players, settings and metrics queries

* update docs stuff

* fix broken palworld hyperlink in games list
2024-04-08 20:11:08 +03:00
Pedro Ivo Hudson a4790bbfaa fix alias reference in tools 2024-02-14 11:33:35 -03:00
Pedro Ivo Hudson 242a1f4035 adds checkAlias option 2024-02-14 11:31:58 -03:00
Pedro Ivo Hudson c9d8e00139 add alias as an extra field 2024-02-09 21:15:36 -03:00
Pedro Ivo Hudson c317cfc760 Merge branch 'master' into fat/add-game-type-alias 2024-02-09 21:09:50 -03:00
Pedro Ivo Hudson cebefe3899 feat: add game type alias 2024-01-18 08:00:08 -03:00
8 changed files with 51 additions and 21 deletions

View File

@ -15,6 +15,7 @@
* Myth of Empires - Added support.
* Fix: BeamMP maxplayers that was displaying player count (By @dgibbs64 #551)
* Fix: BeamMP filter servers by address, not host (By @Rephot #558)
* Palworld - Replace old and broken protocol with the new one (#560)
## 5.0.0-beta.2
* Fixed support for projects using `require`.

View File

@ -210,7 +210,7 @@
| openarena | OpenArena | |
| openttd | OpenTTD | |
| painkiller | Painkiller | |
| palworld | Palworld | [EOS Protocol](#epic) |
| palworld | Palworld | [Notes](#palworld) |
| pce | Primal Carnage: Extinction | [Valve Protocol](#valve) |
| pixark | PixARK | [Valve Protocol](#valve) |
| postal2 | Postal 2 | |
@ -459,3 +459,8 @@ option: `requestRules: true`. Beware that this may increase query time.
### <a name="epic"></a>Epic Online Services (EOS) Protocol
EOS does not provide players data.
### <a name="palworld"></a>Palworld
Palworld support can be unstable, the devs mention the api is currently experimental.
To query palworld servers, the `RESTAPIEnabled` must be `True` in the configuration file, and you need to pass
the `username` (currently always `admin`) and `password` (settings parameter) for it.

View File

@ -59,6 +59,7 @@ Confused on how this works, or you want to see more? Checkout the [examples](/ex
| **portCache** | boolean | true | After you queried a server, the second time you query that exact server (identified by specified ip and port), first add an attempt to query with the last successful port. |
| **noBreadthOrder** | boolean | false | Enable the behaviour of retrying an attempt X times followed by the next attempt X times, otherwise try attempt A, then B, then A, then B until reaching the X retry count of each. |
| **checkOldIDs** | boolean | false | Also checks the old ids amongst the current ones. |
| **checkAlias** | boolean | false | Also checks for alternative game ids. |
## Query Response

View File

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

View File

@ -13,6 +13,12 @@ export const lookup = (options) => {
let game = games[type]
if (options.checkAlias) {
Object.keys(games).forEach((id) => {
if (games[id]?.extra?.alias) game = games[id]
})
}
if (options.checkOldIDs) {
Object.keys(games).forEach((id) => {
if (games[id]?.extra?.old_id === type) {

View File

@ -2092,8 +2092,9 @@ export const games = {
name: 'Palworld',
release_year: 2024,
options: {
port: 8211,
protocol: 'palworld'
port: 8212,
protocol: 'palworld',
doc_notes: 'palworld'
}
},
pvak2: {

View File

@ -1,20 +1,32 @@
import Epic from './epic.js'
import Core from './core.js'
export default class palworld extends Epic {
constructor () {
super()
export default class palworld extends Core {
async makeCall (endpoint) {
const url = `http://${this.options.host}:${this.options.port}/v1/api/${endpoint}`
const headers = {
Authorization: `Basic ${Buffer.from(`${this.options.username}:${this.options.password}`).toString('base64')}`,
Accept: 'application/json'
}
// OAuth2 credentials extracted from Palworld files.
this.clientId = 'xyza78916PZ5DF0fAahu4tnrKKyFpqRE'
this.clientSecret = 'j0NapLEPm3R3EOrlQiM8cRLKq3Rt02ZVVwT0SkZstSg'
this.deploymentId = '0a18471f93d448e2a1f60e47e03d3413'
this.authByExternalToken = true
return await this.request({ url, headers, method: 'GET', responseType: 'json' })
}
async run (state) {
await super.run(state)
state.name = state.raw.attributes.NAME_s
state.numplayers = state.raw.attributes.PLAYERS_l
state.version = state.raw.attributes.VERSION_S
const serverInfo = await this.makeCall('info')
state.version = serverInfo.version
state.name = serverInfo.servername
state.raw.serverInfo = serverInfo
const { players } = await this.makeCall('players')
state.numplayers = players.length
state.players = players.map(p => p.name)
state.raw.players = players
state.raw.settings = await this.makeCall('settings')
const metrics = await this.makeCall('metrics')
state.numplayers = metrics.currentplayernum
state.maxplayers = metrics.maxplayernum
state.raw.metrics = metrics
}
}

View File

@ -21,12 +21,16 @@ sortedGamesIds.forEach(key => {
})
let generated = ''
generated += '| GameDig Type ID | Name | See Also\n'
generated += '|---|---|---\n'
generated += '| GameDig Type ID | Alias | Name | See Also\n'
generated += '|---|---|---|---\n'
for (const id in sortedGames) {
const game = sortedGames[id]
generated += '| ' + id.padEnd(10, ' ') + ' | ' + game.name
if (!game?.extra?.alias) {
game.alias = ' '
}
generated += '| ' + id.padEnd(10, ' ') + ' | ' + game.alias + ' | ' + game.name
const notes = []
if (game?.extra?.doc_notes) {
notes.push('[Notes](#' + game.extra.doc_notes + ')')
@ -34,7 +38,7 @@ for (const id in sortedGames) {
if (game.options.protocol === 'valve' || game.options.protocol === 'dayz') {
notes.push('[Valve Protocol](#valve)')
}
if (game.options.protocol === 'epic' || game.options.protocol === 'asa' || game.options.protocol === 'palworld' || game.options.protocol === 'theisleevrima') {
if (game.options.protocol === 'epic' || game.options.protocol === 'asa' || game.options.protocol === 'theisleevrima') {
notes.push('[EOS Protocol](#epic)')
}
if (notes.length) {