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)
def protoDoJoinServer(self, proto, world=None): """ Makes the protocol join the server. """ # Send the basic information over def afterNewPlayer(): d = self.sendStateUpdate(proto.sessionID, proto.player, requireResponse=True) self.logger.info("Sent request for {} to join worldServer {}".format(proto.player["username"], self.id)) return d return self.sendNewPlayer(proto.sessionID).addCallback(noArgs(afterNewPlayer))
def gotData(): # OK, see if there's anyone else with that username usernameList = self.parent.factory.buildUsernameList() if self.parent.player["username"].lower() in usernameList: # Kick the other guy out self.parent.factory.clients[usernameList[self.parent.player["username"]]]["protocol"].sendError( "You logged in on another computer.", disconnectNow=True) return # All check complete. Request World Server to prepare level self.parent.identified = True self.parent.factory.assignWorldServer(self.parent).addBoth(noArgs(afterAssignedWorldServer))
def gotBans(data): # Are they banned? if data: self.parent.sendError("You are banned: {}".format(data["reason"])) return self.parent.factory.getUserByUsername(self.parent.player["username"]).addBoth(populateData).addBoth(noArgs(gotData))
def afterDBAPIReady(): # Get our ID wsFactory.loadID().addCallback(noArgs(afterLoadedSelfID))
def afterLoadedSelfID(): serv.factories["WorldServerFactory"].loadPreloadedWorlds().addCallback(noArgs(afterLoadedPreloadedWorlds))