Mercurial > xib
comparison bridge.py @ 72:6c4b841144f6
Better handling of participants
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Wed, 02 Sep 2009 14:57:57 +0200 |
parents | 8fc496eaa17b |
children | 844ccdcf66be |
comparison
equal
deleted
inserted
replaced
71:c5e4bf95f52a | 72:6c4b841144f6 |
---|---|
18 import muc | 18 import muc |
19 xmpp = muc.xmpp | 19 xmpp = muc.xmpp |
20 del muc | 20 del muc |
21 from participant import * | 21 from participant import * |
22 from encoding import * | 22 from encoding import * |
23 from irclib import ServerConnection | |
23 import traceback | 24 import traceback |
24 import re | 25 import re |
25 import threading | 26 import threading |
26 | 27 |
27 | 28 |
106 except xmpp.muc.NicknameConflict: | 107 except xmpp.muc.NicknameConflict: |
107 self.bot.error('[Error] "'+self.bot.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self)+'"') | 108 self.bot.error('[Error] "'+self.bot.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self)+'"') |
108 raise Exception('[Error] "'+self.bot.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self)+'"') | 109 raise Exception('[Error] "'+self.bot.nickname+'" is already used in the XMPP MUC or reserved on the XMPP server of bridge "'+str(self)+'"') |
109 | 110 |
110 | 111 |
111 def addParticipant(self, protocol, nickname): | 112 def addParticipant(self, from_protocol, nickname): |
112 """Add a participant to the bridge.""" | 113 """Add a participant to the bridge.""" |
113 if (protocol == 'irc' and nickname == self.irc_connection.get_nickname()) or (protocol == 'xmpp' and nickname == self.xmpp_room.nickname): | 114 if (from_protocol == 'irc' and nickname == self.irc_connection.get_nickname()) or (from_protocol == 'xmpp' and nickname == self.xmpp_room.nickname): |
114 self.bot.error('===> Debug: not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) | 115 self.bot.error('===> Debug: not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True) |
115 return | 116 return |
116 try: | 117 try: |
117 p = self.getParticipant(nickname) | 118 p = self.getParticipant(nickname) |
118 if p.protocol != protocol: | 119 if p.protocol != from_protocol: |
119 if protocol == 'irc': | 120 if from_protocol == 'irc' and isinstance(p.irc_connection, ServerConnection) and p.irc_connection.really_connected == True or from_protocol == 'xmpp' and isinstance(p.muc, xmpp.muc) and p.muc.connected == True: |
120 p.createDuplicateOnXMPP() | 121 return |
121 elif protocol == 'xmpp': | 122 self.bot.error('===> Debug: "'+nickname+'" is on both sides of bridge "'+str(self)+'"', debug=True) |
122 p.createDuplicateOnIRC() | 123 self.say('[Warning] The nickname "'+nickname+'" is used on both sides of the bridge, please avoid that if possible') |
123 else: | 124 if isinstance(p.irc_connection, ServerConnection): |
124 raise Exception('[Internal Error] bad protocol') | 125 p.irc_connection.close('') |
126 p.irc_connection = 'both' | |
127 if isinstance(p.muc, xmpp.muc): | |
128 p.muc.leave('') | |
129 self.bot.close_xmpp_connection(p.nickname) | |
130 p.xmpp_c = 'both' | |
125 return | 131 return |
126 except NoSuchParticipantException: | 132 except NoSuchParticipantException: |
127 pass | 133 pass |
128 self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+protocol+'" to bridge "'+str(self)+'"', debug=True) | 134 self.bot.error('===> Debug: adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) |
129 try: | 135 try: |
130 p = participant(self, protocol, nickname) | 136 p = participant(self, from_protocol, nickname) |
131 except IOError: | 137 except IOError: |
132 self.bot.error('===> Debug: IOError while adding participant "'+nickname+'" from "'+protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) | 138 self.bot.error('===> Debug: IOError while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'", reconnectiong ...', debug=True) |
133 p.xmpp_c.reconnectAndReauth() | 139 p.xmpp_c.reconnectAndReauth() |
134 except: | 140 except: |
135 self.bot.error('===> Debug: unknown error while adding participant "'+nickname+'" from "'+protocol+'" to bridge "'+str(self)+'"', debug=True) | 141 self.bot.error('===> Debug: unknown error while adding participant "'+nickname+'" from "'+from_protocol+'" to bridge "'+str(self)+'"', debug=True) |
136 traceback.print_exc() | 142 traceback.print_exc() |
137 return | 143 return |
138 self.participants.append(p) | 144 self.participants.append(p) |
139 if self.mode != 'normal' and protocol == 'xmpp': | 145 if self.mode != 'normal' and from_protocol == 'xmpp': |
140 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) | 146 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) |
141 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) | 147 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) |
142 return p | 148 return p |
143 | 149 |
144 | 150 |
179 p = self.getParticipant(nickname) | 185 p = self.getParticipant(nickname) |
180 if p.protocol == 'xmpp': | 186 if p.protocol == 'xmpp': |
181 if left_protocol == 'irc': | 187 if left_protocol == 'irc': |
182 was_on_both = True | 188 was_on_both = True |
183 elif left_protocol == 'xmpp': | 189 elif left_protocol == 'xmpp': |
184 if p.irc_connection == None and self.mode == 'normal': | 190 if p.irc_connection == 'both': |
185 was_on_both = True | 191 was_on_both = True |
186 p.protocol = 'irc' | 192 p.protocol = 'irc' |
187 p.createDuplicateOnXMPP() | 193 p.createDuplicateOnXMPP() |
188 else: | 194 else: |
189 was_on_both = False | 195 was_on_both = False |
190 | 196 |
191 elif p.protocol == 'irc': | 197 elif p.protocol == 'irc': |
192 if left_protocol == 'xmpp': | 198 if left_protocol == 'xmpp': |
193 was_on_both = True | 199 was_on_both = True |
194 elif left_protocol == 'irc': | 200 elif left_protocol == 'irc': |
195 if p.xmpp_c == None and self.mode != 'minimal': | 201 if p.xmpp_c == 'both': |
196 was_on_both = True | 202 was_on_both = True |
197 p.protocol = 'xmpp' | 203 p.protocol = 'xmpp' |
198 p.createDuplicateOnIRC() | 204 p.createDuplicateOnIRC() |
199 else: | 205 else: |
200 was_on_both = False | 206 was_on_both = False |
266 self.mode = 'normal-limited' | 272 self.mode = 'normal-limited' |
267 i = 0 | 273 i = 0 |
268 for p in self.participants: | 274 for p in self.participants: |
269 if p.protocol == 'xmpp': | 275 if p.protocol == 'xmpp': |
270 i += 1 | 276 i += 1 |
271 if p.irc_connection != None: | 277 if isinstance(self.irc_connection, ServerConnection): |
272 p.irc_connection.close('Bridge is switching to limited mode') | 278 p.irc_connection.close('Bridge is switching to limited mode') |
273 p.irc_connection = None | 279 p.irc_connection = None |
274 self.irc_connections_limit = i | 280 self.irc_connections_limit = i |
275 self.bot.error('===> Bridge is switching to limited mode. Limit seems to be '+str(self.irc_connections_limit)+' on "'+self.irc_server+'".') | 281 self.bot.error('===> Bridge is switching to limited mode. Limit seems to be '+str(self.irc_connections_limit)+' on "'+self.irc_server+'".') |
276 self.say('[Warning] Bridge is switching to limited mode, it means that it will be transparent for XMPP users but not for IRC users, this is due to the IRC servers\' per-IP-address connections\' limit number which seems to be '+str(self.irc_connections_limit)+' on "'+self.irc_server+'".') | 282 self.say('[Warning] Bridge is switching to limited mode, it means that it will be transparent for XMPP users but not for IRC users, this is due to the IRC servers\' per-IP-address connections\' limit number which seems to be '+str(self.irc_connections_limit)+' on "'+self.irc_server+'".') |