Bring discord protocol up to date with gamedig 3.0

This commit is contained in:
Michael Morrison 2021-05-18 22:33:36 -05:00
parent d9310db38b
commit fe124a4487
6 changed files with 43 additions and 29 deletions

View File

@ -160,6 +160,7 @@ Games List
| `devastation` | Devastation (2003) | `devastation` | Devastation (2003)
| `dinodday` | Dino D-Day (2011) | [Valve Protocol](#valve) | `dinodday` | Dino D-Day (2011) | [Valve Protocol](#valve)
| `dirttrackracing2` | Dirt Track Racing 2 (2002) | `dirttrackracing2` | Dirt Track Racing 2 (2002)
| `discord` | Discord | [Notes](#discord)
| `doom3` | Doom 3 (2004) | `doom3` | Doom 3 (2004)
| `dota2` | Dota 2 (2013) | [Valve Protocol](#valve) | `dota2` | Dota 2 (2013) | [Valve Protocol](#valve)
| `drakan` | Drakan: Order of the Flame (1999) | `drakan` | Drakan: Order of the Flame (1999)
@ -428,6 +429,11 @@ Games with Additional Notes
To receive a full player list response from CS:GO servers, the server must To receive a full player list response from CS:GO servers, the server must
have set the cvar: host_players_show 2 have set the cvar: host_players_show 2
### Discord
You must set the `guildId` request field to the server's guild ID. Do not provide an IP.
The Guild ID can be found in server widget settings (Server ID) or by enabling developer mode in client settings and right-clicking the server's icon.
In order to retrieve information from discord server's they must have the `Enable server widget` option enabled.
### Mumble ### Mumble
For full query results from Mumble, you must be running the For full query results from Mumble, you must be running the
[GTmurmur plugin](http://www.gametracker.com/downloads/gtmurmurplugin.php). [GTmurmur plugin](http://www.gametracker.com/downloads/gtmurmurplugin.php).

View File

@ -4,7 +4,8 @@ const Minimist = require('minimist'),
Gamedig = require('..'); Gamedig = require('..');
const argv = Minimist(process.argv.slice(2), { const argv = Minimist(process.argv.slice(2), {
boolean: ['pretty','debug','givenPortOnly'] boolean: ['pretty','debug','givenPortOnly'],
string: ['guildId']
}); });
const debug = argv.debug; const debug = argv.debug;

View File

@ -88,7 +88,7 @@ deusex|Deus Ex (2000)|gamespy2|port=7791,port_query_offset=1
devastation|Devastation (2003)|unreal2|port=7777,port_query_offset=1 devastation|Devastation (2003)|unreal2|port=7777,port_query_offset=1
dinodday|Dino D-Day (2011)|valve|port=27015 dinodday|Dino D-Day (2011)|valve|port=27015
dirttrackracing2|Dirt Track Racing 2 (2002)|gamespy1|port=32240,port_query_offset=-100 dirttrackracing2|Dirt Track Racing 2 (2002)|gamespy1|port=32240,port_query_offset=-100
discord|Discord|discord|port=443 discord|Discord|discord||doc_notes=discord
dnl|Dark and Light (2017)|valve|port=7777,port_query=27015 dnl|Dark and Light (2017)|valve|port=7777,port_query=27015
dod|Day of Defeat (2003)|valve|port=27015 dod|Day of Defeat (2003)|valve|port=27015
dods|Day of Defeat: Source (2005)|valve|port=27015 dods|Day of Defeat: Source (2005)|valve|port=27015

View File

@ -66,7 +66,12 @@ class QueryRunner {
port: gameOptions.port + (gameQueryPortOffset || 0) port: gameOptions.port + (gameQueryPortOffset || 0)
}); });
} else { } else {
throw new Error("Could not determine port to query. Did you provide a port or gameid?"); // Hopefully the request doesn't need a port. If it does, it'll fail when making the request.
attempts.push({
...defaultOptions,
...gameOptions,
...userOptions
});
} }
const numRetries = userOptions.maxAttempts || gameOptions.maxAttempts || defaultOptions.maxAttempts; const numRetries = userOptions.maxAttempts || gameOptions.maxAttempts || defaultOptions.maxAttempts;

View File

@ -146,7 +146,10 @@ class Core extends EventEmitter {
} }
assertValidPort(port) { assertValidPort(port) {
if (!port || port < 1 || port > 65535) { if (!port) {
throw new Error("Could not determine port to query. Did you provide a port?");
}
if (port < 1 || port > 65535) {
throw new Error("Invalid tcp/ip port: " + port); throw new Error("Invalid tcp/ip port: " + port);
} }
} }

View File

@ -1,32 +1,31 @@
const Core = require('./core'); const Core = require('./core');
class Discord extends Core { class Discord extends Core {
constructor() { async run(state) {
super(); const guildId = this.options.guildId;
this.dnsResolver = { resolve: function(address) {return {address: address} } }; if (typeof guildId !== 'string') {
} throw new Error('guildId option must be set when querying discord. Ensure the guildId is a string and not a number.'
+ " (It's too large of a number for javascript to store without losing precision)");
async run(state) { }
this.usedTcp = true; this.usedTcp = true;
const raw = await this.request({ const raw = await this.request({
uri: 'https://discordapp.com/api/guilds/' + this.options.address + '/widget.json', url: 'https://discordapp.com/api/guilds/' + guildId + '/widget.json',
}); });
const json = JSON.parse(raw); const json = JSON.parse(raw);
state.name = json.name; state.name = json.name;
if (json.instant_invite) { if (json.instant_invite) {
state.connect = json.instant_invite; state.connect = json.instant_invite;
} else { } else {
state.connect = 'https://discordapp.com/channels/' + this.options.address state.connect = 'https://discordapp.com/channels/' + guildId;
}
for (const member of json.members) {
const {username: name, ...rest} = member;
state.players.push({ name, ...rest });
}
delete json.members;
state.maxplayers = 500000;
state.raw = json;
} }
state.players = json.members.map(v => {
return {
name: v.username,
team: v.status
}
});
state.maxplayers = json.presence_count;
state.raw = json;
}
} }
module.exports = Discord; module.exports = Discord;