Properly disconnect DCC connexion when any part leave

This commit is contained in:
Némunaire 2012-10-15 01:15:07 +02:00
parent 9c7884f092
commit 7de644a784
3 changed files with 14 additions and 4 deletions

13
DCC.py
View File

@ -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)

View File

@ -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)

View File

@ -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