mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-04 00:47:21 +01:00 
			
		
		
		
	ts6_common: add abstraction to convert UIDs->outgoing nicks
This is a more complete fix for #193.
This commit is contained in:
		
							parent
							
								
									9f20f8f767
								
							
						
					
					
						commit
						75984c3c4c
					
				@ -43,11 +43,23 @@ class TS6BaseProtocol(Protocol):
 | 
			
		||||
                        "isn't in our user list!", self.irc.name, target)
 | 
			
		||||
        return target
 | 
			
		||||
 | 
			
		||||
    def _getOutgoingNick(self, uid):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the outgoing nick for the given UID. In the base ts6_common implementation,
 | 
			
		||||
        this does nothing, but other modules subclassing this can override it.
 | 
			
		||||
        For example, this can be used to turn PUIDs (used to store legacy, UID-less users)
 | 
			
		||||
        to actual nicks in outgoing messages, so that a remote IRCd can understand it.
 | 
			
		||||
        """
 | 
			
		||||
        return uid
 | 
			
		||||
 | 
			
		||||
    ### OUTGOING COMMANDS
 | 
			
		||||
 | 
			
		||||
    def numeric(self, source, numeric, target, text):
 | 
			
		||||
        """Sends raw numerics from a server to a remote client, used for WHOIS
 | 
			
		||||
        replies."""
 | 
			
		||||
        # Mangle the target for IRCds that require it.
 | 
			
		||||
        target = self._getOutgoingNick(target)
 | 
			
		||||
 | 
			
		||||
        self._send(source, '%s %s %s' % (numeric, target, text))
 | 
			
		||||
 | 
			
		||||
    def kick(self, numeric, channel, target, reason=None):
 | 
			
		||||
@ -60,6 +72,10 @@ class TS6BaseProtocol(Protocol):
 | 
			
		||||
        channel = utils.toLower(self.irc, channel)
 | 
			
		||||
        if not reason:
 | 
			
		||||
            reason = 'No reason given'
 | 
			
		||||
 | 
			
		||||
        # Mangle kick targets for IRCds that require it.
 | 
			
		||||
        target = self._getOutgoingNick(target)
 | 
			
		||||
 | 
			
		||||
        self._send(numeric, 'KICK %s %s :%s' % (channel, target, reason))
 | 
			
		||||
 | 
			
		||||
        # We can pretend the target left by its own will; all we really care about
 | 
			
		||||
@ -98,12 +114,20 @@ class TS6BaseProtocol(Protocol):
 | 
			
		||||
        """Sends a PRIVMSG from a PyLink client."""
 | 
			
		||||
        if not self.irc.isInternalClient(numeric):
 | 
			
		||||
            raise LookupError('No such PyLink client exists.')
 | 
			
		||||
 | 
			
		||||
        # Mangle message targets for IRCds that require it.
 | 
			
		||||
        target = self._getOutgoingNick(target)
 | 
			
		||||
 | 
			
		||||
        self._send(numeric, 'PRIVMSG %s :%s' % (target, text))
 | 
			
		||||
 | 
			
		||||
    def notice(self, numeric, target, text):
 | 
			
		||||
        """Sends a NOTICE from a PyLink client."""
 | 
			
		||||
        if not self.irc.isInternalClient(numeric):
 | 
			
		||||
            raise LookupError('No such PyLink client exists.')
 | 
			
		||||
 | 
			
		||||
        # Mangle message targets for IRCds that require it.
 | 
			
		||||
        target = self._getOutgoingNick(target)
 | 
			
		||||
 | 
			
		||||
        self._send(numeric, 'NOTICE %s :%s' % (target, text))
 | 
			
		||||
 | 
			
		||||
    def topic(self, numeric, target, text):
 | 
			
		||||
 | 
			
		||||
@ -56,6 +56,18 @@ class UnrealProtocol(TS6BaseProtocol):
 | 
			
		||||
            log.warning('(%s) mixed_link is experimental and may cause problems. '
 | 
			
		||||
                        'You have been warned!', self.irc.name)
 | 
			
		||||
 | 
			
		||||
    def _getOutgoingNick(self, uid):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the outgoing nick for the given UID. For PUIDs (used to store UID-less
 | 
			
		||||
        3.2 users), this will change the PUID given to the actual user's nick,
 | 
			
		||||
        so that that the older IRCds can understand it.
 | 
			
		||||
        """
 | 
			
		||||
        if uid in self.irc.users and '@' in uid:
 | 
			
		||||
            # UID exists and has a @ in it, meaning it's a PUID (orignick@counter style).
 | 
			
		||||
            # Return this user's nick accordingly.
 | 
			
		||||
            return self.irc.users[uid].nick
 | 
			
		||||
        return uid
 | 
			
		||||
 | 
			
		||||
    ### OUTGOING COMMAND FUNCTIONS
 | 
			
		||||
    def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
 | 
			
		||||
            server=None, ip='0.0.0.0', realname=None, ts=None, opertype='IRC Operator',
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user