Move scripts into sub-folder

This commit is contained in:
2019-02-16 23:38:53 -07:00
parent 0a57df155f
commit 73850eaba8
3 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
<script type="text/javascript">
RED.nodes.registerType('query-game-server', {
category: 'advanced',
color: '#a6bbcf',
defaults: {
name: { value: '' },
type: { value: '', required: true },
host: { value: '', type: 'server', required: true },
port: { value: '' },
halt_if: { value: '' }
},
inputs:1,
outputs:1,
icon: "icons/down_arrow.png",
label: function() {
return this.name || 'query-game-server' || `query-game-server: ${this.server}`;
}
});
</script>
<script type="text/x-red" data-template-name="query-game-server">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-type"><i class="fa fa-cube"></i> Type</label>
<input type="text" id="node-input-type">
<span>Check <a href="https://github.com/sonicsnes/node-gamedig">node-gamedig</a> README for supported types</span>
</div>
<div class="form-row">
<label for="node-input-host"><i class="fa fa-server"></i> Host</label>
<input type="text" id="node-input-host" />
<span>Host without port</span>
</div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-server"></i> Port</label>
<input type="text" id="node-input-port" />
<span>Query port for the server (not always the same as the join port)</span>
</div>
<div class="form-row">
<label for="node-input-halt_if"><i class="fa fa-hand-paper-o"></i> Halt If</label>
<input type="text" id="node-input-halt_if" placeholder="off"/>
<span>Enter "online" or "offline" (without quotes) to filter out the state you don't want.</span>
</div>
</script>

View File

@@ -0,0 +1,39 @@
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);
};