crlf -> lf conversion

This commit is contained in:
Michael Morrison 2014-10-29 01:42:33 -05:00
parent c209686798
commit a3c3184eb8
32 changed files with 3307 additions and 3307 deletions

View file

@ -1,74 +1,74 @@
/* based on Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
var Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function() {
var args = Array.prototype.slice.call(arguments);
var name = 'Class';
var parent = this;
var prop = {};
if(typeof args[0] == 'string') name = args.shift();
if(args.length >= 2) parent = args.shift();
prop = args.shift();
// Copy prototype from the parent object
var prototype = {};
for(var name in parent.prototype) {
prototype[name] = parent.prototype[name];
}
// Copy the properties over onto the new prototype
for(var name in prop) {
if(typeof prop[name] == "function" && fnTest.test(prop[name])) {
// this is a function that references _super, so we have to wrap it
// and provide it with its super function
prototype[name] = (function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
if(typeof parent.prototype[name] == 'undefined') {
if(name == 'init') this._super = parent.prototype.constructor;
else this._super = function() { throw new Error('Called _super in method without a parent'); }
} else this._super = parent.prototype[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]);
} else {
prototype[name] = prop[name];
}
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if(this.init) this.init.apply(this, arguments);
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.prototype.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
module.exports = Class;
/* based on Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
var Class = function(){};
// Create a new Class that inherits from this class
Class.extend = function() {
var args = Array.prototype.slice.call(arguments);
var name = 'Class';
var parent = this;
var prop = {};
if(typeof args[0] == 'string') name = args.shift();
if(args.length >= 2) parent = args.shift();
prop = args.shift();
// Copy prototype from the parent object
var prototype = {};
for(var name in parent.prototype) {
prototype[name] = parent.prototype[name];
}
// Copy the properties over onto the new prototype
for(var name in prop) {
if(typeof prop[name] == "function" && fnTest.test(prop[name])) {
// this is a function that references _super, so we have to wrap it
// and provide it with its super function
prototype[name] = (function(name, fn){
return function() {
var tmp = this._super;
// Add a new ._super() method that is the same method
// but on the super-class
if(typeof parent.prototype[name] == 'undefined') {
if(name == 'init') this._super = parent.prototype.constructor;
else this._super = function() { throw new Error('Called _super in method without a parent'); }
} else this._super = parent.prototype[name];
// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
};
})(name, prop[name]);
} else {
prototype[name] = prop[name];
}
}
// The dummy class constructor
function Class() {
// All construction is actually done in the init method
if(this.init) this.init.apply(this, arguments);
}
// Populate our constructed prototype object
Class.prototype = prototype;
// Enforce the constructor to be what we expect
Class.prototype.constructor = Class;
// And make this class extendable
Class.extend = arguments.callee;
return Class;
};
module.exports = Class;

View file

@ -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;

View file

@ -1,124 +1,124 @@
var Iconv = require('iconv-lite'),
Long = require('long');
function readUInt64BE(buffer,offset) {
var high = buffer.readUInt32BE(offset);
var low = buffer.readUInt32BE(offset+4);
return new Long(low,high,true);
}
function readUInt64LE(buffer,offset) {
var low = buffer.readUInt32LE(offset);
var high = buffer.readUInt32LE(offset+4);
return new Long(low,high,true);
}
function Reader(query,buffer) {
this.query = query;
this.buffer = buffer;
this.i = 0;
}
Reader.prototype = {
offset: function() { return this.i; },
skip: function(i) { this.i += i; },
string: function() {
var args = Array.prototype.slice.call(arguments);
var options = {};
if(args.length == 0) {
options = {};
} else if(args.length == 1) {
if(typeof args[0] == 'string') options = { delimiter: args[0] };
else if(typeof args[0] == 'number') options = { length: args[0] };
else options = args[0];
}
options.encoding = options.encoding || this.query.encoding;
if(options.encoding == 'latin1') options.encoding = 'win1252';
var start = this.i+0;
var end = start;
if(!('length' in options)) {
// terminated by the delimiter
var delim = options.delimiter || this.query.delimiter;
if(typeof delim == 'string') delim = delim.charCodeAt(0);
while(true) {
if(end >= this.buffer.length) {
end = this.buffer.length;
break;
}
if(this.buffer.readUInt8(end) == delim) break;
end++;
}
this.i = end+1;
} else {
end = start+options.length;
if(end >= this.buffer.length) {
end = this.buffer.length;
}
this.i = end;
}
var out = this.buffer.slice(start, end);
var enc = options.encoding;
if(enc == 'utf8' || enc == 'ucs2' || enc == 'binary') {
out = out.toString(enc);
} else {
out = Iconv.decode(out,enc);
}
return out;
},
int: function(bytes) {
var r = 0;
if(this.remaining() >= bytes) {
if(this.query.byteorder == 'be') {
if(bytes == 1) r = this.buffer.readInt8(this.i);
else if(bytes == 2) r = this.buffer.readInt16BE(this.i);
else if(bytes == 4) r = this.buffer.readInt32BE(this.i);
} else {
if(bytes == 1) r = this.buffer.readInt8(this.i);
else if(bytes == 2) r = this.buffer.readInt16LE(this.i);
else if(bytes == 4) r = this.buffer.readInt32LE(this.i);
}
}
this.i += bytes;
return r;
},
uint: function(bytes) {
var r = 0;
if(this.remaining() >= bytes) {
if(this.query.byteorder == 'be') {
if(bytes == 1) r = this.buffer.readUInt8(this.i);
else if(bytes == 2) r = this.buffer.readUInt16BE(this.i);
else if(bytes == 4) r = this.buffer.readUInt32BE(this.i);
else if(bytes == 8) r = readUInt64BE(this.buffer,this.i).toString();
} else {
if(bytes == 1) r = this.buffer.readUInt8(this.i);
else if(bytes == 2) r = this.buffer.readUInt16LE(this.i);
else if(bytes == 4) r = this.buffer.readUInt32LE(this.i);
else if(bytes == 8) r = readUInt64LE(this.buffer,this.i).toString();
}
}
this.i += bytes;
return r;
},
float: function() {
var r = 0;
if(this.remaining() >= 4) {
if(this.query.byteorder == 'be') r = this.buffer.readFloatBE(this.i);
else r = this.buffer.readFloatLE(this.i);
}
this.i += 4;
return r;
},
remaining: function() {
return this.buffer.length-this.i;
},
rest: function() {
return this.buffer.slice(this.i);
},
done: function() {
return this.i >= this.buffer.length;
}
};
module.exports = Reader;
var Iconv = require('iconv-lite'),
Long = require('long');
function readUInt64BE(buffer,offset) {
var high = buffer.readUInt32BE(offset);
var low = buffer.readUInt32BE(offset+4);
return new Long(low,high,true);
}
function readUInt64LE(buffer,offset) {
var low = buffer.readUInt32LE(offset);
var high = buffer.readUInt32LE(offset+4);
return new Long(low,high,true);
}
function Reader(query,buffer) {
this.query = query;
this.buffer = buffer;
this.i = 0;
}
Reader.prototype = {
offset: function() { return this.i; },
skip: function(i) { this.i += i; },
string: function() {
var args = Array.prototype.slice.call(arguments);
var options = {};
if(args.length == 0) {
options = {};
} else if(args.length == 1) {
if(typeof args[0] == 'string') options = { delimiter: args[0] };
else if(typeof args[0] == 'number') options = { length: args[0] };
else options = args[0];
}
options.encoding = options.encoding || this.query.encoding;
if(options.encoding == 'latin1') options.encoding = 'win1252';
var start = this.i+0;
var end = start;
if(!('length' in options)) {
// terminated by the delimiter
var delim = options.delimiter || this.query.delimiter;
if(typeof delim == 'string') delim = delim.charCodeAt(0);
while(true) {
if(end >= this.buffer.length) {
end = this.buffer.length;
break;
}
if(this.buffer.readUInt8(end) == delim) break;
end++;
}
this.i = end+1;
} else {
end = start+options.length;
if(end >= this.buffer.length) {
end = this.buffer.length;
}
this.i = end;
}
var out = this.buffer.slice(start, end);
var enc = options.encoding;
if(enc == 'utf8' || enc == 'ucs2' || enc == 'binary') {
out = out.toString(enc);
} else {
out = Iconv.decode(out,enc);
}
return out;
},
int: function(bytes) {
var r = 0;
if(this.remaining() >= bytes) {
if(this.query.byteorder == 'be') {
if(bytes == 1) r = this.buffer.readInt8(this.i);
else if(bytes == 2) r = this.buffer.readInt16BE(this.i);
else if(bytes == 4) r = this.buffer.readInt32BE(this.i);
} else {
if(bytes == 1) r = this.buffer.readInt8(this.i);
else if(bytes == 2) r = this.buffer.readInt16LE(this.i);
else if(bytes == 4) r = this.buffer.readInt32LE(this.i);
}
}
this.i += bytes;
return r;
},
uint: function(bytes) {
var r = 0;
if(this.remaining() >= bytes) {
if(this.query.byteorder == 'be') {
if(bytes == 1) r = this.buffer.readUInt8(this.i);
else if(bytes == 2) r = this.buffer.readUInt16BE(this.i);
else if(bytes == 4) r = this.buffer.readUInt32BE(this.i);
else if(bytes == 8) r = readUInt64BE(this.buffer,this.i).toString();
} else {
if(bytes == 1) r = this.buffer.readUInt8(this.i);
else if(bytes == 2) r = this.buffer.readUInt16LE(this.i);
else if(bytes == 4) r = this.buffer.readUInt32LE(this.i);
else if(bytes == 8) r = readUInt64LE(this.buffer,this.i).toString();
}
}
this.i += bytes;
return r;
},
float: function() {
var r = 0;
if(this.remaining() >= 4) {
if(this.query.byteorder == 'be') r = this.buffer.readFloatBE(this.i);
else r = this.buffer.readFloatLE(this.i);
}
this.i += 4;
return r;
},
remaining: function() {
return this.buffer.length-this.i;
},
rest: function() {
return this.buffer.slice(this.i);
},
done: function() {
return this.i >= this.buffer.length;
}
};
module.exports = Reader;