mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
commit
6ce09ba9b0
6 changed files with 22 additions and 14 deletions
|
@ -9,7 +9,7 @@ Parse and serialize minecraft packets, plus authentication and encryption.
|
|||
## Features
|
||||
|
||||
* Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4),
|
||||
1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), and 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1)
|
||||
1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a)
|
||||
* Parses all packets and emits events with packet fields as JavaScript
|
||||
objects.
|
||||
* Send a packet by supplying fields as a JavaScript object.
|
||||
|
|
|
@ -41,9 +41,9 @@
|
|||
"endian-toggle": "^0.0.0",
|
||||
"lodash.get": "^4.1.2",
|
||||
"lodash.merge": "^4.3.0",
|
||||
"minecraft-data": "^2.20.0",
|
||||
"minecraft-data": "^2.25.0",
|
||||
"node-rsa": "^0.4.2",
|
||||
"prismarine-nbt": "^1.0.0",
|
||||
"prismarine-nbt": "^1.2.0",
|
||||
"protodef": "^1.5.1",
|
||||
"readable-stream": "^2.0.5",
|
||||
"uuid-1345": "^0.99.6",
|
||||
|
|
|
@ -97,7 +97,8 @@ class Client extends EventEmitter
|
|||
parsed.data=parsed.data.params;
|
||||
parsed.metadata.state=state;
|
||||
debug("read packet " + state + "." + parsed.metadata.name);
|
||||
debug(parsed.data);
|
||||
const s=JSON.stringify(parsed.data,null,2);
|
||||
debug(s.length > 10000 ? parsed.data : s);
|
||||
this.emit('packet', parsed.data, parsed.metadata);
|
||||
this.emit(parsed.metadata.name, parsed.data, parsed.metadata);
|
||||
this.emit('raw.' + parsed.metadata.name, parsed.buffer, parsed.metadata);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
module.exports={
|
||||
defaultVersion:'1.12.1',
|
||||
supportedVersions:['1.7','1.8','1.9','1.10','1.11.2','1.12.1']
|
||||
defaultVersion:'1.12.2',
|
||||
supportedVersions:['1.7','1.8','1.9','1.10','1.11.2','1.12.2','17w50a']
|
||||
};
|
||||
|
|
|
@ -117,15 +117,15 @@ mc.supportedVersions.forEach(function(supportedVersion,i) {
|
|||
assert.strictEqual(message.translate, "chat.type.text");
|
||||
assert.deepEqual(message["with"][0].clickEvent, {
|
||||
action: "suggest_command",
|
||||
value: "/msg Player "
|
||||
value: mcData.version.version>340 ? "/tell Player " : "/msg Player "
|
||||
});
|
||||
assert.deepEqual(message["with"][0].text, "Player");
|
||||
assert.strictEqual(message["with"][1], "hello everyone; I have logged in.");
|
||||
} else if (chatCount === 2) {
|
||||
assert.strictEqual(message.translate, "chat.type.announcement");
|
||||
assert.strictEqual(message["with"][0].text ? message["with"][0].text : message["with"][0], "Server");
|
||||
assert.deepEqual(message["with"][1].extra[0].text ?
|
||||
message["with"][1].extra[0].text : message["with"][1].extra[0], "hello");
|
||||
assert.deepEqual(message["with"][1].extra ? (message["with"][1].extra[0].text ?
|
||||
message["with"][1].extra[0].text : message["with"][1].extra[0]) : message["with"][1].text, "hello");
|
||||
wrap.removeListener('line', lineListener);
|
||||
client.end();
|
||||
done();
|
||||
|
|
|
@ -42,7 +42,7 @@ const values = {
|
|||
"..": context
|
||||
};
|
||||
Object.keys(typeArgs).forEach(function(index){
|
||||
const v=getValue(typeArgs[index].type, results);
|
||||
const v=typeArgs[index].name==="type" && typeArgs[index].type==="string" ? "crafting_shapeless" : getValue(typeArgs[index].type, results);
|
||||
if(typeArgs[index].anon) {
|
||||
Object.keys(v).forEach(key => {
|
||||
results[key]=v[key];
|
||||
|
@ -130,21 +130,26 @@ const values = {
|
|||
'restBuffer': new Buffer(0),
|
||||
'switch': function(typeArgs, context) {
|
||||
const i = typeArgs.fields[getField(typeArgs.compareTo, context)];
|
||||
if (typeof i === "undefined")
|
||||
if (typeof i === "undefined") {
|
||||
if(typeArgs.default === undefined)
|
||||
throw new Error("couldn't find the field "+typeArgs.compareTo+" of the compareTo and the default is not defined");
|
||||
return getValue(typeArgs.default, context);
|
||||
}
|
||||
else
|
||||
return getValue(i, context);
|
||||
},
|
||||
'option': function(typeArgs, context) {
|
||||
return getValue(typeArgs, context);
|
||||
},
|
||||
'bitfield': function(typeArgs) {
|
||||
'bitfield': function(typeArgs, context) {
|
||||
const results={};
|
||||
Object.keys(typeArgs).forEach(function(index){
|
||||
results[typeArgs[index].name] = 1;
|
||||
context[typeArgs[index].name] = 1;
|
||||
});
|
||||
return results;
|
||||
}
|
||||
},
|
||||
'tags':[{'tagName':'hi','entries':[1,2,3,4,5]}]
|
||||
};
|
||||
|
||||
function getValue(_type, packet) {
|
||||
|
@ -192,7 +197,9 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
|
|||
let packetInfo, field;
|
||||
Object.keys(packets).filter(function(state){return state!=="types"}).forEach(function(state){
|
||||
Object.keys(packets[state]).forEach(function(direction){
|
||||
Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!=="packet"}).forEach(function(packetName){
|
||||
Object.keys(packets[state][direction].types)
|
||||
.filter(function(packetName){return packetName!=="packet" && packetName.startsWith("packet_")})
|
||||
.forEach(function(packetName){
|
||||
packetInfo = packets[state][direction].types[packetName];
|
||||
packetInfo=packetInfo ? packetInfo : null;
|
||||
it(state + ","+(direction==="toServer" ? "Server" : "Client")+"Bound," + packetName,
|
||||
|
|
Loading…
Reference in a new issue