1 Commits

Author SHA1 Message Date
skylord123 f6078118c0 Merge pull request #2 from skylord123/dev
update version to 2.1.1
2021-09-04 23:01:58 -06:00
5 changed files with 551 additions and 543 deletions
+5 -10
View File
@@ -1,21 +1,16 @@
# node-red-contrib-gamedig
Query for server information of most game/voice servers using Node-RED.
Query for the status 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/
- #### 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.
#### 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/
### Other Packages
+523 -400
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-gamedig",
"version": "2.1.2",
"version": "2.1.1",
"description": "Query for the status of any game server using node-red",
"repository": {
"type": "git",
@@ -23,6 +23,6 @@
}
},
"dependencies": {
"gamedig": "^4.0.6"
"gamedig": "^3.0.0"
}
}
+7 -82
View File
@@ -11,10 +11,6 @@
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,
@@ -34,13 +30,12 @@
oneditprepare: function() {
$.getJSON('/gamedig/types', function(data) {
let html = '<table>' +
'<thead id="query-game-server-types-table"><tr><td><strong>Type</strong></td><td><strong>Name</strong></td><td><strong>Protocol</strong></td></tr></thead>' +
'<thead id="query-game-server-types-table"><tr><td><strong>Type</strong></td><td><strong>Name</strong></td></tr></thead>' +
'<tbody id="query-game-server-type-rows">';
for(let game of data) {
for(var type in data) {
html += "<tr class=\"query-game-server-type-row\">" +
"<td>"+game['type']+"</td>" +
"<td>"+game['name']+"</td>" +
"<td>"+game['protocol']+"</td>" +
"<td>"+type+"</td>" +
"<td>"+data[type]+"</td>" +
"</tr>";
}
html += '</tbody>' +
@@ -83,7 +78,7 @@
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-server"></i> Port</label>
<label for="node-input-port"><i class="fa fa-ethernet"></i> Port</label>
<input type="text" id="node-input-port" placeholder="msg.host" />
</div>
<div style="margin-left: 105px;width: 50%;margin-bottom: 10px;margin-top: -10px;">
@@ -121,63 +116,13 @@
</div>
<div class="form-row">
<label for="node-input-attempt_timeout"><i class="fa fa-cogs"></i> Attempt Timeout</label>
<label for="node-input-attempt_timeout"><i class="fas fa-cogs"></i> Attempt Timeout</label>
<input type="text" id="node-input-attempt_timeout" placeholder="10000" />
</div>
<div style="margin-left: 105px;width: 50%;margin-bottom: 10px;margin-top: -10px;">
Milliseconds allowed for an entire query attempt. This timeout is not commonly hit, as the socketTimeout typically fires first.
</div>
<div class="form-row">
<label for="node-input-given_port_only"><i class="fa fa-lock"></i> Lock port</label>
<input
type="checkbox"
id="node-input-given_port_only"
style="width: auto; vertical-align: top"
/>
<span>
Only attempt to query server on given port (default: false).
</span>
</div>
<div class="form-row">
<label for="node-input-debug"><i class="fa fa-bug"></i> Debug mode</label>
<input
type="checkbox"
id="node-input-debug"
style="width: auto; vertical-align: top"
/>
<span>
Enables massive amounts of debug logging to stdout.
</span>
</div>
<div class="form-row">
<label for="node-input-request_rules" style="vertical-align: top"><i class="fa fa-server"></i> Request rules</label>
<div style="width: 50%;display: inline-block;">
<input
type="checkbox"
id="node-input-request_rules"
style="width: auto; vertical-align: top"
/>
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.
</div>
</div>
<div class="form-row">
<label for="node-input-ip_family"><i class="fa fa-server"></i> IP Rules</label>
<select
id="node-input-ip_family"
style="width: auto; vertical-align: top">
<option value="0">IPv4 and IPv6</option>
<option value="4">IPv4</option>
<option value="6">IPv6</option>
</select>
</div>
<div style="margin-left: 105px;width: 50%;margin-bottom: 10px;margin-top: -10px;">
IP family/version returned when looking up hostnames via DNS, can be IPv4 and IPv6, IPv4 only or IPv6 only.
</div>
<h3 id="gamdig-types">Server Types</h3>
<p>
Search available types below.<br>
@@ -209,7 +154,7 @@
</script>
<script type="text/html" data-help-name="query-game-server">
<p>Query most Game/Voice server's using the <a href="https://github.com/gamedig/node-gamedig" target="_blank">GameDig</a> library. I recommend visiting the <a href="https://github.com/gamedig/node-gamedig" target="_blank">node-gamedig GitHub page</a> for more documentation.</p>
<p>Query most Game/Voice server's using the <a href="https://github.com/gamedig/node-gamedig" target="_blank">GameDig</a> library.</p>
<h3>Inputs</h3>
<dl class="message-properties">
@@ -242,26 +187,6 @@
msg.attempt_timeout <span class="property-type">integer | null</span>
</dt>
<dd>Milliseconds allowed for an entire query attempt. This timeout is not commonly hit, as the socketTimeout typically fires first. Ignored if configured on the node.</dd>
<dt class="optional">
msg.given_port_only <span class="property-type">boolean</span>
</dt>
<dd>Only attempt to query server on given port. Ignored if configured on the node.</dd>
<dt class="optional">
msg.ip_family <span class="property-type">number</span>
</dt>
<dd>IP family/version returned when looking up hostnames via DNS, can be 0 (IPv4 and IPv6), 4 (IPv4 only) or 6 (IPv6 only). (default 0).</dd>
<dt class="optional">
msg.debug <span class="property-type">boolean</span>
</dt>
<dd>Enables massive amounts of debug logging to stdout. (default false)</dd>
<dt class="optional">
msg.request_rules <span class="property-type">boolean</span>
</dt>
<dd>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.</dd>
</dl>
<h3>Outputs</h3>
+14 -49
View File
@@ -12,10 +12,6 @@ module.exports = function(RED) {
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;
node.on('input', function(msg) {
if(node.server_type) {
msg.server_type = node.server_type;
@@ -49,33 +45,13 @@ module.exports = function(RED) {
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
'attemptTimeout': msg.attempt_timeout
})
.then(function(state) {
msg.payload = 'online';
@@ -107,31 +83,20 @@ module.exports = function(RED) {
// 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')
results = [];
let availableTypes = fs.readFileSync(require.resolve("gamedig/README.md"))
.toString()
.matchAll(/^\| `(.*)` * \| ([a-zA-Z: (0-9)\-'.]*)/gm),
results = {};
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('|');
results.push({
'name': game_type,
'type': game_type,
'protocol': game_protocol
});
});
for (const match of availableTypes) {
if(match[1].indexOf("`<br>`") >= 0) {
let names = match[1].split("`<br>`");
results[names[0]] = match[2];
results[names[1]] = match[2];
} else {
results[match[1]] = match[2];
}
}
res.json(results);
});
};