From e193844f6f988fc98809358c36227c2a438d8518 Mon Sep 17 00:00:00 2001 From: CloudKeeper <46334817+CloudKeeper@users.noreply.github.com> Date: Sat, 10 Sep 2022 11:10:35 +1000 Subject: [PATCH 1/2] Add 'search' lock for obj.search() and --- evennia/objects/objects.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index def8ba0843..2174bfe972 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -387,6 +387,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): quiet=False, exact=False, candidates=None, + use_locks=True, nofound_string=None, multimatch_string=None, use_dbref=None, @@ -444,6 +445,8 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): is given. If not set, this list will automatically be defined to include the location, the contents of location and the caller's contents (inventory). + use_locks (bool): If True (default) - removes search results which + fail the "search" lock. nofound_string (str): optional custom string for not-found error message. multimatch_string (str): optional custom string for multimatch error header. use_dbref (bool or None, optional): If `True`, allow to enter e.g. a query "#123" @@ -529,6 +532,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): use_dbref=use_dbref, ) + if use_locks: + results = [x for x in list(results) if x.access(self, "search")] + nresults = len(results) if stacked > 0 and nresults > 1: # handle stacks, disable multimatch errors @@ -1797,7 +1803,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): def get_visible_contents(self, looker, **kwargs): """ Get all contents of this object that a looker can see (whatever that means, by default it - checks the 'view' lock), grouped by type. Helper method to return_appearance. + checks the 'view' and 'search' locks), grouped by type. Helper method to return_appearance. Args: looker (Object): The entity looking. @@ -1811,7 +1817,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): """ def filter_visible(obj_list): - return [obj for obj in obj_list if obj != looker and obj.access(looker, "view")] + return [obj for obj in obj_list if obj != looker and obj.access(looker, "view") and obj.access(looker, "search")] return { "exits": filter_visible(self.contents_get(content_type="exit")), From 30fe8070b6bc4ff0b01254410362f3a4f21988ff Mon Sep 17 00:00:00 2001 From: CloudKeeper <46334817+CloudKeeper@users.noreply.github.com> Date: Sun, 11 Sep 2022 13:25:05 +1000 Subject: [PATCH 2/2] Update objects.py --- evennia/objects/objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 2174bfe972..fbdf81a01f 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -533,7 +533,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): ) if use_locks: - results = [x for x in list(results) if x.access(self, "search")] + results = [x for x in list(results) if x.access(self, "search", default=True)] nresults = len(results) if stacked > 0 and nresults > 1: @@ -1817,7 +1817,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase): """ def filter_visible(obj_list): - return [obj for obj in obj_list if obj != looker and obj.access(looker, "view") and obj.access(looker, "search")] + return [obj for obj in obj_list if obj != looker and obj.access(looker, "view") and obj.access(looker, "search", default=True)] return { "exits": filter_visible(self.contents_get(content_type="exit")),