def __init__(self, name): """ Load a world from disk. :Parameters: name : str The configuration key to use to look up configuration data. """ world_url = configuration.get("world %s" % name, "url") world_sf_name = configuration.get("world %s" % name, "serializer") sf = retrieve_named_plugins(ISerializerFactory, [world_sf_name])[0] self.serializer = sf(world_url) verifyObject(ISerializer, self.serializer) self.chunk_cache = weakref.WeakValueDictionary() self.dirty_chunk_cache = dict() self._pending_chunks = dict() self.spawn = (0, 0, 0) self.seed = random.randint(0, sys.maxint) self.serializer.load_level(self) self.serializer.save_level(self) self.chunk_management_loop = LoopingCall(self.sort_chunks) self.chunk_management_loop.start(1) log.msg("World started on %s, using serializer %s" % (world_url, self.serializer.name)) log.msg("Using Ampoule: %s" % async)
def signedOn(self): for channel in configuration.get(self.config, "channels").split(","): if configuration.has_option(self.config, "%s_key" % channel): key = configuration.get(self.config, "%s_key" % channel) else: key = None self.join(channel, key)
def __init__(self): BetaServerProtocol.__init__(self) log.msg("Registering client hooks...") names = configuration.get("bravo", "build_hooks").split(",") self.build_hooks = retrieve_named_plugins(IBuildHook, names) names = configuration.get("bravo", "dig_hooks").split(",") self.dig_hooks = retrieve_named_plugins(IDigHook, names) self.last_dig_build_timer = time()
def __init__(self, name): self.name = name self.port = configuration.getint("infininode %s" % name, "port") self.gateway = configuration.get("infininode %s" % name, "gateway") if configuration.has_option("infininode %s" % name, "private_key"): self.private_key = configuration.get("infininode %s" % name, "private_key") self.broadcast_loop = LoopingCall(self.broadcast) self.broadcast_loop.start(220)
def start(self): """ Load a world from disk. """ world_url = configuration.get(self.config_name, "url") world_sf_name = configuration.get(self.config_name, "serializer") try: sf = retrieve_named_plugins(ISerializerFactory, [world_sf_name])[0] self.serializer = verify_plugin(ISerializer, sf(world_url)) except PluginException, pe: log.msg(pe) raise RuntimeError("Fatal error: Couldn't set up serializer!")
def __init__(self, worlds, config): """ Set up. :param str config: configuration key to use for finding settings """ self.factories = dict((factory.name, factory) for factory in worlds) self.config = "irc %s" % config self.host = configuration.get(self.config, "server") self.nickname = configuration.get(self.config, "nick") log.msg("Spawned IRC client '%s'!" % config)
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.port = configuration.getint("world %s" % name, "port") if configuration.has_option("world %s" % name, "host"): self.interface = configuration.get("world %s" % name, "host") world_folder = configuration.get("world %s" % name, "path") self.world = World(world_folder) self.world.factory = self if configuration.has_option("world %s" % name, "perm_cache"): cache_level = configuration.getint("world %s" % name, "perm_cache") self.world.enable_cache(cache_level) self.protocols = dict() self.eid = 1 self.entities = set() self.time_loop = LoopingCall(self.update_time) self.time_loop.start(2) authenticator = configuration.get("world %s" % 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("bravo", "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 __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 """ self.name = name self.config_name = "world %s" % name self.world = World(self.name) self.world.factory = self self.protocols = dict() self.connectedIPs = defaultdict(int) self.mode = configuration.get(self.config_name, "mode") if self.mode not in ("creative", "survival"): raise Exception("Unsupported mode %s" % self.mode) self.limitConnections = configuration.getintdefault(self.config_name, "limitConnections", 0) self.limitPerIP = configuration.getintdefault(self.config_name, "limitPerIP", 0) self.vane = WeatherVane(self)
def startFactory(self): log.msg("Initializing factory for world '%s'..." % self.name) 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 # Get our plugins set up. self.register_plugins() log.msg("Starting world...") self.world.start() if configuration.has_option(self.config_name, "perm_cache"): cache_level = configuration.getint(self.config_name, "perm_cache") self.world.enable_cache(cache_level) log.msg("Starting timekeeping...") self.timestamp = reactor.seconds() self.time = self.world.time self.update_season() self.time_loop = LoopingCall(self.update_time) self.time_loop.start(2) # Start automatons. for automaton in self.automatons: automaton.start() self.chat_consumers = set() log.msg("Factory successfully initialized for world '%s'!" % self.name)
def __init__(self, worlds, config): """ Set up. :param str config: configuration key to use for finding settings """ self.factories = dict((factory.name, factory) for factory in worlds) for factory in self.factories.itervalues(): factory.chat_consumers.add(self) self.config = "irc %s" % config self.host = configuration.get(self.config, "server") self.nickname = configuration.get(self.config, "nick") self.channels = set() log.msg("Spawned IRC client '%s'!" % config)
def __init__(self, name): """ Load a world from disk. :Parameters: name : str The configuration key to use to look up configuration data. """ self.config_name = "world %s" % name world_url = configuration.get(self.config_name, "url") world_sf_name = configuration.get(self.config_name, "serializer") try: sf = retrieve_named_plugins(ISerializerFactory, [world_sf_name])[0] self.serializer = verify_plugin(ISerializer, sf(world_url)) except PluginException, pe: log.msg(pe) raise RuntimeError("Fatal error: Couldn't set up serializer!")
def __init__(self, factories, config): """ Set up. :param str config: configuration key to use for finding settings """ self.factories = factories for factory in self.factories: factory.chat_consumers.add(self) self.config = "irc %s" % config self.name = self.config self.host = configuration.get(self.config, "server") self.nickname = configuration.get(self.config, "nick") self.channels = set() log.msg("Spawned IRC client '%s'!" % config)
def login(self, protocol, container): if container.password != configuration.get("bravo", "password"): protocol.error("Wrong password.") return fail() protocol.username = container.username packet = make_packet("login", protocol=protocol.eid, username="", unused="", seed=0, dimension=0) protocol.transport.write(packet) return succeed(None)
def login(self, protocol, container): if container.password != configuration.get("bravo", "password"): protocol.error("Wrong password.") return fail() protocol.username = container.username packet = make_packet("login", protocol=protocol.eid, username="", unused="", seed=protocol.factory.world.seed, dimension=protocol.factory.world.dimension) protocol.transport.write(packet) return succeed(None)
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 """ self.name = name self.port = configuration.getint(name, "port") world_folder = configuration.get(name, "world") self.world = World(world_folder) self.world.factory = self self.protocols = dict() self.eid = 1 self.entities = set() self.time_loop = LoopingCall(self.update_time) self.time_loop.start(2) authenticator = configuration.get("bravo", "authenticator") selected = retrieve_named_plugins(IAuthenticator, [authenticator])[0] print "Using authenticator %s" % selected.name self.handshake_hook = selected.handshake self.login_hook = selected.login generators = configuration.get("bravo", "generators").split(",") generators = retrieve_named_plugins(ITerrainGenerator, generators) print "Using generators %s" % ", ".join(i.name for i in generators) self.world.pipeline = generators print "Factory init'd"
def login(self, protocol, container): if container.password != configuration.get("bravo", "password"): protocol.error("Wrong password.") return fail() protocol.username = container.username packet = make_packet("login", protocol=protocol.eid, username="", seed=protocol.factory.world.seed, mode=protocol.factory.mode, dimension=protocol.factory.world.dimension, unknown=1, height=128, players=0) protocol.transport.write(packet) return succeed(None)
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 pipeline(): generators = configuration.get("bravo", "generators").split(",") generators = retrieve_named_plugins(ITerrainGenerator, generators) before = time.time() for i in range(10): chunk = Chunk(i, i) for generator in generators: generator.populate(chunk, 0) after = time.time() return after - before
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)
from bravo.config import configuration if configuration.get("bravo", "serializer") in ("alpha", "nbt"): from bravo.serializers.alpha import * elif configuration.get("bravo", "serializer") in ("json",): from bravo.serializers.json_serializer import * else: print "Warning: Early start: Couldn't find preferred serializer %s" % (configuration.get("bravo", "serializer")) print "Defaulting to NBT." from bravo.serializers.alpha import * __all__ = ( "ChestSerializer", "ChunkSerializer", "InventorySerializer", "LevelSerializer", "PlayerSerializer", "SignSerializer", "read_from_file", "write_to_file", "extension", )
def request_chunk(self, x, z): """ Request a ``Chunk`` to be delivered later. :returns: Deferred that will be called with the Chunk """ if not async: return deferLater(reactor, 0.000001, self.factory.world.load_chunk, x, z) if (x, z) in self.chunk_cache: return succeed(self.chunk_cache[x, z]) elif (x, z) in self.dirty_chunk_cache: return succeed(self.dirty_chunk_cache[x, z]) elif (x, z) in self._pending_chunks: # Rig up another Deferred and wrap it up in a to-go box. d = Deferred() self._pending_chunks[x, z].chainDeferred(d) return d chunk = Chunk(x, z) first, second, filename = names_for_chunk(x, z) f = self.folder.child(first).child(second) if not f.exists(): f.makedirs() f = f.child(filename) if f.exists() and f.getsize(): chunk.load_from_tag(read_from_file(f.open("r"))) if chunk.populated: self.chunk_cache[x, z] = chunk return succeed(chunk) d = deferToAMPProcess(MakeChunk, x=x, z=z, seed=self.seed, generators=configuration.get("bravo", "generators")) self._pending_chunks[x, z] = d def pp(kwargs): chunk.blocks = fromstring(kwargs["blocks"], dtype=uint8).reshape(chunk.blocks.shape) chunk.heightmap = fromstring(kwargs["heightmap"], dtype=uint8).reshape(chunk.heightmap.shape) chunk.metadata = fromstring(kwargs["metadata"], dtype=uint8).reshape(chunk.metadata.shape) chunk.skylight = fromstring(kwargs["skylight"], dtype=uint8).reshape(chunk.skylight.shape) chunk.blocklight = fromstring(kwargs["blocklight"], dtype=uint8).reshape(chunk.blocklight.shape) chunk.populated = True chunk.dirty = True # Apply the current season to the chunk. if self.season: self.season.transform(chunk) # Since this chunk hasn't been given to any player yet, there's no # conceivable way that any meaningful damage has been accumulated; # anybody loading any part of this chunk will want the entire thing. # Thus, it should start out undamaged. chunk.clear_damage() self.dirty_chunk_cache[x, z] = chunk del self._pending_chunks[x, z] return chunk # Set up callbacks. d.addCallback(pp) # Multiple people might be subscribed to this pending callback. We're # going to keep it for ourselves and fork off another Deferred for our # caller. forked = Deferred() d.chainDeferred(forked) forked.addCallback(lambda none: chunk) return forked
def __init__(self, worlds, config): self.worlds = worlds self.config = config self.host = configuration.get("irc %s" % config, "server") self.port = configuration.getint("irc %s" % config, "port")
from bravo.config import configuration if configuration.get("bravo", "serializer") in ("alpha", "nbt"): from bravo.serializers.alpha import * elif configuration.get("bravo", "serializer") in ("json",): from bravo.serializers.json import * else: print "Warning: Early start: Couldn't find preferred serializer %s" % ( configuration.get("bravo", "serializer")) print "Defaulting to JSON." from bravo.serializers.json import * __all__ = ( "ChestSerializer", "ChunkSerializer", "InventorySerializer", "LevelSerializer", "PlayerSerializer", "SignSerializer", "read_from_file", "write_to_file", "extension", )
def __init__(self, factories, config): self.factories = factories self.config = config self.host = configuration.get("irc %s" % config, "server") self.port = configuration.getint("irc %s" % config, "port")