mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-01 19:46:58 -05:00
Start on updating protocol to 1.8
This commit is contained in:
parent
ba4d871984
commit
29a93f319e
1 changed files with 157 additions and 130 deletions
287
lib/protocol.js
287
lib/protocol.js
|
@ -15,7 +15,7 @@ var states = {
|
|||
var packets = {
|
||||
handshaking: {
|
||||
toClient: {},
|
||||
toServer: {
|
||||
toServer: {
|
||||
set_protocol: {id: 0x00, fields: [
|
||||
{ name: "protocolVersion", type: "varint" },
|
||||
{ name: "serverHost", type: "string" },
|
||||
|
@ -76,7 +76,7 @@ var packets = {
|
|||
play: {
|
||||
toClient: {
|
||||
keep_alive: {id: 0x00, fields: [
|
||||
{ name: "keepAliveId", type: "int" },
|
||||
{ name: "keepAliveId", type: "int" /* TODO: Int or VarInt */ },
|
||||
]},
|
||||
login: {id: 0x01, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
|
@ -85,27 +85,27 @@ var packets = {
|
|||
{ name: "difficulty", type: "ubyte" },
|
||||
{ name: "maxPlayers", type: "ubyte" },
|
||||
{ name: "levelType", type: "string" },
|
||||
{ name: "reducedDebugInfo", type: "bool"}
|
||||
]},
|
||||
chat: {id: 0x02, fields: [
|
||||
{ name: "message", type: "ustring" },
|
||||
{ name: "position", type: "byte" }
|
||||
]},
|
||||
update_time: {id: 0x03, fields: [
|
||||
{ name: "age", type: "long" },
|
||||
{ name: "time", type: "long" },
|
||||
]},
|
||||
entity_equipment: {id: 0x04, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" /* TODO: Int or VarInt */ },
|
||||
{ name: "slot", type: "short" },
|
||||
{ name: "item", type: "slot" }
|
||||
]},
|
||||
spawn_position: {id: 0x05, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" }
|
||||
{ name: "location", type: "position" } /* TODO: Implement position */
|
||||
]},
|
||||
update_health: {id: 0x06, fields: [
|
||||
{ name: "health", type: "float" },
|
||||
{ name: "food", type: "short" },
|
||||
{ name: "food", type: "varint" },
|
||||
{ name: "foodSaturation", type: "float" }
|
||||
]},
|
||||
respawn: {id: 0x07, fields: [
|
||||
|
@ -120,16 +120,14 @@ var packets = {
|
|||
{ name: "z", type: "double" },
|
||||
{ name: "yaw", type: "float" },
|
||||
{ name: "pitch", type: "float" },
|
||||
{ name: "onGround", type: "bool" }
|
||||
{ name: "flags", type: "byte" /* <Dinnerbone> It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute. */}
|
||||
]},
|
||||
held_item_slot: {id: 0x09, fields: [
|
||||
{ name: "slot", type: "byte" }
|
||||
]},
|
||||
bed: {id: 0x0a, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "ubyte" },
|
||||
{ name: "z", type: "int" }
|
||||
{ name: "position", type: "location" }
|
||||
]},
|
||||
animation: {id: 0x0b, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
|
@ -137,15 +135,7 @@ var packets = {
|
|||
]},
|
||||
named_entity_spawn: {id: 0x0c, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
{ name: "playerUUID", type: "string" },
|
||||
{ name: "playerName", type: "string" },
|
||||
{ name: "dataCount", type: "count", typeArgs: { type: "varint", countFor: "data" }},
|
||||
{ name: "data", type: "array", typeArgs: { count: "dataCount",
|
||||
type: "container", typeArgs: { fields: [
|
||||
{ name: "name", type: "string" },
|
||||
{ name: "value", type: "string" },
|
||||
{ name: "signature", type: "string" }
|
||||
]}}},
|
||||
{ name: "playerUUID", type: "UUID"},
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
|
@ -155,8 +145,8 @@ var packets = {
|
|||
{ name: "metadata", type: "entityMetadata" }
|
||||
]},
|
||||
collect: {id: 0x0d, fields: [
|
||||
{ name: "collectedEntityId", type: "int" },
|
||||
{ name: "collectorEntityId", type: "int" }
|
||||
{ name: "collectedEntityId", type: "int" /* TODO: Int or VarInt */},
|
||||
{ name: "collectorEntityId", type: "int" /* TODO: Int or VarInt */}
|
||||
]},
|
||||
spawn_entity: {id: 0x0e, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
|
@ -177,7 +167,7 @@ var packets = {
|
|||
{ name: "velocityZ", type: "short", condition: function(field_values) {
|
||||
return field_values['this']['intField'] != 0;
|
||||
}}
|
||||
]}}
|
||||
]}}
|
||||
]},
|
||||
spawn_entity_living: {id: 0x0f, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
|
@ -185,9 +175,9 @@ var packets = {
|
|||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "yaw", type: "byte" },
|
||||
{ name: "pitch", type: "byte" },
|
||||
{ name: "headPitch", type: "byte" },
|
||||
{ name: "yaw", type: "byte" },
|
||||
{ name: "velocityX", type: "short" },
|
||||
{ name: "velocityY", type: "short" },
|
||||
{ name: "velocityZ", type: "short" },
|
||||
|
@ -196,10 +186,8 @@ var packets = {
|
|||
spawn_entity_painting: {id: 0x10, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
{ name: "title", type: "string" },
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "direction", type: "int" }
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "direction", type: "ubyte" }
|
||||
]},
|
||||
spawn_entity_experience_orb: {id: 0x11, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
|
@ -215,41 +203,45 @@ var packets = {
|
|||
{ name: "velocityZ", type: "short" }
|
||||
]},
|
||||
entity_destroy: {id: 0x13, fields: [
|
||||
{ name: "count", type: "count", typeArgs: { type: "byte", countFor: "entityIds" } },
|
||||
{ name: "count", type: "count", typeArgs: { type: "byte", countFor: "entityIds" } }, /* TODO: Might not be correct */
|
||||
{ name: "entityIds", type: "array", typeArgs: { type: "int", count: "count" } }
|
||||
]},
|
||||
entity: {id: 0x14, fields: [
|
||||
{ name: "entityId", type: "int" }
|
||||
{ name: "entityId", type: "int" }
|
||||
]},
|
||||
rel_entity_move: {id: 0x15, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "dX", type: "byte" },
|
||||
{ name: "dY", type: "byte" },
|
||||
{ name: "dZ", type: "byte" }
|
||||
{ name: "dZ", type: "byte" },
|
||||
{ name: "onGround", type: "bool"}
|
||||
]},
|
||||
entity_look: {id: 0x16, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "yaw", type: "byte" },
|
||||
{ name: "pitch", type: "byte" }
|
||||
{ name: "pitch", type: "byte" },
|
||||
{ name: "onGround", type: "bool"}
|
||||
]},
|
||||
entity_move_look: {id: 0x17, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "dX", type: "byte" },
|
||||
{ name: "dY", type: "byte" },
|
||||
{ name: "dZ", type: "byte" },
|
||||
{ name: "yaw", type: "byte" },
|
||||
{ name: "pitch", type: "byte" }
|
||||
{ name: "pitch", type: "byte" },
|
||||
{ name: "onGround", type: "bool"}
|
||||
]},
|
||||
entity_teleport: {id: 0x18, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "yaw", type: "byte" },
|
||||
{ name: "pitch", type: "byte" }
|
||||
{ name: "pitch", type: "byte" },
|
||||
{ name: "onGround", type: "bool"}
|
||||
]},
|
||||
entity_head_rotation: {id: 0x19, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "headYaw", type: "byte" },
|
||||
]},
|
||||
entity_status: {id: 0x1a, fields: [
|
||||
|
@ -262,33 +254,34 @@ var packets = {
|
|||
{ name: "leash", type: "bool" }
|
||||
]},
|
||||
entity_metadata: {id: 0x1c, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "metadata", type: "entityMetadata" }
|
||||
]},
|
||||
entity_effect: {id: 0x1d, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "effectId", type: "byte" },
|
||||
{ name: "amplifier", type: "byte" },
|
||||
{ name: "duration", type: "short" }
|
||||
{ name: "duration", type: "varint" },
|
||||
{ name: "hideParticles", type: "bool" }
|
||||
]},
|
||||
remove_entity_effect: {id: 0x1e, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "effectId", type: "byte" }
|
||||
]},
|
||||
experience: {id: 0x1f, fields: [
|
||||
{ name: "experienceBar", type: "float" },
|
||||
{ name: "level", type: "short" },
|
||||
{ name: "totalExperience", type: "short" }
|
||||
{ name: "level", type: "varint" },
|
||||
{ name: "totalExperience", type: "varint" }
|
||||
]},
|
||||
update_attributes: {id: 0x20, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: Int or VarInt */
|
||||
{ name: "count", type: "count", typeArgs: { type: "int", countFor: "properties" } },
|
||||
{ name: "properties", type: "array", typeArgs: { count: "count",
|
||||
{ name: "properties", type: "array", typeArgs: { count: "count",
|
||||
type: "container", typeArgs: { fields: [
|
||||
{ name: "key", type: "string" },
|
||||
{ name: "value", type: "double" },
|
||||
{ name: "listLength", type: "count", typeArgs: { type: "short", countFor: "this.modifiers" } },
|
||||
{ name: "modifiers", type: "array", typeArgs: { count: "this.listLength",
|
||||
{ name: "modifiers", type: "array", typeArgs: { count: "this.listLength",
|
||||
type: "container", typeArgs: { fields: [
|
||||
{ name: "UUID", type: "UUID" },
|
||||
{ name: "amount", type: "double" },
|
||||
|
@ -302,45 +295,38 @@ var packets = {
|
|||
{ name: "z", type: "int" },
|
||||
{ name: "groundUp", type: "bool" },
|
||||
{ name: "bitMap", type: "ushort" },
|
||||
{ name: "addBitMap", type: "ushort" },
|
||||
{ name: "compressedChunkDataLength", type: "count", typeArgs: { type: "int", countFor: "compressedChunkData" } },
|
||||
{ name: "compressedChunkData", type: "buffer", typeArgs: { count: "compressedChunkDataLength" } },
|
||||
{ name: "chunkDataLength", type: "count", typeArgs: { type: "int", countFor: "compressedChunkData" } }, /* TODO: Int or VarInt */
|
||||
{ name: "chunkData", type: "buffer", typeArgs: { count: "compressedChunkDataLength" } },
|
||||
]},
|
||||
multi_block_change: {id: 0x22, fields: [
|
||||
{ name: "chunkX", type: "int" },
|
||||
{ name: "chunkZ", type: "int" },
|
||||
{ name: "recordCount", type: "short" },
|
||||
{ name: "recordCount", type: "varint" },
|
||||
/* TODO: Is dataLength needed? */
|
||||
{ name: "dataLength", type: "count", typeArgs: { type: "int", countFor: "data" } },
|
||||
{ name: "data", type: "buffer", typeArgs: { count: "dataLength" } },
|
||||
]},
|
||||
block_change: {id: 0x23, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "ubyte" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "type", type: "varint" },
|
||||
{ name: "metadata", type: "ubyte" }
|
||||
]},
|
||||
block_action: {id: 0x24, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "short" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "byte1", type: "ubyte" },
|
||||
{ name: "byte2", type: "ubyte" },
|
||||
{ name: "blockId", type: "varint" }
|
||||
]},
|
||||
block_break_animation: {id: 0x25, fields: [
|
||||
{ name: "entityId", type: "varint" },
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "destroyStage", type: "byte" }
|
||||
]},
|
||||
map_chunk_bulk: {id: 0x26, fields: [
|
||||
{ name: "chunkColumnCount", type: "count", typeArgs: { type: "short", countFor: "meta" } },
|
||||
{ name: "dataLength", type: "count", typeArgs: { type: "int", countFor: "compressedChunkData" } },
|
||||
map_chunk_bulk: {id: 0x26, fields: [ /* TODO: This is probably wrong */
|
||||
{ name: "skyLightSent", type: "bool" },
|
||||
{ name: "compressedChunkData", type: "buffer", typeArgs: { count: "dataLength" } },
|
||||
{ name: "meta", type: "array", typeArgs: { count: "chunkColumnCount",
|
||||
{ name: "chunkColumnCount", type: "count", typeArgs: { type: "varint", countFor: "meta" } },
|
||||
{ name: "dataLength", type: "count", typeArgs: { type: "int", countFor: "chunkData" } },
|
||||
{ name: "chunkData", type: "buffer", typeArgs: { count: "dataLength" } },
|
||||
{ name: "meta", type: "array", typeArgs: { count: "chunkColumnCount",
|
||||
type: "container", typeArgs: { fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "z", type: "int" },
|
||||
|
@ -367,9 +353,7 @@ var packets = {
|
|||
]},
|
||||
world_event: {id: 0x28, fields: [ // TODO : kinda wtf naming there
|
||||
{ name: "effectId", type: "int" },
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "byte" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "data", type: "int" },
|
||||
{ name: "global", type: "bool" }
|
||||
]},
|
||||
|
@ -382,15 +366,17 @@ var packets = {
|
|||
{ name: "pitch", type: "ubyte" }
|
||||
]},
|
||||
world_particles: {id: 0x2a, fields: [
|
||||
{ name: "particleName", type: "string" },
|
||||
{ name: "particleId", type: "int" },
|
||||
{ name: "longDistance", type: "bool"},
|
||||
{ name: "x", type: "float" },
|
||||
{ name: "y", type: "float" },
|
||||
{ name: "z", type: "float" },
|
||||
{ name: "offsetX", type: "float" },
|
||||
{ name: "offsetY", type: "float" },
|
||||
{ name: "offsetZ", type: "float" },
|
||||
{ name: "particleSpeed", type: "float" },
|
||||
{ name: "particleData", type: "float" },
|
||||
{ name: "particles", type: "int" }
|
||||
/* TODO: Create an Array of VarInts */
|
||||
]},
|
||||
game_state_change: {id: 0x2b, fields: [
|
||||
{ name: "reason", type: "ubyte" },
|
||||
|
@ -405,10 +391,9 @@ var packets = {
|
|||
]},
|
||||
open_window: {id: 0x2d, fields: [
|
||||
{ name: "windowId", type: "ubyte" },
|
||||
{ name: "inventoryType", type: "ubyte" },
|
||||
{ name: "inventoryType", type: "string" },
|
||||
{ name: "windowTitle", type: "string" },
|
||||
{ name: "slotCount", type: "ubyte" },
|
||||
{ name: "useProvidedTitle", type: "bool" },
|
||||
{ name: "entityId", type: "int", condition: function(field_values) {
|
||||
return field_values['inventoryType'] == 11;
|
||||
} }
|
||||
|
@ -417,7 +402,7 @@ var packets = {
|
|||
{ name: "windowId", type: "ubyte" }
|
||||
]},
|
||||
set_slot: {id: 0x2f, fields: [
|
||||
{ name: "windowId", type: "ubyte" },
|
||||
{ name: "windowId", type: "byte" },
|
||||
{ name: "slot", type: "short" },
|
||||
{ name: "item", type: "slot" }
|
||||
]},
|
||||
|
@ -426,53 +411,47 @@ var packets = {
|
|||
{ name: "count", type: "count", typeArgs: { type: "short", countFor: "items" } },
|
||||
{ name: "items", type: "array", typeArgs: { type: "slot", count: "count" } }
|
||||
]},
|
||||
craft_progress_bar: {id: 0x31, fields: [
|
||||
craft_progress_bar: {id: 0x31, fields: [ /* TODO: Bad name for this packet imo */
|
||||
{ name: "windowId", type: "ubyte" },
|
||||
{ name: "property", type: "short" },
|
||||
{ name: "value", type: "short" }
|
||||
]},
|
||||
transaction:{id: 0x32, fields: [
|
||||
{ name: "windowId", type: "ubyte" },
|
||||
{ name: "windowId", type: "byte" },
|
||||
{ name: "action", type: "short" },
|
||||
{ name: "accepted", type: "bool" }
|
||||
]},
|
||||
update_sign: {id: 0x33, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "short" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "text1", type: "string" },
|
||||
{ name: "text2", type: "string" },
|
||||
{ name: "text3", type: "string" },
|
||||
{ name: "text4", type: "string" }
|
||||
]},
|
||||
map: {id: 0x34, fields: [
|
||||
map: {id: 0x34, fields: [ /* TODO: No clue how to do this */
|
||||
{ name: "itemDamage", type: "varint" },
|
||||
{ name: "dataLength", type: "count", typeArgs: { type: "short", countFor: "data" } },
|
||||
{ name: "data", type: "buffer", typeArgs: { count: "dataLength" } },
|
||||
]},
|
||||
tile_entity_data:{id: 0x35, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "short" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "action", type: "ubyte" },
|
||||
{ name: "nbtDataLength", type: "count", typeArgs: { type: "short", countFor: "nbtData" } },
|
||||
{ name: "nbtData", type: "buffer", typeArgs: { count: "nbtDataLength" } },
|
||||
]},
|
||||
open_sign_entity: {id: 0x36, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "int" },
|
||||
{ name: "z", type: "int" }
|
||||
{ name: "location", type: "position" },
|
||||
]},
|
||||
statistics: {id: 0x37, fields: [
|
||||
{ name: "count", type: "count", typeArgs: { type: "varint", countFor: "entries" } },
|
||||
{ name: "entries", type: "array", typeArgs: { count: "count",
|
||||
{ name: "entries", type: "array", typeArgs: { count: "count",
|
||||
type: "container", typeArgs: { fields: [
|
||||
{ name: "name", type: "string" },
|
||||
{ name: "value", type: "varint" }
|
||||
]}
|
||||
}}
|
||||
]},
|
||||
player_info: {id: 0x38, fields: [
|
||||
player_info: {id: 0x38, fields: [ /* TODO: Again, no clue */
|
||||
{ name: "playerName", type: "string" },
|
||||
{ name: "online", type: "bool" },
|
||||
{ name: "ping", type: "short" }
|
||||
|
@ -488,17 +467,16 @@ var packets = {
|
|||
]},
|
||||
scoreboard_objective: {id: 0x3b, fields: [
|
||||
{ name: "name", type: "string" },
|
||||
{ name: "action", type: "byte" },
|
||||
{ name: "displayText", type: "string" },
|
||||
{ name: "action", type: "byte" }
|
||||
{ name: "type", type: "string"}
|
||||
]},
|
||||
scoreboard_score: {id: 0x3c, fields: [
|
||||
scoreboard_score: {id: 0x3c, fields: [ /* TODO: itemName and scoreName may need to be switched */
|
||||
{ name: "itemName", type: "string" },
|
||||
{ name: "remove", type: "bool" },
|
||||
{ name: "scoreName", type: "string", condition: function(field_values) {
|
||||
return !field_values['remove']
|
||||
} },
|
||||
{ name: "action", type: "byte" },
|
||||
{ name: "scoreName", type: "string" },
|
||||
{ name: "value", type: "int", condition: function(field_values) {
|
||||
return !field_values['remove']
|
||||
return field_values['action'] != 1;
|
||||
} }
|
||||
]},
|
||||
scoreboard_display_objective: {id: 0x3d, fields: [
|
||||
|
@ -534,18 +512,66 @@ var packets = {
|
|||
]},
|
||||
kick_disconnect: {id: 0x40, fields: [
|
||||
{ name: "reason", type: "string" }
|
||||
]},
|
||||
difficulty: { id: 0x41, fields [
|
||||
{ name: "difficulty", type: "ubyte" }
|
||||
]},
|
||||
combat_event: { id: 0x42, fields: [
|
||||
{ name: "event", type: "varint"},
|
||||
{ name: "duration", type: "varint", condition: function(field_values) {
|
||||
return field_values['event'] == 1;
|
||||
} },
|
||||
{ name: "entityId", type: "int", condition: function(field_values) {
|
||||
return field_values['event'] == 1;
|
||||
} },
|
||||
{ name: "playerId", type: "varint", condition: function(field_values) {
|
||||
return field_values['event'] == 2;
|
||||
} },
|
||||
{ name: "entityId", type: "int", condition: function(field_values) {
|
||||
return field_values['event'] == 2;
|
||||
} },
|
||||
{ name: "message", type: "string", condition: function(field_values) {
|
||||
return field_values['event'] == 2;
|
||||
} }
|
||||
]},
|
||||
camera: { id: 0x43, fields: [
|
||||
{ name: "cameraId", type: "varint" }
|
||||
]},
|
||||
world_border: { id: 0x44, fields: [
|
||||
/* TODO: Going to be a pain... */
|
||||
]},
|
||||
title: { id: 0x45, fields: [
|
||||
/* TODO: Going to be a pain too */
|
||||
]},
|
||||
set_compression: { id: 0x46, fields: [
|
||||
{ name: "threshold", type: "varint"}
|
||||
]},
|
||||
playerlist_header: { id: 0x47, fields: [
|
||||
{ name: "header", type: "string" },
|
||||
{ name: "footer", type; "string" }
|
||||
]},
|
||||
resource_pack_send: { id: 0x48, fields: [
|
||||
{ name: "url", type: "string" },
|
||||
{ name: "hash", type: "string" }
|
||||
]},
|
||||
update_entity_nbt: { id: 0x49, fields: [
|
||||
{ name: "entityId": type: "varint" },
|
||||
{ name: "tag", type: "string"} /* TODO: Should be of type "NBT Tag" */
|
||||
]}
|
||||
},
|
||||
toServer: {
|
||||
keep_alive: {id: 0x00, fields: [
|
||||
{ name: "keepAliveId", type: "int" }
|
||||
{ name: "keepAliveId", type: "int" /* TODO: Int or VarInt */ }
|
||||
]},
|
||||
chat: {id: 0x01, fields: [
|
||||
{ name: "message", type: "string" }
|
||||
]},
|
||||
use_entity: {id: 0x02, fields: [
|
||||
{ name: "target", type: "int" },
|
||||
{ name: "mouse", type: "byte" }
|
||||
{ name: "target", type: "int" /* TODO: Int or VarInt */},
|
||||
{ name: "mouse", type: "byte" },
|
||||
{ name: "x", type: "float"},
|
||||
{ name: "y", type: "float"},
|
||||
{ name: "size", type: "float"}
|
||||
]},
|
||||
flying: {id: 0x03, fields: [
|
||||
{ name: "onGround", type: "bool" }
|
||||
|
@ -564,7 +590,6 @@ var packets = {
|
|||
]},
|
||||
position_look: {id: 0x06, fields: [
|
||||
{ name: "x", type: "double" },
|
||||
{ name: "stance", type: "double" },
|
||||
{ name: "y", type: "double" },
|
||||
{ name: "z", type: "double" },
|
||||
{ name: "yaw", type: "float" },
|
||||
|
@ -573,15 +598,11 @@ var packets = {
|
|||
]},
|
||||
block_dig: {id: 0x07, fields: [
|
||||
{ name: "status", type: "byte" },
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "ubyte" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position"}
|
||||
{ name: "face", type: "byte" }
|
||||
]},
|
||||
block_place: {id: 0x08, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "ubyte" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "direction", type: "byte" },
|
||||
{ name: "heldItem", type: "slot" },
|
||||
{ name: "cursorX", type: "byte" },
|
||||
|
@ -592,19 +613,18 @@ var packets = {
|
|||
{ name: "slotId", type: "short" }
|
||||
]},
|
||||
arm_animation: {id: 0x0a, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "entityId", type: "int" }, /* TODO: wiki.vg says this is empty? */
|
||||
{ name: "animation", type: "byte" }
|
||||
]},
|
||||
entity_action: {id: 0x0b, fields: [
|
||||
{ name: "entityId", type: "int" },
|
||||
{ name: "actionId", type: "byte" },
|
||||
{ name: "jumpBoost", type: "int" }
|
||||
{ name: "entityId", type: "varint" /* TODO: Int or VarInt */},
|
||||
{ name: "actionId", type: "varint" },
|
||||
{ name: "jumpBoost", type: "varint" /* TODO: Int or VarInt */}
|
||||
]},
|
||||
steer_vehicle: {id: 0x0c, fields: [
|
||||
{ name: "sideways", type: "float" },
|
||||
{ name: "forward", type: "float" },
|
||||
{ name: "jump", type: "bool" },
|
||||
{ name: "unmount", type: "bool" }
|
||||
{ name: "jump", type: "ubyte" }
|
||||
]},
|
||||
close_window: {id: 0x0d, fields: [
|
||||
{ name: "windowId", type: "byte" }
|
||||
|
@ -631,9 +651,7 @@ var packets = {
|
|||
{ name: "enchantment", type: "byte" }
|
||||
]},
|
||||
update_sign: {id: 0x12, fields: [
|
||||
{ name: "x", type: "int" },
|
||||
{ name: "y", type: "short" },
|
||||
{ name: "z", type: "int" },
|
||||
{ name: "location", type: "position" },
|
||||
{ name: "text1", type: "string" },
|
||||
{ name: "text2", type: "string" },
|
||||
{ name: "text3", type: "string" },
|
||||
|
@ -645,23 +663,32 @@ var packets = {
|
|||
{ name: "walkingSpeed", type: "float" }
|
||||
]},
|
||||
tab_complete: {id: 0x14, fields: [
|
||||
{ name: "text", type: "string" }
|
||||
{ name: "text", type: "string" },
|
||||
{ name: "hasPosition", type: "boolean" },
|
||||
{ name: "block", type: "position", condition: function(field_values) {
|
||||
return field_values['hasPosition'];
|
||||
} }
|
||||
]},
|
||||
settings: {id: 0x15, fields: [
|
||||
{ name: "locale", type: "string" },
|
||||
{ name: "viewDistance", type: "byte" },
|
||||
{ name: "chatFlags", type: "byte" },
|
||||
{ name: "chatColors", type: "bool" },
|
||||
{ name: "difficulty", type: "byte" },
|
||||
{ name: "showCape", type: "bool" }
|
||||
{ name: "skinParts", type: "ubyte" }
|
||||
]},
|
||||
client_command: {id: 0x16, fields: [
|
||||
{ name: "payload", type: "byte" }
|
||||
{ name: "payload", type: "varint" }
|
||||
]},
|
||||
custom_payload: {id: 0x17, fields: [
|
||||
{ name: "channel", type: "string" },
|
||||
{ name: "dataLength", type: "count", typeArgs: { type: "short", countFor: "data" } },
|
||||
{ name: "data", type: "buffer", typeArgs: { count: "dataLength" } },
|
||||
{ name: "channel", type: "string" }, /* TODO: wiki.vg sats no dataLength is needed? */
|
||||
{ name: "data", type: "buffer"}
|
||||
]},
|
||||
spectate: { id: 0x18, fields: [
|
||||
{ name: "target", type: "UUID"}
|
||||
]},
|
||||
resource_pack_receive: { id: 0x19, fields: [
|
||||
{ name: "hash", type: "string" },
|
||||
{ name: "result", type: "varint" }
|
||||
]}
|
||||
}
|
||||
}
|
||||
|
@ -834,10 +861,10 @@ function readString (buffer, offset) {
|
|||
var stringLength = length.value;
|
||||
var strEnd = cursor + stringLength;
|
||||
if (strEnd > buffer.length) return null;
|
||||
|
||||
|
||||
var value = buffer.toString('utf8', cursor, strEnd);
|
||||
cursor = strEnd;
|
||||
|
||||
|
||||
return {
|
||||
value: value,
|
||||
size: cursor - offset,
|
||||
|
@ -1055,7 +1082,7 @@ function readVarInt(buffer, offset) {
|
|||
var result = 0;
|
||||
var shift = 0;
|
||||
var cursor = offset;
|
||||
|
||||
|
||||
while (true) {
|
||||
if (cursor + 1 > buffer.length) return null;
|
||||
var b = buffer.readUInt8(cursor);
|
||||
|
@ -1130,7 +1157,7 @@ function sizeOfContainer(value, typeArgs, rootNode) {
|
|||
return size;
|
||||
}
|
||||
|
||||
function readBuffer(buffer, offset, typeArgs, rootNode) {
|
||||
function readBuffer(buffer, offset, typeArgs, rootNode) {
|
||||
var count = getField(typeArgs.count, rootNode);
|
||||
return {
|
||||
value: buffer.slice(offset, offset + count),
|
||||
|
@ -1292,11 +1319,11 @@ function parsePacket(buffer, state, isServer, packetsToParse) {
|
|||
cursor += lengthField.size;
|
||||
if (length + lengthField.size > buffer.length) return null;
|
||||
var buffer = buffer.slice(0, length + cursor); // fail early if too much is read.
|
||||
|
||||
|
||||
var packetIdField = readVarInt(buffer, cursor);
|
||||
var packetId = packetIdField.value;
|
||||
cursor += packetIdField.size;
|
||||
|
||||
|
||||
var results = { id: packetId };
|
||||
// Only parse the packet if there is a need for it, AKA if there is a listener attached to it
|
||||
var name = packetNames[state][isServer ? "toServer" : "toClient"][packetId];
|
||||
|
@ -1309,7 +1336,7 @@ function parsePacket(buffer, state, isServer, packetsToParse) {
|
|||
results: results
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var packetInfo = get(packetId, state, isServer);
|
||||
if (packetInfo === null) {
|
||||
return {
|
||||
|
@ -1321,7 +1348,7 @@ function parsePacket(buffer, state, isServer, packetsToParse) {
|
|||
} else {
|
||||
debug("read packetId " + packetId + " (0x" + packetId.toString(16) + ")");
|
||||
}
|
||||
|
||||
|
||||
var i, fieldInfo, readResults;
|
||||
for (i = 0; i < packetInfo.length; ++i) {
|
||||
fieldInfo = packetInfo[i];
|
||||
|
|
Loading…
Reference in a new issue