mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 08:16:30 +01:00
Adding the first bit of permissions checking as an example. See cmd_who and the Object class's user_has_perm method for examples. We'll need to start fleshing this stuff out before adding many more new commands. For existing games, remove your auth_permissions table and re-sync your DB.
This commit is contained in:
parent
f1dd985294
commit
2fc06adcfa
3 changed files with 51 additions and 17 deletions
|
|
@ -21,4 +21,5 @@ class GenericPerm(models.Model):
|
|||
("shutdown", "May @shutdown the site"),
|
||||
("tel_anywhere", "May @teleport anywhere"),
|
||||
("tel_anyone", "May @teleport anything"),
|
||||
("see_session_data", "May see detailed player session data"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -129,6 +129,22 @@ class Object(models.Model):
|
|||
else:
|
||||
return profile[0].is_superuser
|
||||
|
||||
def user_has_perm(self, perm):
|
||||
"""
|
||||
Checks to see whether a user has the specified permission or is a super
|
||||
user.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
||||
if self.is_superuser():
|
||||
return True
|
||||
|
||||
if self.get_user_account().has_perm(perm):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def owns_other(self, other_obj):
|
||||
"""
|
||||
See if the envoked object owns another object.
|
||||
|
|
|
|||
|
|
@ -302,29 +302,46 @@ def cmd_who(cdat):
|
|||
session_list = session_mgr.get_session_list()
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
|
||||
retval = "Player Name On For Idle Room Cmds Host\n\r"
|
||||
show_session_data = pobject.user_has_perm("genperms.see_session_data")
|
||||
|
||||
# Only those with the see_session_data or superuser status can see
|
||||
# session details.
|
||||
if show_session_data:
|
||||
retval = "Player Name On For Idle Room Cmds Host\n\r"
|
||||
else:
|
||||
retval = "Player Name On For Idle\n\r"
|
||||
|
||||
for player in session_list:
|
||||
if not player.logged_in:
|
||||
continue
|
||||
delta_cmd = time.time() - player.cmd_last_visible
|
||||
delta_conn = time.time() - player.conn_time
|
||||
plr_pobject = player.get_pobject()
|
||||
|
||||
retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \
|
||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||
# On-time
|
||||
functions_general.time_format(delta_conn,0), \
|
||||
# Idle time
|
||||
functions_general.time_format(delta_cmd,1), \
|
||||
# Flags
|
||||
'', \
|
||||
# Location
|
||||
plr_pobject.get_location().id, \
|
||||
player.cmd_total, \
|
||||
# More flags?
|
||||
'', \
|
||||
player.address[0])
|
||||
|
||||
if show_session_data:
|
||||
retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \
|
||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||
# On-time
|
||||
functions_general.time_format(delta_conn,0), \
|
||||
# Idle time
|
||||
functions_general.time_format(delta_cmd,1), \
|
||||
# Flags
|
||||
'', \
|
||||
# Location
|
||||
plr_pobject.get_location().id, \
|
||||
player.cmd_total, \
|
||||
# More flags?
|
||||
'', \
|
||||
player.address[0])
|
||||
else:
|
||||
retval += '%-16s%9s %4s%-3s\r\n' % \
|
||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||
# On-time
|
||||
functions_general.time_format(delta_conn,0), \
|
||||
# Idle time
|
||||
functions_general.time_format(delta_cmd,1), \
|
||||
# Flags
|
||||
'')
|
||||
retval += '%d Players logged in.' % (len(session_list),)
|
||||
|
||||
session.msg(retval)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue