mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
More async
This commit is contained in:
parent
29ce0b82d0
commit
e937c725bb
20 changed files with 100 additions and 86 deletions
|
|
@ -9,7 +9,7 @@ class BuildAndShoot extends Core {
|
|||
|
||||
let m;
|
||||
|
||||
m = body.match(/status server for (.*?)\r|\n/);
|
||||
m = body.match(/status server for (.*?)\.?(\r|\n)/);
|
||||
if(m) state.name = m[1];
|
||||
|
||||
m = body.match(/Current uptime: (\d+)/);
|
||||
|
|
@ -24,6 +24,11 @@ class BuildAndShoot extends Core {
|
|||
state.maxplayers = m[2];
|
||||
}
|
||||
|
||||
m = body.match(/aos:\/\/[0-9]+:[0-9]+/);
|
||||
if (m) {
|
||||
state.connect = m[0];
|
||||
}
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
$('#playerlist tbody tr').each((i,tr) => {
|
||||
if (!$(tr).find('td').first().attr('colspan')) {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class Core extends EventEmitter {
|
|||
state.notes = this.options.notes;
|
||||
|
||||
// because lots of servers prefix with spaces to try to appear first
|
||||
state.name = state.name.trim();
|
||||
state.name = (state.name || '').trim();
|
||||
|
||||
state.duration = Date.now() - startMillis;
|
||||
if (!('connect' in state)) {
|
||||
|
|
@ -185,9 +185,9 @@ class Core extends EventEmitter {
|
|||
* @param {function(Socket):Promise<T>} fn
|
||||
* @returns {Promise<T>}
|
||||
*/
|
||||
async withTcp(fn) {
|
||||
async withTcp(fn, port) {
|
||||
const address = this.options.address;
|
||||
const port = this.options.port;
|
||||
if (!port) port = this.options.port;
|
||||
this.assertValidPort(port);
|
||||
|
||||
let socket, connectionTimeout;
|
||||
|
|
@ -342,10 +342,9 @@ class Core extends EventEmitter {
|
|||
log(() => params.uri + " HTTP-->");
|
||||
requestPromise
|
||||
.then((response) => log(params.uri + " <--HTTP " + response.statusCode))
|
||||
.catch(() => {
|
||||
});
|
||||
.catch(() => {});
|
||||
});
|
||||
const wrappedPromise = promise.then(response => response.body);
|
||||
const wrappedPromise = requestPromise.then(response => response.body);
|
||||
return await Promise.race([wrappedPromise, this.abortedPromise]);
|
||||
} finally {
|
||||
requestPromise && requestPromise.cancel();
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class Doom3 extends Core {
|
|||
}
|
||||
|
||||
state.raw.osmask = reader.uint(4);
|
||||
if(isEtqw) {
|
||||
if (isEtqw) {
|
||||
state.raw.ranked = reader.uint(1);
|
||||
state.raw.timeleft = reader.uint(4);
|
||||
state.raw.gamestate = reader.uint(1);
|
||||
|
|
@ -85,10 +85,12 @@ class Doom3 extends Core {
|
|||
}
|
||||
}
|
||||
|
||||
if(state.raw.si_name) state.name = state.raw.si_name;
|
||||
if(state.raw.si_map) state.map = state.raw.si_map;
|
||||
if(state.raw.si_maxplayers) state.maxplayers = parseInt(state.raw.si_maxplayers);
|
||||
if(state.raw.si_usepass === '1') state.password = true;
|
||||
if (state.raw.si_name) state.name = state.raw.si_name;
|
||||
if (state.raw.si_map) state.map = state.raw.si_map;
|
||||
if (state.raw.si_maxplayers) state.maxplayers = parseInt(state.raw.si_maxplayers);
|
||||
if (state.raw.si_maxPlayers) state.maxplayers = parseInt(state.raw.si_maxplayers);
|
||||
if (state.raw.si_usepass === '1') state.password = true;
|
||||
if (state.raw.si_needPass === '1') state.password = true;
|
||||
if (this.options.port === 27733) state.gamePort = 3074; // etqw has a different query and game port
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class Ffow extends Valve {
|
|||
state.raw.gamemode = reader.string();
|
||||
state.raw.description = reader.string();
|
||||
state.raw.version = reader.string();
|
||||
state.raw.port = reader.uint(2);
|
||||
state.gamePort = reader.uint(2);
|
||||
state.raw.numplayers = reader.uint(1);
|
||||
state.maxplayers = reader.uint(1);
|
||||
state.raw.listentype = String.fromCharCode(reader.uint(1));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class Gamespy1 extends Core {
|
|||
if ('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if (this.trueTest(state.raw.password)) state.password = true;
|
||||
if ('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if ('hostport' in state.raw) state.gamePort = parseInt(state.raw.hostport);
|
||||
}
|
||||
{
|
||||
const data = await this.sendPacket('rules');
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ class Gamespy2 extends Core {
|
|||
if (!key) break;
|
||||
state.raw[key] = value;
|
||||
}
|
||||
if('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
if('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if(this.trueTest(state.raw.password)) state.password = true;
|
||||
if('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if ('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
if ('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if (this.trueTest(state.raw.password)) state.password = true;
|
||||
if ('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if ('hostport' in state.raw) state.gamePort = parseInt(state.raw.hostport);
|
||||
}
|
||||
|
||||
// Parse players
|
||||
|
|
@ -57,10 +58,6 @@ class Gamespy2 extends Core {
|
|||
player.name = stripColor(player.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (state.raw.hostport) {
|
||||
state.gamePort = parseInt(state.raw.hostport);
|
||||
}
|
||||
}
|
||||
|
||||
async sendPacket(type) {
|
||||
|
|
|
|||
|
|
@ -109,11 +109,12 @@ class Gamespy3 extends Core {
|
|||
|
||||
// Turn all that raw state into something useful
|
||||
|
||||
if('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
if ('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
else if('servername' in state.raw) state.name = state.raw.servername;
|
||||
if('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if(state.raw.password === '1') state.password = true;
|
||||
if('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if ('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if (state.raw.password === '1') state.password = true;
|
||||
if ('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if ('hostport' in state.raw) state.gamePort = parseInt(state.raw.hostport);
|
||||
|
||||
if('' in state.raw.playerTeamInfo) {
|
||||
for (const playerInfo of state.raw.playerTeamInfo['']) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@ class Hexen2 extends Quake1 {
|
|||
this.sendHeader = '\xFFstatus\x0a';
|
||||
this.responseHeader = '\xffn';
|
||||
}
|
||||
async run(state) {
|
||||
await super.run(state);
|
||||
state.gamePort = this.options.port - 50;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Hexen2;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class Kspdmp extends Core {
|
|||
}
|
||||
state.name = json.server_name;
|
||||
state.maxplayers = json.max_players;
|
||||
state.gamePort = json.port;
|
||||
if (json.players) {
|
||||
const split = json.players.split(', ');
|
||||
for (const name of split) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class M2mp extends Core {
|
|||
state.maxplayers = this.readString(reader);
|
||||
state.raw.gamemode = this.readString(reader);
|
||||
state.password = !!reader.uint(1);
|
||||
state.gamePort = this.options.port - 1;
|
||||
|
||||
while(!reader.done()) {
|
||||
const name = this.readString(reader);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
const Core = require('./core');
|
||||
|
||||
class Mumble extends Core {
|
||||
constructor() {
|
||||
super();
|
||||
this.options.socketTimeout = 5000;
|
||||
}
|
||||
|
||||
async run(state) {
|
||||
const json = await this.withTcp(async socket => {
|
||||
return await this.tcpSend(socket, 'json', (buffer) => {
|
||||
|
|
@ -24,6 +19,7 @@ class Mumble extends Core {
|
|||
|
||||
state.raw = json;
|
||||
state.name = json.name;
|
||||
state.gamePort = json.x_gtmurmur_connectport || 64738;
|
||||
|
||||
let channelStack = [state.raw.root];
|
||||
while(channelStack.length) {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ class Nadeo extends Core {
|
|||
state.raw.nextmapUid = results.UId;
|
||||
}
|
||||
|
||||
if (this.options.port === 5000) {
|
||||
state.gamePort = 2350;
|
||||
}
|
||||
|
||||
state.raw.players = await this.methodCall(client, 'GetPlayerList', 10000, 0);
|
||||
for (const player of state.raw.players) {
|
||||
state.players.push({
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ const Core = require('./core');
|
|||
|
||||
class Teamspeak2 extends Core {
|
||||
async run(state) {
|
||||
const queryPort = this.options.teamspeakQueryPort || 51234;
|
||||
|
||||
await this.withTcp(async socket => {
|
||||
{
|
||||
const data = await this.sendCommand(socket, 'sel '+this.options.port);
|
||||
|
|
@ -55,7 +57,7 @@ class Teamspeak2 extends Core {
|
|||
state.raw.channels.push(channel);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, queryPort);
|
||||
}
|
||||
|
||||
async sendCommand(socket,cmd) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ const Core = require('./core');
|
|||
|
||||
class Teamspeak3 extends Core {
|
||||
async run(state) {
|
||||
const queryPort = this.options.teamspeakQueryPort || 10011;
|
||||
|
||||
await this.withTcp(async socket => {
|
||||
{
|
||||
const data = await this.sendCommand(socket, 'use port='+this.options.port, true);
|
||||
|
|
@ -31,7 +33,7 @@ class Teamspeak3 extends Core {
|
|||
const data = await this.sendCommand(socket, 'channellist -topic');
|
||||
state.raw.channels = data;
|
||||
}
|
||||
});
|
||||
}, queryPort);
|
||||
}
|
||||
|
||||
async sendCommand(socket,cmd,raw) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Terraria extends Core {
|
|||
}
|
||||
|
||||
state.name = json.name;
|
||||
state.raw.port = json.port;
|
||||
state.gamePort = json.port;
|
||||
state.raw.numplayers = json.playercount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Unreal2 extends Core {
|
|||
const reader = this.reader(b);
|
||||
state.raw.serverid = reader.uint(4);
|
||||
state.raw.ip = this.readUnrealString(reader);
|
||||
state.raw.port = reader.uint(4);
|
||||
state.gamePort = reader.uint(4);
|
||||
state.raw.queryport = reader.uint(4);
|
||||
state.name = this.readUnrealString(reader, true);
|
||||
state.map = this.readUnrealString(reader, true);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ class Valve extends Core {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.options.port = 27015;
|
||||
|
||||
// legacy goldsrc info response -- basically not used by ANYTHING now,
|
||||
// as most (all?) goldsrc servers respond with the source info reponse
|
||||
// delete in a few years if nothing ends up using it anymore
|
||||
|
|
@ -28,6 +26,7 @@ class Valve extends Core {
|
|||
}
|
||||
|
||||
async run(state) {
|
||||
if (!this.options.port) this.options.port = 27015;
|
||||
await this.queryInfo(state);
|
||||
await this.queryChallenge();
|
||||
await this.queryPlayers(state);
|
||||
|
|
@ -93,7 +92,7 @@ class Valve extends Core {
|
|||
}
|
||||
state.raw.version = reader.string();
|
||||
const extraFlag = reader.uint(1);
|
||||
if(extraFlag & 0x80) state.raw.port = reader.uint(2);
|
||||
if(extraFlag & 0x80) state.gamePort = reader.uint(2);
|
||||
if(extraFlag & 0x10) state.raw.steamid = reader.uint(8);
|
||||
if(extraFlag & 0x40) {
|
||||
state.raw.sourcetvport = reader.uint(2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue