feat: replace cheerio and update build-and-shoot (#683)

* Implement fast-xml-parser replacing cheerio for farmingsim

* Add extra player raw fields

* Update buildandshoot for server 0.75 which uses json.

* Remove cheerio

* Add changelog entry

* Add notes for build and shoot query server

* Update CHANGELOG.md

* Update package.json to fix version

* Update buildandshoot.js

* update lock

* Add specific key and value to bas config in note

* Add spacing for import

* Run eslint on bas protocol

* Use includes for check. Add doc notes to games.js

* Updates GAMES_LIST.md

* fix: support stable and master

* attempt to manually fix conflict

* fix players

* fix fx

* Update CHANGELOG.md

---------

Co-authored-by: CosminPerRam <cosmin.p@live.com>
This commit is contained in:
James Causon 2025-04-25 21:57:04 +01:00 committed by GitHub
parent 58f045dd36
commit 47c9182bed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 129 additions and 404 deletions

View file

@ -1,55 +1,42 @@
import Core from './core.js'
import * as cheerio from 'cheerio'
// We are doing some shenanigans here as we are trying to support the stable version and the git master version
// as in the latest (0.75) releases they are mixed up.
export default class buildandshoot extends Core {
async run (state) {
const body = await this.request({
url: 'http://' + this.options.address + ':' + this.options.port + '/'
const request = await this.request({
url: 'http://' + this.options.address + ':' + this.options.port + '/json',
responseType: 'json'
})
let m
state.name = request.serverName
state.map = request.map.name
state.version = request.serverVersion
m = body.match(/status server for (.*?)\.?[\r\n]/)
if (m) state.name = m[1]
m = body.match(/Current uptime: (\d+)/)
if (m) state.raw.uptime = m[1]
m = body.match(/currently running (.*?) by /)
if (m) state.map = m[1]
m = body.match(/Current players: (\d+)\/(\d+)/)
if (m) {
state.numplayers = parseInt(m[1])
state.maxplayers = m[2]
const bluePlayers = request.players?.blue || []
const greenPlayers = request.players?.green || []
let players = bluePlayers.concat(greenPlayers)
if (Array.isArray(request.players)) {
players = players.concat(request.players)
}
m = body.match(/aos:\/\/[0-9]+:[0-9]+/)
if (m) {
state.connect = m[0]
}
state.numplayers = players.length
state.maxplayers = request.maxPlayers || request.players?.maxPlayers
const $ = cheerio.load(body)
$('#playerlist tbody tr').each((i, tr) => {
if (!$(tr).find('td').first().attr('colspan')) {
state.players = []
for (const player of players) {
if (typeof player === 'string') {
state.players.push({
name: $(tr).find('td').eq(2).text(),
ping: $(tr).find('td').eq(3).text().trim(),
team: $(tr).find('td').eq(4).text().toLowerCase(),
score: parseInt($(tr).find('td').eq(5).text())
name: player
})
} else {
state.players.push({
...player,
name: player.name
})
}
})
/*
var m = this.options.address.match(/(\d+)\.(\d+)\.(\d+)\.(\d+)/);
if(m) {
var o1 = parseInt(m[1]);
var o2 = parseInt(m[2]);
var o3 = parseInt(m[3]);
var o4 = parseInt(m[4]);
var addr = o1+(o2<<8)+(o3<<16)+(o4<<24);
state.raw.url = 'aos://'+addr;
}
*/
}
state.raw = request
}
}