def joinDefaultWorld(self): """ Joins the default world. """ mode = self.factory.settings["main"]["entry-mode"] if mode == "solo": # Find out which WS has the default world and join it def afterGetDefaultWorld(res): hasFailed(res) if not res: raise wsf = self.factory.getFactory("WorldServerCommServerFactory") # Get world server link if res[0]["worldServerID"] not in wsf.worldServers: # WorldServer down, raise hell self.logger.debug(str(res[0])) raise WorldServerLinkException(200, "World server link not established") # Send the player over wsf.worldServers[res[0]["worldServerID"]].protoDoJoinServer(self, res[0]["id"]) # TODO World name or ID? return self.db.runQuery( *World.select(World.name, World.id, World.filePath, World.worldServerID).where(World.isDefault == 1).sql() ).addCallbacks(afterGetDefaultWorld, self._joinWorldFailedErrback) elif mode == "distributed": # Find out which WS has the default world and join any of them. self.otherThings()
def loadWorldByID(self, worldID): """ Loads the world given the ID. """ def afterWorldSelect(res): if len(res) == 0: self.logger.error("No world with ID named {} found".format(worldID)) return self.loadWorld(res[0]) return self.db.runQuery(*World.select().where( World.worldServerID == self.id and World.id == worldID).sql( )).addCallback(afterWorldSelect)
def loadWorldByWorldName(self, worldName): """ Loads the world given its name :param worldName The world name. :return int World ID. """ def afterWorldSelect(res): if len(res) == 0: self.logger.error("No world named {} found".format(worldName)) return self.loadWorld(res[0]) return self.db.runQuery(*World.select().where( World.worldServerID == self.id and World.name == worldName).sql() ).addCallback(afterWorldSelect)
def loadPreloadedWorlds(self): """ Loads the world that needs to be preloaded. """ # TODO Check for broken data? def afterWorldSelect(res): if len(res) == 0: self.logger.critical("No default world set; did you run the installation script?") self.parentService.stop() return self.loadWorld(res[0]) return self.db.runQuery(*World.select().where( World.worldServerID == self.id and (World.preloadAtServerStart == 1 or World.isDefault == 1)).sql() ).addCallback(afterWorldSelect)
def assignWorldServer(self, proto, world=None): if not world: world = "default" # TODO Link to settings assert proto.wsID is None, "Tried to reassign already assigned client." def afterAddedNewClient(wsProto): # Confirm the assginment proto.wsID = wsProto.id self.logger.info(wsProto.id) def gotWorldServer(res): hasFailed(res) if not res: raise NoResultsException ws = res[0]["worldServerID"] if ws not in self.getFactory("WorldServerCommServerFactory").worldServers: raise WorldServerLinkNotEstablishedException wsProto = self.getFactory("WorldServerCommServerFactory").worldServers[ws] return wsProto.protoDoJoinServer(proto, world).addCallback(noArgs(afterAddedNewClient), wsProto) return self.db.runQuery( *World.select(World.worldServerID).where(World.name == world).sql() ).addBoth(gotWorldServer)
def getWorldServerByWorldName(self, worldName): return self.db.runQuery(*World.select(World.worldServerID).where(World.name == worldName).sql())