mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2026-05-26 00:53:28 -06:00
Release v3.0.0
- Update gamedig from 4.0.6 to 5.1.0 (breaking change! various server types renamed) - Fixed autocomplete for server types and now selecting a server type auto fills the query port with the default - Added strip colors gamedig option - Added address gamedig option to skip DNS resolution - Added github funding links
This commit is contained in:
+31
-55
@@ -1,34 +1,25 @@
|
||||
module.exports = function(RED) {
|
||||
const gamedig = require('gamedig');
|
||||
const fs = require('fs');
|
||||
const { GameDig, games } = require('gamedig');
|
||||
|
||||
function QueryGameServer(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
let node = this;
|
||||
this.server_type = config.server_type;
|
||||
this.host = config.host;
|
||||
this.port = config.port;
|
||||
this.halt_if = config.halt_if;
|
||||
this.max_attempts = config.max_attempts || 1;
|
||||
this.socket_timeout = config.socket_timeout || 2000;
|
||||
this.attempt_timeout = config.attempt_timeout || 10000;
|
||||
this.given_port_only = config.given_port_only || false;
|
||||
this.ip_family = config.ip_family || 0;
|
||||
this.debug = config.debug || false;
|
||||
this.request_rules = config.request_rules || false;
|
||||
this.output_options = config.output_options || false;
|
||||
node.on('input', function(msg) {
|
||||
let options = {
|
||||
'type': node.server_type || msg.server_type || undefined,
|
||||
'host': node.host || msg.host || undefined,
|
||||
'port': node.port || msg.port || undefined,
|
||||
'maxAttempts': node.max_attempts || msg.max_attempts || undefined,
|
||||
'socketTimeout': node.socket_timeout || msg.socket_timeout || undefined,
|
||||
'attemptTimeout': node.attempt_timeout || msg.attempt_timeout || undefined,
|
||||
'givenPortOnly': node.given_port_only || msg.given_port_only || undefined,
|
||||
'ipFamily': node.ip_family || msg.ip_family || undefined,
|
||||
'debug': node.debug || msg.config || undefined,
|
||||
'requestRules': node.request_rules || msg.request_rules || undefined
|
||||
'type': config.server_type || msg.server_type || undefined,
|
||||
'host': config.host || msg.host || undefined,
|
||||
'address': config.address || msg.address || undefined,
|
||||
'port': config.port || msg.port || undefined,
|
||||
'maxAttempts': config.max_attempts || msg.max_attempts || 1,
|
||||
'socketTimeout': config.socket_timeout || msg.socket_timeout || 2000,
|
||||
'attemptTimeout': config.attempt_timeout || msg.attempt_timeout || 10000,
|
||||
'givenPortOnly': config.given_port_only || msg.given_port_only || false,
|
||||
'ipFamily': config.ip_family || msg.ip_family || undefined,
|
||||
'debug': config.debug || msg.config || undefined,
|
||||
'requestRules': config.request_rules || msg.request_rules || undefined,
|
||||
'strip_colors': typeof config.strip_colors === "undefined" ? true : config.strip_colors
|
||||
};
|
||||
|
||||
if(typeof msg.options === 'object' && msg.options)
|
||||
@@ -38,15 +29,20 @@ module.exports = function(RED) {
|
||||
|
||||
// set the things we want to return
|
||||
msg.server_type = options.type;
|
||||
msg.host = options.host;
|
||||
if(options.host) {
|
||||
msg.host = options.host;
|
||||
}
|
||||
if(options.address) {
|
||||
msg.address = options.address;
|
||||
}
|
||||
msg.port = options.port;
|
||||
if(node.output_options)
|
||||
{
|
||||
msg.options = options;
|
||||
}
|
||||
|
||||
if(!options.host) {
|
||||
node.error("host missing from input.");
|
||||
if(!msg.host && !msg.address) {
|
||||
node.error("host/address missing from input.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +51,7 @@ module.exports = function(RED) {
|
||||
return;
|
||||
}
|
||||
|
||||
gamedig.query(options)
|
||||
GameDig.query(options)
|
||||
.then(function(state) {
|
||||
msg.payload = 'online';
|
||||
msg.data = state;
|
||||
@@ -81,39 +77,19 @@ module.exports = function(RED) {
|
||||
|
||||
RED.httpAdmin.get(
|
||||
"/gamedig/types",
|
||||
RED.auth.needsPermission('gamedig.types'),
|
||||
RED.auth.needsPermission('flows.write'),
|
||||
function(req, res) {
|
||||
// gamedig has no way of listing available server types
|
||||
// so we just use regex to parse the info from the README
|
||||
// this could break so we also reference the gamedig repo
|
||||
let availableTypesContent = fs.readFileSync(require.resolve("gamedig/games.txt"), 'utf-8')
|
||||
server_types = [];
|
||||
console.log(games);
|
||||
let server_types = Object.keys(games).map(gameKey => {
|
||||
let game = games[gameKey];
|
||||
game["type"] = gameKey;
|
||||
return game;
|
||||
});
|
||||
|
||||
availableTypesContent
|
||||
.split(/\r?\n/)
|
||||
.forEach(line => {
|
||||
if(
|
||||
line.trim().length === 0
|
||||
|| line.trim().length === 0
|
||||
|| line.trim().startsWith('#')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// examples:
|
||||
// avp2|Aliens versus Predator 2 (2001)|gamespy1|port=27888
|
||||
// avp2010|Aliens vs. Predator (2010)|valve|port=27015
|
||||
|
||||
let [game_type, game_name, game_protocol] = line.split('|');
|
||||
server_types.push({
|
||||
'name': game_name,
|
||||
'type': game_type,
|
||||
'protocol': game_protocol
|
||||
});
|
||||
});
|
||||
res.json({
|
||||
'result': 'ok',
|
||||
'server_types': server_types
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user