From 2915d962a8a14df0118ee6cf71a67b4e80f2f500 Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Sat, 1 Feb 2014 20:04:41 -0600 Subject: [PATCH] Fix issues with corrupt strings in unreal2 protocol --- README.md | 2 +- games/killingfloor.js | 2 -- games/protocols/core.js | 18 +++++++++++++++ games/protocols/unreal2.js | 45 +++++++++++++++++++++++++++++--------- games/ut2004.js | 6 ++--- 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fdd816c..cac00a4 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ Supported Games * TrackMania 2 (trackmania2) [[Additional Notes](#nadeo-shootmania--trackmania--etc)] * TrackMania Forever (trackmaniaforever) [[Additional Notes](#nadeo-shootmania--trackmania--etc)] * Unreal Tournament (ut) [[Separate Query Port - Usually port+1](#separate-query-port)] -* Unreal Tournament 2004 (ut2004) +* Unreal Tournament 2004 (ut2004) [[Separate Query Port - Usually port+1](#separate-query-port)] * Unreal Tournament 3 (ut3) [[Separate Query Port - Usually 6500](#separate-query-port)] * Warsow (warsow) * Wolfenstein 2009 (wolfenstein2009) diff --git a/games/killingfloor.js b/games/killingfloor.js index 6425e2d..041394d 100644 --- a/games/killingfloor.js +++ b/games/killingfloor.js @@ -5,8 +5,6 @@ module.exports = require('./protocols/unreal2').extend({ this.pretty = 'Killing Floor'; }, readExtraInfo: function(reader,state) { - state.raw.numplayers = reader.uint(4); - state.maxplayers = reader.uint(4); state.raw.wavecurrent = reader.uint(4); state.raw.wavetotal = reader.uint(4); } diff --git a/games/protocols/core.js b/games/protocols/core.js index ea05f58..d2c320a 100644 --- a/games/protocols/core.js +++ b/games/protocols/core.js @@ -177,6 +177,24 @@ module.exports = Class.extend(EventEmitter,{ } return false; }, + debugBuffer: function(buffer) { + var out = ''; + var out2 = ''; + for(var i = 0; i < buffer.length; i++) { + var sliced = buffer.slice(i,i+1); + out += sliced.toString('hex')+' '; + var chr = sliced.toString(); + if(chr < ' ' || chr > '~') chr = ' '; + out2 += chr+' '; + if(out.length > 60) { + console.log(out); + console.log(out2); + out = out2 = ''; + } + } + console.log(out); + console.log(out2); + }, diff --git a/games/protocols/unreal2.js b/games/protocols/unreal2.js index 807fa89..cfe9f8c 100644 --- a/games/protocols/unreal2.js +++ b/games/protocols/unreal2.js @@ -18,9 +18,10 @@ module.exports = require('./core').extend({ state.raw.port = reader.uint(4); state.raw.queryport = reader.uint(4); state.name = self.readUnrealString(reader,true); - self.readUnrealString(reader); // unknown? state.map = self.readUnrealString(reader,true); state.raw.gametype = self.readUnrealString(reader,true); + state.raw.numplayers = reader.uint(4); + state.maxplayers = reader.uint(4); self.readExtraInfo(reader,state); c(); @@ -47,15 +48,37 @@ module.exports = require('./core').extend({ function(c) { self.sendPacket(2,false,function(b) { var reader = self.reader(b); + while(!reader.done()) { - var id = reader.uint(4); - var name = self.readUnrealString(reader,true); - var ping = reader.uint(4); - var score = reader.uint(4); - reader.skip(4); - (ping == 0 ? state.bots : state.players).push({ - id: id, name: name, ping: ping, score: score - }); + var player = {}; + player.id = reader.uint(4); + if(!player.id) break; + if(player.id == 0) { + // Unreal2XMP Player (ID is always 0) + reader.skip(4); + } + player.name = self.readUnrealString(reader,true); + player.ping = reader.uint(4); + player.score = reader.int(4); + reader.skip(4); // stats ID + + // Extra data for Unreal2XMP players + if(player.id == 0) { + var count = reader.uint(1); + for(var iField = 0; iField < count; iField++) { + var key = self.readUnrealString(reader,true); + var value = self.readUnrealString(reader,true); + player[key] = value; + } + } + + if(player.id == 0 && player.name == 'Player') { + // these show up in ut2004 queries, but aren't real + // not even really sure why they're there + continue; + } + + (player.ping ? state.players : state.bots).push(player); } c(); }); @@ -79,7 +102,9 @@ module.exports = require('./core').extend({ var length = reader.uint(1); var out; if(length < 0x80) { - out = reader.string({length:length}); + //out = reader.string({length:length}); + out = ''; + if(length > 0) out = reader.string(); } else { length = (length&0x7f)*2; out = length+reader.string({encoding:'ucs2',length:length}); diff --git a/games/ut2004.js b/games/ut2004.js index 06f883d..ea1b9f4 100644 --- a/games/ut2004.js +++ b/games/ut2004.js @@ -5,8 +5,8 @@ module.exports = require('./protocols/unreal2').extend({ this.pretty = 'Unreal Tournament 2004'; }, readExtraInfo: function(reader,state) { - reader.skip(18); - state.raw.numplayers = reader.uint(4); - state.maxplayers = reader.uint(4); + state.raw.ping = reader.uint(4); + state.raw.flags = reader.uint(4); + state.raw.skill = reader.uint(2); } });