node-gamedig/protocols/ase.js
Michael Morrison bc6b5c9225 Super epic commit 3
Move everything around
Add another 50 or so games
*** 'port' option should now be CONNECT port, not query port ***
add reference for many missing games
2014-02-03 14:00:51 -06:00

47 lines
1.5 KiB
JavaScript

module.exports = require('./core').extend({
run: function(state) {
var self = this;
self.udpSend('s',function(buffer) {
var reader = self.reader(buffer);
var header = reader.string({length:4});
if(header != 'EYE1') return;
state.raw.gamename = self.readString(reader);
state.raw.port = parseInt(self.readString(reader));
state.name = self.readString(reader);
state.raw.gametype = self.readString(reader);
state.map = self.readString(reader);
state.raw.version = self.readString(reader);
state.password = self.readString(reader) == '1';
state.raw.numplayers = parseInt(self.readString(reader));
state.maxplayers = parseInt(self.readString(reader));
while(!reader.done()) {
var key = self.readString(reader);
if(!key) break;
var value = self.readString(reader);
state.raw[key] = value;
}
console.log(reader.rest());
while(!reader.done()) {
var flags = reader.uint(1);
var player = {};
if(flags & 1) player.name = self.readString(reader);
if(flags & 2) player.team = self.readString(reader);
if(flags & 4) player.skin = self.readString(reader);
if(flags & 8) player.score = parseInt(self.readString(reader));
if(flags & 16) player.ping = parseInt(self.readString(reader));
if(flags & 32) player.time = parseInt(self.readString(reader));
state.players.push(player);
}
self.finish(state);
});
},
readString: function(reader) {
var len = reader.uint(1);
return reader.string({length:len-1});
}
});