feat: Add support for ARK: Survival Ascended using EOS protocol (#402)

* Add epic protocol

* Add support for ARK: Survival Ascended

- Using epic protocol

* Fix online player count

* Final cleanup
This commit is contained in:
Guilherme Werner 2023-11-12 06:38:59 -03:00 committed by GitHub
parent c49d463858
commit a8bc7521f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 280 additions and 3 deletions

12
protocols/asa.js Normal file
View file

@ -0,0 +1,12 @@
import Epic from './epic.js'
export default class asa extends Epic {
constructor () {
super()
// OAuth2 credentials extracted from ARK: Survival Ascended files.
this.clientId = 'xyza7891muomRmynIIHaJB9COBKkwj6n'
this.clientSecret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s'
this.deploymentId = 'ad9a8feffb3b4b2ca315546f038c3ae2'
}
}

107
protocols/epic.js Normal file
View file

@ -0,0 +1,107 @@
import Core from './core.js'
import axios from 'axios'
export default class Epic extends Core {
constructor () {
super()
/**
* To get information about game servers using Epic's EOS, you need some credentials to authenticate using OAuth2.
*
* https://dev.epicgames.com/docs/web-api-ref/authentication
*
* These credentials can be provided by the game developers or extracted from the game's files.
*/
this.clientId = null
this.clientSecret = null
this.deploymentId = null
this.epicApi = 'https://api.epicgames.dev'
this.accessToken = null
}
async run (state) {
await this.getAccessToken()
await this.queryInfo(state)
await this.cleanup(state)
}
async getAccessToken () {
this.logger.debug('Requesting acess token ...')
const url = `${this.epicApi}/auth/v1/oauth/token`
const body = `grant_type=client_credentials&deployment_id=${this.deploymentId}`
const headers = {
Authorization: `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded'
}
this.logger.debug(`POST: ${url}`)
const response = await axios.post(url, body, { headers })
if (response.status !== 200) {
throw new Error('Failed to get OAuth token')
}
this.accessToken = response.data.access_token
}
async queryInfo (state) {
const url = `${this.epicApi}/matchmaking/v1/${this.deploymentId}/filter`
const body = {
criteria: [
{
key: 'attributes.ADDRESS_s',
op: 'EQUAL',
value: this.options.address
}
]
}
const headers = {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${this.accessToken}`
}
this.logger.debug(`POST: ${url}`)
const response = await axios.post(url, body, { headers })
if (response.status !== 200) {
throw new Error('Failed to get server info')
}
const reader = response.data
// Epic returns a list of sessions, we need to find the one with the desired port.
const hasDesiredPort = (session) => session.attributes.ADDRESSBOUND_s === `0.0.0.0:${this.options.port}` ||
session.attributes.ADDRESSBOUND_s === `${this.options.address}:${this.options.port}`
const desiredServer = reader.sessions.find(hasDesiredPort)
if (!desiredServer) {
throw new Error('Server not found')
}
state.name = desiredServer.attributes.CUSTOMSERVERNAME_s
state.map = desiredServer.attributes.MAPNAME_s
state.password = desiredServer.attributes.SERVERPASSWORD_b
state.maxplayers = desiredServer.settings.maxPublicPlayers
// If the game returns the player list, we can use it otherwise we use the total players.
if (desiredServer.totalPlayers === desiredServer.publicPlayers.length) {
for (const player of desiredServer.publicPlayers) {
state.players.push({
name: player.name,
raw: player
})
}
} else {
for (let i = 0; i < desiredServer.totalPlayers; i++) {
state.players.push('')
}
}
state.raw = desiredServer
}
async cleanup (state) {
this.accessToken = null
}
}

View file

@ -1,5 +1,6 @@
import armagetron from './armagetron.js'
import ase from './ase.js'
import asa from './asa.js'
import assettocorsa from './assettocorsa.js'
import battlefield from './battlefield.js'
import buildandshoot from './buildandshoot.js'
@ -7,6 +8,7 @@ import cs2d from './cs2d.js'
import discord from './discord.js'
import doom3 from './doom3.js'
import eco from './eco.js'
import epic from './epic.js'
import ffow from './ffow.js'
import fivem from './fivem.js'
import gamespy1 from './gamespy1.js'
@ -46,10 +48,10 @@ import vcmp from './vcmp.js'
import ventrilo from './ventrilo.js'
import warsow from './warsow.js'
export {
armagetron, ase, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, ffow, fivem, gamespy1,
export {
armagetron, ase, asa, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, epic, ffow, fivem, gamespy1,
gamespy2, gamespy3, geneshift, goldsrc, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft,
minecraftbedrock, minecraftvanilla, mumble, mumbleping, nadeo, openttd, quake1, quake2, quake3, rfactor, samp,
savage2, starmade, starsiege, teamspeak2, teamspeak3, terraria, tribes1, tribes1master, unreal2, ut3, valve,
vcmp, ventrilo, warsow
vcmp, ventrilo, warsow
}