mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-04 08:57:25 +01:00 
			
		
		
		
	core: reuse existing service client UIDs for all service bots
This prevents nick collision wars caused by spawn_service when an ENDBURST hook for the uplink is received multiple times.
This commit is contained in:
		
							parent
							
								
									21b8b51cba
								
							
						
					
					
						commit
						cad55097f1
					
				
							
								
								
									
										20
									
								
								classes.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								classes.py
									
									
									
									
									
								
							@ -468,16 +468,13 @@ class PyLinkNetworkCore(structures.DeprecatedAttributesObject, structures.CamelC
 | 
			
		||||
        if not userobj:
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        # Look for the "service" attribute in the User object, if one exists.
 | 
			
		||||
        try:
 | 
			
		||||
            sname = userobj.service
 | 
			
		||||
            # Warn if the service name we fetched isn't a registered service.
 | 
			
		||||
            if sname not in world.services.keys():
 | 
			
		||||
                log.warning("(%s) User %s / %s had a service bot record to a service that doesn't "
 | 
			
		||||
                            "exist (%s)!", self.name, uid, userobj.nick, sname)
 | 
			
		||||
            return world.services.get(sname)
 | 
			
		||||
        except AttributeError:
 | 
			
		||||
            return False
 | 
			
		||||
        # Look for the "service" attribute in the User object,sname = userobj.service
 | 
			
		||||
        # Warn if the service name we fetched isn't a registered service.
 | 
			
		||||
        sname = userobj.service
 | 
			
		||||
        if sname not in world.services.keys():
 | 
			
		||||
            log.warning("(%s) User %s / %s had a service bot record to a service that doesn't "
 | 
			
		||||
                        "exist (%s)!", self.name, uid, userobj.nick, sname)
 | 
			
		||||
        return world.services.get(sname)
 | 
			
		||||
 | 
			
		||||
structures._BLACKLISTED_COPY_TYPES.append(PyLinkNetworkCore)
 | 
			
		||||
 | 
			
		||||
@ -1596,6 +1593,9 @@ class User():
 | 
			
		||||
        # Cloaked host for IRCds that use it
 | 
			
		||||
        self.cloaked_host = None
 | 
			
		||||
 | 
			
		||||
        # Stores service bot name if applicable
 | 
			
		||||
        self.service = None
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        return 'User(%s/%s)' % (self.uid, self.nick)
 | 
			
		||||
IrcUser = User
 | 
			
		||||
 | 
			
		||||
@ -22,10 +22,11 @@ def spawn_service(irc, source, command, args):
 | 
			
		||||
    # Get the ServiceBot object.
 | 
			
		||||
    sbot = world.services[name]
 | 
			
		||||
 | 
			
		||||
    if name == 'pylink' and irc.pseudoclient:
 | 
			
		||||
        # irc.pseudoclient already exists, for protocols like clientbot
 | 
			
		||||
        log.debug('(%s) spawn_service: Using existing nick %r for service %r', irc.name, irc.pseudoclient.nick, name)
 | 
			
		||||
        userobj = irc.pseudoclient
 | 
			
		||||
    old_userobj = irc.users.get(sbot.uids.get(irc.name))
 | 
			
		||||
    if old_userobj and old_userobj.service:
 | 
			
		||||
        # A client already exists, so reuse it.
 | 
			
		||||
        log.debug('(%s) spawn_service: Using existing nick %r for service %r', irc.name, old_userobj.nick, name)
 | 
			
		||||
        userobj = old_userobj
 | 
			
		||||
        userobj.opertype = "PyLink Service"
 | 
			
		||||
        userobj.manipulatable = sbot.manipulatable
 | 
			
		||||
    else:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user