Make proxy able to spot discrepencies in input/output buffer.

This commit is contained in:
roblabla 2015-03-03 12:43:46 +00:00
parent 77f702e9cb
commit c1ced61d47
2 changed files with 44 additions and 5 deletions

View File

@ -53,22 +53,60 @@ srv.on('login', function (client) {
host: host,
port: port,
username: user,
password: passwd
password: passwd,
'online-mode': passwd != null ? true : false
});
var brokenPackets = [/*0x04, 0x2f, 0x30*/];
client.on('packet', function(packet) {
if (targetClient.state == states.PLAY && packet.state == states.PLAY) {
console.log(`client->server: ${client.state}.${packet.id} : ${JSON.stringify(packet)}`);
//console.log(`client->server: ${client.state}.${packet.id} : ${JSON.stringify(packet)}`);
if (!endedTargetClient)
targetClient.write(packet.id, packet);
}
});
targetClient.on('packet', function(packet) {
if (packet.state == states.PLAY && client.state == states.PLAY) {
console.log(`client<-server: ${targetClient.state}.${packet.id} : ${packet.id != 38 ? JSON.stringify(packet) : "Packet too big"}`);
if (packet.state == states.PLAY && client.state == states.PLAY &&
brokenPackets.indexOf(packet.id) === -1)
{
//console.log(`client<-server: ${targetClient.state}.${packet.id} : ${packet.id != 38 ? JSON.stringify(packet) : "Packet too big"}`);
if (!endedClient)
client.write(packet.id, packet);
}
});
var buffertools = require('buffertools');
targetClient.on('raw', function(buffer, state) {
if (client.state != states.PLAY || state != states.PLAY)
return;
var packetId = mc.protocol.types.varint[0](buffer, 0);
var packetData = mc.protocol.parsePacketData(buffer, state, false, {"packet": 1}).results;
var packetBuff = mc.protocol.createPacketBuffer(packetData.id, packetData.state, packetData, true);
if (buffertools.compare(buffer, packetBuff) != 0)
{
console.log(`client<-server: Error in packetId ${state}.0x${packetId.value.toString(16)}`);
console.log(buffer.toString('hex'));
console.log(packetBuff.toString('hex'));
}
/*if (client.state == states.PLAY && brokenPackets.indexOf(packetId.value) !== -1)
{
console.log(`client<-server: raw packet`);
console.log(packetData);
if (!endedClient)
client.writeRaw(buffer);
}*/
});
client.on('raw', function(buffer, state) {
if (state != states.PLAY || targetClient.state != states.PLAY)
return;
var packetId = mc.protocol.types.varint[0](buffer, 0);
var packetData = mc.protocol.parsePacketData(buffer, state, true, {"packet": 1}).results;
var packetBuff = mc.protocol.createPacketBuffer(packetData.id, packetData.state, packetData, false);
if (buffertools.compare(buffer, packetBuff) != 0)
{
console.log(`client->server: Error in packetId ${state}.0x${packetId.value.toString(16)}`);
console.log(buffer.toString('hex'));
console.log(packetBuff.toString('hex'));
}
});
targetClient.on('end', function() {
endedTargetClient = true;
console.log('Connection closed by server', '('+addr+')');

View File

@ -30,7 +30,8 @@
"mkdirp": "~0.3.4",
"rimraf": "~2.1.1",
"zfill": "0.0.1",
"batch": "~0.3.1"
"batch": "~0.3.1",
"buffertools": "^2.1.2"
},
"dependencies": {
"ansi-color": "0.2.1",