示例#1
0
    def __init__(self, server):
        super().__init__(server)

        if self.server.config.type == 'world':
            self.server.penguin_string_compiler[
                'Nameglow'] = PenguinStringCompiler.custom_attribute_by_name(
                    'nameglow')
            self.server.penguin_string_compiler[
                'Namecolor'] = PenguinStringCompiler.custom_attribute_by_name(
                    'namecolor')
            self.server.penguin_string_compiler[
                'Bubblecolor'] = PenguinStringCompiler.custom_attribute_by_name(
                    'bubblecolor')
            self.server.penguin_string_compiler[
                'Bubbletext'] = PenguinStringCompiler.custom_attribute_by_name(
                    'bubbletext')
            self.server.penguin_string_compiler[
                'Ringcolor'] = PenguinStringCompiler.custom_attribute_by_name(
                    'ringcolor')
            self.server.penguin_string_compiler[
                'Size'] = PenguinStringCompiler.custom_attribute_by_name(
                    'size')
            self.server.penguin_string_compiler[
                'Transparency'] = PenguinStringCompiler.custom_attribute_by_name(
                    'transparency')
            self.server.penguin_string_compiler[
                'Rotation'] = PenguinStringCompiler.custom_attribute_by_name(
                    'rotation')
            self.server.penguin_string_compiler[
                'Walls'] = PenguinStringCompiler.custom_attribute_by_name(
                    'walls')
            self.server.penguin_string_compiler[
                'Speed'] = PenguinStringCompiler.custom_attribute_by_name(
                    'speed')
            self.server.penguin_string_compiler[
                'Mood'] = PenguinStringCompiler.custom_attribute_by_name(
                    'mood')
            self.server.penguin_string_compiler[
                'Moodcolor'] = PenguinStringCompiler.custom_attribute_by_name(
                    'moodcolor')
            self.server.penguin_string_compiler[
                'Snowball'] = PenguinStringCompiler.custom_attribute_by_name(
                    'snowball')
示例#2
0
    async def start(self):
        self.config = config

        self.server_config = copy.deepcopy(
            self.config.servers[self.server_name])
        self.server_config.update(self.server_config_override)

        self.config.database.update(self.database_config_override)
        self.config.redis.update(self.redis_config_override)
        self.config.commands.update(self.commands_config_override)
        self.config.client.update(self.client_config_override)

        general_log_directory = os.path.dirname(
            self.server_config["Logging"]["General"])
        errors_log_directory = os.path.dirname(
            self.server_config["Logging"]["Errors"])

        if not os.path.exists(general_log_directory):
            os.mkdir(general_log_directory)

        if not os.path.exists(errors_log_directory):
            os.mkdir(errors_log_directory)

        self.logger = logging.getLogger('houdini')
        universal_handler = RotatingFileHandler(
            self.server_config['Logging']['General'],
            maxBytes=2097152,
            backupCount=3,
            encoding='utf-8')

        error_handler = logging.FileHandler(
            self.server_config['Logging']['Errors'])
        console_handler = logging.StreamHandler(stream=sys.stdout)

        log_formatter = logging.Formatter(
            '%(asctime)s [%(levelname)-5.5s]  %(message)s')
        error_handler.setLevel(logging.ERROR)

        universal_handler.setFormatter(log_formatter)
        console_handler.setFormatter(log_formatter)

        self.logger.addHandler(universal_handler)
        self.logger.addHandler(console_handler)
        self.logger.addHandler(error_handler)

        level = logging.getLevelName(self.server_config['Logging']['Level'])
        self.logger.setLevel(level)

        self.server = await asyncio.start_server(self.client_connected,
                                                 self.server_config['Address'],
                                                 self.server_config['Port'])

        await self.db.set_bind('postgresql://{}:{}@{}/{}'.format(
            self.config.database['Username'], self.config.database['Password'],
            self.config.database['Address'], self.config.database['Name']))

        self.logger.info('Booting Houdini')

        self.redis = await aioredis.create_redis_pool('redis://{}:{}'.format(
            self.config.redis['Address'], self.config.redis['Port']),
                                                      minsize=5,
                                                      maxsize=10)

        if self.server_config['World']:
            await self.redis.delete(
                f'houdini.players.{self.server_config["Id"]}')
            await self.redis.hdel(f'houdini.population',
                                  self.server_config["Id"])

            caches.set_config({
                'default': {
                    'cache': SimpleMemoryCache,
                    'namespace': 'houdini',
                    'ttl': self.server_config['CacheExpiry']
                }
            })
            self.cache = caches.get('default')

            self.client_class = Penguin
            self.penguin_string_compiler = PenguinStringCompiler()
            self.anonymous_penguin_string_compiler = PenguinStringCompiler()

            PenguinStringCompiler.setup_default_builder(
                self.penguin_string_compiler)
            PenguinStringCompiler.setup_anonymous_default_builder(
                self.anonymous_penguin_string_compiler)

            await self.xml_listeners.setup(
                houdini.handlers, exclude_load='houdini.handlers.login.login')
            await self.xt_listeners.setup(houdini.handlers)
            await self.dummy_event_listeners.setup(houdini.handlers)
            self.logger.info('World server started')
        else:
            await self.xml_listeners.setup(houdini.handlers,
                                           'houdini.handlers.login.login')
            self.logger.info('Login server started')

        self.items = await ItemCollection.get_collection()
        self.logger.info(f'Loaded {len(self.items)} clothing items')

        self.igloos = await IglooCollection.get_collection()
        self.logger.info(f'Loaded {len(self.igloos)} igloos')

        self.furniture = await FurnitureCollection.get_collection()
        self.logger.info(f'Loaded {len(self.furniture)} furniture items')

        self.locations = await LocationCollection.get_collection()
        self.logger.info(f'Loaded {len(self.locations)} igloo locations')

        self.flooring = await FlooringCollection.get_collection()
        self.logger.info(f'Loaded {len(self.flooring)} igloo flooring')

        self.rooms = await RoomCollection.get_collection()
        self.spawn_rooms = self.rooms.spawn_rooms
        await self.rooms.setup_tables()
        await self.rooms.setup_waddles()
        self.logger.info(
            f'Loaded {len(self.rooms)} rooms ({len(self.spawn_rooms)} spawn)')

        self.postcards = await PostcardCollection.get_collection()
        self.logger.info(f'Loaded {len(self.postcards)} postcards')

        self.stamps = await StampCollection.get_collection()
        self.logger.info(f'Loaded {len(self.stamps)} stamps')

        self.cards = await CardCollection.get_collection()
        self.logger.info(f'Loaded {len(self.cards)} ninja cards')

        self.puffles = await PuffleCollection.get_collection()
        self.logger.info(f'Loaded {len(self.puffles)} puffles')

        self.puffle_items = await PuffleItemCollection.get_collection()
        self.logger.info(f'Loaded {len(self.puffle_items)} puffle care items')

        self.characters = await CharacterCollection.get_collection()
        self.logger.info(f'Loaded {len(self.characters)} characters')

        self.permissions = await PermissionCollection.get_collection()

        self.logger.info(
            f'Multi-client support is '
            f'{"enabled" if self.config.client["MultiClientSupport"] else "disabled"}'
        )
        self.logger.info(
            f'Listening on {self.server_config["Address"]}:{self.server_config["Port"]}'
        )

        if self.config.client['AuthStaticKey'] != 'houdini':
            self.logger.warning(
                'The static key has been changed from the default, '
                'this may cause authentication issues!')

        await self.plugins.setup(houdini.plugins)

        self.heartbeat = asyncio.create_task(server_heartbeat(self))
        self.egg_timer = asyncio.create_task(server_egg_timer(self))

        self.music = SoundStudio(self)

        async with self.server:
            await self.server.serve_forever()
示例#3
0
    async def start(self):
        general_log_file = self.config.logging_general_path if self.config.logging_general_path \
            else f'logs/{self.config.name.lower()}.log'
        errors_log_file = self.config.logging_error_path if self.config.logging_error_path \
            else f'logs/{self.config.name.lower()}-errors.log'
        general_log_directory = os.path.dirname(general_log_file)
        errors_log_directory = os.path.dirname(errors_log_file)

        if not os.path.exists(general_log_directory):
            os.mkdir(general_log_directory)

        if not os.path.exists(errors_log_directory):
            os.mkdir(errors_log_directory)

        self.logger = logging.getLogger('houdini')
        universal_handler = RotatingFileHandler(general_log_file,
                                                maxBytes=2097152,
                                                backupCount=3,
                                                encoding='utf-8')

        error_handler = logging.FileHandler(errors_log_file)
        console_handler = logging.StreamHandler(stream=sys.stdout)

        log_formatter = logging.Formatter(
            '%(asctime)s [%(levelname)-5.5s]  %(message)s')
        error_handler.setLevel(logging.ERROR)

        universal_handler.setFormatter(log_formatter)
        console_handler.setFormatter(log_formatter)

        self.logger.addHandler(universal_handler)
        self.logger.addHandler(console_handler)
        self.logger.addHandler(error_handler)

        level = logging.getLevelName(self.config.logging_level)
        self.logger.setLevel(level)

        self.server = await asyncio.start_server(self.client_connected,
                                                 self.config.address,
                                                 self.config.port)

        await self.db.set_bind('postgresql://{}:{}@{}/{}'.format(
            self.config.database_username, self.config.database_password,
            self.config.database_address, self.config.database_name))

        self.logger.info('Booting Houdini')

        self.redis = await aioredis.create_redis_pool('redis://{}:{}'.format(
            self.config.redis_address, self.config.redis_port),
                                                      minsize=5,
                                                      maxsize=10)

        if self.config.type == 'world':
            await self.redis.delete(f'houdini.players.{self.config.id}')
            await self.redis.hset(f'houdini.population', self.config.id, 0)

            self.cache = Cache(maxsize=None, ttl=self.config.cache_expiry)

            self.client_class = Penguin
            self.penguin_string_compiler = PenguinStringCompiler()
            self.anonymous_penguin_string_compiler = PenguinStringCompiler()

            PenguinStringCompiler.setup_default_builder(
                self.penguin_string_compiler)
            PenguinStringCompiler.setup_anonymous_default_builder(
                self.anonymous_penguin_string_compiler)

            await self.xml_listeners.setup(
                houdini.handlers, exclude_load='houdini.handlers.login.login')
            await self.xt_listeners.setup(houdini.handlers)
            self.logger.info('World server started')
        else:
            await self.xml_listeners.setup(houdini.handlers,
                                           'houdini.handlers.login.login')
            self.logger.info('Login server started')

        await self.dummy_event_listeners.setup(houdini.handlers)
        await self.dummy_event_listeners.fire('boot', self)

        self.permissions = await PermissionCollection.get_collection()

        self.logger.info(
            f'Multi-client support is '
            f'{"enabled" if not self.config.single_client_mode else "disabled"}'
        )
        self.logger.info(
            f'Listening on {self.config.address}:{self.config.port}')

        if self.config.auth_key != 'houdini':
            self.logger.warning(
                'The static key has been changed from the default, '
                'this may cause authentication issues!')

        await self.plugins.setup(houdini.plugins)

        self.heartbeat = asyncio.create_task(server_heartbeat(self))
        self.egg_timer = asyncio.create_task(server_egg_timer(self))
        self.puffle_killer = asyncio.create_task(decrease_stats(self))

        self.music = SoundStudio(self)

        async with self.server:
            await self.server.serve_forever()