Mercurial > xib
changeset 189:e04410e7e527
split the leaving process in two, first call to Bridge.removeParticipant() calls Participant.leave(), second call (when the bot receives the part or quit event) removes it from Bridge.participants
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 20 Feb 2010 23:08:39 +0100 |
parents | bd185885d4ca |
children | 6db99e458168 |
files | bridge.py participant.py |
diffstat | 2 files changed, 13 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/bridge.py +++ b/bridge.py @@ -278,6 +278,14 @@ class Bridge: was_on_both = None p = self.getParticipant(nickname) + + if p.left: + self.lock.acquire() + self.participants.remove(p) + del p + self.lock.release() + return + if p.protocol == 'xmpp': if p.irc_connection == 'both': was_on_both = True @@ -290,6 +298,7 @@ class Bridge: if left_protocol == 'xmpp': was_on_both = False elif left_protocol == 'irc': + # got disconnected somehow if isinstance(p.irc_connection, ServerConnection): p.irc_connection.join(self.irc_room) else: @@ -311,6 +320,7 @@ class Bridge: if left_protocol == 'irc': was_on_both = False elif left_protocol == 'xmpp': + # got disconnected somehow if isinstance(p.xmpp_c, xmpp.client.Client): self.bot.reopen_xmpp_connection(p.xmpp_c) return @@ -322,19 +332,15 @@ class Bridge: self.bot.error(3, '"'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+left_protocol, debug=True) elif was_on_both == False: - self.lock.acquire() self.bot.error(3, 'removing participant "'+nickname+'" from bridge "'+str(self)+'"', debug=True) - self.participants.remove(p) p.leave(leave_message) - del p - self.lock.release() if left_protocol == 'xmpp': if self.mode not in ['normal', 'bypass']: self.show_participants_list_on(protocols=['irc']) elif left_protocol == 'irc': if self.mode == 'minimal': self.show_participants_list_on(protocols=['xmpp']) - + else: self.bot.error(1, 'Bad decision tree, p.protocol='+p.protocol+' left_protocol='+left_protocol+'\np.xmpp_c='+str(p.xmpp_c)+'\np.irc_connection='+str(p.irc_connection), debug=True)
--- a/participant.py +++ b/participant.py @@ -37,6 +37,7 @@ class Participant: self.irc_connection = None self.xmpp_c = None self.muc = None + self.left = False if protocol == 'xmpp' and self.bridge.mode in ['normal', 'bypass']: self.createDuplicateOnIRC() elif protocol == 'irc' and self.bridge.mode != 'minimal': @@ -331,6 +332,7 @@ class Participant: def leave(self, message): if message == None: message = '' + self.left = True self._close_xmpp_connection(message) self._close_irc_connection(message)