2014-06-07 01:47:34 +02:00
|
|
|
from io import BytesIO
|
2015-03-17 18:15:27 +01:00
|
|
|
from zlib import compress
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-04-02 23:25:34 +02:00
|
|
|
from .types import (
|
|
|
|
VarInt, Integer, Float, Double, UnsignedShort, Long, Byte, UnsignedByte,
|
2015-09-05 09:33:12 +02:00
|
|
|
String, VarIntPrefixedByteArray, Boolean, UUID
|
2015-04-02 23:25:34 +02:00
|
|
|
)
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
class PacketBuffer(object):
|
2014-11-10 16:25:30 +01:00
|
|
|
def __init__(self):
|
2015-04-02 23:25:34 +02:00
|
|
|
self.bytes = BytesIO()
|
2014-06-07 01:47:34 +02:00
|
|
|
|
|
|
|
def send(self, value):
|
2015-03-17 18:15:27 +01:00
|
|
|
"""
|
|
|
|
Writes the given bytes to the buffer, designed to emulate socket.send
|
|
|
|
:param value: The bytes to write
|
|
|
|
"""
|
2015-04-02 23:25:34 +02:00
|
|
|
self.bytes.write(value)
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
def read(self, length):
|
2015-04-02 23:25:34 +02:00
|
|
|
return self.bytes.read(length)
|
2015-03-17 18:15:27 +01:00
|
|
|
|
2015-04-03 05:51:53 +02:00
|
|
|
def recv(self, length):
|
|
|
|
return self.read(length)
|
|
|
|
|
2015-03-22 13:39:15 +01:00
|
|
|
def reset(self):
|
2015-04-02 23:25:34 +02:00
|
|
|
self.bytes = BytesIO()
|
2015-03-22 13:39:15 +01:00
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
def reset_cursor(self):
|
2015-04-02 23:25:34 +02:00
|
|
|
self.bytes.seek(0)
|
2015-03-17 18:15:27 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
def get_writable(self):
|
2015-04-02 23:25:34 +02:00
|
|
|
return self.bytes.getvalue()
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2015-03-22 15:05:55 +01:00
|
|
|
class PacketListener(object):
|
|
|
|
def __init__(self, callback, *args):
|
|
|
|
self.callback = callback
|
2015-09-04 19:59:21 +02:00
|
|
|
self.packets_to_listen = []
|
2015-03-22 15:05:55 +01:00
|
|
|
for arg in args:
|
|
|
|
if issubclass(arg, Packet):
|
|
|
|
self.packets_to_listen.append(arg)
|
|
|
|
|
|
|
|
def call_packet(self, packet):
|
|
|
|
for packet_type in self.packets_to_listen:
|
|
|
|
if isinstance(packet, packet_type):
|
|
|
|
self.callback(packet)
|
|
|
|
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
class Packet(object):
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "base"
|
|
|
|
id = -0x01
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = []
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2015-04-12 04:26:12 +02:00
|
|
|
def __init__(self, **kwargs):
|
2014-10-08 19:12:37 +02:00
|
|
|
pass
|
|
|
|
|
2015-04-12 04:26:12 +02:00
|
|
|
def set_values(self, **kwargs):
|
|
|
|
for key, value in kwargs.items():
|
|
|
|
setattr(self, key, value)
|
|
|
|
return self
|
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
def read(self, file_object):
|
|
|
|
for field in self.definition:
|
2015-04-03 05:51:53 +02:00
|
|
|
for var_name, data_type in field.items():
|
2015-03-17 18:15:27 +01:00
|
|
|
value = data_type.read(file_object)
|
|
|
|
setattr(self, var_name, value)
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-04-01 16:58:37 +02:00
|
|
|
def write(self, socket, compression_threshold=None):
|
2015-04-02 23:25:34 +02:00
|
|
|
# buffer the data since we need to know the length of each packet's
|
|
|
|
# payload
|
2014-06-07 01:47:34 +02:00
|
|
|
packet_buffer = PacketBuffer()
|
2015-03-17 18:15:27 +01:00
|
|
|
# write packet's id right off the bat in the header
|
2014-06-07 01:47:34 +02:00
|
|
|
VarInt.send(self.id, packet_buffer)
|
|
|
|
|
|
|
|
for field in self.definition:
|
2015-04-03 05:51:53 +02:00
|
|
|
for var_name, data_type in field.items():
|
2014-06-07 01:47:34 +02:00
|
|
|
data = getattr(self, var_name)
|
|
|
|
data_type.send(data, packet_buffer)
|
|
|
|
|
2015-04-01 16:58:37 +02:00
|
|
|
# compression_threshold of None means compression is disabled
|
|
|
|
if compression_threshold is not None:
|
2015-04-03 18:30:31 +02:00
|
|
|
if len(packet_buffer.get_writable()) > compression_threshold != -1:
|
2015-03-22 14:16:47 +01:00
|
|
|
# compress the current payload
|
|
|
|
compressed_data = compress(packet_buffer.get_writable())
|
|
|
|
packet_buffer.reset()
|
|
|
|
# write out the length of the compressed payload
|
|
|
|
VarInt.send(len(compressed_data), packet_buffer)
|
|
|
|
# write the compressed payload itself
|
|
|
|
packet_buffer.send(compressed_data)
|
|
|
|
else:
|
|
|
|
# write out a 0 to indicate uncompressed data
|
2015-04-03 18:30:31 +02:00
|
|
|
packet_data = packet_buffer.get_writable()
|
2015-03-22 14:16:47 +01:00
|
|
|
packet_buffer.reset()
|
|
|
|
VarInt.send(0, packet_buffer)
|
2015-04-03 18:30:31 +02:00
|
|
|
packet_buffer.send(packet_data)
|
2015-03-17 18:15:27 +01:00
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
VarInt.send(len(packet_buffer.get_writable()), socket) # Packet Size
|
|
|
|
socket.send(packet_buffer.get_writable()) # Packet Payload
|
2014-06-07 01:47:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Handshake State
|
2014-10-08 19:12:37 +02:00
|
|
|
# ==============
|
2014-06-07 01:47:34 +02:00
|
|
|
class HandShakePacket(Packet):
|
|
|
|
id = 0x00
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "handshake"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'protocol_version': VarInt},
|
|
|
|
{'server_address': String},
|
|
|
|
{'server_port': UnsignedShort},
|
|
|
|
{'next_state': VarInt}]
|
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_HANDSHAKE_CLIENTBOUND = {
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
}
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_HANDSHAKE_SERVERBOUND = {
|
2014-06-07 01:47:34 +02:00
|
|
|
0x00: HandShakePacket
|
|
|
|
}
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
# Status State
|
2015-03-17 18:15:27 +01:00
|
|
|
# ==============
|
2014-06-07 01:47:34 +02:00
|
|
|
class ResponsePacket(Packet):
|
|
|
|
id = 0x00
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "response"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'json_response': String}]
|
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-04-03 00:13:22 +02:00
|
|
|
class PingPacketResponse(Packet):
|
2014-06-07 01:47:34 +02:00
|
|
|
id = 0x01
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "ping"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'time': Long}]
|
|
|
|
|
2015-04-02 23:25:34 +02:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_STATUS_CLIENTBOUND = {
|
2014-06-07 01:47:34 +02:00
|
|
|
0x00: ResponsePacket,
|
2015-04-03 00:13:22 +02:00
|
|
|
0x01: PingPacketResponse
|
2014-06-07 01:47:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
class RequestPacket(Packet):
|
|
|
|
id = 0x00
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "request"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = []
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
class PingPacket(Packet):
|
|
|
|
id = 0x01
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "ping"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'time': Long}]
|
|
|
|
|
2015-04-02 23:25:34 +02:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_STATUS_SERVERBOUND = {
|
2014-06-07 01:47:34 +02:00
|
|
|
0x00: RequestPacket,
|
|
|
|
0x01: PingPacket
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
# Login State
|
2015-03-17 18:15:27 +01:00
|
|
|
# ==============
|
2014-06-07 01:47:34 +02:00
|
|
|
class DisconnectPacket(Packet):
|
|
|
|
id = 0x00
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "disconnect"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'json_data': String}]
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
|
|
|
class EncryptionRequestPacket(Packet):
|
2014-06-07 01:47:34 +02:00
|
|
|
id = 0x01
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "encryption request"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'server_id': String},
|
2015-03-17 18:15:27 +01:00
|
|
|
{'public_key': VarIntPrefixedByteArray},
|
|
|
|
{'verify_token': VarIntPrefixedByteArray}]
|
2014-06-07 01:47:34 +02:00
|
|
|
|
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
class LoginSuccessPacket(Packet):
|
2014-06-07 01:47:34 +02:00
|
|
|
id = 0x02
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "login success"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'UUID': String},
|
|
|
|
{'Username': String}]
|
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
class SetCompressionPacket(Packet):
|
|
|
|
id = 0x03
|
|
|
|
packet_name = "set compression"
|
|
|
|
definition = [
|
|
|
|
{'threshold': VarInt}]
|
|
|
|
|
2015-04-02 23:25:34 +02:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_LOGIN_CLIENTBOUND = {
|
2014-06-07 01:47:34 +02:00
|
|
|
0x00: DisconnectPacket,
|
|
|
|
0x01: EncryptionRequestPacket,
|
2015-03-17 18:15:27 +01:00
|
|
|
0x02: LoginSuccessPacket,
|
|
|
|
0x03: SetCompressionPacket
|
2014-06-07 01:47:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
class LoginStartPacket(Packet):
|
|
|
|
id = 0x00
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "login start"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2014-10-08 19:12:37 +02:00
|
|
|
{'name': String}]
|
2014-06-07 01:47:34 +02:00
|
|
|
|
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
class EncryptionResponsePacket(Packet):
|
2014-06-07 01:47:34 +02:00
|
|
|
id = 0x01
|
2015-03-17 18:15:27 +01:00
|
|
|
packet_name = "encryption response"
|
2014-06-07 01:47:34 +02:00
|
|
|
definition = [
|
2015-03-17 18:15:27 +01:00
|
|
|
{'shared_secret': VarIntPrefixedByteArray},
|
|
|
|
{'verify_token': VarIntPrefixedByteArray}]
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2015-04-02 23:25:34 +02:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_LOGIN_SERVERBOUND = {
|
2014-06-07 01:47:34 +02:00
|
|
|
0x00: LoginStartPacket,
|
|
|
|
0x01: EncryptionResponsePacket
|
2015-03-17 18:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Playing State
|
|
|
|
# ==============
|
|
|
|
|
|
|
|
class KeepAlivePacket(Packet):
|
|
|
|
id = 0x00
|
|
|
|
packet_name = "keep alive"
|
|
|
|
definition = [
|
|
|
|
{'keep_alive_id': VarInt}]
|
|
|
|
|
|
|
|
|
|
|
|
class JoinGamePacket(Packet):
|
|
|
|
id = 0x01
|
|
|
|
packet_name = "join game"
|
|
|
|
definition = [
|
|
|
|
{'entity_id': Integer},
|
|
|
|
{'game_mode': UnsignedByte},
|
|
|
|
{'dimension': Byte},
|
|
|
|
{'difficulty': UnsignedByte},
|
|
|
|
{'max_players': UnsignedByte},
|
|
|
|
{'level_type': String},
|
|
|
|
{'reduced_debug_info': Boolean}]
|
|
|
|
|
|
|
|
|
2015-03-22 15:05:55 +01:00
|
|
|
class ChatMessagePacket(Packet):
|
|
|
|
id = 0x02
|
|
|
|
packet_name = "chat message"
|
|
|
|
definition = [
|
|
|
|
{'json_data': String},
|
|
|
|
{'position': Byte}]
|
|
|
|
|
|
|
|
|
2015-03-22 14:16:47 +01:00
|
|
|
class PlayerPositionAndLookPacket(Packet):
|
|
|
|
id = 0x08
|
|
|
|
packet_name = "player position and look"
|
|
|
|
definition = [
|
|
|
|
{'x': Double},
|
|
|
|
{'y': Double},
|
|
|
|
{'z': Double},
|
|
|
|
{'yaw': Float},
|
|
|
|
{'pitch': Float},
|
|
|
|
{'flags': Byte}]
|
|
|
|
|
|
|
|
|
|
|
|
class DisconnectPacketPlayState(Packet):
|
|
|
|
id = 0x40
|
|
|
|
packet_name = "disconnect"
|
|
|
|
|
|
|
|
definition = [
|
|
|
|
{'json_data': String}]
|
|
|
|
|
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
class SetCompressionPacketPlayState(Packet):
|
|
|
|
id = 0x46
|
|
|
|
packet_name = "set compression"
|
|
|
|
definition = [
|
|
|
|
{'threshold': VarInt}]
|
|
|
|
|
2015-09-05 09:33:12 +02:00
|
|
|
class PlayerListItemPacket(Packet):
|
|
|
|
id = 0x38
|
|
|
|
packet_name = "player list item"
|
|
|
|
|
|
|
|
class PlayerList(object):
|
|
|
|
__slots__ = 'players_by_uuid'
|
|
|
|
def __init__(self):
|
|
|
|
self.players_by_uuid = dict()
|
|
|
|
|
|
|
|
class PlayerListItem(object):
|
|
|
|
__slots__ = (
|
|
|
|
'uuid', 'name', 'properties', 'gamemode', 'ping', 'display_name')
|
|
|
|
def __init__(self, **kwds):
|
|
|
|
for key, val in kwds.iteritems():
|
|
|
|
setattr(self, key, val)
|
|
|
|
|
|
|
|
class PlayerProperty(object):
|
|
|
|
__slots__ = 'name', 'value', 'signature'
|
|
|
|
def read(self, file_object):
|
|
|
|
self.name = String.read(file_object)
|
|
|
|
self.value = String.read(file_object)
|
|
|
|
is_signed = Boolean.read(file_object)
|
|
|
|
if is_signed:
|
|
|
|
self.signature = String.read(file_object)
|
|
|
|
else:
|
|
|
|
self.signature = None
|
|
|
|
|
|
|
|
class Action(object):
|
|
|
|
__slots__ = 'uuid'
|
|
|
|
def read(self, file_object):
|
|
|
|
self.uuid = UUID.read(file_object)
|
|
|
|
self._read(file_object)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def type_from_id(cls, action_id):
|
|
|
|
subcls = {
|
|
|
|
0: PlayerListItemPacket.AddPlayerAction,
|
|
|
|
1: PlayerListItemPacket.UpdateGameModeAction,
|
|
|
|
2: PlayerListItemPacket.UpdateLatencyAction,
|
|
|
|
3: PlayerListItemPacket.UpdateDisplayNameAction,
|
|
|
|
4: PlayerListItemPacket.RemovePlayerAction
|
|
|
|
}.get(action_id)
|
|
|
|
if subcls is None: raise ValueError(
|
|
|
|
"Unknown player list action ID: %s." % action_id)
|
|
|
|
return subcls
|
|
|
|
|
|
|
|
class AddPlayerAction(Action):
|
|
|
|
__slots__ = 'name', 'properties', 'gamemode', 'ping', 'display_name'
|
|
|
|
def _read(self, file_object):
|
|
|
|
self.name = String.read(file_object)
|
|
|
|
prop_count = VarInt.read(file_object)
|
|
|
|
self.properties = []
|
|
|
|
for i in range(prop_count):
|
|
|
|
property = PlayerListItemPacket.PlayerProperty()
|
|
|
|
property.read(file_object)
|
|
|
|
self.properties.append(property)
|
|
|
|
self.gamemode = VarInt.read(file_object)
|
|
|
|
self.ping = VarInt.read(file_object)
|
|
|
|
has_display_name = Boolean.read(file_object)
|
|
|
|
if has_display_name:
|
|
|
|
self.display_name = String.read(file_object)
|
|
|
|
else:
|
|
|
|
self.display_name = None
|
|
|
|
def apply(self, player_list):
|
|
|
|
player = PlayerListItemPacket.PlayerListItem(
|
|
|
|
uuid = self.uuid,
|
|
|
|
name = self.name,
|
|
|
|
properties = self.properties,
|
|
|
|
gamemode = self.gamemode,
|
|
|
|
ping = self.ping,
|
|
|
|
display_name = self.display_name)
|
|
|
|
player_list.players_by_uuid[self.uuid] = player
|
|
|
|
|
|
|
|
class UpdateGameModeAction(Action):
|
|
|
|
__slots__ = 'gamemode'
|
|
|
|
def _read(self, file_object):
|
|
|
|
self.gamemode = VarInt.read(file_object)
|
|
|
|
def apply(self, player_list):
|
|
|
|
player = player_list.players_by_uuid.get(self.uuid)
|
|
|
|
if player: player.gamemode = self.gamemode
|
|
|
|
|
|
|
|
class UpdateLatencyAction(Action):
|
|
|
|
__slots__ = 'ping'
|
|
|
|
def _read(self, file_object):
|
|
|
|
self.ping = VarInt.read(file_object)
|
|
|
|
def apply(self, player_list):
|
|
|
|
player = player_list.players_by_uuid.get(self.uuid)
|
|
|
|
if player: player.ping = self.ping
|
|
|
|
|
|
|
|
class UpdateDisplayNameAction(Action):
|
|
|
|
__slots__ = 'display_name'
|
|
|
|
def _read(self, file_object):
|
|
|
|
has_display_name = Boolean.read(file_object)
|
|
|
|
if has_display_name:
|
|
|
|
self.display_name = String.read(file_object)
|
|
|
|
else:
|
|
|
|
self.display_name = None
|
|
|
|
def apply(self, player_list):
|
|
|
|
player = player_list.players_by_uuid.get(self.uuid)
|
|
|
|
if player: player.display_name = self.display_name
|
|
|
|
|
|
|
|
class RemovePlayerAction(Action):
|
|
|
|
def _read(self, file_object):
|
|
|
|
pass
|
|
|
|
def apply(self, player_list):
|
|
|
|
if self.uuid in player_list.players_by_uuid:
|
|
|
|
del player_list.players_by_uuid[self.uuid]
|
|
|
|
|
|
|
|
def read(self, file_object):
|
|
|
|
action_id = VarInt.read(file_object)
|
|
|
|
self.action_type = PlayerListItemPacket.Action.type_from_id(action_id)
|
|
|
|
action_count = VarInt.read(file_object)
|
|
|
|
self.actions = []
|
|
|
|
for i in range(action_count):
|
|
|
|
action = self.action_type()
|
|
|
|
action.read(file_object)
|
|
|
|
self.actions.append(action)
|
|
|
|
|
|
|
|
def apply(self, player_list):
|
|
|
|
for action in self.actions:
|
|
|
|
action.apply(player_list)
|
|
|
|
|
|
|
|
def write(self, socket, compression_threshold=None):
|
|
|
|
raise NotImplementedError
|
2015-03-17 18:15:27 +01:00
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_PLAYING_CLIENTBOUND = {
|
2015-03-17 18:15:27 +01:00
|
|
|
0x00: KeepAlivePacket,
|
|
|
|
0x01: JoinGamePacket,
|
2015-03-22 15:05:55 +01:00
|
|
|
0x02: ChatMessagePacket,
|
2015-03-22 14:16:47 +01:00
|
|
|
0x08: PlayerPositionAndLookPacket,
|
2015-09-05 09:33:12 +02:00
|
|
|
0x38: PlayerListItemPacket,
|
2015-03-22 14:16:47 +01:00
|
|
|
0x40: DisconnectPacketPlayState,
|
2015-03-17 18:15:27 +01:00
|
|
|
0x46: SetCompressionPacketPlayState
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-22 15:05:55 +01:00
|
|
|
class ChatPacket(Packet):
|
|
|
|
id = 0x01
|
|
|
|
packet_name = "chat"
|
|
|
|
definition = [
|
|
|
|
{'message': String}]
|
|
|
|
|
|
|
|
|
2015-03-22 14:16:47 +01:00
|
|
|
class PositionAndLookPacket(Packet):
|
|
|
|
id = 0x06
|
|
|
|
packet_name = "position and look"
|
|
|
|
definition = [
|
|
|
|
{'x': Double},
|
|
|
|
{'feet_y': Double},
|
|
|
|
{'z': Double},
|
|
|
|
{'yaw': Float},
|
|
|
|
{'pitch': Float},
|
|
|
|
{'on_ground': Boolean}]
|
|
|
|
|
2015-04-02 22:44:03 +02:00
|
|
|
STATE_PLAYING_SERVERBOUND = {
|
2015-03-22 14:16:47 +01:00
|
|
|
0x00: KeepAlivePacket,
|
2015-03-22 15:05:55 +01:00
|
|
|
0x01: ChatPacket,
|
2015-03-22 14:16:47 +01:00
|
|
|
0x06: PositionAndLookPacket
|
2015-04-02 23:25:34 +02:00
|
|
|
}
|