mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -04:00
Merge branch 'master' of https://github.com/PrismarineJS/node-minecraft-protocol into fix-122
This commit is contained in:
commit
c6404f0274
3
.npmignore
Normal file
3
.npmignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
test/npm-debug.log
|
||||||
|
test/server
|
12
README.md
12
README.md
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
[](https://gitter.im/PrismarineJS/node-minecraft-protocol?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/PrismarineJS/node-minecraft-protocol?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
|
[](https://circleci.com/gh/PrismarineJS/node-minecraft-protocol)
|
||||||
|
|
||||||
Parse and serialize minecraft packets, plus authentication and encryption.
|
Parse and serialize minecraft packets, plus authentication and encryption.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@ -379,6 +381,16 @@ NODE_DEBUG="minecraft-protocol" node [...]
|
|||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
|
### 0.13.2
|
||||||
|
|
||||||
|
* Fixed particle packet.
|
||||||
|
* Fixed release. 0.13.1 release was missing an entire folder.
|
||||||
|
|
||||||
|
### 0.13.1
|
||||||
|
|
||||||
|
* Externalized rsa-wrap library to its own npm module, named ursa-native
|
||||||
|
* Fixed broken bed-related packets (thanks [rom1504](https://github.com/rom1504))
|
||||||
|
|
||||||
### 0.13.0
|
### 0.13.0
|
||||||
|
|
||||||
* Updated protocol version to support 1.8.1 (thanks [wtfaremyinitials](https://github.com/wtfaremyinitials))
|
* Updated protocol version to support 1.8.1 (thanks [wtfaremyinitials](https://github.com/wtfaremyinitials))
|
||||||
|
10
circle.yml
Normal file
10
circle.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
machine:
|
||||||
|
node:
|
||||||
|
version: 0.10.28
|
||||||
|
dependencies:
|
||||||
|
override:
|
||||||
|
- npm install --dev
|
||||||
|
test:
|
||||||
|
override:
|
||||||
|
- node_modules/.bin/mocha -g "packets"
|
||||||
|
- node_modules/.bin/mocha -g "mc-server"
|
@ -1,27 +1,74 @@
|
|||||||
var mc = require('../');
|
var mc = require('../');
|
||||||
|
|
||||||
var states = mc.protocol.states;
|
var states = mc.protocol.states;
|
||||||
function print_help() {
|
function printHelpAndExit(exitCode) {
|
||||||
console.log("usage: node proxy.js <target_srv> <user> [<password>]");
|
console.log("usage: node proxy.js [<options>...] <target_srv> <user> [<password>]");
|
||||||
|
console.log("options:");
|
||||||
|
console.log(" --dump ID");
|
||||||
|
console.log(" print to stdout messages with the specified ID.");
|
||||||
|
console.log(" --dump-all");
|
||||||
|
console.log(" print to stdout all messages, except those specified with -x.");
|
||||||
|
console.log(" -x ID");
|
||||||
|
console.log(" do not print messages with this ID.");
|
||||||
|
console.log(" ID");
|
||||||
|
console.log(" an integer in decimal or hex (given to JavaScript's parseInt())");
|
||||||
|
console.log(" optionally prefixed with o for client->server or i for client<-server.");
|
||||||
|
console.log("examples:");
|
||||||
|
console.log(" node proxy.js --dump-all -x 0x0 -x 0x3 -x 0x12 -x 0x015 -x 0x16 -x 0x17 -x 0x18 -x 0x19 localhost Player");
|
||||||
|
console.log(" print all messages except for some of the most prolific.");
|
||||||
|
console.log(" node examples/proxy.js --dump i0x2d --dump i0x2e --dump i0x2f dump i0x30 --dump i0x31 --dump i0x32 --dump o0x0d --dump o0x0e --dump o0x0f --dump o0x10 --dump o0x11 localhost Player");
|
||||||
|
console.log(" print messages relating to inventory management.");
|
||||||
|
|
||||||
|
process.exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv.length < 4) {
|
if (process.argv.length < 4) {
|
||||||
console.log("Too few arguments!");
|
console.log("Too few arguments!");
|
||||||
print_help();
|
printHelpAndExit(1);
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.argv.forEach(function(val, index, array) {
|
process.argv.forEach(function(val, index, array) {
|
||||||
if (val == "-h") {
|
if (val == "-h") {
|
||||||
print_help();
|
printHelpAndExit(0);
|
||||||
process.exit(0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var host = process.argv[2];
|
var args = process.argv.slice(2);
|
||||||
|
var host;
|
||||||
var port = 25565;
|
var port = 25565;
|
||||||
var user = process.argv[3];
|
var user;
|
||||||
var passwd = process.argv[4];
|
var passwd;
|
||||||
|
|
||||||
|
var printAllIds = false;
|
||||||
|
var printIdWhitelist = {};
|
||||||
|
var printIdBlacklist = {};
|
||||||
|
(function() {
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
var option = args[i];
|
||||||
|
if (!/^-/.test(option)) break;
|
||||||
|
if (option == "--dump-all") {
|
||||||
|
printAllIds = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
var match = /^([io]?)(.*)/.exec(args[i]);
|
||||||
|
var prefix = match[1];
|
||||||
|
if (prefix === "") prefix = "io";
|
||||||
|
var number = parseInt(match[2]);
|
||||||
|
if (isNaN(number)) printHelpAndExit(1);
|
||||||
|
if (option == "--dump") {
|
||||||
|
printIdWhitelist[number] = prefix;
|
||||||
|
} else if (option == "-x") {
|
||||||
|
printIdBlacklist[number] = prefix;
|
||||||
|
} else {
|
||||||
|
printHelpAndExit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(i + 2 <= args.length && args.length <= i + 3)) printHelpAndExit(1);
|
||||||
|
host = args[i++];
|
||||||
|
user = args[i++];
|
||||||
|
passwd = args[i++];
|
||||||
|
})();
|
||||||
|
|
||||||
if (host.indexOf(':') != -1) {
|
if (host.indexOf(':') != -1) {
|
||||||
port = host.substring(host.indexOf(':')+1);
|
port = host.substring(host.indexOf(':')+1);
|
||||||
@ -59,7 +106,11 @@ srv.on('login', function (client) {
|
|||||||
var brokenPackets = [/*0x04, 0x2f, 0x30*/];
|
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)}`);
|
if (shouldDump(packet.id, "o")) {
|
||||||
|
console.log("client->server:",
|
||||||
|
client.state + ".0x" + packet.id.toString(16) + " :",
|
||||||
|
JSON.stringify(packet));
|
||||||
|
}
|
||||||
if (!endedTargetClient)
|
if (!endedTargetClient)
|
||||||
targetClient.write(packet.id, packet);
|
targetClient.write(packet.id, packet);
|
||||||
}
|
}
|
||||||
@ -68,7 +119,11 @@ srv.on('login', function (client) {
|
|||||||
if (packet.state == states.PLAY && client.state == states.PLAY &&
|
if (packet.state == states.PLAY && client.state == states.PLAY &&
|
||||||
brokenPackets.indexOf(packet.id) === -1)
|
brokenPackets.indexOf(packet.id) === -1)
|
||||||
{
|
{
|
||||||
//console.log(`client<-server: ${targetClient.state}.${packet.id} : ${packet.id != 38 ? JSON.stringify(packet) : "Packet too big"}`);
|
if (shouldDump(packet.id, "i")) {
|
||||||
|
console.log("client<-server:",
|
||||||
|
targetClient.state + ".0x" + packet.id.toString(16) + " :",
|
||||||
|
(packet.id != 38 ? JSON.stringify(packet) : "Packet too big"));
|
||||||
|
}
|
||||||
if (!endedClient)
|
if (!endedClient)
|
||||||
client.write(packet.id, packet);
|
client.write(packet.id, packet);
|
||||||
}
|
}
|
||||||
@ -120,3 +175,13 @@ srv.on('login', function (client) {
|
|||||||
client.end("Error");
|
client.end("Error");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function shouldDump(id, direction) {
|
||||||
|
if (matches(printIdBlacklist[id])) return false;
|
||||||
|
if (printAllIds) return true;
|
||||||
|
if (matches(printIdWhitelist[id])) return true;
|
||||||
|
return false;
|
||||||
|
function matches(result) {
|
||||||
|
return result != null && result.indexOf(direction) !== -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "minecraft-protocol",
|
"name": "minecraft-protocol",
|
||||||
"version": "0.13.0",
|
"version": "0.13.2",
|
||||||
"description": "Parse and serialize minecraft packets, plus authentication and encryption.",
|
"description": "Parse and serialize minecraft packets, plus authentication and encryption.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -320,7 +320,7 @@ function createClient(options) {
|
|||||||
hash.update(packet.publicKey);
|
hash.update(packet.publicKey);
|
||||||
|
|
||||||
var digest = mcHexDigest(hash);
|
var digest = mcHexDigest(hash);
|
||||||
joinServer(this.username, digest, accessToken, client.session.selectedProfile.id, cb);
|
joinServer(client.username, digest, accessToken, client.session.selectedProfile.id, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendEncryptionKeyResponse() {
|
function sendEncryptionKeyResponse() {
|
||||||
|
@ -131,12 +131,12 @@ var packets = {
|
|||||||
{ name: "slot", type: "byte" }
|
{ name: "slot", type: "byte" }
|
||||||
]},
|
]},
|
||||||
bed: {id: 0x0a, fields: [
|
bed: {id: 0x0a, fields: [
|
||||||
{ name: "entityId", type: "int" },
|
{ name: "entityId", type: "varint" },
|
||||||
{ name: "location", type: "position" }
|
{ name: "location", type: "position" }
|
||||||
]},
|
]},
|
||||||
animation: {id: 0x0b, fields: [
|
animation: {id: 0x0b, fields: [
|
||||||
{ name: "entityId", type: "varint" },
|
{ name: "entityId", type: "varint" },
|
||||||
{ name: "animation", type: "byte" }
|
{ name: "animation", type: "ubyte" }
|
||||||
]},
|
]},
|
||||||
named_entity_spawn: {id: 0x0c, fields: [
|
named_entity_spawn: {id: 0x0c, fields: [
|
||||||
{ name: "entityId", type: "varint" },
|
{ name: "entityId", type: "varint" },
|
||||||
@ -379,8 +379,15 @@ var packets = {
|
|||||||
{ name: "offsetY", type: "float" },
|
{ name: "offsetY", type: "float" },
|
||||||
{ name: "offsetZ", type: "float" },
|
{ name: "offsetZ", type: "float" },
|
||||||
{ name: "particleData", type: "float" },
|
{ name: "particleData", type: "float" },
|
||||||
{ name: "particles", type: "count", typeArgs: { countFor: "data", type: "int" } },
|
{ name: "particles", type: "int" },
|
||||||
{ name: "data", type: "array", typeArgs: { count: "particles", type: "varint" } }
|
{ name: "data", type: "array", typeArgs: { count: function(fields) {
|
||||||
|
if (fields.particleId === 36)
|
||||||
|
return 2;
|
||||||
|
else if (fields.particleId === 37 || fields.particleId === 38)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}, type: "varint" } }
|
||||||
]},
|
]},
|
||||||
game_state_change: {id: 0x2b, fields: [
|
game_state_change: {id: 0x2b, fields: [
|
||||||
{ name: "reason", type: "ubyte" },
|
{ name: "reason", type: "ubyte" },
|
||||||
@ -1090,8 +1097,11 @@ function readBool(buffer, offset) {
|
|||||||
function readPosition(buffer, offset) {
|
function readPosition(buffer, offset) {
|
||||||
var longVal = readLong(buffer, offset).value; // I wish I could do destructuring...
|
var longVal = readLong(buffer, offset).value; // I wish I could do destructuring...
|
||||||
var x = longVal[0] >> 6;
|
var x = longVal[0] >> 6;
|
||||||
|
if(x>33554432) x-=67108864;
|
||||||
var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f);
|
var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f);
|
||||||
|
if(y>2048) y-=4096;
|
||||||
var z = longVal[1] & 0x3FFFFFF;
|
var z = longVal[1] & 0x3FFFFFF;
|
||||||
|
if(z>33554432) z-=67108864;
|
||||||
return {
|
return {
|
||||||
value: { x: x, y: y, z: z },
|
value: { x: x, y: y, z: z },
|
||||||
size: 8
|
size: 8
|
||||||
@ -1348,7 +1358,11 @@ function readArray(buffer, offset, typeArgs, rootNode) {
|
|||||||
value: [],
|
value: [],
|
||||||
size: 0
|
size: 0
|
||||||
}
|
}
|
||||||
var count = getField(typeArgs.count, rootNode);
|
var count;
|
||||||
|
if (typeof typeArgs.count === "function")
|
||||||
|
count = typeArgs.count(rootNode);
|
||||||
|
else
|
||||||
|
count = getField(typeArgs.count, rootNode);
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var readResults = read(buffer, offset, { type: typeArgs.type, typeArgs: typeArgs.typeArgs }, rootNode);
|
var readResults = read(buffer, offset, { type: typeArgs.type, typeArgs: typeArgs.typeArgs }, rootNode);
|
||||||
results.size += readResults.size;
|
results.size += readResults.size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user