Added Farming Simulator 2022

This commit is contained in:
Vito0912 2024-02-01 19:05:55 +01:00
parent 06c1539efb
commit 6c234a940e
No known key found for this signature in database
GPG Key ID: 29A3D509FE70B237
6 changed files with 72 additions and 4 deletions

View File

@ -4,6 +4,7 @@
* Euro Truck Simulator 2 (2012) - Added support (By @podrivo #523)
* Eco - Fixed querying servers using reverse queries and player names (By @Vito0912 #526)
* Factorio (2016) - Added support (By @Vito0912 #527)
* Farming Simulator 22 (2021) - Added support (By @Vito0912)
## 5.0.0-beta.2
* Fixed support for projects using `require`.

View File

@ -120,6 +120,7 @@
| ets2 | Euro Truck Simulator 2 | [Valve Protocol](#valve) |
| f1c9902 | F1 Challenge '99-'02 | |
| factorio | Factorio | |
| farmingsimulator2022 | Farming Simulator 2022 | [Notes](#farmingsimulator) |
| farcry | Far Cry | |
| farcry2 | Far Cry 2 | |
| fear | F.E.A.R. | |
@ -352,7 +353,6 @@
* Doom - Skulltag
* Doom - ZDaemon
* ECO Global Survival ([Ref](https://github.com/Austinb/GameQ/blob/v3/src/GameQ/Protocols/Eco.php))
* Farming Simulator
* Freelancer
* Ghost Recon
* GRAV Online
@ -460,6 +460,10 @@ Conan Exiles never responds to player query.
### <a name="minecraft">Minecraft
Many Minecraft servers do not respond with players data.
### <a name='farmingsimulator'>Farming Simulator
Farming Simulator 2022 servers need a token (reffered as code in the game). It can be obtained at your server's web interface (http://ip:port/settings.html). It can be passed to GameDig with the additional option: `token`
The response includes much information about the server. Currently, only the fields about server information (name, map, version, etc.), players and mods are parsed.
Protocols with Additional Notes
---

View File

@ -102,7 +102,7 @@ export default class QueryRunner {
errors.push(e)
}
}
console.log(errors)
const err = new Error('Failed all ' + errors.length + ' attempts')
for (const e of errors) {
err.stack += '\n' + e.stack

View File

@ -1186,6 +1186,14 @@ export const games = {
protocol: 'ase'
}
},
farmingsimulator2022: {
name: 'Farming Simulator 2022',
release_year: 2021,
options: {
port: 8080,
protocol: 'farmingsimulator'
}
},
fof: {
name: 'Fistful of Frags',
release_year: 2014,

View File

@ -0,0 +1,54 @@
import Core from './core.js'
import cheerio from 'cheerio'
export default class farmingsimulator extends Core {
async run (state) {
if (!this.options.port) this.options.port = 8080
if (!this.options.token) throw new Error(`No token provided. You can get it from http://${this.options.host}:${this.options.port}/settings.html`)
const request = await this.request({
url: `http://${this.options.host}:${this.options.port}/feed/dedicated-server-stats.xml?code=${this.options.token}`,
responseType: 'text'
})
const $ = cheerio.load(request, {
xmlMode: true,
})
const serverInfo = $('Server');
const playerInfo = serverInfo.find('Slots');
state.name = serverInfo.attr('name');
state.map = serverInfo.attr('mapName');
state.numplayers = playerInfo.attr('numUsed')
state.maxplayers = playerInfo.attr('capacity')
$('Player').each(function () {
if ($(this).attr('isUsed') === 'true') {
state.players.push({
name: $(this).text(),
raw: {
isAdmin: $(this).attr('isAdmin') === 'true',
uptime: parseInt($(this).attr('uptime'), 10)
}
});
}
});
state.mods = [];
$('Mod').each(function () {
if ($(this).attr('name') !== undefined) {
state.mods.push({
name: $(this).text(),
short_name: $(this).attr('name'),
author: $(this).attr('author'),
version: $(this).attr('version'),
hash: $(this).attr('hash'),
});
}
});
// TODO: Add state.raw
}
}

View File

@ -11,6 +11,7 @@ import eco from './eco.js'
import eldewrito from './eldewrito.js'
import epic from './epic.js'
import factorio from './factorio.js'
import farmingsimulator from './farmingsimulator.js'
import ffow from './ffow.js'
import fivem from './fivem.js'
import gamespy1 from './gamespy1.js'
@ -56,8 +57,8 @@ import dayz from './dayz.js'
import theisleevrima from './theisleevrima.js'
export {
armagetron, ase, asa, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, epic, factorio, ffow, fivem, gamespy1,
gamespy2, gamespy3, geneshift, goldsrc, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft,
armagetron, ase, asa, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, epic, factorio, farmingsimulator, ffow,
fivem, gamespy1, gamespy2, gamespy3, geneshift, goldsrc, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft,
minecraftbedrock, minecraftvanilla, mumble, mumbleping, nadeo, openttd, palworld, quake1, quake2, quake3, rfactor, samp,
savage2, starmade, starsiege, teamspeak2, teamspeak3, terraria, tribes1, tribes1master, unreal2, ut3, valve,
vcmp, ventrilo, warsow, eldewrito, beammpmaster, beammp, dayz, theisleevrima