Compare commits

..

No commits in common. "facf77e1fa6ac664e30e5ba53d333005ff18637a" and "f6078118c09c41bd4e39ad8a2aa6cc0171769447" have entirely different histories.

4 changed files with 542 additions and 431 deletions

923
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-gamedig", "name": "node-red-contrib-gamedig",
"version": "2.1.2", "version": "2.1.1",
"description": "Query for the status of any game server using node-red", "description": "Query for the status of any game server using node-red",
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,6 +23,6 @@
} }
}, },
"dependencies": { "dependencies": {
"gamedig": "^4.0.6" "gamedig": "^3.0.0"
} }
} }

View File

@ -30,13 +30,12 @@
oneditprepare: function() { oneditprepare: function() {
$.getJSON('/gamedig/types', function(data) { $.getJSON('/gamedig/types', function(data) {
let html = '<table>' + let html = '<table>' +
'<thead id="query-game-server-types-table"><tr><td><strong>Type</strong></td><td><strong>Name</strong></td><td><strong>Protocol</strong></td></tr></thead>' + '<thead id="query-game-server-types-table"><tr><td><strong>Type</strong></td><td><strong>Name</strong></td></tr></thead>' +
'<tbody id="query-game-server-type-rows">'; '<tbody id="query-game-server-type-rows">';
for(let game of data) { for(var type in data) {
html += "<tr class=\"query-game-server-type-row\">" + html += "<tr class=\"query-game-server-type-row\">" +
"<td>"+game['type']+"</td>" + "<td>"+type+"</td>" +
"<td>"+game['name']+"</td>" + "<td>"+data[type]+"</td>" +
"<td>"+game['protocol']+"</td>" +
"</tr>"; "</tr>";
} }
html += '</tbody>' + html += '</tbody>' +

View File

@ -83,31 +83,20 @@ module.exports = function(RED) {
// gamedig has no way of listing available server types // gamedig has no way of listing available server types
// so we just use regex to parse the info from the README // so we just use regex to parse the info from the README
// this could break so we also reference the gamedig repo // this could break so we also reference the gamedig repo
let availableTypesContent = fs.readFileSync(require.resolve("gamedig/games.txt"), 'utf-8') let availableTypes = fs.readFileSync(require.resolve("gamedig/README.md"))
results = []; .toString()
.matchAll(/^\| `(.*)` * \| ([a-zA-Z: (0-9)\-'.]*)/gm),
results = {};
availableTypesContent for (const match of availableTypes) {
.split(/\r?\n/) if(match[1].indexOf("`<br>`") >= 0) {
.forEach(line => { let names = match[1].split("`<br>`");
if( results[names[0]] = match[2];
line.trim().length === 0 results[names[1]] = match[2];
|| line.trim().length === 0 } else {
|| line.trim().startsWith('#') results[match[1]] = match[2];
) { }
return; }
}
// examples:
// avp2|Aliens versus Predator 2 (2001)|gamespy1|port=27888
// avp2010|Aliens vs. Predator (2010)|valve|port=27015
let [game_type, game_name, game_protocol] = line.split('|');
results.push({
'name': game_type,
'type': game_type,
'protocol': game_protocol
});
});
res.json(results); res.json(results);
}); });
}; };