Update dependencies

This commit is contained in:
mmorrison 2019-10-15 15:03:11 -05:00
parent 9cec162b94
commit 899627a92f
3 changed files with 166 additions and 123 deletions

View file

@ -6,13 +6,13 @@ class Nadeo extends Core {
async run(state) {
await this.withClient(async client => {
const start = Date.now();
await this.methodCall(client, 'Authenticate', this.options.login, this.options.password);
await this.query(client, 'Authenticate', this.options.login, this.options.password);
this.registerRtt(Date.now()-start);
//const data = this.methodCall(client, 'GetStatus');
{
const results = await this.methodCall(client, 'GetServerOptions');
const results = await this.query(client, 'GetServerOptions');
state.name = this.stripColors(results.Name);
state.password = (results.Password !== 'No password');
state.maxplayers = results.CurrentMaxPlayers;
@ -20,13 +20,13 @@ class Nadeo extends Core {
}
{
const results = await this.methodCall(client, 'GetCurrentMapInfo');
const results = await this.query(client, 'GetCurrentMapInfo');
state.map = this.stripColors(results.Name);
state.raw.mapUid = results.UId;
}
{
const results = await this.methodCall(client, 'GetCurrentGameInfo');
const results = await this.query(client, 'GetCurrentGameInfo');
let gamemode = '';
const igm = results.GameMode;
if(igm === 0) gamemode="Rounds";
@ -40,7 +40,7 @@ class Nadeo extends Core {
}
{
const results = await this.methodCall(client, 'GetNextMapInfo');
const results = await this.query(client, 'GetNextMapInfo');
state.raw.nextmapName = this.stripColors(results.Name);
state.raw.nextmapUid = results.UId;
}
@ -49,7 +49,7 @@ class Nadeo extends Core {
state.gamePort = 2350;
}
state.raw.players = await this.methodCall(client, 'GetPlayerList', 10000, 0);
state.raw.players = await this.query(client, 'GetPlayerList', 10000, 0);
for (const player of state.raw.players) {
state.players.push({
name:this.stripColors(player.Name || player.NickName)
@ -59,31 +59,22 @@ class Nadeo extends Core {
}
async withClient(fn) {
const socket = gbxremote.createClient(this.options.port, this.options.host);
const socket = new gbxremote.Client(this.options.port, this.options.host);
try {
const connectPromise = new Promise((resolve,reject) => {
socket.on('connect', resolve);
socket.on('error', e => reject(new Error('GBX Remote Connection Error: ' + e)));
socket.on('close', () => reject(new Error('GBX Remote Connection Refused')));
});
const connectPromise = socket.connect();
const timeoutPromise = Promises.createTimeout(this.options.socketTimeout, 'GBX Remote Opening');
const socket = await Promise.race([connectPromise, timeoutPromise, this.abortedPromise]);
await Promise.race([connectPromise, timeoutPromise, this.abortedPromise]);
return await fn(socket);
} finally {
socket.terminate();
}
}
async methodCall(client, ...cmdset) {
async query(client, ...cmdset) {
const cmd = cmdset[0];
const params = cmdset.slice(1);
const sentPromise = new Promise(async (resolve,reject) => {
client.methodCall(cmd, params, (err, value) => {
if (err) reject(new Error('XMLRPC error ' + JSON.stringify(err)));
resolve(value);
});
});
const sentPromise = client.query(cmd, params);
const timeoutPromise = Promises.createTimeout(this.options.socketTimeout, 'GBX Method Call');
return await Promise.race([sentPromise, timeoutPromise, this.abortedPromise]);
}