Added more session info to ooclook. Working on a bug that causes superuser to not be recognized now and then - this seems to be related to character.player returning None. This revision contains some printout debug messages since that bug is not yet fixed.
This commit is contained in:
parent
406800f254
commit
29e313492f
6 changed files with 53 additions and 27 deletions
|
|
@ -188,27 +188,34 @@ class Command(object):
|
|||
"""
|
||||
return self.lockhandler.check(srcobj, access_type, default=default)
|
||||
|
||||
def msg(self, msg="", data=None, from_obj=None, to_obj=None, all_sessions=False):
|
||||
def msg(self, msg="", to_obj=None, from_obj=None, data=None, sessid=None, all_sessions=False):
|
||||
"""
|
||||
This is a shortcut instad of calling msg() directly on an object - it will
|
||||
determine
|
||||
|
||||
detect if caller is an Object or a Player and also appends self.sessid
|
||||
automatically.
|
||||
|
||||
msg - text string of message to send
|
||||
data - optional dictionary of data
|
||||
from_obj - source of message. Defaults to self.caller.
|
||||
to_obj - target object of message. Defaults to self.caller
|
||||
from_obj - source of message. Defaults to to_obj
|
||||
data - optional dictionary of data
|
||||
sessid - supply data only to a unique sessid (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
|
||||
"""
|
||||
from_obj = from_obj or self.caller
|
||||
to_obj = to_obj or from_obj
|
||||
if hasattr(to_obj, "sessid"):
|
||||
sessid = all_sessions and None or to_obj.sessid
|
||||
else:
|
||||
sessid = None
|
||||
if not sessid:
|
||||
if hasattr(to_obj, "sessid"):
|
||||
# this is the case when to_obj is e.g. a Character
|
||||
sessid = all_sessions and None or to_obj.sessid
|
||||
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, data=data, sessid=sessid)
|
||||
|
||||
# Common Command hooks
|
||||
|
|
|
|||
|
|
@ -769,6 +769,12 @@ class CmdColorTest(MuxCommand):
|
|||
|
||||
#------------------------------------------------------------
|
||||
# OOC commands
|
||||
#
|
||||
# Note that in commands inheriting from MuxCommandOOC,
|
||||
# self.caller is always the Player object, not the Character.
|
||||
# A property self.character can be used to access the
|
||||
# connecter character (this can be None if no character is
|
||||
# currently controlled by the Player).
|
||||
#------------------------------------------------------------
|
||||
|
||||
class CmdOOCLook(MuxCommandOOC, CmdLook):
|
||||
|
|
@ -809,24 +815,33 @@ class CmdOOCLook(MuxCommandOOC, CmdLook):
|
|||
# caller is always a player at this point.
|
||||
player = self.caller
|
||||
sessid = self.sessid
|
||||
# get all our characters
|
||||
# get all our characters and sessions
|
||||
characters = player.db._playable_characters
|
||||
string = "You are logged in as {g%s{n." % player.key
|
||||
string += "\nUse {w@ic <character>{n to enter the game, {w@occ{n to get back here."
|
||||
sessions = player.get_all_sessions()
|
||||
|
||||
sessidstr = sessid and "(session id %i)" % sessid or ""
|
||||
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 <character>{n to enter the game, {w@occ{n to get back here."
|
||||
if characters:
|
||||
string += "\n\nAvailable character%s:" % (len(characters) > 1 and "s" or "")
|
||||
for char in characters:
|
||||
csessid = char.sessid
|
||||
if csessid:
|
||||
# character is already puppeted
|
||||
if player.get_session(csessid):
|
||||
string += "\n - {G%s{n (played by you in another session)" % char.key
|
||||
sess = player.get_session(csessid)
|
||||
if sess:
|
||||
string += "\n - {G%s{n (played by you from session with id %i)" % (char.key, sess.sessid)
|
||||
else:
|
||||
string += "\n - {R%s{n (played by someone else)" % char.key
|
||||
else:
|
||||
# character is "free to puppet"
|
||||
string += "\n - %s" % char.key
|
||||
player.msg(string)
|
||||
self.msg(string)
|
||||
|
||||
def func(self):
|
||||
"implement the ooc look command"
|
||||
|
|
@ -957,7 +972,7 @@ class CmdIC(MuxCommandOOC):
|
|||
|
||||
class CmdOOC(MuxCommandOOC):
|
||||
"""
|
||||
@ooc - go ooc
|
||||
go ooc
|
||||
|
||||
Usage:
|
||||
@ooc
|
||||
|
|
@ -977,9 +992,6 @@ class CmdOOC(MuxCommandOOC):
|
|||
|
||||
caller = self.caller
|
||||
|
||||
if utils.inherits_from(caller, "src.objects.objects.Object"):
|
||||
caller = self.caller.player
|
||||
|
||||
old_char = caller.get_character(sessid=self.sessid)
|
||||
if not old_char:
|
||||
string = "You are already OOC."
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ class MuxCommandOOC(MuxCommand):
|
|||
|
||||
This class makes sure that caller is always a Player object, while
|
||||
creating a new property "character" that is set only if a
|
||||
character is actually attached to the Player.
|
||||
character is actually attached to this Player and Session.
|
||||
"""
|
||||
def parse(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue