mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2025-04-18 03:53:03 -06:00
- Changed structure layout
- 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
This commit is contained in:
parent
73850eaba8
commit
d3c076bb6a
@ -2,10 +2,6 @@
|
|||||||
"name": "node-red-contrib-gamedig",
|
"name": "node-red-contrib-gamedig",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Query for the status of any game server using node-red",
|
"description": "Query for the status of any game server using node-red",
|
||||||
"main": "query-game-server/query-game-server.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/skylord123/node-red-contrib-gamedig.git"
|
"url": "git+https://github.com/skylord123/node-red-contrib-gamedig.git"
|
||||||
@ -18,10 +14,10 @@
|
|||||||
"homepage": "https://github.com/skylord123/node-red-contrib-gamedig#readme",
|
"homepage": "https://github.com/skylord123/node-red-contrib-gamedig#readme",
|
||||||
"node-red": {
|
"node-red": {
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"query-game-server": "query-game-server/query-game-server.js"
|
"query-game-server": "query-game-server.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gamedig": "^2.0.13"
|
"gamedig": "^2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
107
query-game-server.html
Normal file
107
query-game-server.html
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
<script type="text/javascript">
|
||||||
|
RED.nodes.registerType('query-game-server', {
|
||||||
|
category: 'advanced',
|
||||||
|
color: '#a6bbcf',
|
||||||
|
defaults: {
|
||||||
|
name: { value: '' },
|
||||||
|
server_type: { value: '', required: true },
|
||||||
|
host: { value: '', required: true },
|
||||||
|
port: { value: '' },
|
||||||
|
halt_if: { value: '' }
|
||||||
|
},
|
||||||
|
inputs:1,
|
||||||
|
outputs:1,
|
||||||
|
icon: "icons/down_arrow.png",
|
||||||
|
label: function() {
|
||||||
|
if(this.host) {
|
||||||
|
return `Query: ${this.host}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.name || 'Query Game 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-server_type"><i class="fa fa-cube"></i> Server Type</label>
|
||||||
|
<input type="text" id="node-input-server_type">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<span>Check <a href="https://github.com/sonicsnes/node-gamedig#games-list" style="color:#0000EE;" target="_blank">here</a> for a list of supported server 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" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<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" />
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<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>
|
||||||
|
<select type="text" id="node-input-halt_if">
|
||||||
|
<option value="">Do not halt</option>
|
||||||
|
<option value="online">Online</option>
|
||||||
|
<option value="offline">Offline</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label> </label>
|
||||||
|
<span>Enter "online" or "offline" (without quotes) to filter out the state you don't want.</span>
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/x-red" data-help-name="query-game-server">
|
||||||
|
<p>Query a Game Server</p>
|
||||||
|
<h3>Config</h3>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt>Server Type <span class="property-type">string</span></dt>
|
||||||
|
<dt>Host <span class="property-type">string</span></dt>
|
||||||
|
<dt>Port <span class="property-type">integer</span></dt>
|
||||||
|
<dt>Halt If <span class="property-type">string</span></dt>
|
||||||
|
</dl>
|
||||||
|
<h3>Inputs</h3>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt class="optional">
|
||||||
|
msg.server_type <span class="property-type">string</span>
|
||||||
|
</dt>
|
||||||
|
<dd>Server type to query. Check <a href="https://github.com/sonicsnes/node-gamedig#games-list" style="color:#0000EE;" target="_blank">here</a> for a list of supported server types</dd>
|
||||||
|
<dt class="optional">
|
||||||
|
msg.host <span class="property-type">string</span>
|
||||||
|
</dt>
|
||||||
|
<dd>Server IP/Hostname</dd>
|
||||||
|
<dt class="optional">
|
||||||
|
msg.port <span class="property-type">integer</span>
|
||||||
|
</dt>
|
||||||
|
<dd>Query port of the server</dd>
|
||||||
|
</dl>
|
||||||
|
<h3>Outputs</h3>
|
||||||
|
<dl class="message-properties">
|
||||||
|
<dt>
|
||||||
|
msg.payload <span class="property-type">string</span>
|
||||||
|
</dt>
|
||||||
|
<dd>Returns either <code>online</code> or <code>offline</code> depending on if we successfully query the server or not.</dd>
|
||||||
|
<dt>
|
||||||
|
msg.data <span class="property-type">object</span>
|
||||||
|
</dt>
|
||||||
|
<dd>Returns back the data we got from GameDig. Click <a href="https://github.com/sonicsnes/node-gamedig#return-value" style="color:#0000EE;">here</a> for more information on what this contains.</dd>
|
||||||
|
</dl>
|
||||||
|
</script>
|
54
query-game-server.js
Normal file
54
query-game-server.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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);
|
||||||
|
};
|
@ -1,47 +0,0 @@
|
|||||||
<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>
|
|
@ -1,39 +0,0 @@
|
|||||||
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);
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user