node-gamedig/games/m2mp.js
Michael Morrison e23aa6cf9c Super epic commit 2
Added pretty much every game ever
Tons of new protocols and game definitions
Cleaned up and discovered some new tricks in gamespy3 and quake2
2014-02-01 17:46:10 -06:00

40 lines
934 B
JavaScript

module.exports = require('./protocols/core').extend({
init: function() {
this._super();
this.encoding = 'latin1';
this.pretty = 'Mafia 2 Multiplayer';
this.options.port = 27016;
},
run: function(state) {
var self = this;
this.udpSend('M2MP',function(buffer) {
var reader = self.reader(buffer);
var header = reader.string({length:4});
if(header != 'M2MP') return;
state.name = self.readString(reader);
state.raw.numplayers = self.readString(reader);
state.maxplayers = self.readString(reader);
state.raw.gamemode = self.readString(reader);
state.password = !!reader.uint(1);
while(!reader.done()) {
var name = self.readString(reader);
if(!name) break;
state.players.push({
name:name
});
}
self.finish(state);
return true;
});
},
readString: function(reader) {
var length = reader.uint(1);
return reader.string({length:length-1});
},
});