mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 23:36:30 +01:00
Added a more comprehensive recursive location-loop checker that shouldn't be too expensive. Thanks to rcaskey for bouncing ideas in IRC!
This commit is contained in:
parent
7de8e3fa82
commit
7997cf62e8
1 changed files with 12 additions and 6 deletions
|
|
@ -285,12 +285,18 @@ class ObjectDB(TypedObject):
|
|||
loc = _GA(location, "dbobj")
|
||||
else:
|
||||
loc = location
|
||||
if loc == self:
|
||||
# block 1st level recursion; best to defer having to do
|
||||
# a full recursive check of location loops if possible -
|
||||
# (it's rather expensive) this could be checked higher up
|
||||
# if a problem.
|
||||
raise RuntimeError
|
||||
|
||||
# recursive location check
|
||||
def is_loc_loop(loc, depth=0):
|
||||
"Recursively traverse the target location to make sure we are not in it."
|
||||
if depth > 10: return
|
||||
elif loc == self: raise RuntimeError
|
||||
elif loc == None: raise RuntimeWarning # just to quickly get out
|
||||
return is_loc_loop(_GA(loc, "db_location"), depth+1)
|
||||
# check so we don't create a location loop - if so, RuntimeError will be raised.
|
||||
try: is_loc_loop(loc)
|
||||
except RuntimeWarning: pass
|
||||
|
||||
# set the location
|
||||
_set_cache(self, "location", loc)
|
||||
# update the contents of each location
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue