Initial commit

This commit is contained in:
2019-02-16 16:08:01 -07:00
parent 8e13c9849b
commit b5a461b805
6 changed files with 762 additions and 0 deletions

42
query-game-server.js Normal file
View File

@@ -0,0 +1,42 @@
console.log("test");
module.exports = function(RED) {
var Gamedig = require('gamedig');
function queryGameServer(config) {
console.log("CREATED YAY");
console.log(Gamedig);
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function(msg) {
var serverInfo = {
'type': this.nodeConfig.type,
'host': this.nodeConfig.host
};
if(this.nodeConfig.port) {
serverInfo['port'] = this.nodeConfig.port;
}
Gamedig.query(serverInfo)
.then(function(state) {
msg.payload = 'online';
msg.data = state;
const shouldHaltIfState = this.nodeConfig.halt_if && ('online' === this.nodeConfig.halt_if);
if (shouldHaltIfState) {
return null;
}
node.send(msg);
}).catch(function(error) {
msg.payload = 'offline';
msg.data = {
'error': error
};
const shouldHaltIfState = this.nodeConfig.halt_if && ('offline' === this.nodeConfig.halt_if);
if (shouldHaltIfState) {
return null;
}
node.send(msg);
});
});
}
RED.nodes.registerType("query-game-server", queryGameServer);
};