Example #1
0
    def __init__(self, name):
        BetaServerProtocol.__init__(self)

        self.config_name = "world %s" % name

        log.msg("Registering client hooks...")
        names = configuration.getlistdefault(self.config_name, "build_hooks",
                                             [])
        self.build_hooks = retrieve_sorted_plugins(IBuildHook, names)
        names = configuration.getlistdefault(self.config_name, "dig_hooks", [])
        self.dig_hooks = retrieve_sorted_plugins(IDigHook, names)
        names = configuration.getlistdefault(self.config_name, "sign_hooks",
                                             [])
        self.sign_hooks = retrieve_sorted_plugins(ISignHook, names)

        names = configuration.getlistdefault(self.config_name, "use_hooks", [])
        self.use_hooks = defaultdict(list)
        for plugin in retrieve_named_plugins(IUseHook, names):
            for target in plugin.targets:
                self.use_hooks[target].append(plugin)

        # Retrieve the MOTD. Only needs to be done once.
        self.motd = configuration.getdefault(self.config_name, "motd", None)

        self.last_dig_build_timer = time()
Example #2
0
File: beta.py Project: driax/bravo
    def __init__(self, name):
        BetaServerProtocol.__init__(self)

        self.config_name = "world %s" % name

        log.msg("Registering client hooks...")
        names = configuration.getlistdefault(self.config_name, "pre_build_hooks",
            [])
        self.pre_build_hooks = retrieve_sorted_plugins(IPreBuildHook, names)
        names = configuration.getlistdefault(self.config_name, "post_build_hooks",
            [])
        self.post_build_hooks = retrieve_sorted_plugins(IPostBuildHook, names)
        names = configuration.getlistdefault(self.config_name, "dig_hooks",
            [])
        self.dig_hooks = retrieve_sorted_plugins(IDigHook, names)
        names = configuration.getlistdefault(self.config_name, "sign_hooks",
            [])
        self.sign_hooks = retrieve_sorted_plugins(ISignHook, names)

        names = configuration.getlistdefault(self.config_name, "use_hooks",
            [])
        self.use_hooks = defaultdict(list)
        for plugin in retrieve_named_plugins(IUseHook, names):
            for target in plugin.targets:
                self.use_hooks[target].append(plugin)

        log.msg("Registering policies...")
        self.dig_policy = dig_policies["notchy"]

        # Retrieve the MOTD. Only needs to be done once.
        self.motd = configuration.getdefault(self.config_name, "motd", None)
Example #3
0
File: beta.py Project: dequis/bravo
    def __init__(self):
        BetaServerProtocol.__init__(self)

        log.msg("Registering client hooks...")
        names = configuration.getlistdefault("bravo", "build_hooks", [])
        self.build_hooks = retrieve_sorted_plugins(IBuildHook, names)
        names = configuration.getlistdefault("bravo", "dig_hooks", [])
        self.dig_hooks = retrieve_sorted_plugins(IDigHook, names)
        names = configuration.getlistdefault("bravo", "sign_hooks", [])
        self.sign_hooks = retrieve_sorted_plugins(ISignHook, names)

        self.last_dig_build_timer = time()
Example #4
0
File: beta.py Project: dequis/bravo
    def __init__(self):
        BetaServerProtocol.__init__(self)

        log.msg("Registering client hooks...")
        names = configuration.getlistdefault("bravo", "build_hooks", [])
        self.build_hooks = retrieve_sorted_plugins(IBuildHook, names)
        names = configuration.getlistdefault("bravo", "dig_hooks", [])
        self.dig_hooks = retrieve_sorted_plugins(IDigHook, names)
        names = configuration.getlistdefault("bravo", "sign_hooks", [])
        self.sign_hooks = retrieve_sorted_plugins(ISignHook, names)

        self.last_dig_build_timer = time()
Example #5
0
    def update_season(self):
        """
        Update the world's season.
        """

        plugins = configuration.getlistdefault(self.config_name, "seasons", [])
        for plugin in retrieve_named_plugins(ISeason, plugins):
            if plugin.day == self.day:
                self.world.season = plugin
Example #6
0
    def update_season(self):
        """
        Update the world's season.
        """

        plugins = configuration.getlistdefault(self.config_name, "seasons", [])
        for plugin in retrieve_named_plugins(ISeason, plugins):
            if plugin.day == self.day:
                self.world.season = plugin
Example #7
0
    def register_plugins(self):
        """
        Setup plugin hooks.
        """

        log.msg("Registering client plugin hooks...")

        plugin_types = {
            "automatons": IAutomaton,
            "generators": ITerrainGenerator,
            "seasons": ISeason,
            "open_hooks": IWindowOpenHook,
            "click_hooks": IWindowClickHook,
            "close_hooks": IWindowCloseHook,
            "pre_build_hooks": IPreBuildHook,
            "post_build_hooks": IPostBuildHook,
            "pre_dig_hooks": IPreDigHook,
            "dig_hooks": IDigHook,
            "sign_hooks": ISignHook,
            "use_hooks": IUseHook,
        }

        pp = {"factory": self,
              "furnaces": self.furnace_manager}

        for t, interface in plugin_types.iteritems():
            l = configuration.getlistdefault(self.config_name, t, [])
            if issubclass(interface, ISortedPlugin):
                plugins = retrieve_sorted_plugins(interface, l, parameters=pp)
            else:
                plugins = retrieve_named_plugins(interface, l, parameters=pp)
            log.msg("Using %s: %s" % (t.replace("_", " "),
                ", ".join(plugin.name for plugin in plugins)))
            setattr(self, t, plugins)

        # Assign generators to the world pipeline.
        self.world.pipeline = self.generators

        # Use hooks have special funkiness.
        uh = self.use_hooks
        self.use_hooks = defaultdict(list)
        for plugin in uh:
            for target in plugin.targets:
                self.use_hooks[target].append(plugin)
Example #8
0
File: beta.py Project: driax/bravo
    def update_season(self):
        """
        Update the world's season.
        """

        # Get a sorted list of all the seasons
        plugins = configuration.getlistdefault(self.config_name, "seasons", [])
        all_seasons = list(retrieve_named_plugins(ISeason, plugins))
        all_seasons.sort(key=lambda s: s.day)

        # Get all the seasons that we have past the start date of this year.
        # We are looking for the season which is closest to our current day,
        # without going over; I call this the Price-is-Right style of season
        # handling. :3
        past_seasons = [s for s in all_seasons if s.day <= self.day]
        if past_seasons:
            # The most recent one is the one we are in
            self.world.season = past_seasons[-1]
        else:
            # We haven't past any seasons yet this year, so grab the last one
            # from 'last year'
            self.world.season = all_seasons[-1]