Further development of the reworking of systems using Sessions rather than session id.

This commit is contained in:
Griatch 2015-11-14 20:32:58 +01:00
parent 709f5ff5b3
commit d496606a3c
19 changed files with 166 additions and 209 deletions

View file

@ -148,7 +148,8 @@ class Command(with_metaclass(CommandMeta, object)):
# auto-set (by Evennia on command instantiation) are:
# obj - which object this command is defined on
# sessid - which session-id (if any) is responsible for triggering this command
# session - which session is responsible for triggering this command. Only set
# if triggered by a player.
def __init__(self, **kwargs):
"""
@ -297,22 +298,18 @@ class Command(with_metaclass(CommandMeta, object)):
return self.lockhandler.check(srcobj, access_type, default=default)
def msg(self, msg="", to_obj=None, from_obj=None,
sessid=None, all_sessions=False, **kwargs):
session=None, **kwargs):
"""
This is a shortcut instad of calling msg() directly on an
object - it will detect if caller is an Object or a Player and
also appends self.sessid automatically.
also appends self.session automatically.
Args:
msg (str, optional): Text string of message to send.
to_obj (Object, optional): Target object of message. Defaults to self.caller.
from_obj (Object, optional): Source of message. Defaults to to_obj.
sessid (int, optional): Supply data only to a unique
session id (normally not used - this is only potentially
useful if to_obj is a Player object different from
self.caller or self.caller.player).
all_sessions (bool): Default is to send only to the session
connected to the target object
session (Session, optional): Supply data only to a unique
session.
Kwargs:
kwargs (any): These are all passed on to the message mechanism. Common
@ -321,26 +318,9 @@ class Command(with_metaclass(CommandMeta, object)):
"""
from_obj = from_obj or self.caller
to_obj = to_obj or from_obj
if not sessid:
if hasattr(to_obj, "sessid"):
# this is the case when to_obj is e.g. a Character
toobj_sessions = to_obj.sessid.get()
# If to_obj has more than one session MULTISESSION_MODE=3
# we need to send to every session.
#(setting it to None, does it)
session_tosend = None
if len(toobj_sessions) == 1:
session_tosend=toobj_sessions[0]
sessid = all_sessions and None or session_tosend
elif to_obj == self.caller:
# this is the case if to_obj is the calling Player
sessid = all_sessions and None or self.sessid
else:
# if to_obj is a different Player, all their sessions
# will be notified unless sessid was given specifically
sessid = None
to_obj.msg(msg, from_obj=from_obj, sessid=sessid, **kwargs)
if not session or to_obj == self.caller:
session = to_obj.sessions.get()
to_obj.msg(msg, from_obj=from_obj, session=session, **kwargs)
# Common Command hooks

View file

@ -92,7 +92,7 @@ class CmdBoot(MuxCommand):
for session in boot_list:
session.msg(feedback)
pobj.disconnect_session_from_player(session.sessid)
pobj.disconnect_session_from_player(session)
# regex matching IP addresses with wildcards, eg. 233.122.4.*

View file

@ -1868,9 +1868,7 @@ class CmdExamine(ObjManipCommand):
string = "\n{wName/key{n: {c%s{n (%s)" % (obj.name, obj.dbref)
if hasattr(obj, "aliases") and obj.aliases.all():
string += "\n{wAliases{n: %s" % (", ".join(utils.make_iter(str(obj.aliases))))
if hasattr(obj, "sessid") and obj.sessid.count():
string += "\n{wsession{n: %s" % obj.sessid.get()
elif hasattr(obj, "sessions") and obj.sessions:
if hasattr(obj, "sessions") and obj.sessions:
string += "\n{wsession(s){n: %s" % (", ".join(str(sess.sessid)
for sess in obj.sessions))
if hasattr(obj, "has_player") and obj.has_player:
@ -1924,16 +1922,16 @@ class CmdExamine(ObjManipCommand):
# if we merge on the object level.
if hasattr(obj, "player") and obj.player:
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.cmdset.all()])
if obj.sessid.count():
if obj.sessions.count():
# if there are more sessions than one on objects it's because of multisession mode 3.
# we only show the first session's cmdset here (it is -in principle- possible that
# different sessions have different cmdsets but for admins who want such madness
# it is better that they overload with their own CmdExamine to handle it).
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.get_session(obj.sessid.get()[0]).cmdset.all()])
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.sessions.all()[0].cmdset.all()])
else:
try:
# we have to protect this since many objects don't have sessions.
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessid.get()).cmdset.all()])
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessions.get()).cmdset.all()])
except (TypeError, AttributeError):
pass
all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()]
@ -2043,7 +2041,7 @@ class CmdExamine(ObjManipCommand):
# we are only interested in specific attributes
caller.msg(self.format_attributes(obj, attrname, crop=False))
else:
if hasattr(obj, "sessid") and obj.sessid.count():
if obj.sessions.count():
mergemode = "session"
elif self.player_mode:
mergemode = "player"

View file

@ -188,6 +188,6 @@ class MuxPlayerCommand(MuxCommand):
self.caller = self.caller.player
elif utils.inherits_from(self.caller, "evennia.players.players.DefaultPlayer"):
# caller was already a Player
self.character = self.caller.get_puppet(self.sessid)
self.character = self.caller.get_puppet(self.session)
else:
self.character = None

View file

@ -101,7 +101,7 @@ class CmdOOCLook(MuxPlayerLookCommand):
return
# call on-player look helper method
self.msg(self.player.at_look(target=self.playable, sessid=self.sessid))
self.msg(self.player.at_look(target=self.playable, session=self.session))
class CmdCharCreate(MuxPlayerCommand):
@ -188,7 +188,7 @@ class CmdIC(MuxPlayerCommand):
Main puppet method
"""
player = self.player
sessid = self.sessid
session = self.session
new_character = None
if not self.args:
@ -205,7 +205,7 @@ class CmdIC(MuxPlayerCommand):
self.msg("That is not a valid character choice.")
return
try:
player.puppet_object(sessid, new_character)
player.puppet_object(session, new_character)
player.db._last_puppet = new_character
except RuntimeError as exc:
self.msg("{rYou cannot become {C%s{n: %s" % (new_character.name, exc))
@ -234,9 +234,9 @@ class CmdOOC(MuxPlayerLookCommand):
"Implement function"
player = self.player
sessid = self.sessid
session = self.session
old_char = player.get_puppet(sessid)
old_char = player.get_puppet(session)
if not old_char:
string = "You are already OOC."
self.msg(string)
@ -246,7 +246,7 @@ class CmdOOC(MuxPlayerLookCommand):
# disconnect
try:
player.unpuppet_object(sessid)
player.unpuppet_object(session)
self.msg("\n{GYou go OOC.{n\n")
if _MULTISESSION_MODE < 2:
@ -254,7 +254,7 @@ class CmdOOC(MuxPlayerLookCommand):
self.msg("You are out-of-character (OOC).\nUse {w@ic{n to get back into the game.")
return
self.msg(player.at_look(target=self.playable, sessid=sessid))
self.msg(player.at_look(target=self.playable, session=session))
except RuntimeError as exc:
self.msg("{rCould not unpuppet from {c%s{n: %s" % (old_char, exc))
@ -480,19 +480,19 @@ class CmdQuit(MuxPlayerCommand):
player = self.player
if 'all' in self.switches:
player.msg("{RQuitting{n all sessions. Hope to see you soon again.", sessid=self.sessid)
for session in player.get_all_sessions():
player.disconnect_session_from_player(session.sessid)
player.msg("{RQuitting{n all sessions. Hope to see you soon again.", session=self.session)
for session in player.sessions.all()
player.disconnect_session_from_player(session)
else:
nsess = len(player.get_all_sessions())
nsess = len(player.sessions.all())
if nsess == 2:
player.msg("{RQuitting{n. One session is still connected.", sessid=self.sessid)
player.msg("{RQuitting{n. One session is still connected.", session=self.session)
elif nsess > 2:
player.msg("{RQuitting{n. %i session are still connected." % (nsess-1), sessid=self.sessid)
player.msg("{RQuitting{n. %i session are still connected." % (nsess-1), session=self.session)
else:
# we are quitting the last available session
player.msg("{RQuitting{n. Hope to see you again, soon.", sessid=self.sessid)
player.disconnect_session_from_player(self.sessid)
player.msg("{RQuitting{n. Hope to see you again, soon.", session=self.session)
player.disconnect_session_from_player(self.session)
@ -601,8 +601,8 @@ class CmdQuell(MuxPlayerCommand):
def _recache_locks(self, player):
"Helper method to reset the lockhandler on an already puppeted object"
if self.sessid:
char = player.get_puppet(self.sessid)
if self.session:
char = session.puppet
if char:
# we are already puppeting an object. We need to reset
# the lock caches (otherwise the superuser status change
@ -625,7 +625,7 @@ class CmdQuell(MuxPlayerCommand):
self.msg("Already quelling Player%s permissions." % permstr)
return
player.attributes.add('_quell', True)
puppet = player.get_puppet(self.sessid)
puppet = self.session.puppet
if puppet:
cpermstr = " (%s)" % ", ".join(puppet.permissions.all())
cpermstr = "Quelling to current puppet's permissions%s." % cpermstr

View file

@ -178,7 +178,7 @@ class CmdPy(MuxCommand):
'inherits_from': utils.inherits_from}
try:
self.msg(">>> %s" % pycode, raw=True, sessid=self.sessid)
self.msg(">>> %s" % pycode, raw=True, session=self.session)
except TypeError:
self.msg(">>> %s" % pycode, raw=True)
@ -209,7 +209,7 @@ class CmdPy(MuxCommand):
ret = "\n".join("<<< %s" % line for line in errlist if line)
try:
self.msg(ret, sessid=self.sessid, raw=True)
self.msg(ret, session=self.session, raw=True)
except TypeError:
self.msg(ret, raw=True)

View file

@ -55,7 +55,6 @@ class CommandTest(EvenniaTest):
cmdobj.cmdstring = cmdobj.key
cmdobj.args = args
cmdobj.cmdset = cmdset
cmdobj.sessid = 1
cmdobj.session = SESSIONS.session_from_sessid(1)
cmdobj.player = self.player
cmdobj.raw_string = cmdobj.key + " " + args
@ -174,7 +173,7 @@ class TestPlayer(CommandTest):
self.call(player.CmdOOC(), "", "You go OOC.", caller=self.player)
def test_ic(self):
self.player.unpuppet_object(self.session.sessid)
self.player.unpuppet_object(self.session)
self.call(player.CmdIC(), "Char", "You become Char.", caller=self.player, receiver=self.char1)
def test_password(self):

View file

@ -237,7 +237,7 @@ class CmdUnconnectedConnect(MuxCommand):
# player.at_init() # always called when object is loaded from disk
# player.at_first_login() # only once, for player-centric setup
# player.at_pre_login()
# player.at_post_login(sessid=sessid)
# player.at_post_login(session=session)
session.sessionhandler.login(session, player)