From c967cc79141ab73feba80b26df8f7b35a4f9e441 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 9 Apr 2013 19:19:53 +0200 Subject: [PATCH] MULTISESSION_MODE 0-2 works as they should. Remains some fixes to migrations. --- src/commands/default/general.py | 6 +++++- src/players/models.py | 14 ++++++-------- src/players/player.py | 12 +++++++++--- src/server/initial_setup.py | 3 +-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/commands/default/general.py b/src/commands/default/general.py index c8e0149505..15b5543f4b 100644 --- a/src/commands/default/general.py +++ b/src/commands/default/general.py @@ -824,13 +824,17 @@ class CmdOOCLook(MuxCommandOOC, CmdLook): sessions = player.get_all_sessions() sessidstr = sessid and " (session id %i)" % sessid or "" - string = "%sYou are logged in as {g%s{n%s." % (" "*10,player.key, sessidstr) + string = "You are logged in as {g%s{n%s." % (player.key, sessidstr) string += "\n\nSession(s) connected:" for sess in sessions: csessid = sess.sessid string += "\n %s %s" % (sessid == csessid and "{w%i{n" % csessid or csessid, sess.address) string += "\n\nUse {w@ic {n to enter the game, {w@occ{n to get back here." + if not characters: + string += "\nYou don't have any character yet. Use {w@charcreate [=description]{n to create one." + elif len(characters) < MAX_NR_CHARACTERS: + string += "\nUse {w@charcreate [=description]{n to create a new character (max %i)" % MAX_NR_CHARACTERS if characters: string += "\n\nAvailable character%s%s:" % (len(characters) > 1 and "s" or "", MAX_NR_CHARACTERS > 1 and " (out of a maximum of %i)" % MAX_NR_CHARACTERS or "") diff --git a/src/players/models.py b/src/players/models.py index c76b2cab0e..1a77f7f750 100644 --- a/src/players/models.py +++ b/src/players/models.py @@ -126,8 +126,6 @@ class PlayerDB(TypedObject): The PlayerDB adds the following properties: user - Connected User object. django field, needs to be save():d. - obj - game object controlled by player - character - alias for obj name - alias for user.username sessions - sessions connected to this player is_superuser - bool if this player is a superuser @@ -144,11 +142,6 @@ class PlayerDB(TypedObject): # this profile model. It is required by django. user = models.ForeignKey(User, unique=True, db_index=True, help_text="The User object holds django-specific authentication for each Player. A unique User should be created and tied to each Player, the two should never be switched or changed around. The User will be deleted automatically when the Player is.") - # the in-game object connected to this player (if any). - # Use the property 'obj' to access. - db_objs = models.ManyToManyField("objects.ObjectDB", null=True, - verbose_name="characters", related_name="objs_set", - help_text="In-game objects.") # store a connected flag here too, not just in sessionhandler. # This makes it easier to track from various out-of-process locations db_is_connected = models.BooleanField(default=False, verbose_name="is_connected", help_text="If player is connected to game or not") @@ -327,7 +320,7 @@ class PlayerDB(TypedObject): session = _MULTISESSION_MODE == 2 and sessid and _GA(self, "get_session")(sessid) or None if session: obj = session.puppet - if char and not char.at_msg_receive(outgoing_string, from_obj=from_obj, data=data): + if obj and not obj.at_msg_receive(outgoing_string, from_obj=from_obj, data=data): # if hook returns false, cancel send return session.msg(outgoing_string, data) @@ -347,6 +340,11 @@ class PlayerDB(TypedObject): data - dictionary of optional data session - session sending this data (no need to look it up again) """ + if _MULTISESSION_MODE == 1: + # many sessions - one puppet + sessions = [session for session in self.get_all_sessions() if session.puppet] + session = sessions and sessions[0] or session + puppet = session.puppet if puppet: # execute command on the puppeted object (this will include diff --git a/src/players/player.py b/src/players/player.py index 36df6a860b..c5a0b6dc20 100644 --- a/src/players/player.py +++ b/src/players/player.py @@ -256,7 +256,7 @@ class Player(TypeClass): to store attributes all players should have, like configuration values etc. """ - # set an attribute holding the characters this player has + # set an (empty) attribute holding the characters this player has lockstring = "attrread:perm(Admins);attredit:perm(Admins);attrcreate:perm(Admins)" self.set_attribute("_playable_characters", [], lockstring=lockstring) @@ -323,11 +323,17 @@ class Player(TypeClass): at_post_login hook. """ self._send_to_connect_channel("{G%s connected{n" % self.key) - if _MULTISESSION_MODE in (0, 1): - # in these modes we should have only one character available. We + if _MULTISESSION_MODE == 0: + # in this mode we should have only one character available. We # try to auto-connect to it by calling the @ic command # (this relies on player.db._last_puppet being set) self.execute_cmd("@ic") + elif _MULTISESSION_MODE == 1: + # in this mode the first session to connect acts like mode 0, + # the following sessions "share" the same view and should + # not perform any actions + if not self.get_all_puppets(): + self.execute_cmd("@ic") elif _MULTISESSION_MODE == 2: # In this mode we by default end up at a character selection # screen. We execute look on the player. diff --git a/src/server/initial_setup.py b/src/server/initial_setup.py index 72fee5c3d5..c35302aabf 100644 --- a/src/server/initial_setup.py +++ b/src/server/initial_setup.py @@ -63,6 +63,7 @@ def create_objects(): god_character.set_attribute("_superuser_character", True) god_player.set_attribute("_first_login", True) god_player.set_attribute("_last_puppet", god_character) + god_player.db._playable_characters.append(god_character) # Limbo is the default "nowhere" starting room @@ -84,8 +85,6 @@ def create_objects(): god_character.location = limbo_obj if not god_character.home: god_character.home = limbo_obj - # store in list as playable character - god_player.db._playable_characters.append(god_character) def create_channels(): """