mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 22:51:23 -04:00
Make proxy able to spot discrepencies in input/output buffer.
This commit is contained in:
parent
77f702e9cb
commit
c1ced61d47
@ -53,22 +53,60 @@ srv.on('login', function (client) {
|
|||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
username: user,
|
username: user,
|
||||||
password: passwd
|
password: passwd,
|
||||||
|
'online-mode': passwd != null ? true : false
|
||||||
});
|
});
|
||||||
|
var brokenPackets = [/*0x04, 0x2f, 0x30*/];
|
||||||
client.on('packet', function(packet) {
|
client.on('packet', function(packet) {
|
||||||
if (targetClient.state == states.PLAY && packet.state == states.PLAY) {
|
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)
|
if (!endedTargetClient)
|
||||||
targetClient.write(packet.id, packet);
|
targetClient.write(packet.id, packet);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
targetClient.on('packet', function(packet) {
|
targetClient.on('packet', function(packet) {
|
||||||
if (packet.state == states.PLAY && client.state == states.PLAY) {
|
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"}`);
|
brokenPackets.indexOf(packet.id) === -1)
|
||||||
|
{
|
||||||
|
//console.log(`client<-server: ${targetClient.state}.${packet.id} : ${packet.id != 38 ? JSON.stringify(packet) : "Packet too big"}`);
|
||||||
if (!endedClient)
|
if (!endedClient)
|
||||||
client.write(packet.id, packet);
|
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() {
|
targetClient.on('end', function() {
|
||||||
endedTargetClient = true;
|
endedTargetClient = true;
|
||||||
console.log('Connection closed by server', '('+addr+')');
|
console.log('Connection closed by server', '('+addr+')');
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
"mkdirp": "~0.3.4",
|
"mkdirp": "~0.3.4",
|
||||||
"rimraf": "~2.1.1",
|
"rimraf": "~2.1.1",
|
||||||
"zfill": "0.0.1",
|
"zfill": "0.0.1",
|
||||||
"batch": "~0.3.1"
|
"batch": "~0.3.1",
|
||||||
|
"buffertools": "^2.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-color": "0.2.1",
|
"ansi-color": "0.2.1",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user