def decode_extra(packet, bbuff): packet.data['entries'] = [ [ datautils.unpack(MC_STRING, bbuff), datautils.unpack(MC_VARINT, bbuff) ] for _ in range(datautils.unpack(MC_VARINT, bbuff))] return packet
def decode(self, bbuff, proto_comp_state): self.data = {} packet_length = datautils.unpack(MC_VARINT, bbuff) packet_data = bbuff.recv(packet_length) pbuff = BoundBuffer(packet_data) if proto_comp_state == mcdata.PROTO_COMP_ON: body_length = datautils.unpack(MC_VARINT, pbuff) if body_length > 0: body_data = zlib.decompress(pbuff.flush(), zlib.MAX_WBITS) pbuff.write(body_data) pbuff.save() try: # Ident self.__ident[2] = datautils.unpack(MC_VARINT, pbuff) self.ident = tuple(self.__ident) self.str_ident = mcdata.packet_ident2str[self.ident] # Payload for dtype, name in mcdata.hashed_structs[self.ident]: self.data[name] = datautils.unpack(dtype, pbuff) # Extension if self.ident in hashed_extensions: hashed_extensions[self.ident].decode_extra(self, pbuff) if len(pbuff) > 0: raise PacketDecodeFailure(self, pbuff) except BufferUnderflowException: raise PacketDecodeFailure(self, pbuff, True) return self
def decode(self, bbuff, proto_comp_state): self.data = {} packet_length = datautils.unpack(MC_VARINT, bbuff) packet_data = bbuff.recv(packet_length) pbuff = BoundBuffer(packet_data) if proto_comp_state == proto.PROTO_COMP_ON: body_length = datautils.unpack(MC_VARINT, pbuff) if body_length: body_data = zlib.decompress(pbuff.flush(), zlib.MAX_WBITS) pbuff.write(body_data) pbuff.save() try: # Ident self.__ident[2] = datautils.unpack(MC_VARINT, pbuff) self.ident = tuple(self.__ident) self.str_ident = proto.packet_ident2str[self.ident] # Payload for dtype, name in proto.hashed_structs[self.ident]: self.data[name] = datautils.unpack(dtype, pbuff) # Extension if self.ident in hashed_extensions: hashed_extensions[self.ident].decode_extra(self, pbuff) if pbuff: raise PacketDecodeFailure(self, pbuff) except BufferUnderflowException: raise PacketDecodeFailure(self, pbuff, True) return self
def decode_extra(packet, bbuff): packet.data['blocks'] = [ [datautils.unpack(MC_BYTE, bbuff) for j in range(3)] for i in range(datautils.unpack(MC_INT, bbuff))] packet.data['player_x'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['player_y'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['player_z'] = datautils.unpack(MC_FLOAT, bbuff) return packet
def decode_extra(packet, bbuff): packet.data['blocks'] = [[ datautils.unpack(MC_BYTE, bbuff) for j in range(3) ] for i in range(datautils.unpack(MC_INT, bbuff))] packet.data['player_x'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['player_y'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['player_z'] = datautils.unpack(MC_FLOAT, bbuff) return packet
def decode_extra(packet, bbuff): act = packet.data["action"] if act == mcdata.TL_TITLE or act == mcdata.TL_SUBTITLE: packet.data["text"] = datautils.unpack(MC_CHAT, bbuff) if act == mcdata.TL_TIMES: packet.data["fade_in"] = datautils.unpack(MC_INT, bbuff) packet.data["stay"] = datautils.unpack(MC_INT, bbuff) packet.data["fade_out"] = datautils.unpack(MC_INT, bbuff) return packet
def decode_extra(packet, bbuff): if packet.data["event"] == mcdata.CE_END_COMBAT: packet.data["duration"] = datautils.unpack(MC_VARINT, bbuff) packet.data["eid"] = datautils.unpack(MC_INT, bbuff) if packet.data["event"] == mcdata.CE_ENTITY_DEAD: packet.data["player_id"] = datautils.unpack(MC_VARINT, bbuff) packet.data["eid"] = datautils.unpack(MC_INT, bbuff) packet.data["message"] = datautils.unpack(MC_STRING, bbuff) return packet
def decode_extra(packet, bbuff): act = packet.data['action'] if act == const.TL_TITLE or act == const.TL_SUBTITLE: packet.data['text'] = datautils.unpack(MC_CHAT, bbuff) if act == const.TL_TIMES: packet.data['fade_in'] = datautils.unpack(MC_INT, bbuff) packet.data['stay'] = datautils.unpack(MC_INT, bbuff) packet.data['fade_out'] = datautils.unpack(MC_INT, bbuff) return packet
def decode_extra(packet, bbuff): if packet.data['event'] == const.CE_END_COMBAT: packet.data['duration'] = datautils.unpack(MC_VARINT, bbuff) packet.data['eid'] = datautils.unpack(MC_INT, bbuff) if packet.data['event'] == const.CE_ENTITY_DEAD: packet.data['player_id'] = datautils.unpack(MC_VARINT, bbuff) packet.data['eid'] = datautils.unpack(MC_INT, bbuff) packet.data['message'] = datautils.unpack(MC_STRING, bbuff) return packet
def decode_extra(packet, bbuff): packet.data['blocks'] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): data = datautils.unpack(MC_USHORT, bbuff) packet.data['blocks'].append({ 'y': data & 0xFF, 'z': (data >> 8) & 0xF, 'x': (data >> 12) & 0xF, 'block_data': datautils.unpack(MC_VARINT, bbuff), }) return packet
def decode_extra(packet, bbuff): sky_light = datautils.unpack(MC_BOOL, bbuff) count = datautils.unpack(MC_VARINT, bbuff) packet.data['sky_light'] = sky_light packet.data['metadata'] = [ { 'chunk_x': datautils.unpack(MC_INT, bbuff), 'chunk_z': datautils.unpack(MC_INT, bbuff), 'primary_bitmap': datautils.unpack(MC_USHORT, bbuff), } for _ in range(count)] packet.data['data'] = bbuff.flush() return packet
def decode_extra(packet, bbuff): packet.data["blocks"] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): data = datautils.unpack(MC_USHORT, bbuff) packet.data["blocks"].append( { "y": data & 0xFF, "z": (data >> 8) & 0xF, "x": (data >> 12) & 0xF, "block_data": datautils.unpack(MC_VARINT, bbuff), } ) return packet
def decode_extra(packet, bbuff): sky_light = datautils.unpack(MC_BOOL, bbuff) count = datautils.unpack(MC_VARINT, bbuff) packet.data["sky_light"] = sky_light packet.data["metadata"] = [ { "chunk_x": datautils.unpack(MC_INT, bbuff), "chunk_z": datautils.unpack(MC_INT, bbuff), "primary_bitmap": datautils.unpack(MC_USHORT, bbuff), } for _ in range(count) ] packet.data["data"] = bbuff.flush() return packet
def decode_extra(packet, bbuff): sky_light = datautils.unpack(MC_BOOL, bbuff) count = datautils.unpack(MC_VARINT, bbuff) packet.data['sky_light'] = sky_light packet.data['metadata'] = [{ 'chunk_x': datautils.unpack(MC_INT, bbuff), 'chunk_z': datautils.unpack(MC_INT, bbuff), 'primary_bitmap': datautils.unpack(MC_USHORT, bbuff), } for _ in range(count)] packet.data['data'] = bbuff.flush() return packet
def decode_extra(packet, bbuff): tag_type = datautils.unpack(MC_BYTE, bbuff) if tag_type == nbt.TAG_COMPOUND: name = nbt.TagString(buffer=bbuff).value nbt_data = nbt.TagCompound(buffer=bbuff) nbt_data.name = name packet.data['nbt'] = nbt_data else: assert (tag_type == nbt.TAG_END) packet.data['nbt'] = None return packet
def decode_extra(packet, bbuff): act = packet.data["action"] if act in [mcdata.TE_CREATE_TEAM, mcdata.TE_UPDATE_TEAM]: packet.data["display_name"] = datautils.unpack(MC_STRING, bbuff) packet.data["team_prefix"] = datautils.unpack(MC_STRING, bbuff) packet.data["team_suffix"] = datautils.unpack(MC_STRING, bbuff) packet.data["friendly_fire"] = datautils.unpack(MC_BYTE, bbuff) packet.data["name_visibility"] = datautils.unpack(MC_STRING, bbuff) packet.data["color"] = datautils.unpack(MC_BYTE, bbuff) if act in [mcdata.TE_CREATE_TEAM, mcdata.TE_ADDPLY_TEAM, mcdata.TE_REMPLY_TEAM]: packet.data["players"] = [ datautils.unpack(MC_STRING, bbuff) for _ in range(datautils.unpack(MC_VARINT, bbuff)) ] return packet
def decode_extra(packet, bbuff): packet.data['icons'] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): byte = datautils.unpack(MC_UBYTE, bbuff) packet.data['icons'].append({ 'direction': byte >> 8, 'type': byte & 0x0F, 'x': datautils.unpack(MC_BYTE, bbuff), 'y': datautils.unpack(MC_BYTE, bbuff), }) packet.data['columns'] = datautils.unpack(MC_BYTE, bbuff) if packet.data['columns']: packet.data['rows'] = datautils.unpack(MC_BYTE, bbuff) packet.data['x'] = datautils.unpack(MC_BYTE, bbuff) packet.data['y'] = datautils.unpack(MC_BYTE, bbuff) packet.data['data'] = bbuff.recv(datautils.unpack( MC_VARINT, bbuff)) return packet
def decode_extra(packet, bbuff): packet.data['icons'] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): byte = datautils.unpack(MC_UBYTE, bbuff) packet.data['icons'].append({ 'direction': byte >> 8, 'type': byte & 0x0F, 'x': datautils.unpack(MC_BYTE, bbuff), 'y': datautils.unpack(MC_BYTE, bbuff), }) packet.data['columns'] = datautils.unpack(MC_BYTE, bbuff) if packet.data['columns']: packet.data['rows'] = datautils.unpack(MC_BYTE, bbuff) packet.data['x'] = datautils.unpack(MC_BYTE, bbuff) packet.data['y'] = datautils.unpack(MC_BYTE, bbuff) packet.data['data'] = bbuff.recv( datautils.unpack(MC_VARINT, bbuff)) return packet
def decode_extra(packet, bbuff): act = packet.data['action'] if act == const.WB_SET_SIZE: packet.data['radius'] = datautils.unpack(MC_VARINT, bbuff) if act == const.WB_SET_CENTER or act == const.WB_INITIALIZE: packet.data['x'] = datautils.unpack(MC_DOUBLE, bbuff) packet.data['z'] = datautils.unpack(MC_DOUBLE, bbuff) if act == const.WB_LERP_SIZE or act == const.WB_INITIALIZE: packet.data['old_radius'] = datautils.unpack(MC_DOUBLE, bbuff) packet.data['new_radius'] = datautils.unpack(MC_DOUBLE, bbuff) packet.data['speed'] = datautils.unpack(MC_VARLONG, bbuff) if act == const.WB_INITIALIZE: packet.data['port_tele_bound'] = datautils.unpack(MC_VARINT, bbuff) if act == const.WB_SET_WARN_TIME or act == const.WB_INITIALIZE: packet.data['warn_time'] = datautils.unpack(MC_VARINT, bbuff) if act == const.WB_SET_WARN_BLOCKS or act == const.WB_INITIALIZE: packet.data['warn_blocks'] = datautils.unpack(MC_VARINT, bbuff) return packet
def decode_extra(packet, bbuff): act = packet.data["action"] if act == mcdata.WB_SET_SIZE: packet.data["radius"] = datautils.unpack(MC_VARINT, bbuff) if act == mcdata.WB_SET_CENTER or act == mcdata.WB_INITIALIZE: packet.data["x"] = datautils.unpack(MC_DOUBLE, bbuff) packet.data["z"] = datautils.unpack(MC_DOUBLE, bbuff) if act == mcdata.WB_LERP_SIZE or act == mcdata.WB_INITIALIZE: packet.data["old_radius"] = datautils.unpack(MC_DOUBLE, bbuff) packet.data["new_radius"] = datautils.unpack(MC_DOUBLE, bbuff) packet.data["speed"] = datautils.unpack(MC_VARLONG, bbuff) if act == mcdata.WB_INITIALIZE: packet.data["port_tele_bound"] = datautils.unpack(MC_VARINT, bbuff) if act == mcdata.WB_SET_WARN_TIME or act == mcdata.WB_INITIALIZE: packet.data["warn_time"] = datautils.unpack(MC_VARINT, bbuff) if act == mcdata.WB_SET_WARN_BLOCKS or act == mcdata.WB_INITIALIZE: packet.data["warn_blocks"] = datautils.unpack(MC_VARINT, bbuff) return packet
def decode_extra(packet, bbuff): act = packet.data['action'] if act in [const.TE_CREATE_TEAM, const.TE_UPDATE_TEAM]: packet.data['display_name'] = datautils.unpack(MC_STRING, bbuff) packet.data['team_prefix'] = datautils.unpack(MC_STRING, bbuff) packet.data['team_suffix'] = datautils.unpack(MC_STRING, bbuff) packet.data['friendly_fire'] = datautils.unpack(MC_BYTE, bbuff) packet.data['name_visibility'] = datautils.unpack(MC_STRING, bbuff) packet.data['color'] = datautils.unpack(MC_BYTE, bbuff) if act in [const.TE_CREATE_TEAM, const.TE_ADDPLY_TEAM, const.TE_REMPLY_TEAM]: packet.data['players'] = [ datautils.unpack(MC_STRING, bbuff) for _ in range(datautils.unpack(MC_VARINT, bbuff))] return packet
def decode_extra(packet, bbuff): packet.data["icons"] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): byte = datautils.unpack(MC_UBYTE, bbuff) packet.data["icons"].append( { "direction": byte >> 8, "type": byte & 0x0F, "x": datautils.unpack(MC_BYTE, bbuff), "y": datautils.unpack(MC_BYTE, bbuff), } ) packet.data["columns"] = datautils.unpack(MC_BYTE, bbuff) if packet.data["columns"]: packet.data["rows"] = datautils.unpack(MC_BYTE, bbuff) packet.data["x"] = datautils.unpack(MC_BYTE, bbuff) packet.data["y"] = datautils.unpack(MC_BYTE, bbuff) packet.data["data"] = bbuff.recv(datautils.unpack(MC_VARINT, bbuff)) return packet
def decode_extra(packet, bbuff): act = packet.data['action'] if act in [const.TE_CREATE_TEAM, const.TE_UPDATE_TEAM]: packet.data['display_name'] = datautils.unpack(MC_STRING, bbuff) packet.data['team_prefix'] = datautils.unpack(MC_STRING, bbuff) packet.data['team_suffix'] = datautils.unpack(MC_STRING, bbuff) packet.data['friendly_fire'] = datautils.unpack(MC_BYTE, bbuff) packet.data['name_visibility'] = datautils.unpack(MC_STRING, bbuff) packet.data['color'] = datautils.unpack(MC_BYTE, bbuff) if act in [ const.TE_CREATE_TEAM, const.TE_ADDPLY_TEAM, const.TE_REMPLY_TEAM ]: packet.data['players'] = [ datautils.unpack(MC_STRING, bbuff) for _ in range(datautils.unpack(MC_VARINT, bbuff)) ] return packet
def decode_extra(packet, bbuff): packet.data['properties'] = [] for i in range(datautils.unpack(MC_INT, bbuff)): prop = { 'key': datautils.unpack(MC_STRING, bbuff), 'value': datautils.unpack(MC_DOUBLE, bbuff), 'modifiers': [], } for j in range(datautils.unpack(MC_VARINT, bbuff)): prop['modifiers'].append({ 'uuid': datautils.unpack(MC_UUID, bbuff), 'amount': datautils.unpack(MC_DOUBLE, bbuff), 'operation': datautils.unpack(MC_BYTE, bbuff), }) packet.data['properties'].append(prop) return packet
def decode_extra(packet, bbuff): packet.data["properties"] = [] for i in range(datautils.unpack(MC_INT, bbuff)): prop = { "key": datautils.unpack(MC_STRING, bbuff), "value": datautils.unpack(MC_DOUBLE, bbuff), "modifiers": [], } for j in range(datautils.unpack(MC_VARINT, bbuff)): prop["modifiers"].append( { "uuid": datautils.unpack(MC_UUID, bbuff), "amount": datautils.unpack(MC_DOUBLE, bbuff), "operation": datautils.unpack(MC_BYTE, bbuff), } ) packet.data["properties"].append(prop) return packet
def decode_extra(packet, bbuff): act = packet.data['action'] if act in [const.SO_CREATE_BOARD, const.SO_UPDATE_BOARD]: packet.data['obj_val'] = datautils.unpack(MC_STRING, bbuff) packet.data['type'] = datautils.unpack(MC_STRING, bbuff) return packet
def decode_extra(packet, bbuff): packet.data['matches'] = [ datautils.unpack(MC_STRING, bbuff) for i in range(datautils.unpack(MC_VARINT, bbuff)) ] return packet
def decode_extra(packet, bbuff): act = packet.data['action'] packet.data['player_list'] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): item = {'uuid': datautils.unpack(MC_UUID, bbuff)} if act == const.PL_ADD_PLAYER: item['name'] = datautils.unpack(MC_STRING, bbuff) item['properties'] = [] for i in range(datautils.unpack(MC_VARINT, bbuff)): prop = { 'name': datautils.unpack(MC_STRING, bbuff), 'value': datautils.unpack(MC_STRING, bbuff), 'signed': datautils.unpack(MC_BOOL, bbuff), } if prop['signed']: prop['signature'] = datautils.unpack(MC_STRING, bbuff) item['properties'].append(prop) if act in [const.PL_ADD_PLAYER, const.PL_UPDATE_GAMEMODE]: item['gamemode'] = datautils.unpack(MC_VARINT, bbuff) if act in [const.PL_ADD_PLAYER, const.PL_UPDATE_LATENCY]: item['ping'] = datautils.unpack(MC_VARINT, bbuff) if act in [const.PL_ADD_PLAYER, const.PL_UPDATE_DISPLAY]: item['has_display'] = datautils.unpack(MC_BOOL, bbuff) if item['has_display']: item['display_name'] = datautils.unpack(MC_CHAT, bbuff) packet.data['player_list'].append(item)
def decode_extra(packet, bbuff): packet.data['entries'] = [[ datautils.unpack(MC_STRING, bbuff), datautils.unpack(MC_VARINT, bbuff) ] for _ in range(datautils.unpack(MC_VARINT, bbuff))] return packet
def decode_extra(packet, bbuff): packet.data['matches'] = [ datautils.unpack(MC_STRING, bbuff) for i in range(datautils.unpack(MC_VARINT, bbuff))] return packet
def decode_extra(packet, bbuff): packet.data['slots'] = [ datautils.unpack(MC_SLOT, bbuff) for i in range(datautils.unpack(MC_SHORT, bbuff))] return packet
def decode_extra(packet, bbuff): if packet.data['inv_type'] == 'EntityHorse': packet.data['eid'] = datautils.unpack(MC_INT, bbuff) return packet
def decode_extra(packet, bbuff): length = datautils.unpack(MC_VARINT, bbuff) packet.data['public_key'] = bbuff.recv(length) length = datautils.unpack(MC_VARINT, bbuff) packet.data['verify_token'] = bbuff.recv(length) return packet
def decode_extra(packet, bbuff): if packet.data['action'] == const.US_UPDATE_SCORE: packet.data['value'] = datautils.unpack(MC_VARINT, bbuff) return packet
def decode_extra(packet, bbuff): packet.data['data'] = [ datautils.unpack(MC_VARINT, bbuff) for i in range(proto.particles[packet.data['id']][1]) ] return packet
def decode_extra(packet, bbuff): if packet.data['action'] == const.INTERACT_ENTITY_AT: packet.data['target_x'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['target_y'] = datautils.unpack(MC_FLOAT, bbuff) packet.data['target_z'] = datautils.unpack(MC_FLOAT, bbuff) return packet
def decode_extra(packet, bbuff): if packet.data['has_position']: packet.data['block_loc'] = datautils.unpack(MC_POSITION, bbuff) return packet
def decode_extra(packet, bbuff): packet.data['data'] = bbuff.recv(datautils.unpack(MC_VARINT, bbuff)) return packet
def decode_extra(packet, bbuff): length = datautils.unpack(MC_VARINT, bbuff) packet.data['shared_secret'] = bbuff.recv(length) length = datautils.unpack(MC_VARINT, bbuff) packet.data['verify_token'] = bbuff.recv(length) return packet
def decode_extra(packet, bbuff): packet.data['slots'] = [ datautils.unpack(MC_SLOT, bbuff) for i in range(datautils.unpack(MC_SHORT, bbuff)) ] return packet
def decode_extra(packet, bbuff): count = datautils.unpack(MC_VARINT, bbuff) packet.data['eids'] = [ datautils.unpack(MC_VARINT, bbuff) for i in range(count) ] return packet
def decode_extra(packet, bbuff): if packet.data['obj_data']: packet.data['speed_x'] = datautils.unpack(MC_SHORT, bbuff) packet.data['speed_y'] = datautils.unpack(MC_SHORT, bbuff) packet.data['speed_z'] = datautils.unpack(MC_SHORT, bbuff) return packet