Ejemplo n.º 1
0
    async def add_map(self, filename, player):
        map_path = os.path.join(self.current_dir, filename)
        logging.debug('Adding map ' + map_path)

        try:
            # Try to parse the map.
            async with self.app.instance.storage.open_map(map_path) as map_fh:
                parser = gbxparser.GbxParser(buffer=map_fh)
                map_info = await parser.parse()

            # Check if already on server.
            if self.app.instance.map_manager.playlist_has_map(map_info['uid']):
                raise Exception(
                    'Map already in playlist! Update? Remove it first!')

            # Add if not.
            if await self.app.instance.map_manager.add_map(map_path):
                message = '$ff0Admin $fff{}$z$s$ff0 has added the map $fff{}$z$s$ff0 by $fff{}$z$s$ff0.'.format(
                    player.nickname, map_info['name'],
                    map_info['author_nickname'])
                await self.app.instance.chat(message)
            else:
                raise Exception('Unknown error while adding the map!')
        except Exception as e:
            logger.warning(
                'Error when player {} was adding map from local disk: {}'.
                format(player.login, str(e)))
            await self.app.instance.chat(
                '$ff0Error: Can\'t add map, Error: {}'.format(str(e)),
                player.login)
Ejemplo n.º 2
0
    async def add_local_map(self, player, data, **kwargs):
        map_file = data.map

        if not await self.instance.storage.driver.exists(
                'UserData/Maps/{}'.format(map_file)):
            message = '$ff0Error: Can\'t add map because the file is not found!'
            await self.instance.chat(message, player.login)
            return

        try:
            # Parse GBX file.
            async with self.instance.storage.open_map(map_file) as map_fh:
                parser = gbxparser.GbxParser(buffer=map_fh)
                map_info = await parser.parse()

            # Test if map isn't yet in our current map list.
            if self.instance.map_manager.playlist_has_map(map_info['uid']):
                raise Exception(
                    'Map already in playlist! Update? remove it first!')

            # Insert map to server.
            result = await self.instance.map_manager.add_map(map_file)

            if result:
                message = '$ff0Admin $fff{}$z$s$ff0 has added the map $fff{}$z$s$ff0 by $fff{}$z$s$ff0.'.format(
                    player.nickname, map_info['name'],
                    map_info['author_nickname'])
                await self.instance.chat(message)
            else:
                raise Exception('Unknown error while adding the map!')
        except Exception as e:
            logger.warning(
                'Error when player {} was adding map from local disk: {}'.
                format(player.login, str(e)))
            message = '$ff0Error: Can\'t add map, Error: {}'.format(str(e))
            await self.instance.chat(message, player.login)
Ejemplo n.º 3
0
    async def add_local_map(self, player, data, **kwargs):
        map_file = data.map

        # Check for the file.
        if not await self.instance.storage.driver.exists(
                'UserData/Maps/{}'.format(map_file)):
            message = '$ff0Error: Can\'t add map because the file is not found!'
            await self.instance.chat(message, player.login)
            return

        # Fetch setting if juke after adding is enabled.
        juke_maps = await self.setting_juke_after_adding.get_value()
        if 'jukebox' not in self.instance.apps.apps:
            juke_maps = False
        juke_list = list()

        try:
            # Parse GBX file.
            async with self.instance.storage.open_map(map_file) as map_fh:
                parser = gbxparser.GbxParser(buffer=map_fh)
                map_info = await parser.parse()

            # Test if map isn't yet in our current map list.
            if self.instance.map_manager.playlist_has_map(map_info['uid']):
                raise Exception(
                    'Map already in playlist! Update? remove it first!')

            # Insert map to server.
            result = await self.instance.map_manager.add_map(map_file)

            if result:
                # Juke if setting has been provided.
                if juke_maps:
                    juke_list.append(map_info['uid'])

                message = '$ff0Admin $fff{}$z$s$ff0 has added{} the map $fff{}$z$s$ff0 by $fff{}$z$s$ff0.'.format(
                    player.nickname, ' and juked' if juke_maps else '',
                    map_info['name'], map_info['author_nickname'])
                await self.instance.chat(message)
            else:
                raise Exception('Unknown error while adding the map!')

            # Save match settings after inserting maps.
            try:
                await self.instance.map_manager.save_matchsettings()
            except:
                pass

            # Reindex and create maps in database.
            try:
                await self.instance.map_manager.update_list(full_update=True)
            except:
                pass

            # Jukebox all the maps requested, in order.
            if juke_maps and len(juke_list) > 0:
                # Fetch map objects.
                for juke_uid in juke_list:
                    map_instance = await self.instance.map_manager.get_map(
                        uid=juke_uid)
                    if map_instance:
                        self.instance.apps.apps['jukebox'].insert_map(
                            player, map_instance)

        except Exception as e:
            logger.warning(
                'Error when player {} was adding map from local disk: {}'.
                format(player.login, str(e)))
            message = '$ff0Error: Can\'t add map, Error: {}'.format(str(e))
            await self.instance.chat(message, player.login)