mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2025-07-08 11:40:59 -06:00
Compare commits
2 Commits
e2e8119d7f
...
bb5cb45cd9
Author | SHA1 | Date | |
---|---|---|---|
bb5cb45cd9 | |||
9d200b60a1 |
15
README.md
15
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
|
||||

|
||||
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
|
||||

|
||||
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
|
||||
|
||||
|
921
package-lock.json
generated
921
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-contrib-gamedig",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.2",
|
||||
"description": "Query for the status of any game server using node-red",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -23,6 +23,6 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"gamedig": "^3.0.0"
|
||||
"gamedig": "^4.0.6"
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,13 @@
|
||||
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></tr></thead>' +
|
||||
'<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>' +
|
||||
'<tbody id="query-game-server-type-rows">';
|
||||
for(var type in data) {
|
||||
for(let game of data) {
|
||||
html += "<tr class=\"query-game-server-type-row\">" +
|
||||
"<td>"+type+"</td>" +
|
||||
"<td>"+data[type]+"</td>" +
|
||||
"<td>"+game['type']+"</td>" +
|
||||
"<td>"+game['name']+"</td>" +
|
||||
"<td>"+game['protocol']+"</td>" +
|
||||
"</tr>";
|
||||
}
|
||||
html += '</tbody>' +
|
||||
|
@ -83,20 +83,31 @@ 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 availableTypes = fs.readFileSync(require.resolve("gamedig/README.md"))
|
||||
.toString()
|
||||
.matchAll(/^\| `(.*)` * \| ([a-zA-Z: (0-9)\-'.]*)/gm),
|
||||
results = {};
|
||||
let availableTypesContent = fs.readFileSync(require.resolve("gamedig/games.txt"), 'utf-8')
|
||||
results = [];
|
||||
|
||||
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];
|
||||
}
|
||||
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
|
||||
});
|
||||
});
|
||||
res.json(results);
|
||||
});
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user