def __init__(self, config, name): """ Create a factory and world. ``name`` is the string used to look up factory-specific settings from the configuration. :param str name: internal name of this factory """ self.name = name self.config = config self.config_name = "world %s" % name self.world = World(self.config, self.name) self.world.factory = self self.protocols = dict() self.connectedIPs = defaultdict(int) self.mode = self.config.get(self.config_name, "mode") if self.mode not in ("creative", "survival"): raise Exception("Unsupported mode %s" % self.mode) self.limitConnections = self.config.getintdefault( self.config_name, "limitConnections", 0) self.limitPerIP = self.config.getintdefault(self.config_name, "limitPerIP", 0) self.vane = WeatherVane(self)
def setUp(self): # Set up world. self.name = "unittest" self.d = tempfile.mkdtemp() self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "file://%s" % self.d) self.bcp.set("world unittest", "serializer", "alpha") self.w = World(self.bcp, self.name) self.w.pipeline = [] self.w.start() # And finally the mock factory. self.f = RedstoneMockFactory() self.f.world = self.w pp = {"factory": self.f} self.p = retrieve_plugins(IDigHook, parameters=pp) if "redstone" not in self.p: raise unittest.SkipTest("Plugin not present") self.hook = self.p["redstone"]
def setUp(self): # Set up world. self.name = "unittest" self.d = tempfile.mkdtemp() self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "file://%s" % self.d) self.bcp.set("world unittest", "serializer", "alpha") self.w = World(self.bcp, self.name) self.w.pipeline = [] self.w.start() # And finally the mock factory. self.f = PhysicsMockFactory() self.f.world = self.w # Using dig hook to grab the plugin since the build hook was nuked in # favor of the automaton interface. pp = {"factory": self.f} self.p = bravo.plugin.retrieve_plugins(IDigHook, parameters=pp) if "water" not in self.p: raise unittest.SkipTest("Plugin not present") self.hook = self.p["water"]
def setUp(self): self.name = "unittest" self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "") self.bcp.set("world unittest", "serializer", "memory") self.w = World(self.bcp, self.name) self.w.pipeline = []
def setUp(self): self.name = "unittest" self.d = tempfile.mkdtemp() self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "file://%s" % self.d) self.bcp.set("world unittest", "serializer", "alpha") self.w = World(self.bcp, self.name) self.w.pipeline = [] self.w.start()
def __init__(self, name): """ Create a factory and world. ``name`` is the string used to look up factory-specific settings from the configuration. :param str name: internal name of this factory """ log.msg("Initializing factory for world '%s'..." % name) self.name = name self.config_name = "world %s" % name self.port = configuration.getint(self.config_name, "port") self.interface = configuration.getdefault(self.config_name, "host", "") self.world = World(name) self.world.factory = self if configuration.has_option(self.config_name, "perm_cache"): cache_level = configuration.getint(self.config_name, "perm_cache") self.world.enable_cache(cache_level) self.protocols = dict() self.eid = 1 self.time = self.world.time self.time_loop = LoopingCall(self.update_time) self.time_loop.start(2) authenticator = configuration.get(self.config_name, "authenticator") selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0] log.msg("Using authenticator %s" % selected.name) self.handshake_hook = selected.handshake self.login_hook = selected.login generators = configuration.getlist(self.config_name, "generators") generators = retrieve_sorted_plugins(ITerrainGenerator, generators) log.msg("Using generators %s" % ", ".join(i.name for i in generators)) self.world.pipeline = generators self.chat_consumers = set() log.msg("Factory successfully initialized for world '%s'!" % name)
def setUp(self): self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "") self.bcp.set("world unittest", "serializer", "memory") self.w = World(self.bcp, "unittest") self.w.pipeline = [] self.w.start() self.f = GrassMockFactory() self.f.world = self.w self.w.factory = self.f plugins = retrieve_plugins(IAutomaton, factory=self.f) self.hook = plugins["grass"]
def setUp(self): # Set up world. self.name = "unittest" self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "") self.bcp.set("world unittest", "serializer", "memory") self.w = World(self.bcp, self.name) self.w.pipeline = [] self.w.start() # And finally the mock factory. self.f = RedstoneMockFactory() self.f.world = self.w self.p = retrieve_plugins(IDigHook, factory=self.f) self.hook = self.p["redstone"]
def setUp(self): # Set up world. self.name = "unittest" self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "") self.bcp.set("world unittest", "serializer", "memory") self.w = World(self.bcp, self.name) self.w.pipeline = [] self.w.start() # And finally the mock factory. self.f = PhysicsMockFactory() self.f.world = self.w # Using dig hook to grab the plugin since the build hook was nuked in # favor of the automaton interface. self.p = bravo.plugin.retrieve_plugins(IDigHook, factory=self.f) self.hook = self.p["water"]
def startFactory(self): log.msg("Initializing factory for world '%s'..." % self.name) self.world = World(self.name) self.world.factory = self if configuration.has_option(self.config_name, "perm_cache"): cache_level = configuration.getint(self.config_name, "perm_cache") self.world.enable_cache(cache_level) self.protocols = dict() log.msg("Starting timekeeping...") self.timestamp = time() self.time = self.world.time self.update_season() self.time_loop = LoopingCall(self.update_time) self.time_loop.start(2) authenticator = configuration.get(self.config_name, "authenticator") selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0] log.msg("Using authenticator %s" % selected.name) self.handshake_hook = selected.handshake self.login_hook = selected.login generators = configuration.getlist(self.config_name, "generators") generators = retrieve_sorted_plugins(ITerrainGenerator, generators) log.msg("Using generators %s" % ", ".join(i.name for i in generators)) self.world.pipeline = generators automatons = configuration.getlist(self.config_name, "automatons") automatons = retrieve_named_plugins(IAutomaton, automatons) log.msg("Using automatons %s" % ", ".join(i.name for i in automatons)) self.automatons = automatons self.chat_consumers = set() log.msg("Factory successfully initialized for world '%s'!" % self.name)
def setUp(self): self.d = tempfile.mkdtemp() self.bcp = BravoConfigParser() self.bcp.add_section("world unittest") self.bcp.set("world unittest", "url", "file://%s" % self.d) self.bcp.set("world unittest", "serializer", "alpha") self.w = World(self.bcp, "unittest") self.w.pipeline = [] self.w.start() self.f = GrassMockFactory() self.f.world = self.w self.w.factory = self.f pp = {"factory": self.f} plugins = retrieve_plugins(IAutomaton, parameters=pp) if "grass" not in plugins: raise unittest.SkipTest("Plugin not present") self.hook = plugins["grass"]
d = retrieve_plugins(ITerrainGenerator) size = int(sys.argv[1]) pipeline = [d[name] for name in sys.argv[2].split(",")] target = sys.argv[3] print "Making map of %dx%d chunks in %s" % (size, size, target) print "Using pipeline: %s" % ", ".join(plugin.name for plugin in pipeline) config = BravoConfigParser() config.add_section("world mapgen") config.set("world mapgen", "url", target) config.set("world mapgen", "serializer", "beta") world = World(config, "mapgen") world.connect() world.pipeline = pipeline world.season = None world.saving = True counts = [1, 2, 4, 5, 8] count = 0 total = size**2 cpu = 0 before = time.time() for i, j in product(xrange(size), repeat=2): start = time.time() d = world.request_chunk(i, j) cpu += (time.time() - start)
print "Not enough arguments." sys.exit() d = retrieve_plugins(ITerrainGenerator) size = int(sys.argv[1]) pipeline = [d[name] for name in sys.argv[2].split(",")] target = sys.argv[3] if not os.path.exists(target): os.makedirs(target) print "Making map of %dx%d chunks in %s" % (size, size, target) print "Using pipeline: %s" % ", ".join(plugin.name for plugin in pipeline) world = World(target) world.pipeline = pipeline world.season = None counts = [1, 2, 4, 5, 8] count = 0 total = size**2 cpu = 0 before = time.time() for i, j in product(xrange(size), repeat=2): start = time.time() chunk = world.load_chunk(i, j) cpu += (time.time() - start) world.save_chunk(chunk) count += 1