From 9db659b86bedaac81cdfe37593d68fe361ae2adf Mon Sep 17 00:00:00 2001 From: cwbr Date: Fri, 27 Dec 2019 19:53:38 +0100 Subject: [PATCH] Add Assetto Corsa support --- README.md | 1 + games.txt | 1 + protocols/assettocorsa.js | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 protocols/assettocorsa.js diff --git a/README.md b/README.md index 8f961db..76ff94e 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ Games List | `armacwa` | ARMA: Cold War Assault (2011) | `armar` | ARMA: Resistance (2011) | `armagetron` | Armagetron Advanced (2001) +| `assettocorsa` | Assetto Corsa (2014) | `atlas` | Atlas (2018) | `baldursgate` | Baldur's Gate (1998) | `bat1944` | Battalion 1944 (2018) diff --git a/games.txt b/games.txt index 9f31c25..fba2198 100644 --- a/games.txt +++ b/games.txt @@ -6,6 +6,7 @@ aoe2|Age of Empires 2 (1999)|ase|port_query=27224 alienarena|Alien Arena (2004)|quake2|port_query=27910 alienswarm|Alien Swarm (2010)|valve|port=27015 arkse|Ark: Survival Evolved (2017)|valve|port=7777,port_query=27015 +assettocorsa|Assetto Corsa (2014)|assettocorsa|port=9610 atlas|Atlas (2018)|valve|port=5761,port_query_offset=51800 avp2|Aliens versus Predator 2 (2001)|gamespy1|port=27888 avp2010|Aliens vs. Predator (2010)|valve|port=27015 diff --git a/protocols/assettocorsa.js b/protocols/assettocorsa.js new file mode 100644 index 0000000..e3fe845 --- /dev/null +++ b/protocols/assettocorsa.js @@ -0,0 +1,41 @@ +const Core = require('./core'); + +class AssettoCorsa extends Core { + async run(state) { + const serverInfo = await this.request({ + json: true, + uri: `http://${this.options.address}:${this.options.port}/INFO` + }); + const carInfo = await this.request({ + json: true, + uri: `http://${this.options.address}:${this.options.port}/JSON|${parseInt(Math.random() * 999999999999999, 10)}` + }); + + if (!serverInfo || !carInfo || !carInfo.Cars) { + throw new Error('Query not successful'); + } + + state.maxplayers = serverInfo.maxclients; + state.name = serverInfo.name; + state.map = serverInfo.track; + state.password = serverInfo.pass; + state.gamePort = serverInfo.port; + state.raw.carInfo = carInfo.Cars; + state.raw.serverInfo = serverInfo; + + state.players = carInfo.Cars.reduce((r, e) => { + if (e.IsConnected) { + r.push({ + name: e.DriverName, + car: e.Model, + skin: e.Skin, + nation: e.DriverNation, + team: e.DriverTeam + }); + } + return r; + }, state.players); + } +} + +module.exports = AssettoCorsa; \ No newline at end of file