def on_client_connect(self, data):
        parsed = client_connect().parse(data.data)
        msgdate = datetime.now().strftime('[%H:%M:%S]')
        connect_player = self.player_manager.get_by_org_name(
            parsed.name.decode('utf-8')
        )
        try:
            if self.player_manager.check_bans(connect_player.ip):
                msgtxt = 'Banned Player {p} tried to join the server.'.format(
                    p=connect_player.name
                )
            else:
                msgtxt = 'Player {p} has joined the server.'.format(
                    p=connect_player.name
                )
        except AttributeError:
            msgtxt = 'New player has joined the server.'
        message = json.dumps(
            {
                'msgdate': msgdate,
                'author': 'SERVER',
                'message': msgtxt
            }
        )
        self.messages.append(message)
        self.messages_log.append(message)

        return True
示例#2
0
 def on_client_connect(self, data):
     client_data = client_connect().parse(data.data)
     try:
         original_name = client_data.name
         for regex in self.regexes:
             client_data.name = re.sub(regex, "", client_data.name)
         if len(client_data.name.strip()) == 0:  # If the username is nothing but spaces.
             raise NameError("Your name must not be empty!")
         if client_data.name != original_name:
             self.logger.info("Player tried to log in with name %s, replaced with %s.",
                              original_name, client_data.name)
         self.protocol.player = self.player_manager.fetch_or_create(
             name=client_data.name,
             uuid=str(client_data.uuid),
             ip=self.protocol.transport.getPeer().host,
             protocol=self.protocol.id)
         return True
     except AlreadyLoggedIn:
         self.reject_with_reason(
             "You're already logged in! If this is not the case, please wait 10 seconds and try again.")
         self.logger.info("Already logged in user tried to log in.")
     except Banned:
         self.reject_with_reason("You have been banned!")
         self.logger.info("Banned user tried to log in.")
         return False
     except NameError as e:
         self.reject_with_reason(str(e))
示例#3
0
文件: plugin.py 项目: TinCow/StarryPy
 def on_client_connect(self, data):
     client_data = client_connect().parse(data.data)
     try:
         original_name = client_data.name
         for regex in self.regexes:
             client_data.name = re.sub(regex, "", client_data.name)
         if len(client_data.name.strip()
                ) == 0:  # If the username is nothing but spaces.
             raise NameError("Your name must not be empty!")
         if client_data.name != original_name:
             self.logger.info(
                 "Player tried to log in with name %s, replaced with %s.",
                 original_name, client_data.name)
         self.protocol.player = self.player_manager.fetch_or_create(
             name=client_data.name,
             uuid=str(client_data.uuid),
             ip=self.protocol.transport.getPeer().host,
             protocol=self.protocol.id)
         return True
     except AlreadyLoggedIn:
         self.reject_with_reason(
             "You're already logged in! If this is not the case, please wait 10 seconds and try again."
         )
         self.logger.info("Already logged in user tried to log in.")
     except Banned:
         self.reject_with_reason("You have been banned!")
         self.logger.info("Banned user tried to log in.")
         return False
     except NameError as e:
         self.reject_with_reason(str(e))
示例#4
0
文件: plugin.py 项目: 8r2y5/StarryPy
    def on_client_connect(self, data):
        client_data = client_connect().parse(data.data)
        try:
            changed_name = client_data.name

            # Replace problematic chars in client name
            for regex in self.regexes:
                changed_name = re.sub(regex, "", changed_name)

            # If the username is nothing but spaces.
            if not client_data.name.strip():
                raise NameError("Your name must not be empty!")

            # Logging changed username
            if client_data.name != changed_name:
                self.logger.info(
                    "Player tried to log in with name %s, replaced with %s.", client_data.name, changed_name
                )

            changed_player = self.player_manager.get_by_uuid(client_data.uuid)
            if changed_player is not None and changed_player.name != changed_name:
                self.logger.info("Got player with changed nickname. Fetching nickname!")
                changed_name = changed_player.name

            duplicate_player = self.player_manager.get_by_org_name(client_data.name)
            if duplicate_player is not None and duplicate_player.uuid != client_data.uuid:
                self.logger.info(
                    "CLONE WARNING: {} "
                    "MAY BE TRYING TO IMPERSONATE {}!".format(self.protocol.transport.getPeer().host, client_data.name)
                )

            if client_data.account == self.adminss:
                admin_login = True
            else:
                admin_login = False

            original_name = client_data.name
            client_data.name = changed_name
            self.protocol.player = self.player_manager.fetch_or_create(
                name=client_data.name,
                org_name=original_name,
                admin_logged_in=admin_login,
                uuid=str(client_data.uuid),
                ip=self.protocol.transport.getPeer().host,
                protocol=self.protocol.id,
            )
            return True

        except AlreadyLoggedIn:
            self.reject_with_reason(
                "You're already logged in! If this is not the case, " "please wait 10 seconds and try again."
            )
            self.logger.info("Already logged in user tried to log in.")

        except Banned:
            self.reject_with_reason("You have been banned!")
            self.logger.info("Banned user tried to log in.")
            return False
        except NameError as e:
            self.reject_with_reason(str(e))
示例#5
0
    def on_client_connect(self, data):
        client_data = client_connect().parse(data.data)
        try:
            original_name = client_data.name
            for regex in self.regexes:
                client_data.name = re.sub(regex, "", client_data.name)
            if len(client_data.name.strip()) == 0:  # If the username is nothing but spaces.
                raise NameError("Your name must not be empty!")
            if client_data.name != original_name:
                self.logger.info("Player tried to log in with name %s, replaced with %s.",
                                 original_name, client_data.name)

            for duplicate_player in self.player_manager.all():
                if duplicate_player.name==client_data.name and duplicate_player.uuid!=client_data.uuid:
                    self.logger.info("Got a duplicate player, asking player to change name")
                    raise NameError("The name of this character is already taken on the server! Please, create a new character with a different name or use Starcheat and change the name.")

            self.protocol.player = self.player_manager.fetch_or_create(
                name=client_data.name,
                uuid=str(client_data.uuid),
                ip=self.protocol.transport.getPeer().host,
                protocol=self.protocol.id,
                )

            return True
        except AlreadyLoggedIn:
            self.reject_with_reason(
                "You're already logged in! If this is not the case, please wait 10 seconds and try again.")
            self.logger.info("Already logged in user tried to log in.")
        except Banned:
            self.reject_with_reason("You have been banned!")
            self.logger.info("Banned user tried to log in.")
            return False
        except NameError as e:
            self.reject_with_reason(str(e))
示例#6
0
    def on_client_connect(self, data):
        parsed = client_connect().parse(data.data)
        self.logger.info(parsed.name)

        for p in self.irc_factory.irc_clients.itervalues():
            p.msg(self.channel, "%s connected" % parsed.name.encode("utf-8"))

        return True
示例#7
0
    def on_client_connect(self, data):
        parsed = client_connect().parse(data.data)
        self.logger.info(parsed.name)

        for p in self.irc_factory.irc_clients.itervalues():
            p.msg(self.channel, "%s connected" % parsed.name.encode("utf-8"))

        return True
示例#8
0
    def on_client_connect(self, data):
        client_data = client_connect().parse(data.data)
        try:
            changed_name = client_data.name
            for regex in self.regexes:  # Replace problematic chars in client name
                changed_name = re.sub(regex, "", changed_name)

            if len(client_data.name.strip()) == 0:  # If the username is nothing but spaces.
                raise NameError("Your name must not be empty!")

            if client_data.name != changed_name:  # Logging changed username
                self.logger.info("Player tried to log in with name %s, replaced with %s.",
                                 client_data.name, changed_name)

            changed_player = self.player_manager.get_by_uuid(client_data.uuid)
            if changed_player is not None and changed_player.name != changed_name:
                self.logger.info("Got player with changed nickname. Fetching nickname!")
                changed_name = changed_player.name

            duplicate_player = self.player_manager.get_by_org_name(client_data.name)
            if duplicate_player is not None and duplicate_player.uuid != client_data.uuid:
                raise NameError(
                    "The name of this character is already taken on the server!\nPlease, create a new character with a different name or talk to an administrator.")
                self.logger.info("Got a duplicate original player name, asking player to change character name!")
                #rnd_append = str(randrange(10, 99))
                #original_name += rnd_append
                #client_data.name += rnd_append

            if client_data.account == self.adminss:
                admin_login = True
            else:
                admin_login = False

            original_name = client_data.name
            client_data.name = changed_name
            self.protocol.player = self.player_manager.fetch_or_create(
                name=client_data.name,
                org_name=original_name,
                admin_logged_in = admin_login,
                uuid=str(client_data.uuid),
                ip=self.protocol.transport.getPeer().host,
                protocol=self.protocol.id,
            )

            return True
        except AlreadyLoggedIn:
            self.reject_with_reason(
                "You're already logged in! If this is not the case, please wait 10 seconds and try again.")
            self.logger.info("Already logged in user tried to log in.")
        except Banned:
            self.reject_with_reason("You have been banned!")
            self.logger.info("Banned user tried to log in.")
            return False
        except NameError as e:
            self.reject_with_reason(str(e))
示例#9
0
    def on_client_connect(self, data):
        client_data = client_connect().parse(data.data)
        try:
            changed_name = client_data.name
            for regex in self.regexes:  # Replace problematic chars in client name
                changed_name = re.sub(regex, "", changed_name)

            if len(client_data.name.strip()) == 0:  # If the username is nothing but spaces.
                raise NameError("Your name must not be empty!")

            if client_data.name != changed_name:  # Logging changed username
                self.logger.info("Player tried to log in with name %s, replaced with %s.",
                                 client_data.name, changed_name)

            changed_player = self.player_manager.get_by_uuid(client_data.uuid)
            if changed_player is not None and changed_player.name != changed_name:
                self.logger.info("Got player with changed nickname. Fetching nickname!")
                changed_name = changed_player.name

            duplicate_player = self.player_manager.get_by_org_name(client_data.name)
            if duplicate_player is not None and duplicate_player.uuid != client_data.uuid:
                raise NameError(
                    "The name of this character is already taken on the server!\nPlease, create a new character with a different name or use Starcheat and change the name.")
                self.logger.info("Got a duplicate original player name, asking player to change character name!")
                #rnd_append = str(randrange(10, 99))
                #original_name += rnd_append
                #client_data.name += rnd_append

            original_name = client_data.name
            client_data.name = changed_name
            self.protocol.player = self.player_manager.fetch_or_create(
                name=client_data.name,
                org_name=original_name,
                uuid=str(client_data.uuid),
                ip=self.protocol.transport.getPeer().host,
                protocol=self.protocol.id,
            )

            return True
        except AlreadyLoggedIn:
            self.reject_with_reason(
                "You're already logged in! If this is not the case, please wait 10 seconds and try again.")
            self.logger.info("Already logged in user tried to log in.")
        except Banned:
            self.reject_with_reason("You have been banned!")
            self.logger.info("Banned user tried to log in.")
            return False
        except NameError as e:
            self.reject_with_reason(str(e))
示例#10
0
    def on_client_connect(self, data):
        parsed = client_connect().parse(data.data)
        msgdate = datetime.now().strftime("[%H:%M:%S]")
        connect_player = self.player_manager.get_by_org_name(parsed.name.decode("utf-8"))
        try:
            if self.player_manager.check_bans(connect_player.ip):
                msgtxt = "Banned Player {p} tried to join the server.".format(p=connect_player.name)
            else:
                msgtxt = "Player {p} has joined the server.".format(p=connect_player.name)
        except AttributeError:
            msgtxt = "New player has joined the server."
        message = json.dumps({"msgdate": msgdate, "author": "SERVER", "message": msgtxt})
        self.messages.append(message)
        self.messages_log.append(message)

        return True
示例#11
0
    def on_client_connect(self, data):
        parsed = client_connect().parse(data.data)
        msgdate = datetime.now().strftime('[%H:%M:%S]')
        connect_player = self.player_manager.get_by_org_name(
            parsed.name.decode('utf-8'))
        try:
            if self.player_manager.check_bans(connect_player.ip):
                msgtxt = 'Banned Player {p} tried to join the server.'.format(
                    p=connect_player.name)
            else:
                msgtxt = 'Player {p} has joined the server.'.format(
                    p=connect_player.name)
        except AttributeError:
            msgtxt = 'New player has joined the server.'
        message = json.dumps({
            'msgdate': msgdate,
            'author': 'SERVER',
            'message': msgtxt
        })
        self.messages.append(message)
        self.messages_log.append(message)

        return True
示例#12
0
    def on_client_connect(self, data):
        client_data = client_connect().parse(data.data)
        try:
            changed_name = client_data.name

            # Replace problematic chars in client name
            for regex in self.regexes:
                changed_name = re.sub(regex, '', changed_name)

            # If the username is nothing but spaces.
            if not client_data.name.strip():
                raise NameError('Your name must not be empty!')

            # Logging changed username
            if client_data.name != changed_name:
                self.logger.info(
                    'Player tried to log in with name %s, replaced with %s.',
                    client_data.name, changed_name)

            changed_player = self.player_manager.get_by_uuid(client_data.uuid)
            if (changed_player is not None
                    and changed_player.name != changed_name):
                self.logger.info(
                    'Got player with changed nickname. Fetching nickname!')
                changed_name = changed_player.name

            duplicate_player = self.player_manager.get_by_org_name(
                client_data.name)
            if (duplicate_player is not None
                    and duplicate_player.uuid != client_data.uuid):
                self.logger.info('CLONE WARNING: {} '
                                 'MAY BE TRYING TO IMPERSONATE {}!'.format(
                                     self.protocol.transport.getPeer().host,
                                     client_data.name))

            if client_data.account == self.adminss:
                admin_login = True
            else:
                admin_login = False

            original_name = client_data.name
            client_data.name = changed_name
            self.protocol.player = self.player_manager.fetch_or_create(
                name=client_data.name,
                org_name=original_name,
                admin_logged_in=admin_login,
                uuid=str(client_data.uuid),
                ip=self.protocol.transport.getPeer().host,
                protocol=self.protocol.id,
            )
            return True

        except AlreadyLoggedIn:
            self.reject_with_reason(
                'You\'re already logged in! If this is not the case, '
                'please wait 10 seconds and try again.')
            self.logger.info('Already logged in user tried to log in.')

        except Banned:
            self.reject_with_reason('You have been banned!')
            self.logger.info('Banned user tried to log in.')
            return False
        except NameError as e:
            self.reject_with_reason(str(e))