Add ClientSettingsPacket and PluginMessagePacket.

Improve Packet string representation.
This commit is contained in:
joo committed 2017-08-24 05:49:32 +01:00
1 parent 3269a022a8
commit e9f095de42
13 files changed
+291 -65

No files matched your search

@@ -1,11 +1,13 @@
from minecraft.networking.packets import (
Packet, KeepAlivePacket as AbstractKeepAlivePacket
Packet, AbstractKeepAlivePacket, AbstractPluginMessagePacket
)
from minecraft.networking.types import (
Double, Float, Boolean, VarInt, String
Double, Float, Boolean, VarInt, String, Enum
)
from .client_settings_packet import ClientSettingsPacket
# Formerly known as state_playing_serverbound.
def get_packets(context):
@@ -15,6 +17,8 @@ def get_packets(context):
PositionAndLookPacket,
AnimationPacket,
ClientStatusPacket,
ClientSettingsPacket,
PluginMessagePacket,
}
if context.protocol_version >= 107:
packets |= {
@@ -82,7 +86,7 @@ class TeleportConfirmPacket(Packet):
{'teleport_id': VarInt}]
class AnimationPacket(Packet):
class AnimationPacket(Packet, Enum):
@staticmethod
def get_id(context):
return 0x1D if context.protocol_version >= 332 else \
@@ -93,11 +97,14 @@ class AnimationPacket(Packet):
packet_name = "animation"
get_definition = staticmethod(lambda context: [
{'hand': VarInt} if context.protocol_version >= 107 else {}])
field_enum = classmethod(
lambda cls, field: cls if field == 'hand' else None)
HAND_MAIN = 0
HAND_OFF = 1
class ClientStatusPacket(Packet):
class ClientStatusPacket(Packet, Enum):
@staticmethod
def get_id(context):
return 0x03 if context.protocol_version >= 336 else \
@@ -110,8 +117,19 @@ class ClientStatusPacket(Packet):
packet_name = "client status"
get_definition = staticmethod(lambda context: [
{'action_id': VarInt}])
field_enum = classmethod(
lambda cls, field: cls if field == 'action_id' else None)
RESPAWN = 0
REQUEST_STATS = 1
# Note: Open Inventory (id 2) was removed in protocol version 319
OPEN_INVENTORY = 2
class PluginMessagePacket(AbstractPluginMessagePacket):
@staticmethod
def get_id(context):
return 0x09 if context.protocol_version >= 336 else \
0x0A if context.protocol_version >= 317 else \
0x09 if context.protocol_version >= 94 else \
0x17
@@ -0,0 +1,51 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import (
String, Byte, VarInt, Boolean, UnsignedByte, Enum, BitFieldEnum
)
class ClientSettingsPacket(Packet):
@staticmethod
def get_id(context):
return 0x04 if context.protocol_version >= 336 else \
0x05 if context.protocol_version >= 318 else \
0x04 if context.protocol_version >= 94 else \
0x15
packet_name = 'client settings'
get_definition = staticmethod(lambda context: [
{'locale': String},
{'view_distance': Byte},
{'chat_mode': VarInt if context.protocol_version > 47 else Byte},
{'chat_colors': Boolean},
{'displayed_skin_parts': UnsignedByte},
{'main_hand': VarInt}])
field_enum = classmethod(
lambda cls, field: {
'chat_mode': cls.ChatMode,
'displayed_skin_parts': cls.SkinParts,
'main_hand': cls.Hand,
}.get(field))
class ChatMode(Enum):
FULL = 0 # Receive all types of chat messages.
SYSTEM = 1 # Receive only command results and game information.
NONE = 2 # Receive only game information.
class SkinParts(BitFieldEnum):
CAPE = 0x01
JACKET = 0x02
LEFT_SLEEVE = 0x04
RIGHT_SLEEVE = 0x08
LEFT_PANTS_LEG = 0x10
RIGHT_PANTS_LEG = 0x20
HAT = 0x40
ALL = 0x7F
NONE = 0x00
class Hand(Enum):
LEFT = 0
RIGHT = 1