# HG changeset patch # User Charly COSTE # Date 1254692829 -7200 # Node ID 6289ac5a2db73406e185ce79d8f8ca143b13a04a # Parent 5390e9abfa44bf20ec30746027ac3a7c8cc88261 Reconnect when a connection is closed Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -105,9 +105,7 @@ class bot(Thread): self.error('=> Debug: invalid stanza', debug=True) unlock = True except xmpp.Conflict: - c.reconnectAndReauth() - for m in c.mucs: - m.rejoin() + self.reopen_xmpp_connection(c) unlock = True except: error = '[Error] Unkonwn exception on XMPP thread:\n' @@ -643,6 +641,31 @@ class bot(Thread): return c + def reopen_xmpp_connection(self, c): + if not isinstance(c, xmpp.client.Client): + return + mucs = c.mucs + nickname = c.nickname + used_by = c.used_by + participants = [] + for b in self.bridges: + for p in b.participants: + if p.xmpp_c == c: + participants.append(p) + p.xmpp_c = None + self.error('===> Debug: reopening XMPP connection for "'+nickname+'"', debug=True) + self.xmpp_connections.pop(nickname) + c.send(xmpp.protocol.Presence(typ='unavailable')) + del c + c = self.get_xmpp_connection(nickname) + c.used_by = used_by + for p in participants: + p.xmpp_c = c + c.mucs = mucs + for m in c.mucs: + m.rejoin() + + def close_xmpp_connection(self, nickname): if not self.xmpp_connections.has_key(nickname): return diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -212,7 +212,15 @@ class bridge: elif left_protocol == 'irc': p.createDuplicateOnIRC() else: - was_on_both = False + if left_protocol == 'xmpp': + was_on_both = False + elif left_protocol == 'irc': + try: + p.irc_connection.join(self.irc_room) + except: + p._close_irc_connection() + p.createDuplicateOnIRC() + return elif p.protocol == 'irc': if p.xmpp_c == 'both': @@ -223,7 +231,12 @@ class bridge: elif left_protocol == 'xmpp': p.createDuplicateOnXMPP() else: - was_on_both = False + if left_protocol == 'irc': + was_on_both = False + elif left_protocol == 'xmpp': + if isinstance(p.xmpp_c, xmpp.client.Client): + self.bot.reopen_xmpp_connection(p.xmpp_c) + return else: raise Exception('[Internal Error] bad protocol')