Exemplo n.º 1
0
    async def load_blacklist(self, filename=None):
        """
		Load blacklist file.

		:param filename: File to load or will get from settings.
		:raise: pyplanet.core.exceptions.ImproperlyConfigured
		:raise: pyplanet.core.storage.exceptions.StorageException
		:return: Boolean if loaded.
		"""
        setting = settings.BLACKLIST_FILE
        if isinstance(setting,
                      dict) and self._instance.process_name in setting:
            setting = setting[self._instance.process_name]
        if not isinstance(setting, str):
            setting = None

        if not filename and not setting:
            raise ImproperlyConfigured(
                'The setting \'BLACKLIST_FILE\' is not configured for this server! We can\'t load the Blacklist!'
            )
        if not filename:
            filename = setting.format(
                server_login=self._instance.game.server_player_login)

        try:
            self._instance.gbx('LoadBlackList', filename)
        except Exception as e:
            logging.exception(e)
            raise StorageException(
                'Can\'t load blacklist according the dedicated server, tried loading from \'{}\'!'
                .format(filename)) from e
Exemplo n.º 2
0
    async def save_blacklist(self, filename=None):
        """
		Save the current blacklisted players to file given or fetch from config.

		:param filename: Give the filename of the blacklist, Leave empty to use the current loaded and configured one.
		:type filename: str
		:raise: pyplanet.core.exceptions.ImproperlyConfigured
		:raise: pyplanet.core.storage.exceptions.StorageException
		"""
        setting = settings.BLACKLIST_FILE
        if isinstance(setting,
                      dict) and self._instance.process_name in setting:
            setting = setting[self._instance.process_name]
        if not isinstance(setting, str):
            setting = None

        if not filename and not setting:
            raise ImproperlyConfigured(
                'The setting \'BLACKLIST_FILE\' is not configured for this server! We can\'t save the Blacklist!'
            )
        if not filename:
            filename = setting.format(
                server_login=self._instance.game.server_player_login)

        try:
            await self._instance.gbx('SaveBlackList', filename)
        except Exception as e:
            logging.exception(e)
            raise StorageException(
                'Can\'t save blacklist file to \'{}\'!'.format(
                    filename)) from e