def CreatePlayer(): try: Player.byPublicName("ThePlayer") except: world = World.byName("TheWorld") #move me zone = Zone.byName(world.startZone) dzone = Zone.byName(world.dstartZone) mzone = Zone.byName(world.mstartZone) p = Player(publicName="ThePlayer",password="******",fantasyName="ThePlayer",logZone=zone,bindZone=zone,darknessLogZone=dzone,darknessBindZone=dzone, monsterLogZone=mzone,monsterBindZone=mzone) #temp t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p.logTransformInternal= t p.bindTransformInternal= t p.darknessLogTransformInternal= dt p.darknessBindTransformInternal= dt p.monsterLogTransformInternal= mt p.monsterBindTransformInternal= mt user = User(name="ThePlayer",password="******") user.addRole(Role.byName("Player")) user.addRole(Role.byName("Immortal"))
def perspective_newPlayer(self,publicName,fantasyName, playerPassword = None): #XXX if you change this function, also change it's mirror in cserveravatar!!! if self.world.pwNewPlayer and playerPassword != self.world.pwNewPlayer: return (-1,"Incorrect player password.",None) #does player already exist? try: player = Player.byPublicName(publicName) except: pass else: return (-1,"You already have an account on this world.",None) try: player = Player.byFantasyName(fantasyName) except: pass else: return (-1,"That avatar name is taken, please choose another.",None) password = GenPasswd().upper() #move me from mud.world.zone import Zone zone = Zone.byName(self.world.startZone) dzone = Zone.byName(self.world.dstartZone) mzone = Zone.byName(self.world.mstartZone) t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p = Player(publicName=publicName,password=password,fantasyName=publicName,logZone=zone,bindZone=zone,darknessLogZone=dzone,darknessBindZone=dzone,monsterLogZone=mzone,monsterBindZone=mzone) #temp p.logTransformInternal=t p.bindTransformInternal=t p.darknessLogTransformInternal=dt p.darknessBindTransformInternal=dt p.monsterLogTransformInternal=mt p.monsterBindTransformInternal=mt user = User(name=publicName,password=password) user.addRole(Role.byName("Player")) if publicName == NewPlayerAvatar.ownerPublicName: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) return (0,"Immortal Account Created.\nYour password is %s"%password,password) return (0,"Account Created.\nYour password is %s"%password,password)
def IDESetup(): if not CoreSettings.IDE: return if CoreSettings.IDE_ZONE: z = Zone.byName(CoreSettings.IDE_ZONE) p = Player.byPublicName("ThePlayer") settransform = False if p.logZone != z or p.darknessLogZone != z or p.monsterLogZone != z: settransform = True p.logZone=z p.bindZone=z p.darknessLogZone=z p.darknessBindZone=z p.monsterLogZone=z p.monsterBindZone=z if settransform: t = z.immTransform p.logTransformInternal= t p.bindTransformInternal= t p.darknessLogTransformInternal= t p.darknessBindTransformInternal= t p.monsterLogTransformInternal= t p.monsterBindTransformInternal= t
def __init__(self,username,role,mind): Avatar.__init__(self,username,role,mind) self.username = username self.mind = mind self.player = Player.byPublicName(username) from mud.world.theworld import World self.world = World.byName("TheWorld")
def __init__(self, username, role, mind): Avatar.__init__(self, username, role, mind) self.username = username self.mind = mind self.player = Player.byPublicName(username) from mud.world.theworld import World self.world = World.byName("TheWorld")
def IDESetup(): if not CoreSettings.IDE: return if CoreSettings.IDE_ZONE: z = Zone.byName(CoreSettings.IDE_ZONE) p = Player.byPublicName("ThePlayer") settransform = False if p.logZone != z or p.darknessLogZone != z or p.monsterLogZone != z: settransform = True p.logZone = z p.bindZone = z p.darknessLogZone = z p.darknessBindZone = z p.monsterLogZone = z p.monsterBindZone = z if settransform: t = z.immTransform p.logTransformInternal = t p.bindTransformInternal = t p.darknessLogTransformInternal = t p.darknessBindTransformInternal = t p.monsterLogTransformInternal = t p.monsterBindTransformInternal = t
def perspective_queryPlayer(self,publicName): #does player already exist? try: player = Player.byPublicName(publicName) except: return False else: return True
def perspective_queryPlayer(self, publicName): #does player already exist? try: player = Player.byPublicName(publicName) except: return False else: return True
def perspective_setPlayerSimObject(self,publicName,simObject): #XXX security, check that player is in Zone #this could be used maliciously player = Player.byPublicName(publicName) player.simObject = simObject self.zone.playerEnterZone(player) self.addSimObject(simObject) self.playerLookup[simObject]=player
def install(self): if not FROMGAME: print "Installing Player: %s" % self.dbAttr["publicName"] # Restore log and bind zone data for the three realms. try: bindZone = Zone.byName(self.bindZone) logZone = Zone.byName(self.logZone) except: bindZone = Zone.byName(self.world.startZone) logZone = Zone.byName(self.world.startZone) self.dbAttr["bindTransformInternal"] = bindZone.immTransform self.dbAttr["logTransformInternal"] = logZone.immTransform try: darknessBindZone = Zone.byName(self.darknessBindZone) darknessLogZone = Zone.byName(self.darknessLogZone) except: darknessBindZone = Zone.byName(self.world.dstartZone) darknessLogZone = Zone.byName(self.world.dstartZone) self.dbAttr[ "darknessBindTransformInternal"] = darknessBindZone.immTransform self.dbAttr[ "darknessLogTransformInternal"] = darknessLogZone.immTransform try: monsterBindZone = Zone.byName(self.monsterBindZone) monsterLogZone = Zone.byName(self.monsterLogZone) except: monsterBindZone = Zone.byName(self.world.mstartZone) monsterLogZone = Zone.byName(self.world.mstartZone) self.dbAttr[ "monsterBindTransformInternal"] = monsterBindZone.immTransform self.dbAttr[ "monsterLogTransformInternal"] = monsterLogZone.immTransform #todo, initial monster before live self.dbAttr["bindZoneID"] = bindZone.id self.dbAttr["logZoneID"] = logZone.id self.dbAttr["darknessBindZoneID"] = darknessBindZone.id self.dbAttr["darknessLogZoneID"] = darknessLogZone.id self.dbAttr["monsterBindZoneID"] = monsterBindZone.id self.dbAttr["monsterLogZoneID"] = monsterLogZone.id FilterColumns(Player, self.dbAttr) player = Player(**self.dbAttr) # Restore character data on this player. for c in self.characters: c.install(player) # Restore monster spawn data on this player. for f in self.mspawns: f.install(player) # Restore bank items of this player. for i in self.items: i.install(player, bank=True)
def remote_kickPlayer(self,publicName): try: player = Player.byPublicName(publicName) except: return try: world = player.world world.kickPlayer(player) except: traceback.print_exc()
def remote_kickPlayer(self, publicName): try: player = Player.byPublicName(publicName) except: return try: world = player.world world.kickPlayer(player) except: traceback.print_exc()
def CreatePlayer(): try: Player.byPublicName("ThePlayer") except: world = World.byName("TheWorld") #move me zone = Zone.byName(world.startZone) dzone = Zone.byName(world.dstartZone) mzone = Zone.byName(world.mstartZone) p = Player(publicName="ThePlayer", password="******", fantasyName="ThePlayer", logZone=zone, bindZone=zone, darknessLogZone=dzone, darknessBindZone=dzone, monsterLogZone=mzone, monsterBindZone=mzone) #temp t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p.logTransformInternal = t p.bindTransformInternal = t p.darknessLogTransformInternal = dt p.darknessBindTransformInternal = dt p.monsterLogTransformInternal = mt p.monsterBindTransformInternal = mt user = User(name="ThePlayer", password="******") user.addRole(Role.byName("Player")) user.addRole(Role.byName("Immortal"))
def createPlayer(self, publicName, code): #from newplayeravatar import NewPlayerAvatar #XXX if you change this function, also change it's mirror in cserveravatar!!! password = GenPasswd().upper() #move me zone = Zone.byName(self.world.startZone) dzone = Zone.byName(self.world.dstartZone) mzone = Zone.byName(self.world.mstartZone) t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p = Player(publicName=publicName, password=password, fantasyName=publicName, logZone=zone, bindZone=zone, darknessLogZone=dzone, darknessBindZone=dzone, monsterLogZone=mzone, monsterBindZone=mzone) #temp p.logTransformInternal = t p.bindTransformInternal = t p.darknessLogTransformInternal = dt p.darknessBindTransformInternal = dt p.monsterLogTransformInternal = mt p.monsterBindTransformInternal = mt user = User(name=publicName, password=password) user.addRole(Role.byName("Player")) if code == 2: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) elif code == 1: user.addRole(Role.byName("Guardian")) return p
def remote_transferPlayer(self,publicName,pbuffer,charname,cbuffer,code,premium,remoteLeaderName,guildInfo): #pbuffer = loads(decodestring(pbuffer)) presults = self.remote_installPlayer(publicName,pbuffer,code,premium,guildInfo) if not presults[0]: #failure! return presults player = Player.byPublicName(publicName) Player.remoteLeaderNames[publicName]=remoteLeaderName cbuffer = loads(decodestring(cbuffer)) InstallCharacterBuffer(player.id,charname,cbuffer) return presults
def __init__(self,username,role,mind): Avatar.__init__(self,username,role,mind) self.mind = mind self.username = username if username == "ZoneServer": self.dedicated = True self.player = None #dedicated! else: self.player = Player.byPublicName(username) self.dedicated = False self.zone = None self.world = World.byName("TheWorld") self.playerLookup ={} self.simObjects = [] self.simLookup = {}
def remote_transferPlayer(self, publicName, pbuffer, charname, cbuffer, code, premium, remoteLeaderName, guildInfo): #pbuffer = loads(decodestring(pbuffer)) presults = self.remote_installPlayer(publicName, pbuffer, code, premium, guildInfo) if not presults[0]: #failure! return presults player = Player.byPublicName(publicName) Player.remoteLeaderNames[publicName] = remoteLeaderName cbuffer = loads(decodestring(cbuffer)) InstallCharacterBuffer(player.id, charname, cbuffer) return presults
def createPlayer(self,publicName,code): #from newplayeravatar import NewPlayerAvatar #XXX if you change this function, also change it's mirror in cserveravatar!!! password = GenPasswd().upper() #move me zone = Zone.byName(self.world.startZone) dzone = Zone.byName(self.world.dstartZone) mzone = Zone.byName(self.world.mstartZone) t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p = Player(publicName=publicName,password=password,fantasyName=publicName,logZone=zone,bindZone=zone,darknessLogZone=dzone,darknessBindZone=dzone,monsterLogZone=mzone,monsterBindZone=mzone) #temp p.logTransformInternal=t p.bindTransformInternal=t p.darknessLogTransformInternal=dt p.darknessBindTransformInternal=dt p.monsterLogTransformInternal=mt p.monsterBindTransformInternal=mt user = User(name=publicName,password=password) user.addRole(Role.byName("Player")) if code == 2: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) elif code == 1: user.addRole(Role.byName("Guardian")) return p
def perspective_onClientEnterGame(self,publicName): player = Player.byPublicName(publicName) #get spawn infos for each party member spinfos = [] for c in player.party.members: spinfos.append(c.spawn.getSpawnInfo()) mobInfos = [] for c in player.party.members: mobInfos.append(c.mob.mobInfo) transform = player.logTransform if player.darkness: transform = player.darknessLogTransform if player.monster: transform = player.monsterLogTransform r = player.avatar.masterPerspective.role.name if player.monster: r = "Monster" return (transform,spinfos,mobInfos,player.modelIndex,r)
def perspective_newPlayer(self, publicName, fantasyName, playerPassword=None): #XXX if you change this function, also change it's mirror in cserveravatar!!! if self.world.pwNewPlayer and playerPassword != self.world.pwNewPlayer: return (-1, "Incorrect player password.", None) #does player already exist? try: player = Player.byPublicName(publicName) except: pass else: return (-1, "You already have an account on this world.", None) try: player = Player.byFantasyName(fantasyName) except: pass else: return (-1, "That avatar name is taken, please choose another.", None) password = GenPasswd().upper() #move me from mud.world.zone import Zone zone = Zone.byName(self.world.startZone) dzone = Zone.byName(self.world.dstartZone) mzone = Zone.byName(self.world.mstartZone) t = zone.immTransform dt = dzone.immTransform mt = mzone.immTransform p = Player(publicName=publicName, password=password, fantasyName=publicName, logZone=zone, bindZone=zone, darknessLogZone=dzone, darknessBindZone=dzone, monsterLogZone=mzone, monsterBindZone=mzone) #temp p.logTransformInternal = t p.bindTransformInternal = t p.darknessLogTransformInternal = dt p.darknessBindTransformInternal = dt p.monsterLogTransformInternal = mt p.monsterBindTransformInternal = mt user = User(name=publicName, password=password) user.addRole(Role.byName("Player")) if publicName == NewPlayerAvatar.ownerPublicName: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) return (0, "Immortal Account Created.\nYour password is %s" % password, password) return (0, "Account Created.\nYour password is %s" % password, password)
def remote_installPlayer(self,publicName,buffer,code,premium,guildInfo): from mud.server.app import THESERVER if buffer: buffer = loads(decodestring(buffer)) if not THESERVER.allowConnections: return (False,"This world is currently unavailable. Please try again in a few minutes.") for p in self.world.activePlayers: if p.publicName == publicName: return (False,"Player already on world") #destroy player p = None try: p = Player.byPublicName(publicName) except: pass if p: #we must destroy this player (this should probably be changed to raw sql for speed) p.destroySelf() try: user = User.byName(publicName) for r in user.roles: r.removeUser(user) user.destroySelf() except: pass if buffer and buffer != "None": error = self.installPlayerBuffer(buffer) if error: return (False,"Error installing player buffer") try: p = Player.byPublicName(publicName) password = GenPasswd().upper() p.password = password user = User(name=publicName,password=password) user.addRole(Role.byName("Player")) if code == 2: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) elif code == 1: user.addRole(Role.byName("Guardian")) except: traceback.print_exc() return (False,"Error setting up installed player") else: try: p = self.createPlayer(publicName,code) except: traceback.print_exc() return (False,"Error creating new player") p.premium = premium p.fantasyName = p.publicName #legacy p.guildName = guildInfo[0] p.guildInfo = guildInfo[1] p.guildMOTD = guildInfo[2] p.guildRank = guildInfo[3] return (True,p.password)
def tick(): global TICK_COUNTER if not AVATAR: return #not official #error? if not AVATAR.mind: return if AVATAR.world.shuttingDown: return try: now = sysTime() #ship off any player buffers from the last time try: from mud.worldserver.charutil import PLAYER_BUFFERS for pname,pbuffer,cbuffer,cvalues in PLAYER_BUFFERS[:]: pbuf = encodestring(dumps(pbuffer, 2)) cbuf = None if cbuffer: cbuf = encodestring(dumps(cbuffer, 2)) print "Sending Player/Character buffers: %s (%ik/%ik)"%(pname,len(pbuf)/1024,len(cbuf)/1024) AVATAR.mind.callRemote("savePlayerBuffer",pname,pbuf,cbuf,cvalues) #xxx add callback/errback EXTRACT_TIMES[pname]=now #should be removing these upon success PLAYER_BUFFERS.remove((pname,pbuffer,cbuffer,cvalues)) except: traceback.print_exc() TICK_COUNTER -= 3 if TICK_COUNTER > 0: return TICK_COUNTER = 6 * 15 #once every minute pnames = [] extractTarget = None best = 0 for p in AVATAR.world.activePlayers: if not p.zone or p.enteringWorld: continue pname = p.publicName pnames.append(pname) extractionTimer = EXTRACT_TIMES.setdefault(pname,now) t = now - extractionTimer if t < (60 * 10): continue if t > best: best = t extractTarget = pname remove = [] for k in EXTRACT_TIMES.iterkeys(): if k not in pnames: remove.append(k) map(EXTRACT_TIMES.__delitem__,remove) if extractTarget: p = Player.byPublicName(extractTarget) #already in active chars if p and p.party: p.backupItems() ExtractPlayer(p.publicName,p.id,p.party.members[0].id) except: traceback.print_exc() #send off all players try: pnames = [] #it's still possible that the player is installed but isn't active #so 2 people sharing an account could still cause problems for p in AVATAR.world.activePlayers: cname = "" if p.curChar: cname = p.curChar.name zname = "" if p.zone: zname = p.zone.zone.niceName pnames.append((p.publicName,cname,p.guildName,zname)) d = AVATAR.mind.callRemote("recordActivePlayers",AVATAR.world.multiName,pnames) d.addCallback(AVATAR.gotGlobalPlayers) except: traceback.print_exc()
def remote_installPlayer(self, publicName, buffer, code, premium, guildInfo): from mud.server.app import THESERVER if buffer: buffer = loads(decodestring(buffer)) if not THESERVER.allowConnections: return ( False, "This world is currently unavailable. Please try again in a few minutes." ) for p in self.world.activePlayers: if p.publicName == publicName: return (False, "Player already on world") #destroy player p = None try: p = Player.byPublicName(publicName) except: pass if p: #we must destroy this player (this should probably be changed to raw sql for speed) p.destroySelf() try: user = User.byName(publicName) for r in user.roles: r.removeUser(user) user.destroySelf() except: pass if buffer and buffer != "None": error = self.installPlayerBuffer(buffer) if error: return (False, "Error installing player buffer") try: p = Player.byPublicName(publicName) password = GenPasswd().upper() p.password = password user = User(name=publicName, password=password) user.addRole(Role.byName("Player")) if code == 2: user.addRole(Role.byName("Immortal")) user.addRole(Role.byName("Guardian")) elif code == 1: user.addRole(Role.byName("Guardian")) except: traceback.print_exc() return (False, "Error setting up installed player") else: try: p = self.createPlayer(publicName, code) except: traceback.print_exc() return (False, "Error creating new player") p.premium = premium p.fantasyName = p.publicName #legacy p.guildName = guildInfo[0] p.guildInfo = guildInfo[1] p.guildMOTD = guildInfo[2] p.guildRank = guildInfo[3] return (True, p.password)
def tick(): global TICK_COUNTER if not AVATAR: return #not official #error? if not AVATAR.mind: return if AVATAR.world.shuttingDown: return try: now = sysTime() #ship off any player buffers from the last time try: from mud.worldserver.charutil import PLAYER_BUFFERS for pname, pbuffer, cbuffer, cvalues in PLAYER_BUFFERS[:]: pbuf = encodestring(dumps(pbuffer, 2)) cbuf = None if cbuffer: cbuf = encodestring(dumps(cbuffer, 2)) print "Sending Player/Character buffers: %s (%ik/%ik)" % ( pname, len(pbuf) / 1024, len(cbuf) / 1024) AVATAR.mind.callRemote("savePlayerBuffer", pname, pbuf, cbuf, cvalues) #xxx add callback/errback EXTRACT_TIMES[pname] = now #should be removing these upon success PLAYER_BUFFERS.remove((pname, pbuffer, cbuffer, cvalues)) except: traceback.print_exc() TICK_COUNTER -= 3 if TICK_COUNTER > 0: return TICK_COUNTER = 6 * 15 #once every minute pnames = [] extractTarget = None best = 0 for p in AVATAR.world.activePlayers: if not p.zone or p.enteringWorld: continue pname = p.publicName pnames.append(pname) extractionTimer = EXTRACT_TIMES.setdefault(pname, now) t = now - extractionTimer if t < (60 * 10): continue if t > best: best = t extractTarget = pname remove = [] for k in EXTRACT_TIMES.iterkeys(): if k not in pnames: remove.append(k) map(EXTRACT_TIMES.__delitem__, remove) if extractTarget: p = Player.byPublicName( extractTarget) #already in active chars if p and p.party: p.backupItems() ExtractPlayer(p.publicName, p.id, p.party.members[0].id) except: traceback.print_exc() #send off all players try: pnames = [] #it's still possible that the player is installed but isn't active #so 2 people sharing an account could still cause problems for p in AVATAR.world.activePlayers: cname = "" if p.curChar: cname = p.curChar.name zname = "" if p.zone: zname = p.zone.zone.niceName pnames.append((p.publicName, cname, p.guildName, zname)) d = AVATAR.mind.callRemote("recordActivePlayers", AVATAR.world.multiName, pnames) d.addCallback(AVATAR.gotGlobalPlayers) except: traceback.print_exc()