Mercurial > xib
comparison bridge.py @ 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 | 594f570f4657 |
children | 6db99e458168 |
comparison
equal
deleted
inserted
replaced
188:bd185885d4ca | 189:e04410e7e527 |
---|---|
276 def removeParticipant(self, left_protocol, nickname, leave_message): | 276 def removeParticipant(self, left_protocol, nickname, leave_message): |
277 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" | 277 """Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge.""" |
278 | 278 |
279 was_on_both = None | 279 was_on_both = None |
280 p = self.getParticipant(nickname) | 280 p = self.getParticipant(nickname) |
281 | |
282 if p.left: | |
283 self.lock.acquire() | |
284 self.participants.remove(p) | |
285 del p | |
286 self.lock.release() | |
287 return | |
288 | |
281 if p.protocol == 'xmpp': | 289 if p.protocol == 'xmpp': |
282 if p.irc_connection == 'both': | 290 if p.irc_connection == 'both': |
283 was_on_both = True | 291 was_on_both = True |
284 if left_protocol == 'xmpp': | 292 if left_protocol == 'xmpp': |
285 p.protocol = 'irc' | 293 p.protocol = 'irc' |
288 p.createDuplicateOnIRC() | 296 p.createDuplicateOnIRC() |
289 else: | 297 else: |
290 if left_protocol == 'xmpp': | 298 if left_protocol == 'xmpp': |
291 was_on_both = False | 299 was_on_both = False |
292 elif left_protocol == 'irc': | 300 elif left_protocol == 'irc': |
301 # got disconnected somehow | |
293 if isinstance(p.irc_connection, ServerConnection): | 302 if isinstance(p.irc_connection, ServerConnection): |
294 p.irc_connection.join(self.irc_room) | 303 p.irc_connection.join(self.irc_room) |
295 else: | 304 else: |
296 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) | 305 c = self.bot.irc.get_connection(self.irc_server, self.irc_port, p.duplicate_nickname) |
297 if not (c and self.irc_room in c.left_channels): | 306 if not (c and self.irc_room in c.left_channels): |
309 p.createDuplicateOnXMPP() | 318 p.createDuplicateOnXMPP() |
310 else: | 319 else: |
311 if left_protocol == 'irc': | 320 if left_protocol == 'irc': |
312 was_on_both = False | 321 was_on_both = False |
313 elif left_protocol == 'xmpp': | 322 elif left_protocol == 'xmpp': |
323 # got disconnected somehow | |
314 if isinstance(p.xmpp_c, xmpp.client.Client): | 324 if isinstance(p.xmpp_c, xmpp.client.Client): |
315 self.bot.reopen_xmpp_connection(p.xmpp_c) | 325 self.bot.reopen_xmpp_connection(p.xmpp_c) |
316 return | 326 return |
317 | 327 |
318 else: | 328 else: |
320 | 330 |
321 if was_on_both == True: | 331 if was_on_both == True: |
322 self.bot.error(3, '"'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+left_protocol, debug=True) | 332 self.bot.error(3, '"'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+left_protocol, debug=True) |
323 | 333 |
324 elif was_on_both == False: | 334 elif was_on_both == False: |
325 self.lock.acquire() | |
326 self.bot.error(3, 'removing participant "'+nickname+'" from bridge "'+str(self)+'"', debug=True) | 335 self.bot.error(3, 'removing participant "'+nickname+'" from bridge "'+str(self)+'"', debug=True) |
327 self.participants.remove(p) | |
328 p.leave(leave_message) | 336 p.leave(leave_message) |
329 del p | |
330 self.lock.release() | |
331 if left_protocol == 'xmpp': | 337 if left_protocol == 'xmpp': |
332 if self.mode not in ['normal', 'bypass']: | 338 if self.mode not in ['normal', 'bypass']: |
333 self.show_participants_list_on(protocols=['irc']) | 339 self.show_participants_list_on(protocols=['irc']) |
334 elif left_protocol == 'irc': | 340 elif left_protocol == 'irc': |
335 if self.mode == 'minimal': | 341 if self.mode == 'minimal': |
336 self.show_participants_list_on(protocols=['xmpp']) | 342 self.show_participants_list_on(protocols=['xmpp']) |
337 | 343 |
338 else: | 344 else: |
339 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) | 345 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) |
340 | 346 |
341 | 347 |
342 def restart(self): | 348 def restart(self): |