Implemented a first working version of MULTISESSION_MODE=3

This commit is contained in:
Griatch 2014-08-04 15:58:51 +02:00
parent 1e41be797b
commit 1ffbc4b9f3
2 changed files with 23 additions and 16 deletions

View file

@ -248,17 +248,22 @@ class CmdIC(MuxPlayerCommand):
self.msg("That is not a valid character choice.") self.msg("That is not a valid character choice.")
return return
# permission checks # permission checks
if player.get_puppet(sessid) == new_character: if player.get_puppjet(sessid) == new_character:
self.msg("{RYou already act as {c%s{n." % new_character.name) self.msg("{RYou already act as {c%s{n." % new_character.name)
return return
if new_character.player: if new_character.player:
# may not puppet an already puppeted character # may not puppet an already puppeted character
if new_character.sessid and new_character.player == player: if new_character.sessid.count() and new_character.player == player:
# as a safeguard we allow "taking over chars from # as a safeguard we allow "taking over" chars from your own sessions.
# your own sessions. if MULTISESSION_MODE == 3:
player.msg("{c%s{n{R is now acted from another of your sessions.{n" % (new_character.name), sessid=new_character.sessid) txt = "{c%s{n{G is now shared from another of your sessions.{n"
txt2 = "Sharing {c%s{n with another of your sessions."
else:
txt = "{c%s{n{R is now acted from another of your sessions.{n"
txt2 = "Taking over {c%s{n from another of your sessions."
player.msg(txt % (new_character.name), sessid=new_character.sessid.get())
player.unpuppet_object(new_character.sessid) player.unpuppet_object(new_character.sessid)
self.msg("Taking over {c%s{n from another of your sessions." % new_character.name) self.msg(txt2 % new_character.name)
elif new_character.player != player and new_character.player.is_connected: elif new_character.player != player and new_character.player.is_connected:
self.msg("{c%s{r is already acted by another player.{n" % new_character.name) self.msg("{c%s{r is already acted by another player.{n" % new_character.name)
return return

View file

@ -230,7 +230,7 @@ class PlayerDB(TypedObject, AbstractUser):
to all sessions connected to this player. This is usually only to all sessions connected to this player. This is usually only
relevant when using msg() directly from a player-command (from relevant when using msg() directly from a player-command (from
a command on a Character, the character automatically stores a command on a Character, the character automatically stores
and handles the sessid). and handles the sessid). Can also be a list of sessids.
kwargs (dict) - All other keywords are parsed as extra data. kwargs (dict) - All other keywords are parsed as extra data.
""" """
if "data" in kwargs: if "data" in kwargs:
@ -247,13 +247,14 @@ class PlayerDB(TypedObject, AbstractUser):
_GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs) _GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
except Exception: except Exception:
pass pass
session = _MULTISESSION_MODE > 1 and sessid and _GA(self, "get_session")(sessid) or None sessions = _MULTISESSION_MODE > 1 and [sessid] and make_iter(_GA(self, "get_session")(sessid)) or None
if session: if sessions:
obj = session.puppet for session in sessions:
if obj and not obj.at_msg_receive(text=text, **kwargs): obj = session.puppet
# if hook returns false, cancel send if obj and not obj.at_msg_receive(text=text, **kwargs):
return # if hook returns false, cancel send
session.msg(text=text, **kwargs) continue
session.msg(text=text, **kwargs)
else: else:
# if no session was specified, send to them all # if no session was specified, send to them all
for sess in _GA(self, 'get_all_sessions')(): for sess in _GA(self, 'get_all_sessions')():
@ -264,6 +265,7 @@ class PlayerDB(TypedObject, AbstractUser):
def get_session(self, sessid): def get_session(self, sessid):
""" """
Return session with given sessid connected to this player. Return session with given sessid connected to this player.
note that the sessionhandler also accepts sessid as an iterable.
""" """
global _SESSIONS global _SESSIONS
if not _SESSIONS: if not _SESSIONS:
@ -347,14 +349,14 @@ class PlayerDB(TypedObject, AbstractUser):
obj = hasattr(session, "puppet") and session.puppet or None obj = hasattr(session, "puppet") and session.puppet or None
if not obj: if not obj:
return False return False
# do the disconnect # do the disconnect, but only if we are the last session to puppet
_GA(obj.typeclass, "at_pre_unpuppet")() _GA(obj.typeclass, "at_pre_unpuppet")()
obj.dbobj.sessid.remove(sessid) obj.dbobj.sessid.remove(sessid)
if not obj.dbobj.sessid.count(): if not obj.dbobj.sessid.count():
del obj.dbobj.player del obj.dbobj.player
_GA(obj.typeclass, "at_post_unpuppet")(_GA(self, "typeclass"), sessid=sessid)
session.puppet = None session.puppet = None
session.puid = None session.puid = None
_GA(obj.typeclass, "at_post_unpuppet")(_GA(self, "typeclass"), sessid=sessid)
return True return True
def unpuppet_all(self): def unpuppet_all(self):