2019-12-27 19:53:38 +01:00
|
|
|
const Core = require('./core');
|
|
|
|
|
|
|
|
class AssettoCorsa extends Core {
|
|
|
|
async run(state) {
|
|
|
|
const serverInfo = await this.request({
|
2020-07-05 06:28:03 +02:00
|
|
|
url: `http://${this.options.address}:${this.options.port}/INFO`,
|
|
|
|
responseType: 'json'
|
2019-12-27 19:53:38 +01:00
|
|
|
});
|
|
|
|
const carInfo = await this.request({
|
2020-07-05 06:28:03 +02:00
|
|
|
url: `http://${this.options.address}:${this.options.port}/JSON|${parseInt(Math.random() * 999999999999999, 10)}`,
|
|
|
|
responseType: 'json'
|
2019-12-27 19:53:38 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-04-11 05:27:33 +02:00
|
|
|
for (const car of carInfo.Cars) {
|
|
|
|
if (car.IsConnected) {
|
|
|
|
state.players.push({
|
|
|
|
name: car.DriverName,
|
|
|
|
car: car.Model,
|
|
|
|
skin: car.Skin,
|
|
|
|
nation: car.DriverNation,
|
|
|
|
team: car.DriverTeam
|
2019-12-27 19:53:38 +01:00
|
|
|
});
|
|
|
|
}
|
2021-04-11 05:27:33 +02:00
|
|
|
}
|
2019-12-27 19:53:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 05:27:33 +02:00
|
|
|
module.exports = AssettoCorsa;
|