mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-03 13:01:04 +01:00
c82554ad1a
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.
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
var dgram = require('dgram'),
|
|
EventEmitter = require('events').EventEmitter,
|
|
util = require('util'),
|
|
dns = require('dns'),
|
|
TypeResolver = require('./typeresolver');
|
|
|
|
var activeQueries = [];
|
|
|
|
var udpSocket = dgram.createSocket('udp4');
|
|
udpSocket.unref();
|
|
udpSocket.bind(21943);
|
|
udpSocket.on('message', function(buffer, rinfo) {
|
|
if(Gamedig.debug) console.log("Received",buffer,rinfo.address,rinfo.port);
|
|
for(var i = 0; i < activeQueries.length; i++) {
|
|
var query = activeQueries[i];
|
|
if(
|
|
query.options.address != rinfo.address
|
|
&& query.options.altaddress != rinfo.address
|
|
) continue;
|
|
if(query.options.port != rinfo.port) continue;
|
|
query._udpResponse(buffer);
|
|
break;
|
|
}
|
|
});
|
|
|
|
Gamedig = {
|
|
|
|
query: function(options,callback) {
|
|
if(callback) options.callback = callback;
|
|
|
|
var query = TypeResolver(options.type);
|
|
if(!query) {
|
|
process.nextTick(function() {
|
|
callback({error:'Invalid server type: '+options.type});
|
|
});
|
|
return;
|
|
}
|
|
query.debug = Gamedig.debug;
|
|
query.udpSocket = udpSocket;
|
|
query.type = options.type;
|
|
|
|
// copy over options
|
|
for(var i in options) query.options[i] = options[i];
|
|
|
|
activeQueries.push(query);
|
|
|
|
query.on('finished',function(state) {
|
|
var i = activeQueries.indexOf(query);
|
|
if(i >= 0) activeQueries.splice(i, 1);
|
|
});
|
|
|
|
process.nextTick(function() {
|
|
query.start();
|
|
});
|
|
|
|
return query;
|
|
}
|
|
|
|
};
|
|
|
|
module.exports = Gamedig;
|