From 935f61c4adf82abc9e4a960a762aa66733d0c8c7 Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Wed, 10 Jul 2013 10:47:23 -0500 Subject: [PATCH] add warsow --- package.json | 3 ++- protocols/quake2.js | 22 +++++++++++++++------- protocols/warsow.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 protocols/warsow.js diff --git a/package.json b/package.json index f70c26d..6b306fe 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "bignum": ">=0.6.1", "async": ">=0.2.9", "compressjs": ">=1.0.0", - "gbxremote": ">=0.1.2" + "gbxremote": ">=0.1.2", + "request": ">=2.22.0" } } diff --git a/protocols/quake2.js b/protocols/quake2.js index 7f39433..19d8d8b 100644 --- a/protocols/quake2.js +++ b/protocols/quake2.js @@ -29,14 +29,22 @@ module.exports = require('./core').extend({ state.players = []; while(!reader.done()) { var player = reader.string(); - var split = player.split('"'); - var split1 = split[0].split(' '); - var frags = parseInt(split1[0]); - var ping = parseInt(split1[1]); - var name = split[1] || ''; - var address = split[3] || ''; - + var args = []; + var split = player.split('"'); + var inQuote = false; + for(var i = 0; i < split; i++) { + var part = split[i]; + var inQuote = (i%2 == 1); + if(inQuote) args.push(part); + else args = args.concat(part.split(' ')); + } + + var frags = parseInt(args[0]); + var ping = parseInt(args[1]); + var name = args[2] || ''; + var address = args[3] || ''; + state.players.push({ frags:frags, ping:ping, name:name, address:address }); diff --git a/protocols/warsow.js b/protocols/warsow.js new file mode 100644 index 0000000..b59f449 --- /dev/null +++ b/protocols/warsow.js @@ -0,0 +1,16 @@ +module.exports = require('./quake3').extend({ + init: function() { + this._super(); + this.options.port = 44400; + }, + prepState: function(state) { + this._super(state); + if(state.players) { + for(var i = 0; i < state.players.length; i++) { + var player = state.players[i]; + player.team = player.address; + delete player.address; + } + } + } +});