mirror of
https://github.com/skylord123/node-red-contrib-gamedig.git
synced 2025-04-10 08:03:08 -06:00
- You can now pass any option to the underlying GameDig library when querying a server by setting msg.options
object on the input. Can be used for example to set msg.options.guildId
that is required for querying Discord servers. Note that this will override even the config settings from the UI.
- New option "Output options" that you can enable from config to output `msg.options` object that contains all options we passed to GameDig to query the server. This overrides all other options (whether set from the UI or from `msg.*` variables) so take note of that when chaining multiple server query nodes together with this enabled. - Breaking Change: This node no longer returns `msg.max_attempts`, `msg.socket_timeout`, and `msg.attempt_timeout`, instead see "Output options" mentioned above if you need this.
This commit is contained in:
parent
8bdb043923
commit
787ee61c4e
@ -6,7 +6,9 @@ This package adds the node "Query Game Server" that uses the NPM package [GameDi
|
||||
|
||||
You can pass the server type, host, and port on the input message or define them on the node (settings defined on the node will override msg values).
|
||||
|
||||
[Click here](https://github.com/gamedig/node-gamedig#return-value) if you want more information about what this library parses and standardizes from the server response.
|
||||
You can also specify manual GameDig options using `msg.options` as an input. This will override any other options. For example: you can set `msg.options.guildId` that is required for querying Discord servers.
|
||||
|
||||
Visit the [GameDig GitLab page](https://github.com/gamedig/node-gamedig#return-value) if you want more information about what this library parses and standardizes from the server response.
|
||||
|
||||
### Usage Examples
|
||||
- #### Inserting query data into InfluxDB and using Grafana to view results
|
||||
|
@ -14,7 +14,8 @@
|
||||
given_port_only: { value: '' },
|
||||
ip_family: { value: '0' },
|
||||
debug: { value: '' },
|
||||
request_rules: { value: '' }
|
||||
request_rules: { value: '' },
|
||||
output_options: { value: '' }
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
@ -182,6 +183,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-output_options" style="vertical-align: top"><i class="fa fa-server"></i> Output options</label>
|
||||
<div style="width: 50%;display: inline-block;">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="node-input-output_options"
|
||||
style="width: auto; vertical-align: top"
|
||||
/>
|
||||
Outputs <code style="white-space: normal;">msg.options</code> as an object that contains all the options used to query the server using GameDig. Note: If you pass <code style="white-space: normal;">msg.options</code> as an input it will override all set options so make sure you unset it if chaining multiple server query nodes together unless that is what you want.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-ip_family"><i class="fa fa-server"></i> IP Rules</label>
|
||||
<select
|
||||
@ -217,6 +230,11 @@
|
||||
</dt>
|
||||
<dd>Query port of the server. Ignored if configured on the node. Uses default query port for the server type if left empty.</dd>
|
||||
|
||||
<dt class="optional">
|
||||
msg.options <span class="property-type">object | null</span>
|
||||
</dt>
|
||||
<dd>Set additional GameDig options. This overrides all other methods of setting options. Can be used for example to set <code style="white-space: normal;">msg.options.guildId</code> that is required for querying Discord servers.</dd>
|
||||
|
||||
<dt class="optional">
|
||||
msg.max_attempts <span class="property-type">integer | null</span>
|
||||
</dt>
|
||||
@ -286,18 +304,8 @@
|
||||
<dd>Query port of the server. Ignored if configured on the node.</dd>
|
||||
|
||||
<dt>
|
||||
msg.max_attempts <span class="property-type">integer</span>
|
||||
msg.options <span class="property-type">object | undefined</span>
|
||||
</dt>
|
||||
<dd>Number of attempts to query server in case of failure. Ignored if configured on the node.</dd>
|
||||
|
||||
<dt>
|
||||
msg.socket_timeout <span class="property-type">integer</span>
|
||||
</dt>
|
||||
<dd>Milliseconds to wait for a single packet. Beware that increasing this will cause many queries to take longer even if the server is online. Ignored if configured on the node.</dd>
|
||||
|
||||
<dt>
|
||||
msg.attempt_timeout <span class="property-type">integer</span>
|
||||
</dt>
|
||||
<dd>Milliseconds allowed for an entire query attempt. This timeout is not commonly hit, as the socketTimeout typically fires first. Ignored if configured on the node.</dd>
|
||||
<dd>Only set if configured to do so. Will return all the options passed to GameDig to query the server.</dd>
|
||||
</dl>
|
||||
</script>
|
@ -4,7 +4,7 @@ module.exports = function(RED) {
|
||||
|
||||
function QueryGameServer(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
var node = this;
|
||||
let node = this;
|
||||
this.server_type = config.server_type;
|
||||
this.host = config.host;
|
||||
this.port = config.port;
|
||||
@ -16,67 +16,46 @@ module.exports = function(RED) {
|
||||
this.ip_family = config.ip_family || 0;
|
||||
this.debug = config.debug || false;
|
||||
this.request_rules = config.request_rules || false;
|
||||
this.output_options = config.output_options || false;
|
||||
node.on('input', function(msg) {
|
||||
if(node.server_type) {
|
||||
msg.server_type = node.server_type;
|
||||
let options = {
|
||||
'type': node.server_type || msg.server_type || undefined,
|
||||
'host': node.host || msg.host || undefined,
|
||||
'port': node.port || msg.port || undefined,
|
||||
'maxAttempts': node.max_attempts || msg.max_attempts || undefined,
|
||||
'socketTimeout': node.socket_timeout || msg.socket_timeout || undefined,
|
||||
'attemptTimeout': node.attempt_timeout || msg.attempt_timeout || undefined,
|
||||
'givenPortOnly': node.given_port_only || msg.given_port_only || undefined,
|
||||
'ipFamily': node.ip_family || msg.ip_family || undefined,
|
||||
'debug': node.debug || msg.config || undefined,
|
||||
'requestRules': node.request_rules || msg.request_rules || undefined
|
||||
};
|
||||
|
||||
if(typeof msg.options === 'object' && msg.options)
|
||||
{
|
||||
options = {...options, ...msg.options};
|
||||
}
|
||||
|
||||
if(node.host) {
|
||||
msg.host = node.host;
|
||||
// set the things we want to return
|
||||
msg.server_type = options.type;
|
||||
msg.host = options.host;
|
||||
msg.port = options.port;
|
||||
if(node.output_options)
|
||||
{
|
||||
msg.options = options;
|
||||
}
|
||||
if(!msg.host) {
|
||||
node.error("msg.host missing from input.");
|
||||
|
||||
if(!options.host) {
|
||||
node.error("host missing from input.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(node.port) {
|
||||
msg.port = node.port;
|
||||
}
|
||||
|
||||
if(node.halt_if) {
|
||||
msg.halt_if = node.halt_if;
|
||||
if(!options.type) {
|
||||
node.error("server_type missing from input.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(node.max_attempts) {
|
||||
msg.max_attempts = node.max_attempts;
|
||||
}
|
||||
|
||||
if(node.socket_timeout) {
|
||||
msg.socket_timeout = node.socket_timeout;
|
||||
}
|
||||
|
||||
if(node.attempt_timeout) {
|
||||
msg.attempt_timeout = node.attempt_timeout;
|
||||
}
|
||||
|
||||
if(node.given_port_only) {
|
||||
msg.given_port_only = node.given_port_only;
|
||||
}
|
||||
|
||||
if(node.ip_family) {
|
||||
msg.ip_family = node.ip_family;
|
||||
}
|
||||
|
||||
if(node.debug) {
|
||||
msg.debug = node.debug;
|
||||
}
|
||||
|
||||
if(node.request_rules) {
|
||||
msg.request_rules = node.request_rules;
|
||||
}
|
||||
|
||||
gamedig.query({
|
||||
'type': msg.server_type,
|
||||
'host': msg.host,
|
||||
'port': msg.port,
|
||||
'maxAttempts': msg.max_attempts,
|
||||
'socketTimeout': msg.socket_timeout,
|
||||
'attemptTimeout': msg.attempt_timeout,
|
||||
'givenPortOnly': msg.given_port_only,
|
||||
'ipFamily': msg.ip_family,
|
||||
'debug': msg.debug,
|
||||
'requestRules': msg.request_rules
|
||||
})
|
||||
gamedig.query(options)
|
||||
.then(function(state) {
|
||||
msg.payload = 'online';
|
||||
msg.data = state;
|
||||
|
Loading…
x
Reference in New Issue
Block a user