mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 22:06:30 +01:00
Changed default dbref search mechanic to require #N format and thus allow searching for objects named as integers (so "@create/drop 2" followed by 'look 2' will now work as expected instead of looking at the object with dbref=2). Doing "look #2" will now look at the object with dbref 2 (Limbo). Resolves Issue 284.
This commit is contained in:
parent
31daf5b013
commit
5b5328e6ca
3 changed files with 13 additions and 7 deletions
|
|
@ -23,12 +23,14 @@ class CommError(Exception):
|
|||
# helper functions
|
||||
#
|
||||
|
||||
def dbref(dbref):
|
||||
def dbref(dbref, reqhash=True):
|
||||
"""
|
||||
Valid forms of dbref (database reference number)
|
||||
are either a string '#N' or an integer N.
|
||||
Output is the integer part.
|
||||
"""
|
||||
if reqhash and not (isinstance(dbref, basestring) and dbref.startswith("#")):
|
||||
return None
|
||||
if isinstance(dbref, basestring):
|
||||
dbref = dbref.lstrip('#')
|
||||
try:
|
||||
|
|
@ -136,7 +138,7 @@ class MsgManager(models.Manager):
|
|||
def get_message_by_id(self, idnum):
|
||||
"Retrieve message by its id."
|
||||
try:
|
||||
return self.get(id=self.dbref(idnum))
|
||||
return self.get(id=self.dbref(idnum, reqhash=False))
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class ScriptManager(TypedObjectManager):
|
|||
return []
|
||||
if key:
|
||||
dbref = self.dbref(key)
|
||||
if dbref:
|
||||
if dbref or dbref == 0:
|
||||
script = self.filter(db_obj=obj, id=dbref)
|
||||
if script:
|
||||
return script
|
||||
|
|
@ -59,7 +59,7 @@ class ScriptManager(TypedObjectManager):
|
|||
if key:
|
||||
script = []
|
||||
dbref = self.dbref(key)
|
||||
if dbref:
|
||||
if dbref or dbref == 0:
|
||||
script = self.dbref_search(dbref)
|
||||
if not script:
|
||||
scripts = self.filter(db_key=key)
|
||||
|
|
@ -153,7 +153,7 @@ class ScriptManager(TypedObjectManager):
|
|||
|
||||
elif not scripts:
|
||||
# normal operation
|
||||
if dbref and self.dbref(dbref):
|
||||
if dbref and self.dbref(dbref, reqhash=False):
|
||||
scripts = self.get_id(dbref)
|
||||
elif obj:
|
||||
scripts = self.get_all_scripts_on_obj(obj, key=key)
|
||||
|
|
|
|||
|
|
@ -67,12 +67,16 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
Common ObjectManager for all dbobjects.
|
||||
"""
|
||||
|
||||
def dbref(self, dbref):
|
||||
def dbref(self, dbref, reqhash=True):
|
||||
"""
|
||||
Valid forms of dbref (database reference number)
|
||||
are either a string '#N' or an integer N.
|
||||
Output is the integer part.
|
||||
reqhash - require input to be on form "#N" to be
|
||||
identified as a dbref
|
||||
"""
|
||||
if reqhash and not (isinstance(dbref, basestring) and dbref.startswith("#")):
|
||||
return None
|
||||
if isinstance(dbref, basestring):
|
||||
dbref = dbref.lstrip('#')
|
||||
try:
|
||||
|
|
@ -98,7 +102,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
|||
"""
|
||||
Find object with given dbref
|
||||
"""
|
||||
dbref = self.dbref(dbref)
|
||||
dbref = self.dbref(dbref, reqhash=False)
|
||||
try:
|
||||
return self.get(id=dbref)
|
||||
except self.model.DoesNotExist:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue