changeset 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 a04840ad92b7
children 0a8f96a1d200
files README bot.py bridge.py
diffstat 3 files changed, 26 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/README
+++ b/README
@@ -24,6 +24,7 @@ Changaco <changaco@changaco.net>
 0.3:
  - new mode "bypass", this allows to connect more than one bot for each IRC server without having so many nickname conflicts that the bot looks like it is in limited mode
  - new bridge attribute "irc_connection_interval" (in seconds)
+ - removed automatic switching to limited mode
 0.2:
  - fixed many many bugs
  - new command system
@@ -54,11 +55,9 @@ Copy "example_config.xml" and modify it 
 "mode" is a per-bridge attribute, it can take three values:
 - 'normal':
 The bot connects on IRC on behalf of XMPP users and connects on XMPP on behalf of IRC users.
-In this mode the bot automatically switches from normal to limited mode and back again when the IRC server clones limit is crossed.
 - 'bypass':
 The bot connects on IRC on behalf of XMPP users and connects on XMPP on behalf of IRC users.
 If a nickname is already used the bot tries to connect with a slightly different nickname, adding a "_" to the original nickname.
-In this mode the bot automatically switches to limited mode and back again when the IRC server clones limit is crossed.
 - 'limited':
 The bot only connects on XMPP on behalf of IRC users but NOT on IRC on behalf of XMPP.
 - 'minimal':
--- a/bot.py
+++ b/bot.py
@@ -649,32 +649,16 @@ class Bot(threading.Thread):
 				return
 		
 		
-		# From here the event is shown
-		self.error(event_str, debug=True)
+		if event.eventtype() in ['disconnect', 'kill', 'error']:
+			if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
+				self.error(event_str, debug=True)
+			else:
+				self.error(event_str, send_to_admins=True)
+			return
 		
 		
-		if event.eventtype() in ['disconnect', 'kill']:
-			if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer':
-				return
-			
-			# TODO: lock self.bridges for thread safety
-			for bridge in self.bridges:
-				if connection.server != bridge.irc_server:
-					continue
-				try:
-					p = bridge.getParticipant(connection.get_nickname())
-					if bridge.mode in ['normal', 'bypass']:
-						bridge.changeMode('limited')
-					else:
-						if p.irc_connection.really_connected == True:
-							p.irc_connection.part(bridge.irc_room, message=message)
-						p.irc_connection.used_by -= 1
-						if p.irc_connection.used_by < 1:
-							p.irc_connection.close(message)
-						p.irc_connection = None
-				except Bridge.NoSuchParticipantException:
-					pass
-			return
+		# From here the event is shown
+		self.error(event_str, debug=True)
 		
 		
 		# Nickname callbacks
--- a/bridge.py
+++ b/bridge.py
@@ -180,11 +180,9 @@ class Bridge:
 		self.lock.release()
 		if self.mode not in ['normal', 'bypass']:
 			if from_protocol == 'xmpp':
-				xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp'])
-				self.say('[Info] Participants on XMPP: '+'  '.join(xmpp_participants_nicknames), on_xmpp=False)
+				self.show_participants_list_on(protocols=['irc'])
 			elif self.mode == 'minimal' and from_protocol == 'irc':
-				irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
-				self.say('[Info] Participants on IRC: '+'  '.join(irc_participants_nicknames), on_irc=False)
+				self.show_participants_list_on(protocols=['xmpp'])
 		return p
 	
 	
@@ -207,8 +205,8 @@ class Bridge:
 		
 		if new_mode in ['normal', 'bypass']:
 			
-			if old_mode[-7:] == 'limited':
-				# From  [{normal,bypass}-]limited  to  {normal,bypass}
+			if old_mode == 'limited':
+				# From  limited  to  {normal,bypass}
 				self.createDuplicatesOn(['irc'])
 			
 			elif old_mode in ['minimal', 'normal']:
@@ -223,7 +221,7 @@ class Bridge:
 				# Unhandled mode changing
 				unhandled = True
 			
-		elif new_mode[-7:] == 'limited':
+		elif new_mode == 'limited':
 			
 			if old_mode == 'minimal':
 				self.createDuplicatesOn(['xmpp'])
@@ -234,13 +232,7 @@ class Bridge:
 					i += 1
 					p._close_irc_connection('Bridge is switching to limited mode')
 			
-			if new_mode[-8:] == '-limited':
-				# to {normal,bypass}-limited
-				self.irc_connections_limit = i
-				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)
-				xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp'])
-				self.say('[Info] Participants on XMPP: '+'  '.join(xmpp_participants_nicknames), on_xmpp=False)
-				return
+			self.show_participants_list_on(protocols=['irc'])
 		
 		elif new_mode == 'minimal':
 			for p in self.participants:
@@ -349,15 +341,11 @@ class Bridge:
 			del p
 			self.lock.release()
 			if left_protocol == 'xmpp':
-				xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp'])
-				if self.irc_connections_limit != -1 and self.irc_connections_limit > len(xmpp_participants_nicknames):
-					self.changeMode(self.mode[:-8])
 				if self.mode not in ['normal', 'bypass']:
-					self.say('[Info] Participants on XMPP: '+'  '.join(xmpp_participants_nicknames), on_xmpp=False)
+					self.show_participants_list_on(protocols=['irc'])
 			elif left_protocol == 'irc':
 				if self.mode == 'minimal':
-					irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
-					self.say('[Info] Participants on IRC: '+'  '.join(irc_participants_nicknames), on_irc=False)
+					self.show_participants_list_on(protocols=['xmpp'])
 		
 		else:
 			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)
@@ -396,6 +384,15 @@ class Bridge:
 			self.irc_connection.privmsg(self.irc_room, message)
 	
 	
+	def show_participants_list_on(self, protocols=[]):
+		if 'irc' in protocols:
+			xmpp_participants_nicknames = self.get_participants_nicknames_list(protocols=['xmpp'])
+			self.say('[Info] Participants on XMPP: '+'  '.join(xmpp_participants_nicknames), on_xmpp=False)
+		if 'xmpp' in protocols:
+			irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
+			self.say('[Info] Participants on IRC: '+'  '.join(irc_participants_nicknames), on_irc=False)
+	
+	
 	def stop(self, message='Stopping bridge'):
 		"""Stop the bridge"""