Esempio n. 1
0
    def pre_handshake(self):
        """
        Set up username and get going.
        """
        if self.username in self.factory.protocols:
            # This username's already taken; find a new one.
            for name in username_alternatives(self.username):
                if name not in self.factory.protocols:
                    self.username = name
                    break
            else:
                self.error("Your username is already taken.")
                return False

        return True
Esempio n. 2
0
    def pre_handshake(self):
        """
        Set up username and get going.
        """
        if self.username in self.factory.protocols:
            # This username's already taken; find a new one.
            for name in username_alternatives(self.username):
                if name not in self.factory.protocols:
                    self.username = name
                    break
            else:
                self.error("Your username is already taken.")
                return False

        return True
Esempio n. 3
0
    def login(self, container):
        """
        Handle a login packet.

        This method wraps a login hook which is permitted to do just about
        anything, as long as it's asynchronous. The hook returns a
        ``Deferred``, which is chained to authenticate the user or disconnect
        them depending on the results of the authentication.
        """

        # Check the username. If it's "Player", then the client is almost
        # certainly cracked, so we'll need to give them a better username.
        # Thankfully, there's a utility function for finding better usernames.
        username = container.username

        if username in self.factory.protocols:
            for name in username_alternatives(username):
                if name not in self.factory.protocols:
                    container.username = name
                    break
            else:
                self.error("Your username is already taken.")
                return


        if container.protocol < SUPPORTED_PROTOCOL:
            # Kick old clients.
            self.error("This server doesn't support your ancient client.")
            return
        elif container.protocol > SUPPORTED_PROTOCOL:
            # Kick new clients.
            self.error("This server doesn't support your newfangled client.")
            return

        log.msg("Authenticating client, protocol version %d" %
            container.protocol)

        d = self.factory.login_hook(self, container)
        d.addErrback(lambda *args, **kwargs: self.transport.loseConnection())
        d.addCallback(lambda *args, **kwargs: self.authenticated())
Esempio n. 4
0
    def login(self, container):
        """
        Handle a login packet.

        This method wraps a login hook which is permitted to do just about
        anything, as long as it's asynchronous. The hook returns a
        ``Deferred``, which is chained to authenticate the user or disconnect
        them depending on the results of the authentication.
        """

        # Check the username. If it's "Player", then the client is almost
        # certainly cracked, so we'll need to give them a better username.
        # Thankfully, there's a utility function for finding better usernames.
        username = container.username

        if username in self.factory.protocols:
            for name in username_alternatives(username):
                if name not in self.factory.protocols:
                    container.username = name
                    break
            else:
                self.error("Your username is already taken.")
                return

        if container.protocol < SUPPORTED_PROTOCOL:
            # Kick old clients.
            self.error("This server doesn't support your ancient client.")
            return
        elif container.protocol > SUPPORTED_PROTOCOL:
            # Kick new clients.
            self.error("This server doesn't support your newfangled client.")
            return

        log.msg("Authenticating client, protocol version %d" %
                container.protocol)

        d = self.factory.login_hook(self, container)
        d.addErrback(lambda *args, **kwargs: self.transport.loseConnection())
        d.addCallback(lambda *args, **kwargs: self.authenticated())