Mercurial > xib
comparison bridge.py @ 152:17305e57f71d
removed automatic switching to limited mode (created Bridge.show_participants_list_on())
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 17 Jan 2010 22:30:23 +0100 |
parents | e0eea72ea493 |
children | 63db565438bd |
comparison
equal
deleted
inserted
replaced
151:a04840ad92b7 | 152:17305e57f71d |
---|---|
178 return | 178 return |
179 self.participants.append(p) | 179 self.participants.append(p) |
180 self.lock.release() | 180 self.lock.release() |
181 if self.mode not in ['normal', 'bypass']: | 181 if self.mode not in ['normal', 'bypass']: |
182 if from_protocol == 'xmpp': | 182 if from_protocol == 'xmpp': |
183 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) | 183 self.show_participants_list_on(protocols=['irc']) |
184 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) | |
185 elif self.mode == 'minimal' and from_protocol == 'irc': | 184 elif self.mode == 'minimal' and from_protocol == 'irc': |
186 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) | 185 self.show_participants_list_on(protocols=['xmpp']) |
187 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) | |
188 return p | 186 return p |
189 | 187 |
190 | 188 |
191 def createDuplicatesOn(self, protocols): | 189 def createDuplicatesOn(self, protocols): |
192 for p in self.participants: | 190 for p in self.participants: |
205 | 203 |
206 unhandled = False | 204 unhandled = False |
207 | 205 |
208 if new_mode in ['normal', 'bypass']: | 206 if new_mode in ['normal', 'bypass']: |
209 | 207 |
210 if old_mode[-7:] == 'limited': | 208 if old_mode == 'limited': |
211 # From [{normal,bypass}-]limited to {normal,bypass} | 209 # From limited to {normal,bypass} |
212 self.createDuplicatesOn(['irc']) | 210 self.createDuplicatesOn(['irc']) |
213 | 211 |
214 elif old_mode in ['minimal', 'normal']: | 212 elif old_mode in ['minimal', 'normal']: |
215 # From {minimal,normal} to {normal,bypass} | 213 # From {minimal,normal} to {normal,bypass} |
216 self.createDuplicatesOn(['irc', 'xmpp']) | 214 self.createDuplicatesOn(['irc', 'xmpp']) |
221 | 219 |
222 else: | 220 else: |
223 # Unhandled mode changing | 221 # Unhandled mode changing |
224 unhandled = True | 222 unhandled = True |
225 | 223 |
226 elif new_mode[-7:] == 'limited': | 224 elif new_mode == 'limited': |
227 | 225 |
228 if old_mode == 'minimal': | 226 if old_mode == 'minimal': |
229 self.createDuplicatesOn(['xmpp']) | 227 self.createDuplicatesOn(['xmpp']) |
230 | 228 |
231 i = 0 | 229 i = 0 |
232 for p in self.participants: | 230 for p in self.participants: |
233 if p.protocol == 'xmpp': | 231 if p.protocol == 'xmpp': |
234 i += 1 | 232 i += 1 |
235 p._close_irc_connection('Bridge is switching to limited mode') | 233 p._close_irc_connection('Bridge is switching to limited mode') |
236 | 234 |
237 if new_mode[-8:] == '-limited': | 235 self.show_participants_list_on(protocols=['irc']) |
238 # to {normal,bypass}-limited | |
239 self.irc_connections_limit = i | |
240 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+'".', log=True) | |
241 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) | |
242 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) | |
243 return | |
244 | 236 |
245 elif new_mode == 'minimal': | 237 elif new_mode == 'minimal': |
246 for p in self.participants: | 238 for p in self.participants: |
247 p.leave('Bridge is switching to minimal mode') | 239 p.leave('Bridge is switching to minimal mode') |
248 | 240 |
347 self.participants.remove(p) | 339 self.participants.remove(p) |
348 p.leave(leave_message) | 340 p.leave(leave_message) |
349 del p | 341 del p |
350 self.lock.release() | 342 self.lock.release() |
351 if left_protocol == 'xmpp': | 343 if left_protocol == 'xmpp': |
352 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) | |
353 if self.irc_connections_limit != -1 and self.irc_connections_limit > len(xmpp_participants_nicknames): | |
354 self.changeMode(self.mode[:-8]) | |
355 if self.mode not in ['normal', 'bypass']: | 344 if self.mode not in ['normal', 'bypass']: |
356 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) | 345 self.show_participants_list_on(protocols=['irc']) |
357 elif left_protocol == 'irc': | 346 elif left_protocol == 'irc': |
358 if self.mode == 'minimal': | 347 if self.mode == 'minimal': |
359 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) | 348 self.show_participants_list_on(protocols=['xmpp']) |
360 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) | |
361 | 349 |
362 else: | 350 else: |
363 self.bot.error('=> Debug: 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) | 351 self.bot.error('=> Debug: 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) |
364 | 352 |
365 | 353 |
394 self.xmpp_room.say(message) | 382 self.xmpp_room.say(message) |
395 if on_irc == True: | 383 if on_irc == True: |
396 self.irc_connection.privmsg(self.irc_room, message) | 384 self.irc_connection.privmsg(self.irc_room, message) |
397 | 385 |
398 | 386 |
387 def show_participants_list_on(self, protocols=[]): | |
388 if 'irc' in protocols: | |
389 xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp']) | |
390 self.say('[Info] Participants on XMPP: '+' '.join(xmpp_participants_nicknames), on_xmpp=False) | |
391 if 'xmpp' in protocols: | |
392 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) | |
393 self.say('[Info] Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) | |
394 | |
395 | |
399 def stop(self, message='Stopping bridge'): | 396 def stop(self, message='Stopping bridge'): |
400 """Stop the bridge""" | 397 """Stop the bridge""" |
401 | 398 |
402 # Close IRC connection if not used by an other bridge, just leave the room otherwise | 399 # Close IRC connection if not used by an other bridge, just leave the room otherwise |
403 if isinstance(self.irc_connection, ServerConnection): | 400 if isinstance(self.irc_connection, ServerConnection): |