From bc94bc1fe05128ddbc007ec40285c8546e5aca9b Mon Sep 17 00:00:00 2001 From: christopher james churchill Date: Mon, 21 Mar 2016 14:46:06 +0000 Subject: [PATCH 1/3] Update proxy.js changing == to === and != to !== becuase js is a bitch see: http://www.impressivewebs.com/why-use-triple-equals-javascipt/ --- examples/proxy/proxy.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/proxy/proxy.js b/examples/proxy/proxy.js index d62ff2f..174fe93 100644 --- a/examples/proxy/proxy.js +++ b/examples/proxy/proxy.js @@ -27,7 +27,7 @@ if(process.argv.length < 4) { } process.argv.forEach(function(val) { - if(val == "-h") { + if(val === "-h") { printHelpAndExit(0); } }); @@ -44,15 +44,15 @@ var printNameBlacklist = {}; for(var i = 0; i < args.length; i++) { var option = args[i]; if(!/^-/.test(option)) break; - if(option == "--dump-all") { + if(option === "--dump-all") { printAllNames = true; continue; } i++; var name = args[i]; - if(option == "--dump") { + if(option === "--dump") { printNameWhitelist[name] = "io"; - } else if(option == "-x") { + } else if(option === "-x") { printNameBlacklist[name] = "io"; } else { printHelpAndExit(1); @@ -63,7 +63,7 @@ var printNameBlacklist = {}; version = args[i++]; })(); -if(host.indexOf(':') != -1) { +if(host.indexOf(':') !== -1) { port = host.substring(host.indexOf(':') + 1); host = host.substring(0, host.indexOf(':')); } @@ -100,7 +100,7 @@ srv.on('login', function(client) { version:version }); client.on('packet', function(data, meta) { - if(targetClient.state == states.PLAY && meta.state == states.PLAY) { + if(targetClient.state === states.PLAY && meta.state === states.PLAY) { if(shouldDump(meta.name, "o")) { console.log("client->server:", client.state + " "+ meta.name + " :", @@ -111,7 +111,7 @@ srv.on('login', function(client) { } }); targetClient.on('packet', function(data, meta) { - if(meta.state == states.PLAY && client.state == states.PLAY) { + if(meta.state === states.PLAY && client.state === states.PLAY) { if(shouldDump(meta.name, "i")) { console.log("client<-server:", targetClient.state + "." + meta.name + " :" + @@ -119,14 +119,15 @@ srv.on('login', function(client) { } if(!endedClient) { client.write(meta.name, data); - if (meta.name === 'set_compression') // Set compression + if(meta.name === 'set_compression'){ client.compressionThreshold = data.threshold; + } // Set compression } } }); var bufferEqual = require('buffer-equal'); targetClient.on('raw', function(buffer, meta) { - if(client.state != states.PLAY || meta.state != states.PLAY) + if(client.state !== states.PLAY || meta.state !== states.PLAY) return; var packetData = targetClient.deserializer.parsePacketBuffer(buffer).data.params; var packetBuff = client.serializer.createPacketBuffer({name:meta.name, params:packetData}); @@ -137,7 +138,7 @@ srv.on('login', function(client) { console.log("received length",buffer.length); console.log("produced length",packetBuff.length); } - /*if (client.state == states.PLAY && brokenPackets.indexOf(packetId.value) !== -1) + /*if (client.state === states.PLAY && brokenPackets.indexOf(packetId.value) !=== -1) { console.log(`client<-server: raw packet); console.log(packetData); @@ -146,7 +147,7 @@ srv.on('login', function(client) { }*/ }); client.on('raw', function(buffer, meta) { - if(meta.state != states.PLAY || targetClient.state != states.PLAY) + if(meta.state !== states.PLAY || targetClient.state !== states.PLAY) return; var packetData = client.deserializer.parsePacketBuffer(buffer).data.params; var packetBuff = targetClient.serializer.createPacketBuffer({name:meta.name, params:packetData}); @@ -179,6 +180,6 @@ function shouldDump(name, direction) { return matches(printNameWhitelist[name]); function matches(result) { - return result != null && result.indexOf(direction) !== -1; + return result !== null && result.indexOf(direction) !== -1; } } From 25750ddf2dd643851b770c3e46d2965bffb82898 Mon Sep 17 00:00:00 2001 From: christopher james churchill Date: Mon, 21 Mar 2016 14:51:26 +0000 Subject: [PATCH 2/3] Update proxy.js ups != was right in one of those cases.... ummm using typeof may be better? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof --- examples/proxy/proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/proxy/proxy.js b/examples/proxy/proxy.js index 174fe93..407a74d 100644 --- a/examples/proxy/proxy.js +++ b/examples/proxy/proxy.js @@ -180,6 +180,6 @@ function shouldDump(name, direction) { return matches(printNameWhitelist[name]); function matches(result) { - return result !== null && result.indexOf(direction) !== -1; + return result != null && result.indexOf(direction) !== -1; } } From 6489d2820705e6c4b85aa0a95737c12bc2946ee5 Mon Sep 17 00:00:00 2001 From: christopher james churchill Date: Mon, 21 Mar 2016 14:52:14 +0000 Subject: [PATCH 3/3] Update proxy.js ups != was right in one of those cases.... ummm using typeof may be better? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof --- examples/proxy/proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/proxy/proxy.js b/examples/proxy/proxy.js index 174fe93..407a74d 100644 --- a/examples/proxy/proxy.js +++ b/examples/proxy/proxy.js @@ -180,6 +180,6 @@ function shouldDump(name, direction) { return matches(printNameWhitelist[name]); function matches(result) { - return result !== null && result.indexOf(direction) !== -1; + return result != null && result.indexOf(direction) !== -1; } }