diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index fb0b7c3..6d12aa1 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -158,9 +158,8 @@ void C64::network_vblank() if (this->quit_thyself) { - if (this->network_connection_type != CONNECT) - remote->Disconnect(); - delete remote; + remote->Disconnect(); + delete remote; this->network = NULL; TheC64->network_connection_type = NONE; diff --git a/network-broker/network-broker b/network-broker/network-broker index 1adb692..db43747 100755 --- a/network-broker/network-broker +++ b/network-broker/network-broker @@ -195,6 +195,11 @@ class PingAckPacket(Packet): """Create data representation of a packet""" return Packet.marshal(self) + struct.pack(">L", self.seq) +class DisconnectPacket(Packet): + def __init__(self): + Packet.__init__(self) + self.type = DISCONNECT + class SelectPeerPacket(Packet): def __init__(self): @@ -507,6 +512,12 @@ class BrokerPacketHandler(SocketServer.DatagramRequestHandler): peer = srv.get_peer(self.client_address) + # Handle disconnects by removing the peer and ignoring the rest + if pkt.get_type() == DISCONNECT: + log_info("Peer disconnected, removing") + self.server.remove_peer(peer) + return + try: peer.handle_packet(pkt) except Exception, e: @@ -630,6 +641,7 @@ packet_class_by_type = { CONNECT_TO_BROKER : ConnectToBrokerPacket, SELECT_PEER : SelectPeerPacket, REGISTER_DATA : RegisterDataPacket, + DISCONNECT : DisconnectPacket, ACK : PingAckPacket, }