mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
crlf -> lf conversion
This commit is contained in:
parent
c209686798
commit
a3c3184eb8
32 changed files with 3307 additions and 3307 deletions
160
lib/index.js
160
lib/index.js
|
|
@ -1,80 +1,80 @@
|
|||
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(rinfo.address+':'+rinfo.port+" <--UDP "+buffer.toString('hex'));
|
||||
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_query != rinfo.port) continue;
|
||||
query._udpResponse(buffer);
|
||||
break;
|
||||
}
|
||||
});
|
||||
udpSocket.on('error', function(e) {
|
||||
if(Gamedig.debug) console.log("UDP ERROR: "+e);
|
||||
});
|
||||
|
||||
Gamedig = {
|
||||
|
||||
query: function(options,callback) {
|
||||
if(callback) options.callback = callback;
|
||||
|
||||
var query;
|
||||
try {
|
||||
query = TypeResolver.lookup(options.type);
|
||||
} catch(e) {
|
||||
process.nextTick(function() {
|
||||
callback({error:e.message});
|
||||
});
|
||||
return;
|
||||
}
|
||||
query.debug = Gamedig.debug;
|
||||
query.udpSocket = udpSocket;
|
||||
query.type = options.type;
|
||||
|
||||
if(!('port' in query.options) && ('port_query' in query.options)) {
|
||||
if(Gamedig.isCommandLine) {
|
||||
process.stderr.write(
|
||||
"Warning! This game is so old, that we don't know"
|
||||
+" what the server's connection port is. We've guessed that"
|
||||
+" the query port for "+query.type+" is "+query.options.port_query+"."
|
||||
+" If you know the connection port for this type of server, please let"
|
||||
+" us know on the GameDig issue tracker, thanks!\n"
|
||||
);
|
||||
}
|
||||
query.options.port = query.options.port_query;
|
||||
delete query.options.port_query;
|
||||
}
|
||||
|
||||
// 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;
|
||||
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(rinfo.address+':'+rinfo.port+" <--UDP "+buffer.toString('hex'));
|
||||
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_query != rinfo.port) continue;
|
||||
query._udpResponse(buffer);
|
||||
break;
|
||||
}
|
||||
});
|
||||
udpSocket.on('error', function(e) {
|
||||
if(Gamedig.debug) console.log("UDP ERROR: "+e);
|
||||
});
|
||||
|
||||
Gamedig = {
|
||||
|
||||
query: function(options,callback) {
|
||||
if(callback) options.callback = callback;
|
||||
|
||||
var query;
|
||||
try {
|
||||
query = TypeResolver.lookup(options.type);
|
||||
} catch(e) {
|
||||
process.nextTick(function() {
|
||||
callback({error:e.message});
|
||||
});
|
||||
return;
|
||||
}
|
||||
query.debug = Gamedig.debug;
|
||||
query.udpSocket = udpSocket;
|
||||
query.type = options.type;
|
||||
|
||||
if(!('port' in query.options) && ('port_query' in query.options)) {
|
||||
if(Gamedig.isCommandLine) {
|
||||
process.stderr.write(
|
||||
"Warning! This game is so old, that we don't know"
|
||||
+" what the server's connection port is. We've guessed that"
|
||||
+" the query port for "+query.type+" is "+query.options.port_query+"."
|
||||
+" If you know the connection port for this type of server, please let"
|
||||
+" us know on the GameDig issue tracker, thanks!\n"
|
||||
);
|
||||
}
|
||||
query.options.port = query.options.port_query;
|
||||
delete query.options.port_query;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue