mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2025-04-18 03:53:03 -06:00
- Fixed query-game-server node so it actually works instead of throwing browser errors when added to the user's work area. - Updated query-game-server.html to look better - Added stuff to the node help
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
var Gamedig = require('gamedig');
|
|
|
|
module.exports = function(RED) {
|
|
function QueryGameServer(config) {
|
|
RED.nodes.createNode(this, config);
|
|
this.server_type = config.server_type;
|
|
this.host = config.host;
|
|
this.port = config.port;
|
|
this.halt_if = config.halt_if;
|
|
var node = this;
|
|
node.on('input', function(msg) {
|
|
var serverInfo = {
|
|
'type': node.server_type,
|
|
'host': node.host
|
|
};
|
|
|
|
if(node.port) {
|
|
serverInfo['port'] = node.port;
|
|
}
|
|
|
|
if(msg.server_type) {
|
|
serverInfo['type'] = msg.server_type;
|
|
}
|
|
|
|
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 === node.halt_if) {
|
|
return null;
|
|
}
|
|
node.send(msg);
|
|
}).catch(function(error) {
|
|
msg.payload = 'offline';
|
|
msg.data = {
|
|
'error': error
|
|
};
|
|
if (msg.payload === node.halt_if) {
|
|
return null;
|
|
}
|
|
node.send(msg);
|
|
});
|
|
});
|
|
}
|
|
RED.nodes.registerType("query-game-server", QueryGameServer);
|
|
}; |