From bb5cb45cd978217703af1d5e064be437dbb248d4 Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Thu, 23 Feb 2023 23:24:23 -0700 Subject: [PATCH 1/4] Updated readme --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 94dcb7a..01470dd 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ # node-red-contrib-gamedig -Query for the status of most game/voice servers using Node-RED. +Query for server information of most game/voice servers using Node-RED. This package adds the node "Query Game Server" that uses the NPM package [GameDig](https://www.npmjs.com/package/gamedig) to query if a server is online or not and if so returns the data of the server. You can pass the server type, host, and port on the input message or define them on the node (settings defined on the node will override msg values). +[Click here](https://github.com/gamedig/node-gamedig#return-value) if you want more information about what this library parses and standardizes from the server response. + ### Usage Examples -#### Inserting query data into InfluxDB and using Grafana to view results -![Flow Preview](https://skylar.tech/content/images/2019/12/image-2.png) -I created a post on my website about how to use this node to query gameservers and store the results in InfluxDB. I then give a dashboard in Grafana that can be used to display the data. Check it out here: -https://skylar.tech/tracking-game-server-statistics-using-node-red-influxdb-and-grafana/ +- #### Inserting query data into InfluxDB and using Grafana to view results + ![Flow Preview](https://skylar.tech/content/images/2019/12/image-2.png) + I created a post on my website about how to use this node to query gameservers and store the results in InfluxDB. I then give a dashboard in Grafana that can be used to display the data. Check it out here: + https://skylar.tech/tracking-game-server-statistics-using-node-red-influxdb-and-grafana/ + +- #### Automatically restarting servers when unavailable + Ever host a server and have it stop responding but the process doesn't crash so it doesn't auto restart? If you pair this with something like [node-red-contrib-dockerode](https://flows.nodered.org/node/node-red-contrib-dockerode) you can automatically restart the container/process if the query fails X times to respond. ### Other Packages From a5498a4ba98ae992fe91dabdc022e2dcceec6b6b Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Tue, 9 May 2023 23:35:48 -0600 Subject: [PATCH 2/4] #10 - Work on adding all available options (including advanced) from damedig --- query-game-server.html | 80 ++++++++++++++++++++++++++++++++++++++++-- query-game-server.js | 26 +++++++++++++- 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/query-game-server.html b/query-game-server.html index bd9f010..8145e42 100644 --- a/query-game-server.html +++ b/query-game-server.html @@ -11,6 +11,10 @@ max_attempts: { value: '' }, socket_timeout: { value: '' }, attempt_timeout: { value: '' }, + given_port_only: { value: '' }, + ip_family: { value: '0' }, + debug: { value: '' }, + request_rules: { value: '' } }, inputs:1, outputs:1, @@ -79,7 +83,7 @@
- +
@@ -117,13 +121,63 @@
- +
Milliseconds allowed for an entire query attempt. This timeout is not commonly hit, as the socketTimeout typically fires first.
+
+ + + + Only attempt to query server on given port (default: false). + +
+ +
+ + + + Enables massive amounts of debug logging to stdout. + +
+ +
+ +
+ + For many valve games, additional 'rules' may be fetched into the unstable raw field by setting this to true. Beware that this may increase query time and this is for Valve games only. +
+
+ +
+ + +
+
+ IP family/version returned when looking up hostnames via DNS, can be IPv4 and IPv6, IPv4 only or IPv6 only. +
+

Server Types

Search available types below.
@@ -155,7 +209,7 @@ \ No newline at end of file diff --git a/query-game-server.js b/query-game-server.js index b1d7a44..cdc2a65 100644 --- a/query-game-server.js +++ b/query-game-server.js @@ -4,7 +4,7 @@ module.exports = function(RED) { function QueryGameServer(config) { RED.nodes.createNode(this, config); - var node = this; + let node = this; this.server_type = config.server_type; this.host = config.host; this.port = config.port; @@ -16,67 +16,46 @@ module.exports = function(RED) { 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) { - if(node.server_type) { - msg.server_type = node.server_type; + 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 + }; + + if(typeof msg.options === 'object' && msg.options) + { + options = {...options, ...msg.options}; } - if(node.host) { - msg.host = node.host; + // set the things we want to return + msg.server_type = options.type; + msg.host = options.host; + msg.port = options.port; + if(node.output_options) + { + msg.options = options; } - if(!msg.host) { - node.error("msg.host missing from input."); + + if(!options.host) { + node.error("host missing from input."); return; } - if(node.port) { - msg.port = node.port; - } - - if(node.halt_if) { - msg.halt_if = node.halt_if; + if(!options.type) { + node.error("server_type missing from input."); + return; } - if(node.max_attempts) { - msg.max_attempts = node.max_attempts; - } - - if(node.socket_timeout) { - msg.socket_timeout = node.socket_timeout; - } - - if(node.attempt_timeout) { - msg.attempt_timeout = node.attempt_timeout; - } - - if(node.given_port_only) { - msg.given_port_only = node.given_port_only; - } - - if(node.ip_family) { - msg.ip_family = node.ip_family; - } - - if(node.debug) { - msg.debug = node.debug; - } - - if(node.request_rules) { - msg.request_rules = node.request_rules; - } - - gamedig.query({ - 'type': msg.server_type, - 'host': msg.host, - 'port': msg.port, - 'maxAttempts': msg.max_attempts, - 'socketTimeout': msg.socket_timeout, - 'attemptTimeout': msg.attempt_timeout, - 'givenPortOnly': msg.given_port_only, - 'ipFamily': msg.ip_family, - 'debug': msg.debug, - 'requestRules': msg.request_rules - }) + gamedig.query(options) .then(function(state) { msg.payload = 'online'; msg.data = state;