From 7de644a7844c2edf7fbe7c6344b1d512665cc2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Mon, 15 Oct 2012 01:15:07 +0200 Subject: [PATCH] Properly disconnect DCC connexion when any part leave --- DCC.py | 13 +++++++++++-- hooks.py | 2 +- networkbot.py | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/DCC.py b/DCC.py index 5e0f989..48bb0b0 100644 --- a/DCC.py +++ b/DCC.py @@ -132,7 +132,7 @@ class DCC(threading.Thread): except: self.setError("Une erreur s'est produite durant la tentative" " d'ouverture d'une session DCC.") - return + return False print ('Listen on', self.port, "for", self.sender) #Send CTCP request for DCC @@ -146,6 +146,7 @@ class DCC(threading.Thread): (self.conn, addr) = s.accept() print ('Connected by', addr) self.connected = True + return True def send_dcc_raw(self, line): self.conn.sendall(line + b'\n') @@ -196,7 +197,9 @@ class DCC(threading.Thread): # Messages connection else: if not self.connected: - self.request_user() + if not self.request_user(): + #TODO: do something here + return False #Start by sending all queued messages for mess in self.messages: @@ -221,6 +224,12 @@ class DCC(threading.Thread): if self.connected: self.conn.close() self.connected = False + + #Remove from DCC connections server list + if self.realname in self.srv.dcc_clients: + del self.srv.dcc_clients[self.realname] + + print ("Close connection with", self.nick) self.stopping.set() #Rearm Thread threading.Thread.__init__(self) diff --git a/hooks.py b/hooks.py index 3bbc4ad..d6a5641 100644 --- a/hooks.py +++ b/hooks.py @@ -53,7 +53,7 @@ class MessagesHook: del self.context.hooks_cache[store] if not hasattr(self, store): - print ("\033[1;35mWarning:\033[0m unrecognized hook store type") + print ("\033[1;35mWarning:\033[0m unrecognized hook store") return attr = getattr(self, store) diff --git a/networkbot.py b/networkbot.py index e0e6485..53e886b 100644 --- a/networkbot.py +++ b/networkbot.py @@ -35,6 +35,7 @@ class NetworkBot: self.dcc = dcc # DCC connection to the other bot self.hooks = list() + self.REGISTERED_HOOKS = list() # Tags monitor self.my_tag = random.randint(0,255) @@ -179,7 +180,7 @@ class NetworkBot: if args[4] == "": args[4] = list() else: args[4] = args[4].split(',') - self.hooks[level].add_hook(args[0], hooks.Hook(self.exec_hook, args[2], None, args[3], args[4])) + self.hooks[level].add_hook(args[0], hooks.Hook(self.exec_hook, args[2], None, args[3], args[4]), self) elif cmd == "HOOK" and len(args) >= 8: # Rebuild the response