diff --git a/package.json b/package.json index 74d0b59..f70c26d 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "iconv-lite": ">=0.2.10", "bignum": ">=0.6.1", "async": ">=0.2.9", - "compressjs": ">=1.0.0" + "compressjs": ">=1.0.0", + "gbxremote": ">=0.1.2" } } diff --git a/protocols/maniaplanet.js b/protocols/maniaplanet.js new file mode 100644 index 0000000..4bd62e7 --- /dev/null +++ b/protocols/maniaplanet.js @@ -0,0 +1,79 @@ +var gbxremote = require('gbxremote'), + async = require('async'); + +module.exports = require('./core').extend({ + init: function() { + this._super(); + this.options.port = 5000; + this.gbxclient = false; + }, + reset: function() { + this._super(); + console.log("~~TERM"); + if(this.gbxclient) this.gbxclient.terminate(); + }, + run: function() { + var self = this; + + var cmds = [ + ['Connect'], + ['Authenticate', this.options.login,this.options.password], + ['GetStatus'], + ['GetPlayerList',500,0], + ['GetServerOptions'], + ['GetCurrentChallengeInfo'], + ['GetCurrentGameInfo'] + ]; + var results = []; + + async.eachSeries(cmds, function(cmdset,c) { + var cmd = cmdset[0]; + var params = cmdset.slice(1); + + if(cmd == 'Connect') { + var client = self.gbxclient = gbxremote.createClient(self.options.port,self.options.host, function(err) { + if(err) return self.error('GBX error '+JSON.stringify(err)); + c(); + }); + client.on('error',function(){}); + } else { + self.gbxclient.methodCall(cmd, params, function(err, value) { + if(err) return self.error('XMLRPC error '+JSON.stringify(err)); + results.push(value); + c(); + }); + } + }, function() { + var state = {}; + for(var i in results[1]) state[i] = results[1][i]; + for(var i in results[3]) state[i] = results[3][i]; + for(var i in results[4]) state[i] = results[4][i]; + + var gamemode = ''; + var igm = results[5].GameMode; + if(igm == 0) gamemode="Rounds"; + if(igm == 1) gamemode="Time Attack"; + if(igm == 2) gamemode="Team"; + if(igm == 3) gamemode="Laps"; + if(igm == 4) gamemode="Stunts"; + if(igm == 5) gamemode="Cup"; + state.gamemode = gamemode; + + console.log(state); + // strip colors from Name, Player.NickName + }); + } +/* + function stripColors($str) { + $str2 = str_replace("$", "\001", preg_replace("`[\001\002]`","","a".$str) ); + $str2 = str_replace("\001\001","$", $str2); + $str2 = preg_replace("`\001[hlHL]`","\002",$str2); + $str2 = preg_replace("`\002\[([^\]]*)\]([^\002]*)\002`","$2",$str2); + $str2 = preg_replace("`\002\[([^\]]*)\]`","",$str2); + $str2 = str_replace("\002","", $str2); + $str2 = preg_replace("`\001([0-9a-fA-F][0-9a-zA-Z][0-9a-zA-Z]|[^\001])`","",$str2); + $str2 = str_replace("\001","$$", substr($str2,1) ); + return $str2; + } +*/ +}); diff --git a/protocols/ut2004.js b/protocols/ut2004.js new file mode 100644 index 0000000..335178b --- /dev/null +++ b/protocols/ut2004.js @@ -0,0 +1,6 @@ +module.exports = require('./gamespy').extend({ + init: function() { + this._super(); + this.options.port = 7778; + } +}); diff --git a/protocols/ut3.js b/protocols/ut3.js new file mode 100644 index 0000000..ea4889d --- /dev/null +++ b/protocols/ut3.js @@ -0,0 +1,35 @@ +module.exports = require('./gamespy').extend({ + init: function() { + this._super(); + this.options.port = 6500; + } + prepState: function(state) { + this._super(state); + + this.translateState(state,{ + 'OwningPlayerName': 'hostname', + 'p1073741825': 'mapname', + 'p1073741826': 'gametype', + 'p1073741827': 'servername', + 'p1073741828': 'custom_mutators', + 'gamemode': 'open', + 's32779': 'gamemode', + 's0': 'bot_skill', + 's6': 'pure_server', + 's7': 'password', + 's8': 'vs_bots', + 's10': 'force_respawn', + 'p268435704': 'frag_limit', + 'p268435705': 'time_limit', + 'p268435703': 'numbots', + 'p268435717': 'stock_mutators' + 's1': false, + 's9': false, + 's11': false, + 's12': false, + 's13': false, + 's14': false + }); + state['custom_mutators'] = state['custom_mutators'].split('\x1c'); + } +});