mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
Super mega-commit
Organize files Rewrite readme for new game IDs and command line Add command line access Replace some dependencies that required binaries with simpler alternatives Switch gbxremote back to upstream, Closes #2 Moved simple aliases into an alias file, rather than seperate files for each Patched nearly every protocol variant with tons of bug fixes Re-tested every combination of server and protocol types except nadeo Added alternative minecraft query check (minecraftping) Fixed mutant factions query Fixed valve gold not working at all Stripped colors more reliably from protocols that support colors Added a couple more fields to ut2004 and killing floor and more that I probably forgot. This shouldn't break compatibility too bad -- at the most, some game IDs may have changed.
This commit is contained in:
parent
a89fb7bbdf
commit
c82554ad1a
31 changed files with 573 additions and 135 deletions
51
lib/typeresolver.js
Normal file
51
lib/typeresolver.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
var Path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var gamesDir = Path.normalize(__dirname+'/../games');
|
||||
|
||||
function readAliases() {
|
||||
var lines = fs.readFileSync(gamesDir+'/aliases.txt','utf8').split('\n');
|
||||
var aliases = {};
|
||||
|
||||
lines.forEach(function(line) {
|
||||
line = line.trim();
|
||||
if(!line) return;
|
||||
if(line.charAt(0) == '#') return;
|
||||
var split = line.split('|');
|
||||
|
||||
aliases[split[0].trim()] = {
|
||||
pretty: split[1].trim(),
|
||||
protocol: split[2].trim(),
|
||||
port: split[3] ? parseInt(split[3]) : 0
|
||||
};
|
||||
});
|
||||
return aliases;
|
||||
}
|
||||
var aliases = readAliases();
|
||||
|
||||
function createQueryInstance(type) {
|
||||
type = Path.basename(type);
|
||||
|
||||
var path = gamesDir+'/'+type;
|
||||
if(type.substr(0,9) == 'protocol-') {
|
||||
path = gamesDir+'/protocols/'+type.substr(9);
|
||||
}
|
||||
|
||||
if(!fs.existsSync(path+'.js')) return false;
|
||||
var protocol = require(path);
|
||||
|
||||
return new protocol();
|
||||
}
|
||||
|
||||
module.exports = function(type) {
|
||||
var alias = aliases[type];
|
||||
|
||||
if(alias) {
|
||||
var query = createQueryInstance('protocol-'+alias.protocol);
|
||||
if(!query) return false;
|
||||
query.pretty = alias.pretty;
|
||||
if(alias.port) query.options.port = alias.port;
|
||||
return query;
|
||||
}
|
||||
return createQueryInstance(type);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue