コード例 #1
0
    def net_cmd_hi(self, args):
        """Handshake.

        HI#<hdid:string>#%

        :param args: a list containing all the arguments

        """
        if self.client.is_checked:
            self.client.disconnect()
            return

        if not self.validate_net_cmd(args, self.ArgType.STR, needs_auth=False):
            return
        hdid = self.client.hdid = args[0]
        ipid = self.client.ipid

        database.add_hdid(ipid, hdid)
        ban = database.find_ban(ipid, hdid)

        if ban is not None:
            try:
                special_ban_data = json.loads(ban.ban_data)
            except (ValueError, TypeError):
                special_ban_data = None

            if special_ban_data is not None:
                try:
                    if special_ban_data['ban_type'] == 'area_curse':
                        self.client.area_curse = special_ban_data[
                            'target_area']
                        self.client.area_curse_info = ban
                        self.client.change_area(
                            self.server.area_manager.get_area_by_id(
                                self.client.area_curse))
                except (KeyError, ValueError):
                    pass
            else:
                if ban.unban_date is not None:
                    unban_date = arrow.get(ban.unban_date)
                else:
                    unban_date = 'N/A'

                msg = f'{ban.reason}\r\n'
                msg += f'ID: {ban.ban_id}\r\n'
                msg += f'Until: {unban_date.humanize()}'

                database.log_connect(self.client, failed=True)
                self.client.send_command('BD', msg)
                self.client.disconnect()
                return

        self.client.is_checked = True

        database.log_connect(self.client, failed=False)
        self.client.send_command('ID', self.client.id, self.server.software,
                                 self.server.version)
        self.client.send_command('PN', self.server.player_count,
                                 self.server.config['playerlimit'])
コード例 #2
0
ファイル: aoprotocol.py プロジェクト: RealKaiser/tsuserverCC
	def net_cmd_hi(self, args):
		"""
		Handshake.
		
		HI#<hdid:string>#%

		:param args: a list containing all the arguments

		"""
		if not self.validate_net_cmd(args, ArgType.STR, needs_auth=False):
			return
		hdid = self.client.hdid = args[0]
		ipid = self.client.ipid

		database.add_hdid(ipid, hdid)
		ban = database.find_ban(ipid, hdid)
		if ban is not None:
			
			if ban.unban_date is not None:
				unban_date = arrow.get(ban.unban_date)
			else:
				unban_date = 'N/A'
	
			msg = f'{ban.reason}\r\n'
			msg += f'ID: {ban.ban_id}\r\n'
			
			if unban_date == 'N/A':
				msg += f'Until: {unban_date}'
			else:
				msg += f'Until: {unban_date.humanize()}'
	
			database.log_connect(self.client, failed=True)
			self.client.send_command('BD', msg)
			self.client.disconnect()
			return
			
		else:
			self.client.is_checked = True

		database.log_connect(self.client, failed=False)
		self.client.send_command('ID', self.client.id, self.server.software,
								 self.server.version)
		self.client.send_command('PN',
								 self.server.player_count,
								 self.server.config['playerlimit'])