Added @sessions command for viewing active sessions connected to a given account.
This commit is contained in:
parent
25505d69a6
commit
458e3e7599
4 changed files with 53 additions and 5 deletions
|
|
@ -31,6 +31,7 @@ class DefaultCmdSet(CmdSet):
|
||||||
self.add(general.CmdSay())
|
self.add(general.CmdSay())
|
||||||
self.add(general.CmdAccess())
|
self.add(general.CmdAccess())
|
||||||
self.add(general.CmdColorTest())
|
self.add(general.CmdColorTest())
|
||||||
|
self.add(general.CmdSessions())
|
||||||
|
|
||||||
# The help system
|
# The help system
|
||||||
self.add(help.CmdHelp())
|
self.add(help.CmdHelp())
|
||||||
|
|
|
||||||
|
|
@ -530,6 +530,46 @@ class CmdSay(MuxCommand):
|
||||||
speech)
|
speech)
|
||||||
caller.location.msg_contents(emit_string,
|
caller.location.msg_contents(emit_string,
|
||||||
exclude=caller)
|
exclude=caller)
|
||||||
|
class CmdSessions(MuxCommand):
|
||||||
|
"""
|
||||||
|
check connected session(s)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
@sessions
|
||||||
|
|
||||||
|
Lists the sessions currently connected to your account.
|
||||||
|
|
||||||
|
"""
|
||||||
|
key = "@sessions"
|
||||||
|
locks = "cmd:all()"
|
||||||
|
help_category = "General"
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
"Implement function"
|
||||||
|
|
||||||
|
# make sure we work on the player, not on the character
|
||||||
|
player = self.caller
|
||||||
|
if hasattr(player, "player"):
|
||||||
|
player = player.player
|
||||||
|
|
||||||
|
sessions = player.get_all_sessions()
|
||||||
|
|
||||||
|
table = [["sessid"], ["host"], ["character"], ["location"]]
|
||||||
|
for sess in sorted(sessions, key=lambda x:x.sessid):
|
||||||
|
sessid = sess.sessid
|
||||||
|
char = player.get_character(sessid)
|
||||||
|
table[0].append(str(sess.sessid))
|
||||||
|
table[1].append(str(sess.address[0]))
|
||||||
|
table[2].append(char and str(char) or "None")
|
||||||
|
table[3].append(char and str(char.location) or "N/A")
|
||||||
|
ftable = utils.format_table(table, 5)
|
||||||
|
string = ""
|
||||||
|
for ir, row in enumerate(ftable):
|
||||||
|
if ir == 0:
|
||||||
|
string += "\n" + "{w%s{n" % ("".join(row))
|
||||||
|
else:
|
||||||
|
string += "\n" + "".join(row)
|
||||||
|
self.msg(string)
|
||||||
|
|
||||||
|
|
||||||
class CmdPose(MuxCommand):
|
class CmdPose(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -678,13 +678,18 @@ class ObjectDB(TypedObject):
|
||||||
data (object): an optional data object that may or may not
|
data (object): an optional data object that may or may not
|
||||||
be used by the protocol.
|
be used by the protocol.
|
||||||
sessid (int): sessid to relay to, if any.
|
sessid (int): sessid to relay to, if any.
|
||||||
If set to 0 (default), use self.sessid automatically
|
If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
|
||||||
If None, echo to all connected sessions
|
If None, echo to all connected sessions
|
||||||
"""
|
"""
|
||||||
if _GA(self, 'player'):
|
if _GA(self, 'player'):
|
||||||
# note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it.
|
# note that we must call the player *typeclass'* msg(), otherwise one couldn't overload it.
|
||||||
_GA(_GA(self, 'player'), "typeclass").msg(msg, from_obj=from_obj, data=data,
|
if sessid == 0:
|
||||||
sessid=(sessid==0 and _GA(self, "sessid") or sessid or None))
|
sessid = None
|
||||||
|
if from_obj and hasattr(from_obj, "sessid"):
|
||||||
|
sessid = from_obj.sessid
|
||||||
|
elif hasattr(self, "sessid"):
|
||||||
|
sessid = self.sessid
|
||||||
|
_GA(_GA(self, 'player'), "typeclass").msg(msg, from_obj=from_obj, data=data, sessid=sessid)
|
||||||
|
|
||||||
def emit_to(self, message, from_obj=None, data=None):
|
def emit_to(self, message, from_obj=None, data=None):
|
||||||
"Deprecated. Alias for msg"
|
"Deprecated. Alias for msg"
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ class Object(TypeClass):
|
||||||
"""
|
"""
|
||||||
return self.dbobj.execute_cmd(raw_string, sessid=sessid)
|
return self.dbobj.execute_cmd(raw_string, sessid=sessid)
|
||||||
|
|
||||||
def msg(self, message, from_obj=None, data=None):
|
def msg(self, message, from_obj=None, data=None, sessid=0):
|
||||||
"""
|
"""
|
||||||
Emits something to any sessions attached to the object.
|
Emits something to any sessions attached to the object.
|
||||||
|
|
||||||
|
|
@ -224,8 +224,10 @@ class Object(TypeClass):
|
||||||
from_obj (obj): object that is sending.
|
from_obj (obj): object that is sending.
|
||||||
data (object): an optional data object that may or may not
|
data (object): an optional data object that may or may not
|
||||||
be used by the protocol.
|
be used by the protocol.
|
||||||
|
sessid: optional session target. If sessid=0, the session will
|
||||||
|
default to self.sessid or from_obj.sessid.
|
||||||
"""
|
"""
|
||||||
self.dbobj.msg(message, from_obj=from_obj, data=data)
|
self.dbobj.msg(message, from_obj=from_obj, data=data, sessid=0)
|
||||||
|
|
||||||
def msg_contents(self, message, exclude=None, from_obj=None, data=None):
|
def msg_contents(self, message, exclude=None, from_obj=None, data=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue