mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2025-04-18 03:53:03 -06:00
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
module.exports = function(RED) {
|
|
var Gamedig = require('gamedig');
|
|
function queryGameServer(config) {
|
|
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);
|
|
}; |