Made search(*playername) commands correctly return a Player typeclass and not a character. Initial startup/character creation: Default permissions are now assigned on player level rather than character level (this gives more safety to @puppet operations). Made @puppet command work only on Character objects.
This commit is contained in:
parent
c9861e06de
commit
547eb53b32
8 changed files with 61 additions and 39 deletions
|
|
@ -5,7 +5,7 @@ from django.conf import settings
|
||||||
from src.permissions.permissions import has_perm, has_perm_string
|
from src.permissions.permissions import has_perm, has_perm_string
|
||||||
from src.objects.models import ObjectDB, ObjAttribute
|
from src.objects.models import ObjectDB, ObjAttribute
|
||||||
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
||||||
from src.utils import create
|
from src.utils import create, utils
|
||||||
|
|
||||||
class ObjManipCommand(MuxCommand):
|
class ObjManipCommand(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1468,16 +1468,20 @@ class CmdExamine(ObjManipCommand):
|
||||||
string += "\n{wAliases{n: %s" % (", ".join(obj.aliases))
|
string += "\n{wAliases{n: %s" % (", ".join(obj.aliases))
|
||||||
if obj.has_player:
|
if obj.has_player:
|
||||||
string += "\n{wPlayer{n: %s" % obj.player.name
|
string += "\n{wPlayer{n: %s" % obj.player.name
|
||||||
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass, obj.typeclass_path)
|
perms = obj.player.permissions
|
||||||
string += "\n{wLocation{n: %s" % obj.location
|
if obj.player.is_superuser:
|
||||||
perms = obj.permissions
|
|
||||||
if obj.player and obj.player.is_superuser:
|
|
||||||
perms = ["<Superuser>"]
|
perms = ["<Superuser>"]
|
||||||
elif not perms:
|
elif not perms:
|
||||||
perms = ["<None>"]
|
perms = ["<None>"]
|
||||||
string += "\n{wPerms/Locks{n: %s" % (", ".join(perms))
|
string += "\n{wPlayer Perms/Locks{n: %s" % (", ".join(perms))
|
||||||
|
|
||||||
|
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass, obj.typeclass_path)
|
||||||
|
string += "\n{wLocation{n: %s" % obj.location
|
||||||
|
perms = obj.permissions
|
||||||
|
if perms:
|
||||||
|
string += "\n{wObj Perms/Locks{n: %s" % (", ".join(perms))
|
||||||
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
|
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
|
||||||
string += "\n{wCurrent Cmdset{n:\n\r %s" % obj.cmdset
|
string += "\n{wCurrent Cmdset (before permission checks){n:\n\r %s" % obj.cmdset
|
||||||
if obj.scripts.all():
|
if obj.scripts.all():
|
||||||
string += "\n{wScripts{n:\n\r %s" % obj.scripts
|
string += "\n{wScripts{n:\n\r %s" % obj.scripts
|
||||||
# add the attributes
|
# add the attributes
|
||||||
|
|
@ -1663,6 +1667,9 @@ class CmdPuppet(MuxCommand):
|
||||||
new_character = caller.search(self.args)
|
new_character = caller.search(self.args)
|
||||||
if not new_character:
|
if not new_character:
|
||||||
return
|
return
|
||||||
|
if not utils.inherits_from(new_character, settings.BASE_CHARACTER_TYPECLASS):
|
||||||
|
caller.msg("%s is not a Character." % self.args)
|
||||||
|
return
|
||||||
if player.swap_character(new_character):
|
if player.swap_character(new_character):
|
||||||
new_character.msg("You now control %s." % new_character.name)
|
new_character.msg("You now control %s." % new_character.name)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ exceptions.
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.conf import settings
|
||||||
from src.server import sessionhandler
|
from src.server import sessionhandler
|
||||||
from src.players.models import PlayerDB
|
from src.players.models import PlayerDB
|
||||||
from src.scripts.models import ScriptDB
|
from src.scripts.models import ScriptDB
|
||||||
|
|
@ -745,49 +746,59 @@ class CmdPerm(MuxCommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
# locate the object/player
|
# locate the object/player
|
||||||
obj = caller.search(self.lhs, global_search=True)
|
obj = caller.search(lhs, global_search=True)
|
||||||
if not obj:
|
if not obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
pstring = ""
|
||||||
|
if utils.inherits_from(obj, settings.BASE_PLAYER_TYPECLASS):
|
||||||
|
pstring = " Player "
|
||||||
|
|
||||||
if not rhs:
|
if not rhs:
|
||||||
string = "Permission string on {w%s{n: " % obj.key
|
string = "Permission string on %s{w%s{n: " % (pstring, obj.key)
|
||||||
if not obj.permissions:
|
if not obj.permissions:
|
||||||
string += "<None>"
|
string += "<None>"
|
||||||
else:
|
else:
|
||||||
string += ", ".join(obj.permissions)
|
string += ", ".join(obj.permissions)
|
||||||
if obj.player and obj.player.is_superuser:
|
if pstring and obj.is_superuser:
|
||||||
|
string += "\n(... But this player is a SUPERUSER! "
|
||||||
|
string += "All access checked are passed automatically.)"
|
||||||
|
elif obj.player and obj.player.is_superuser:
|
||||||
string += "\n(... But this object's player is a SUPERUSER! "
|
string += "\n(... But this object's player is a SUPERUSER! "
|
||||||
string += "All access checked are passed automatically.)"
|
string += "All access checked are passed automatically.)"
|
||||||
|
|
||||||
|
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
# we supplied an argument on the form obj = perm
|
# we supplied an argument on the form obj = perm
|
||||||
|
|
||||||
|
cstring = ""
|
||||||
|
tstring = ""
|
||||||
if 'del' in switches:
|
if 'del' in switches:
|
||||||
# delete the given permission from object.
|
# delete the given permission(s) from object.
|
||||||
|
for perm in self.rhslist:
|
||||||
try:
|
try:
|
||||||
index = obj.permissions.index(rhs)
|
index = obj.permissions.index(perm)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
caller.msg("Permission '%s' was not defined on object." % rhs)
|
cstring += "\nPermission '%s' was not defined on %s%s." % (perm, pstring, lhs)
|
||||||
return
|
continue
|
||||||
permissions = obj.permissions
|
permissions = obj.permissions
|
||||||
del permissions[index]
|
del permissions[index]
|
||||||
obj.permissions = permissions
|
obj.permissions = permissions
|
||||||
caller.msg("Permission '%s' was removed from object %s." % (rhs, obj.name))
|
cstring += "\nPermission '%s' was removed from %s%s." % (perm, pstring, obj.name)
|
||||||
obj.msg("%s revokes the permission '%s' from you." % (caller.name, rhs))
|
tstring += "\n%s revokes the permission '%s' from you." % (caller.name, perm)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# As an extra check, we warn the user if they customize the
|
# As an extra check, we warn the user if they customize the
|
||||||
# permission string (which is okay, and is used by the lock system)
|
# permission string (which is okay, and is used by the lock system)
|
||||||
permissions = obj.permissions
|
permissions = obj.permissions
|
||||||
if rhs in permissions:
|
for perm in self.rhslist:
|
||||||
string = "Permission '%s' is already defined on %s." % (rhs, obj.name)
|
|
||||||
else:
|
|
||||||
permissions.append(rhs)
|
|
||||||
obj.permissions = permissions
|
|
||||||
string = "Permission '%s' given to %s." % (rhs, obj.name)
|
|
||||||
obj.msg("%s granted you the permission '%s'." % (caller.name, rhs))
|
|
||||||
caller.msg(string)
|
|
||||||
|
|
||||||
|
if perm in permissions:
|
||||||
|
cstring += "\nPermission '%s' is already defined on %s%s." % (rhs, pstring, obj.name)
|
||||||
|
else:
|
||||||
|
permissions.append(perm)
|
||||||
|
obj.permissions = permissions
|
||||||
|
cstring += "\nPermission '%s' given to %s%s." % (rhs, pstring, obj.name)
|
||||||
|
tstring += "\n%s granted you the permission '%s'." % (caller.name, rhs)
|
||||||
|
caller.msg(cstring.strip())
|
||||||
|
if tstring:
|
||||||
|
obj.msg(tstring.strip())
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
cmdsetclass = CACHED_CMDSETS.get(wanted_cache_key, None)
|
cmdsetclass = CACHED_CMDSETS.get(wanted_cache_key, None)
|
||||||
errstring = ""
|
errstring = ""
|
||||||
if not cmdsetclass:
|
if not cmdsetclass:
|
||||||
print "cmdset %s not in cache. Reloading." % wanted_cache_key
|
#print "cmdset %s not in cache. Reloading." % wanted_cache_key
|
||||||
# Not in cache. Reload from disk.
|
# Not in cache. Reload from disk.
|
||||||
modulepath, classname = python_path.rsplit('.', 1)
|
modulepath, classname = python_path.rsplit('.', 1)
|
||||||
module = __import__(modulepath, fromlist=[True])
|
module = __import__(modulepath, fromlist=[True])
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
A player<->user is a one-to-relationship, so this always
|
A player<->user is a one-to-relationship, so this always
|
||||||
returns just one result or None.
|
returns just one result or None.
|
||||||
|
|
||||||
user - mayb be a user object or user id.
|
user - may be a user object or user id.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
uid = int(user)
|
uid = int(user)
|
||||||
|
|
@ -281,7 +281,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
player_string = ostring.lstrip("*")
|
player_string = ostring.lstrip("*")
|
||||||
player_match = self.get_object_with_player(player_string)
|
player_match = self.get_object_with_player(player_string)
|
||||||
if player_match is not None:
|
if player_match is not None:
|
||||||
return [player_match]
|
return [player_match.player]
|
||||||
|
|
||||||
# find suitable objects
|
# find suitable objects
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -414,6 +414,8 @@ class ObjectDB(TypedObject):
|
||||||
ostring: (str) The string to match object names against.
|
ostring: (str) The string to match object names against.
|
||||||
Obs - To find a player, append * to the
|
Obs - To find a player, append * to the
|
||||||
start of ostring.
|
start of ostring.
|
||||||
|
global_search: Search all objects, not just the current
|
||||||
|
location/inventory
|
||||||
attribute_name: (string) Which attribute to match
|
attribute_name: (string) Which attribute to match
|
||||||
(if None, uses default 'name')
|
(if None, uses default 'name')
|
||||||
use_nicks : Use nickname replace (off by default)
|
use_nicks : Use nickname replace (off by default)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ PERMS = [
|
||||||
'examine',
|
'examine',
|
||||||
'typeclass',
|
'typeclass',
|
||||||
'debug',
|
'debug',
|
||||||
|
'puppet',
|
||||||
|
|
||||||
'batchcommands',
|
'batchcommands',
|
||||||
'batchcodes',
|
'batchcodes',
|
||||||
|
|
@ -89,6 +90,7 @@ GROUPS = {
|
||||||
'perm',
|
'perm',
|
||||||
'batchcommands',
|
'batchcommands',
|
||||||
'batchcodes',
|
'batchcodes',
|
||||||
|
'puppet',
|
||||||
|
|
||||||
'wall',
|
'wall',
|
||||||
'boot',
|
'boot',
|
||||||
|
|
|
||||||
|
|
@ -434,6 +434,6 @@ def create_player(name, email, password,
|
||||||
new_character = create_object(typeclass, name,
|
new_character = create_object(typeclass, name,
|
||||||
location, home,
|
location, home,
|
||||||
player=new_player)
|
player=new_player)
|
||||||
set_perm(new_character, permissions)
|
#set_perm(new_character, permissions)
|
||||||
return new_character
|
return new_character
|
||||||
return new_player
|
return new_player
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ def validate_email_address(emailaddress):
|
||||||
|
|
||||||
def inherits_from(obj, parent):
|
def inherits_from(obj, parent):
|
||||||
"""
|
"""
|
||||||
Takes an object and tries to determine if it inherits
|
Takes an object and tries to determine if it inherits at any distance
|
||||||
from parent. What differs this function from e.g. isinstance()
|
from parent. What differs this function from e.g. isinstance()
|
||||||
is that obj may be both an instance and a class, and parent
|
is that obj may be both an instance and a class, and parent
|
||||||
may be an instance, a class, or the python path to a class (counting
|
may be an instance, a class, or the python path to a class (counting
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue