mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
feat: Add Farming Simulator 22/19 (#531)
* Added token paramter * Added Farming Simulator 2022 * Fixed order * Undo debug line * Update Farming Simulator 22 support (By @Vito0912 #531) * Added Farming Simulator 2019 support * Revert change * Update release year for Farming Simulator 2019 * Update mods array to raw.mods in farmingsimulator.js * Update Farming Simulator naming in GAMES_LIST.md * Missed some names * Add server version to state.raw and eslint
This commit is contained in:
parent
321f35999e
commit
3a17184862
6 changed files with 83 additions and 4 deletions
55
protocols/farmingsimulator.js
Normal file
55
protocols/farmingsimulator.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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.raw.mods = []
|
||||
$('Mod').each(function () {
|
||||
if ($(this).attr('name') !== undefined) {
|
||||
state.raw.mods.push({
|
||||
name: $(this).text(),
|
||||
short_name: $(this).attr('name'),
|
||||
author: $(this).attr('author'),
|
||||
version: $(this).attr('version'),
|
||||
hash: $(this).attr('hash')
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
state.raw.version = serverInfo.attr('version')
|
||||
|
||||
// TODO: Add state.raw
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue