Merge pull request #20 from skylord123/dev

Next release v3.1.2
This commit is contained in:
2026-10-16 11:59:29 -06:00
committed by GitHub
5 changed files with 52 additions and 64 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ You can pass the server type, host, and port on the input message or define them
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.
Visit the [GameDig GitHub 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.
### Help fund development
@@ -27,7 +27,7 @@ If you use this node and find it helpful please consider donating to help fund f
### Other Packages
- [node-red-contrib-matrix-chat](https://www.npmjs.com/package/node-red-contrib-gamedig) - Matrix chat server client for Node-RED
- [node-red-contrib-matrix-chat](https://www.npmjs.com/package/node-red-contrib-matrix-chat) - Matrix chat server client for Node-RED
### Developers
So far me (skylord123) is the only person that has contributed towards this package. Feel free to do any pull-requests to get your name here!
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "node-red-contrib-gamedig",
"version": "3.1.1",
"version": "3.1.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "node-red-contrib-gamedig",
"version": "3.1.1",
"version": "3.1.2",
"license": "MIT",
"dependencies": {
"gamedig": "^5.3.3"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-gamedig",
"version": "3.1.1",
"version": "3.1.2",
"description": "Query for the status of any game server using node-red",
"repository": {
"type": "git",
+11 -7
View File
@@ -82,8 +82,12 @@
if(server_type['type'] !== val) return;
let query_port = server_type.options.port_query || server_type.options.port || null;
if(query_port && server_type.options.port_query_offset) {
query_port += server_type.options.port_query_offset;
let offset = server_type.options.port_query_offset;
if(Array.isArray(offset)) {
offset = offset[0];
}
if(query_port && offset) {
query_port += offset;
}
$("#node-input-port").val(query_port);
@@ -261,7 +265,7 @@
<dt class="optional">
msg.server_type <span class="property-type">string | null</span>
</dt>
<dd>Server type to query. View available types either at the bottom of the node editor or <a href="https://github.com/sonicsnes/node-gamedig#games-list" style="color:#0000EE;" target="_blank">click here</a>. Ignored if configured on the node.</dd>
<dd>Server type to query. View available types <a href="https://github.com/gamedig/node-gamedig#games-list" style="color:#0000EE;" target="_blank">here</a>. Ignored if configured on the node.</dd>
<dt class="optional">
msg.host <span class="property-type">string | null</span>
@@ -329,17 +333,17 @@
<dt>
msg.data <span class="property-type">object</span>
</dt>
<dd>Returns back the results we got from GameDig. Click <a href="https://github.com/sonicsnes/node-gamedig#return-value" target="_blank" style="color:#0000EE;">here</a> for more information on what this contains.</dd>
<dd>Returns back the results we got from GameDig. Click <a href="https://github.com/gamedig/node-gamedig#return-value" target="_blank" style="color:#0000EE;">here</a> for more information on what this contains.</dd>
<dt>
msg.data.error <span class="property-type">string</span>
msg.data.error <span class="property-type">Error</span>
</dt>
<dd>Reason the server failed to query. Only returns if <code>msg.payload</code> is <code>offline</code>.</dd>
<dt>
msg.server_type <span class="property-type">string</span>
</dt>
<dd>Server type to query. View available types either at the bottom of the node editor or <a href="https://github.com/sonicsnes/node-gamedig#games-list" style="color:#0000EE;" target="_blank">click here</a>. Ignored if configured on the node.</dd>
<dd>Server type that was queried.</dd>
<dt>
msg.host <span class="property-type">string</span>
@@ -354,7 +358,7 @@
<dt>
msg.port <span class="property-type">integer</span>
</dt>
<dd>Query port of the server. Ignored if configured on the node.</dd>
<dd>Query port of the server.</dd>
<dt>
msg.options <span class="property-type">object | undefined</span>
+36 -52
View File
@@ -22,41 +22,23 @@ module.exports = function(RED) {
return errorLines.every(line => SERVER_DOWN_PATTERNS.some(re => re.test(line)));
}
// GameDig returns Results, Players and Player class instances; Node-RED
// cannot clone those, so convert them to plain objects and arrays.
function deepCloneToPlain(obj) {
// Handle null/undefined
if (!obj) {
return obj;
if (Array.isArray(obj)) {
return Array.from(obj, deepCloneToPlain);
}
// Handle arrays and array-like objects (including Players collection)
if (Array.isArray(obj) || (typeof obj === 'object' && obj.length >= 0)) {
return Array.from(obj, item => deepCloneToPlain(item));
}
// Handle instances of custom classes (like Player, Results)
if (obj && typeof obj === 'object' && Object.getPrototypeOf(obj) !== Object.prototype) {
// Convert to plain object while preserving enumerable properties
const plainObj = {};
for (const key of Object.keys(obj)) {
plainObj[key] = deepCloneToPlain(obj[key]);
}
return plainObj;
}
// Handle plain objects
if (obj && typeof obj === 'object') {
const result = {};
for (const key of Object.keys(obj)) {
// Skip the Buffer instance
if (key === 'rulesBytes' && Buffer.isBuffer(obj[key])) {
// Skip raw rule bytes
if (Buffer.isBuffer(obj[key])) {
continue;
}
result[key] = deepCloneToPlain(obj[key]);
}
return result;
}
// Return primitive values as-is
return obj;
}
@@ -65,20 +47,24 @@ module.exports = function(RED) {
let node = this;
this.halt_if = config.halt_if;
this.output_options = config.output_options || false;
node.on('input', function(msg) {
node.on('input', function(msg, send, done) {
// Node-RED 0.x does not pass send/done
send = send || function() { node.send.apply(node, arguments); };
done = done || function(err) { if (err) node.error(err, msg); };
let options = {
'type': config.server_type || msg.server_type || undefined,
'host': config.host || msg.host || undefined,
'address': config.address || msg.address || undefined,
'port': config.port || msg.port || undefined,
'maxAttempts': config.max_attempts || msg.max_attempts || 1,
'socketTimeout': config.socket_timeout || msg.socket_timeout || 2000,
'attemptTimeout': config.attempt_timeout || msg.attempt_timeout || 10000,
'maxRetries': Number(config.max_attempts || msg.max_attempts || 1),
'socketTimeout': Number(config.socket_timeout || msg.socket_timeout || 2000),
'attemptTimeout': Number(config.attempt_timeout || msg.attempt_timeout || 10000),
'givenPortOnly': config.given_port_only || msg.given_port_only || false,
'ipFamily': config.ip_family || msg.ip_family || undefined,
'debug': config.debug || msg.config || undefined,
'ipFamily': Number(config.ip_family) || Number(msg.ip_family) || 0,
'debug': config.debug || msg.debug || undefined,
'requestRules': config.request_rules || msg.request_rules || undefined,
'strip_colors': typeof config.strip_colors === "undefined" ? true : config.strip_colors
'stripColors': typeof config.strip_colors === "undefined" ? true : config.strip_colors
};
if(typeof msg.options === 'object' && msg.options)
@@ -86,6 +72,13 @@ module.exports = function(RED) {
options = {...options, ...msg.options};
}
// GameDig only resolves host when address is absent, so drop unset options
for (const key of Object.keys(options)) {
if (options[key] === undefined) {
delete options[key];
}
}
// set the things we want to return
msg.server_type = options.type;
if(options.host) {
@@ -101,12 +94,12 @@ module.exports = function(RED) {
}
if(!msg.host && !msg.address) {
node.error("host/address missing from input.");
done("host/address missing from input.");
return;
}
if(!options.type) {
node.error("server_type missing from input.");
done("server_type missing from input.");
return;
}
@@ -114,17 +107,15 @@ module.exports = function(RED) {
.then(function(state) {
try {
msg.payload = 'online';
// GameDig returns Results, Players, and Player objects that we need to convert
// to standard Array/Object instances so that Node-RED doesn't error
msg.data = deepCloneToPlain(state);
if (msg.payload === node.halt_if) {
return null;
}
node.status({ fill: "green", shape: "dot", text: `Online ${state.players.length} players` });
node.send(msg);
if (msg.payload !== node.halt_if) {
send(msg);
}
done();
} catch(e) {
node.error("Failed returning data: " + e.stack);
done("Failed returning data: " + e.stack);
}
})
.catch(function(error) {
@@ -133,30 +124,23 @@ module.exports = function(RED) {
error,
stack: error.stack,
};
if (msg.payload === node.halt_if) {
return null;
}
node.status({ fill: "red", shape: "dot", text: "Offline" });
node.send(msg);
if (!isServerDownError(error)) {
node.error(`GameDig Error: \n${error.stack}`, msg);
if (msg.payload !== node.halt_if) {
send(msg);
}
done(isServerDownError(error) ? undefined : `GameDig Error: \n${error.stack}`);
});
});
}
RED.nodes.registerType("query-game-server", QueryGameServer);
const server_types = Object.keys(games).map(type => ({ ...games[type], type }));
RED.httpAdmin.get(
"/gamedig/types",
RED.auth.needsPermission('flows.write'),
function(req, res) {
let server_types = Object.keys(games).map(gameKey => {
let game = games[gameKey];
game["type"] = gameKey;
return game;
});
res.json({
'result': 'ok',
'server_types': server_types