Fixed initial_setup and set up the _playable_characters attribute on all players, for handling multi-accounts. Still some issues with how the character's permissions is accessed.

This commit is contained in:
Griatch 2013-02-03 20:04:40 +01:00
parent 70b8f074f1
commit b82a75d816
6 changed files with 40 additions and 57 deletions

View file

@ -735,9 +735,11 @@ class CmdOOCLook(MuxCommandOOC, CmdLook):
"Hook method for when an argument is given." "Hook method for when an argument is given."
# caller is assumed to be a player object here. # caller is assumed to be a player object here.
caller = self.caller caller = self.caller
looktarget = caller.get_character(key=self.args) key = self.args.lower()
chars = dict((utils.to_str(char.key.lower()), char) for char in caller.db._playable_characters)
looktarget = chars.get(key)
if looktarget: if looktarget:
caller.msg(looktarget.return_appearance()) caller.msg(looktarget.return_appearance(caller))
else: else:
caller.msg("No such character.") caller.msg("No such character.")
return return
@ -748,24 +750,22 @@ class CmdOOCLook(MuxCommandOOC, CmdLook):
player = self.caller player = self.caller
sessid = self.sessid sessid = self.sessid
# get all our characters # get all our characters
characters = player.get_all_characters() # get all characters characters = player.db._playable_characters
string = "You are logged in as {g%s{n." % player.key string = "You are logged in as {g%s{n." % player.key
string += " Use {w@ic <character>{n to enter the game." string += " Use {w@ic <character>{n to enter the game."
string += "\n\nAvailable character%s:" % (len(characters) > 1 and "s" or "") if characters:
for char in characters: string += "\n\nAvailable character%s:" % (len(characters) > 1 and "s" or "")
csessid = char.sessid for char in characters:
if csessid: csessid = char.sessid
# character is already puppeted if csessid:
if csessid == sessid: # character is already puppeted
# this should not happen. if player.get_session(csessid):
string += "\n - {r%s{n (sessid not properly cleared! Contact an admin!)" % char.key string += "\n - {G%s{n (played by you in another session)"
elif player.get_session(csessid): else:
string += "\n - {G%s{n (played by you in another session)" string += "\n - {R%s{n (played by someone else)" % char.key
else: else:
string += "\n - {R%s{n (played by someone else)" % char.key # character is "free to puppet"
else: string += "\n - %s" % char.key
# character is "free to puppet"
string += "\n - %s" % char.key
player.msg(string) player.msg(string)
def func(self): def func(self):
@ -802,10 +802,7 @@ class CmdCharCreate(MuxCommandOOC):
return return
key = self.lhs key = self.lhs
desc = self.rhs desc = self.rhs
if not player.db._created_chars: if player.db._playeable_characters and len(player.db._playable_characters) >= self.MAX_NR_CHARACTERS:
lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)"
player.set_attribute("_created_chars", [], lockstring=lockstring)
if len(player.db._created_chars) >= self.MAX_NR_CHARACTERS:
player.msg("You may only create a maximum of %i characters." % self.MAX_NR_CHARACTERS) player.msg("You may only create a maximum of %i characters." % self.MAX_NR_CHARACTERS)
return return
# create the character # create the character
@ -817,7 +814,7 @@ class CmdCharCreate(MuxCommandOOC):
new_character = create.create_object(typeclass, key=key, location=default_home, new_character = create.create_object(typeclass, key=key, location=default_home,
home=default_home, permissions=permissions) home=default_home, permissions=permissions)
player.db._created_chars.append(new_character) player.db._playable_characters.append(new_character)
if desc: if desc:
new_character.db.desc = desc new_character.db.desc = desc
player.msg("Created new character %s." % new_character.key) player.msg("Created new character %s." % new_character.key)

View file

@ -156,7 +156,7 @@ class CmdPy(MuxCommand):
'ev':ev, 'ev':ev,
'inherits_from':utils.inherits_from} 'inherits_from':utils.inherits_from}
caller.msg(">>> %s" % pycode, data={"raw":True}) caller.msg(">>> %s" % pycode, data={"raw":True}, sessid=self.sessid)
mode = "eval" mode = "eval"
try: try:
@ -185,7 +185,7 @@ class CmdPy(MuxCommand):
ret = "\n".join("{n<<< %s" % line for line in errlist if line) ret = "\n".join("{n<<< %s" % line for line in errlist if line)
if ret != None: if ret != None:
caller.msg(ret) caller.msg(ret, sessid=self.sessid)
# helper function. Kept outside so it can be imported and run # helper function. Kept outside so it can be imported and run
# by other commands. # by other commands.

View file

@ -161,15 +161,19 @@ class CmdUnconnectedCreate(MuxCommand):
permissions = settings.PERMISSION_PLAYER_DEFAULT permissions = settings.PERMISSION_PLAYER_DEFAULT
try: try:
new_character = create.create_player(playername, None, password, new_player = create.create_player(playername, None, password,
permissions=permissions, permissions=permissions)
character_typeclass=typeclass,
character_location=default_home, # create character to go with player
character_home=default_home) new_character = create_object(character_typeclass, key=name,
location=default_home, home=default_home,
permissions=permissions)
# set list
new_player.db._playable_characters.append(new_character)
except Exception: except Exception:
session.msg("There was an error creating the default Character/Player:\n%s\n If this problem persists, contact an admin.") session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin.")
return return
new_player = new_character.player
# This needs to be called so the engine knows this player is logging in for the first time. # This needs to be called so the engine knows this player is logging in for the first time.
# (so it knows to call the right hooks during login later) # (so it knows to call the right hooks during login later)

View file

@ -246,8 +246,9 @@ class Player(TypeClass):
to store attributes all players should have, to store attributes all players should have,
like configuration values etc. like configuration values etc.
""" """
pass # set an attribute holding the characters this player has
lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)"
self.set_attribute("_playable_characters", [], lockstring=lockstring)
def at_init(self): def at_init(self):
""" """

View file

@ -52,10 +52,8 @@ def create_objects():
# exists. Also, all properties (name, email, password, is_superuser) # exists. Also, all properties (name, email, password, is_superuser)
# is inherited from the user so we don't specify it again here. # is inherited from the user so we don't specify it again here.
god_character = create.create_player(god_user.username, None, None, god_player = create.create_player(god_user.username, None, None, user=god_user)
user=god_user, god_character = create.create_object(character_typeclass, key=god_user.username)
create_character=True,
character_typeclass=character_typeclass)
god_character.id = 1 god_character.id = 1
god_character.db.desc = _('This is User #1.') god_character.db.desc = _('This is User #1.')
@ -83,6 +81,8 @@ def create_objects():
god_character.location = limbo_obj god_character.location = limbo_obj
if not god_character.home: if not god_character.home:
god_character.home = limbo_obj god_character.home = limbo_obj
# store in list as playable character
god_player.db._playable_characters.append(god_character)
def create_channels(): def create_channels():
""" """

View file

@ -53,7 +53,7 @@ _GA = object.__getattribute__
# #
def create_object(typeclass, key=None, location=None, def create_object(typeclass, key=None, location=None,
home=None, player=None, permissions=None, locks=None, home=None, permissions=None, locks=None,
aliases=None, destination=None, report_to=None): aliases=None, destination=None, report_to=None):
""" """
Create a new in-game object. Any game object is a combination Create a new in-game object. Any game object is a combination
@ -116,11 +116,6 @@ def create_object(typeclass, key=None, location=None,
# from now on we can use the typeclass object # from now on we can use the typeclass object
# as if it was the database object. # as if it was the database object.
if player:
# link a player and the object together
new_object.player = player
player.obj = new_object
new_object.destination = destination new_object.destination = destination
# call the hook method. This is where all at_creation # call the hook method. This is where all at_creation
@ -397,11 +392,8 @@ def create_player(name, email, password,
typeclass=None, typeclass=None,
is_superuser=False, is_superuser=False,
locks=None, permissions=None, locks=None, permissions=None,
create_character=True, character_typeclass=None,
character_location=None, character_home=None,
player_dbobj=None, report_to=None): player_dbobj=None, report_to=None):
""" """
This creates a new player, handling the creation of the User This creates a new player, handling the creation of the User
object and its associated Player object. object and its associated Player object.
@ -510,17 +502,6 @@ def create_player(name, email, password,
if locks: if locks:
new_player.locks.add(locks) new_player.locks.add(locks)
# create *in-game* 'player' object
if create_character:
if not character_typeclass:
character_typeclass = settings.BASE_CHARACTER_TYPECLASS
# creating the object automatically links the player
# and object together by player.obj <-> obj.player
new_character = create_object(character_typeclass, key=name,
location=character_location, home=character_location,
permissions=permissions,
player=new_player, report_to=report_to)
return new_character
return new_player return new_player
except Exception: except Exception:
# a failure in creating the character # a failure in creating the character