Made lock command warn for using the wrong input form. Strip extraneous quotes from lock strings to avoid strange issue with escaped quotes from the command system. Resolves #758.

This commit is contained in:
Griatch 2015-06-13 00:08:12 +02:00
parent f00f917e41
commit 4d69e80787

View file

@ -4,6 +4,7 @@ import sys
Building and world design commands Building and world design commands
""" """
import re
from django.conf import settings from django.conf import settings
from django.db.models import Q from django.db.models import Q
from evennia.objects.models import ObjectDB from evennia.objects.models import ObjectDB
@ -1654,7 +1655,7 @@ class CmdLock(ObjManipCommand):
object. object.
Lockstring is on the form Lockstring is on the form
'access_type:[NOT] func1(args)[ AND|OR][ NOT] func2(args) ...] access_type:[NOT] func1(args)[ AND|OR][ NOT] func2(args) ...]
Where func1, func2 ... valid lockfuncs with or without arguments. Where func1, func2 ... valid lockfuncs with or without arguments.
Separator expressions need not be capitalized. Separator expressions need not be capitalized.
@ -1681,6 +1682,7 @@ class CmdLock(ObjManipCommand):
string = "@lock <object>[ = <lockstring>] or @lock[/switch] object/<access_type>" string = "@lock <object>[ = <lockstring>] or @lock[/switch] object/<access_type>"
caller.msg(string) caller.msg(string)
return return
if '/' in self.lhs: if '/' in self.lhs:
# call on the form @lock obj/access_type # call on the form @lock obj/access_type
objname, access_type = [p.strip() for p in self.lhs.split('/', 1)] objname, access_type = [p.strip() for p in self.lhs.split('/', 1)]
@ -1688,6 +1690,7 @@ class CmdLock(ObjManipCommand):
if not obj: if not obj:
return return
lockdef = obj.locks.get(access_type) lockdef = obj.locks.get(access_type)
string = ""
if lockdef: if lockdef:
if 'del' in self.switches: if 'del' in self.switches:
if not obj.access(caller, 'control'): if not obj.access(caller, 'control'):
@ -1695,6 +1698,8 @@ class CmdLock(ObjManipCommand):
return return
obj.locks.delete(access_type) obj.locks.delete(access_type)
string = "deleted lock %s" % lockdef string = "deleted lock %s" % lockdef
else:
string = lockdef
else: else:
string = "%s has no lock of access type '%s'." % (obj, access_type) string = "%s has no lock of access type '%s'." % (obj, access_type)
caller.msg(string) caller.msg(string)
@ -1702,6 +1707,13 @@ class CmdLock(ObjManipCommand):
if self.rhs: if self.rhs:
# we have a = separator, so we are assigning a new lock # we have a = separator, so we are assigning a new lock
if self.switches:
swi = ", ".join(self.switches)
caller.msg("Switch(es) {w%s{n can not be used with a "\
"lock assignment. Use e.g. " \
"{w@lock/del objname/locktype{n instead." % swi)
return
objname, lockdef = self.lhs, self.rhs objname, lockdef = self.lhs, self.rhs
obj = caller.search(objname) obj = caller.search(objname)
if not obj: if not obj:
@ -1710,6 +1722,7 @@ class CmdLock(ObjManipCommand):
caller.msg("You are not allowed to do that.") caller.msg("You are not allowed to do that.")
return return
ok = False ok = False
lockdef = re.sub(r"\'|\"", "", lockdef)
try: try:
ok = obj.locks.add(lockdef) ok = obj.locks.add(lockdef)
except LockException, e: except LockException, e: