Compare commits

..

No commits in common. "6836b82b0bd7a3283130db324868e0c7d1099be4" and "539f7fe21f05f73d79e11f84644fc3607408e97b" have entirely different histories.

3 changed files with 22 additions and 41 deletions

View File

@ -1,19 +1,2 @@
# node-red-contrib-gamedig
Query for the status of any game server 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).
### 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/
### Developers
So far me (skylord123) is the only person that has contributed towards this package. Feel free to do any pull-requests to get your name here!
### License
This project is licensed under the MIT License. Check [here](LICENSE) for more information.
Query for the status of any game server using Node Red

View File

@ -1,6 +1,6 @@
{
"name": "node-red-contrib-gamedig",
"version": "1.1.5",
"version": "1.0.0",
"description": "Query for the status of any game server using node-red",
"repository": {
"type": "git",
@ -12,7 +12,6 @@
"url": "https://github.com/skylord123/node-red-contrib-gamedig/issues"
},
"homepage": "https://github.com/skylord123/node-red-contrib-gamedig#readme",
"keywords": [ "node-red", "gamedig", "query game server" ],
"node-red": {
"nodes": {
"query-game-server": "query-game-server.js"

View File

@ -9,45 +9,44 @@ module.exports = function(RED) {
this.halt_if = config.halt_if;
var node = this;
node.on('input', function(msg) {
if(node.server_type) {
msg.server_type = node.server_type;
}
if(node.host) {
msg.host = node.host;
}
var serverInfo = {
'type': node.server_type,
'host': node.host
};
if(node.port) {
msg.port = node.port;
serverInfo['port'] = node.port;
}
if(node.halt_if) {
msg.halt_if = node.halt_if;
if(msg.server_type) {
serverInfo['type'] = msg.server_type;
}
Gamedig.query({
'type': msg.server_type,
'host': msg.host
})
if(msg.host) {
serverInfo['host'] = msg.host;
}
if(msg.port) {
serverInfo['port'] = msg.port;
}
Gamedig.query(serverInfo)
.then(function(state) {
msg.payload = 'online';
msg.data = state;
if (msg.payload === msg.halt_if) {
if (msg.payload === node.halt_if) {
return null;
}
node.status({fill:"green",shape:"dot",text: 'Online ' + msg.data.players.length + ' players' });
node.send(msg);
node.send(msg);
}).catch(function(error) {
msg.payload = 'offline';
msg.data = {
'error': error
};
if (msg.payload === msg.halt_if) {
if (msg.payload === node.halt_if) {
return null;
}
node.status({fill:"red", shape:"dot", text: 'Offline'});
node.send(msg);
node.send(msg);
});
});
}