diff --git a/game.py b/game.py index 74aa9fc..1bf8082 100644 --- a/game.py +++ b/game.py @@ -21,7 +21,7 @@ from protocol.packets import ( ClientWindowConfirmationPacket, EntityMetadataPacket, SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket, EntityActionPacket, EntityTeleport, InteractEntityPacket, TradeListPacket, - SelectTradePacket, + SelectTradePacket, DisconnectPacket, ) from protocol.types import Slot @@ -374,6 +374,7 @@ class Game: register(self.handle_update_health, clientbound.play.UpdateHealthPacket) #register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket) register(self.handle_trade_list, TradeListPacket) + register(self.handle_disconnect, DisconnectPacket) #register(self.handle_packet, Packet, early=True) @@ -1230,6 +1231,12 @@ class Game: packet.selected_slot = num self.g.connection.write_packet(packet) + def handle_disconnect(self, packet): + print(packet) + print('Client disconnected!') + import os + os._exit(1) + def tick(self): if self.g.breaking: self.animate() diff --git a/monkey_patch.py b/monkey_patch.py index 1388658..67b1eb5 100644 --- a/monkey_patch.py +++ b/monkey_patch.py @@ -19,6 +19,7 @@ def get_packets(old_get_packets): mc_packets.add(packets.DestroyEntitiesPacket) mc_packets.add(packets.EntityTeleport) mc_packets.add(packets.TradeListPacket) + mc_packets.add(packets.DisconnectPacket) return mc_packets diff --git a/protocol/packets.py b/protocol/packets.py index 577fd0a..1a5b1f4 100644 --- a/protocol/packets.py +++ b/protocol/packets.py @@ -447,3 +447,14 @@ class SelectTradePacket(Packet): definition = [ {'selected_slot': VarInt}, ] + +class DisconnectPacket(Packet): + # Sent by the server before it disconnects a client + # https://wiki.vg/Protocol#Disconnect_.28play.29 + + id = 0x19 + packet_name = 'disconnect' + + definition = [ + {'reason': String}, + ]