From fecb1d10e98cde20f2d1152793c978e121f130f2 Mon Sep 17 00:00:00 2001 From: TheSnoozer Date: Mon, 31 Jul 2017 14:34:03 +0200 Subject: [PATCH] add Client Status Packet and allow client to respawn when issuing '/respawn' --- minecraft/networking/packets.py | 16 ++++++++++++++++ start.py | 14 ++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/minecraft/networking/packets.py b/minecraft/networking/packets.py index 6f565bb..9469d1c 100644 --- a/minecraft/networking/packets.py +++ b/minecraft/networking/packets.py @@ -861,6 +861,21 @@ class AnimationPacketServerbound(Packet): HAND_MAIN = 0 HAND_OFF = 1 +class ServerClientStatus(Packet): + @staticmethod + def get_id(context): + return 0x04 if context.protocol_version >= 318 else \ + 0x03 if context.protocol_version >= 80 else \ + 0x02 if context.protocol_version >= 67 else \ + 0x17 if context.protocol_version >= 49 else \ + 0x16 + + packet_name = "client status" + get_definition = staticmethod(lambda context: [ + {'action_id': VarInt}]) + + RESPAWN = 0 + REQUEST_STATS = 1 def state_playing_serverbound(context): packets = { @@ -868,6 +883,7 @@ def state_playing_serverbound(context): ChatPacket, PositionAndLookPacket, AnimationPacketServerbound, + ServerClientStatus, } if context.protocol_version >= 107: packets |= { diff --git a/start.py b/start.py index 81a04b9..5dbe3ce 100755 --- a/start.py +++ b/start.py @@ -7,7 +7,7 @@ from optparse import OptionParser from minecraft import authentication from minecraft.exceptions import YggdrasilError from minecraft.networking.connection import Connection -from minecraft.networking.packets import ChatMessagePacket, ChatPacket +from minecraft.networking.packets import ChatMessagePacket, ChatPacket, ServerClientStatus from minecraft.compat import input @@ -77,9 +77,15 @@ def main(): while True: try: text = input() - packet = ChatPacket() - packet.message = text - connection.write_packet(packet) + if text == "/respawn": + print("respawning...") + packet = ServerClientStatus() + packet.action_id = ServerClientStatus.RESPAWN + connection.write_packet(packet) + else: + packet = ChatPacket() + packet.message = text + connection.write_packet(packet) except KeyboardInterrupt: print("Bye!") sys.exit()