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"),
|
("shutdown", "May @shutdown the site"),
|
||||||
("tel_anywhere", "May @teleport anywhere"),
|
("tel_anywhere", "May @teleport anywhere"),
|
||||||
("tel_anyone", "May @teleport anything"),
|
("tel_anyone", "May @teleport anything"),
|
||||||
|
("see_session_data", "May see detailed player session data"),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,22 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return profile[0].is_superuser
|
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):
|
def owns_other(self, other_obj):
|
||||||
"""
|
"""
|
||||||
See if the envoked object owns another object.
|
See if the envoked object owns another object.
|
||||||
|
|
|
||||||
|
|
@ -302,8 +302,15 @@ def cmd_who(cdat):
|
||||||
session_list = session_mgr.get_session_list()
|
session_list = session_mgr.get_session_list()
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
pobject = session.get_pobject()
|
pobject = session.get_pobject()
|
||||||
|
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"
|
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:
|
for player in session_list:
|
||||||
if not player.logged_in:
|
if not player.logged_in:
|
||||||
continue
|
continue
|
||||||
|
|
@ -311,6 +318,7 @@ def cmd_who(cdat):
|
||||||
delta_conn = time.time() - player.conn_time
|
delta_conn = time.time() - player.conn_time
|
||||||
plr_pobject = player.get_pobject()
|
plr_pobject = player.get_pobject()
|
||||||
|
|
||||||
|
if show_session_data:
|
||||||
retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \
|
retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \
|
||||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||||
# On-time
|
# On-time
|
||||||
|
|
@ -325,6 +333,15 @@ def cmd_who(cdat):
|
||||||
# More flags?
|
# More flags?
|
||||||
'', \
|
'', \
|
||||||
player.address[0])
|
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),)
|
retval += '%d Players logged in.' % (len(session_list),)
|
||||||
|
|
||||||
session.msg(retval)
|
session.msg(retval)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue