mirror of
https://github.com/evennia/evennia.git
synced 2026-03-20 23:06:31 +01:00
Move standard_objsearch to Objects.search_for_object. Also make sure @alias only accepts alphanumeric strings.
This commit is contained in:
parent
eacdf8b33c
commit
7ff97599be
7 changed files with 93 additions and 90 deletions
|
|
@ -121,9 +121,8 @@ def cmd_look(command):
|
|||
# If an argument is provided with the command, search for the object.
|
||||
# else look at the current room.
|
||||
if command.command_argument:
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
else:
|
||||
|
|
@ -151,10 +150,9 @@ def cmd_get(command):
|
|||
source_object.emit_to("Get what?")
|
||||
return
|
||||
else:
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument,
|
||||
search_contents=False)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument,
|
||||
search_contents=False)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -193,10 +191,9 @@ def cmd_drop(command):
|
|||
source_object.emit_to("Drop what?")
|
||||
return
|
||||
else:
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument,
|
||||
search_location=False)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument,
|
||||
search_location=False)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -248,9 +245,8 @@ def cmd_examine(command):
|
|||
obj_searchstr = command.command_argument
|
||||
|
||||
# Resolve the target object.
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
obj_searchstr)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(obj_searchstr)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ def cmd_teleport(command):
|
|||
# a direct teleport, @tel <destination>.
|
||||
if len(eq_args) > 1:
|
||||
# Equal sign teleport.
|
||||
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
victim = source_object.search_for_object(eq_args[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not victim:
|
||||
return
|
||||
|
||||
destination = Object.objects.standard_objsearch(source_object, eq_args[1])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
destination = source_object.search_for_object(eq_args[1])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
|
|
@ -50,9 +50,8 @@ def cmd_teleport(command):
|
|||
victim.move_to(destination, quiet=tel_quietly)
|
||||
else:
|
||||
# Direct teleport (no equal sign)
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -83,11 +82,15 @@ def cmd_alias(command):
|
|||
new_alias = eq_args[1]
|
||||
|
||||
# An Object instance for the victim.
|
||||
target = Object.objects.standard_objsearch(source_object, target_string)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target = source_object.search_for_object(target_string)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target:
|
||||
source_object.emit_to("I can't find that player.")
|
||||
return
|
||||
|
||||
if not new_alias.isalnum():
|
||||
source_object.emit_to("Aliases must be alphanumeric.")
|
||||
return
|
||||
|
||||
old_alias = target.get_attribute_value('ALIAS')
|
||||
duplicates = Object.objects.player_alias_search(source_object, new_alias)
|
||||
|
|
@ -130,8 +133,8 @@ def cmd_wipe(command):
|
|||
else:
|
||||
searchstr = command.command_argument
|
||||
|
||||
target_obj = Object.objects.standard_objsearch(source_object, attr_split[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(attr_split[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -173,8 +176,8 @@ def cmd_set(command):
|
|||
source_object.emit_to("Set what?")
|
||||
return
|
||||
|
||||
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
victim = source_object.search_for_object(eq_args[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not victim:
|
||||
return
|
||||
|
||||
|
|
@ -297,7 +300,7 @@ def cmd_cpattr(command):
|
|||
source_attr_string = source[1].strip().upper()
|
||||
|
||||
# Check whether src_obj exists
|
||||
src_obj = Object.objects.standard_objsearch(source_object, source_string)
|
||||
src_obj = source_object.search_for_object(source_string)
|
||||
|
||||
if not src_obj:
|
||||
source_object.emit_to("Source object does not exist.")
|
||||
|
|
@ -319,7 +322,7 @@ def cmd_cpattr(command):
|
|||
tar_string = tar[0].strip()
|
||||
tar_attr_string = tar[1].strip().upper()
|
||||
|
||||
tar_obj = Object.objects.standard_objsearch(source_object, tar_string)
|
||||
tar_obj = source_object.search_for_object(tar_string)
|
||||
|
||||
# Does target exist?
|
||||
if not tar_obj:
|
||||
|
|
@ -372,9 +375,8 @@ def cmd_open(command):
|
|||
if len(eq_args) > 1:
|
||||
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
||||
comma_split = eq_args[1].split(',', 1)
|
||||
destination = Object.objects.standard_objsearch(source_object,
|
||||
comma_split[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
destination = source_object.search_for_object(comma_split[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
|
|
@ -438,8 +440,8 @@ def cmd_chown(command):
|
|||
return
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(target_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -447,8 +449,8 @@ def cmd_chown(command):
|
|||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||
return
|
||||
|
||||
owner_obj = Object.objects.standard_objsearch(source_object, owner_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
owner_obj = source_object.search_for_object(owner_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not owner_obj:
|
||||
return
|
||||
if not owner_obj.is_player():
|
||||
|
|
@ -488,8 +490,8 @@ def cmd_chzone(command):
|
|||
return
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(target_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -503,8 +505,8 @@ def cmd_chzone(command):
|
|||
source_object.emit_to("%s is no longer zoned." % (target_obj))
|
||||
return
|
||||
|
||||
zone_obj = Object.objects.standard_objsearch(source_object, zone_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
zone_obj = source_object.search_for_object(zone_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not zone_obj:
|
||||
return
|
||||
|
||||
|
|
@ -538,8 +540,8 @@ def cmd_link(command):
|
|||
return
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(target_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -553,8 +555,8 @@ def cmd_link(command):
|
|||
source_object.emit_to("You have unlinked %s." % (target_obj,))
|
||||
return
|
||||
|
||||
destination = Object.objects.standard_objsearch(source_object, dest_name)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
destination = source_object.search_for_object(dest_name)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
|
|
@ -578,9 +580,8 @@ def cmd_unlink(command):
|
|||
source_object.emit_to("Unlink what?")
|
||||
return
|
||||
else:
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -637,8 +638,8 @@ def cmd_name(command):
|
|||
if len(eq_args) < 2 or eq_args[1] == '':
|
||||
source_object.emit_to("What would you like to name that object?")
|
||||
else:
|
||||
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(eq_args[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -663,8 +664,8 @@ def cmd_description(command):
|
|||
source_object.emit_to("How would you like to describe that object?")
|
||||
return
|
||||
|
||||
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(eq_args[0])
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
@ -695,9 +696,8 @@ def cmd_destroy(command):
|
|||
if "override" in command.command_switches:
|
||||
switch_override = True
|
||||
|
||||
target_obj = Object.objects.standard_objsearch(source_object,
|
||||
command.command_argument)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(command.command_argument)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ def cmd_newpassword(command):
|
|||
source_object.emit_to("You must supply a new password.")
|
||||
return
|
||||
|
||||
target_obj = Object.objects.standard_objsearch(source_object, searchstring)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
target_obj = source_object.search_for_object(searchstring)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -84,8 +84,7 @@ def build_query(source_object, search_query, search_player, search_type,
|
|||
# Look up an Object matching the player search query
|
||||
if search_player:
|
||||
# Replace the string variable with an Object reference
|
||||
search_player = Object.objects.standard_objsearch(source_object,
|
||||
search_player)
|
||||
search_player = source_object.search_for_object(search_player)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results
|
||||
if not search_player:
|
||||
return None
|
||||
|
|
@ -121,9 +120,8 @@ def build_query(source_object, search_query, search_player, search_type,
|
|||
search_query = search_query.filter(name__icontains=search_restriction,
|
||||
type=defines_global.OTYPE_PLAYER)
|
||||
elif search_type == "zone":
|
||||
zone_obj = Object.objects.standard_objsearch(source_object,
|
||||
search_restriction)
|
||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||
zone_obj = source_object.search_for_object(search_restriction)
|
||||
# Use search_for_object to handle duplicate/nonexistant results.
|
||||
if not zone_obj:
|
||||
return None
|
||||
search_query = search_query.filter(zone=zone_obj)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
[{"pk": 1, "model": "helpsys.helpentry", "fields": {"entrytext": "This is to prevent a weird encoding error with SQLite3.", "topicname": "Z19kD", "staff_only": false}}]
|
||||
[{"pk": 1, "model": "helpsys.helpentry", "fields": {"entrytext": " This is the TinyMUX online help facility.\r\n\r\n Notes on help descriptions:\r\n [text] - Text enclosed in []'s is optional. The []'s are never typed\r\n in as part of the command.\r\n <parameter> - Information parameter for a command. The <>'s are\r\n never typed in as part of the command.\r\n\r\n - Syntax of help command:\r\n help [<command>]\r\n\r\n - To get a list of TinyMUX topics:\r\n help topics\r\n\r\n - To get a list of Comsystem commands:\r\n help comsys\r\n\r\n - To get a list of TinyMUX Commands:\r\n help commands (or @list commands)\r\n\r\n Some of the configuration shown in the help.txt might not be the same as\r\n the configuration of this MUX. If you notice any errors, contact an admin.\r\n", "topicname": "Help Index", "staff_only": false}}]
|
||||
|
|
|
|||
|
|
@ -99,34 +99,6 @@ class ObjectManager(models.Manager):
|
|||
else:
|
||||
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
|
||||
|
||||
|
||||
def standard_objsearch(self, source_object, ostring, search_contents=True,
|
||||
search_location=True, dbref_only=False,
|
||||
limit_types=False):
|
||||
"""
|
||||
Perform a standard object search, handling multiple
|
||||
results and lack thereof gracefully.
|
||||
|
||||
source_object: (Object) The Object doing the searching
|
||||
ostring: (str) The string to match object names against.
|
||||
"""
|
||||
results = self.local_and_global_search(source_object, ostring,
|
||||
search_contents=search_contents,
|
||||
search_location=search_location,
|
||||
dbref_only=dbref_only,
|
||||
limit_types=limit_types)
|
||||
|
||||
if len(results) > 1:
|
||||
source_object.emit_to("More than one match found (please narrow target):")
|
||||
for result in results:
|
||||
source_object.emit_to(" %s" % (result.get_name(),))
|
||||
return False
|
||||
elif len(results) == 0:
|
||||
source_object.emit_to("I don't see that here.")
|
||||
return False
|
||||
else:
|
||||
return results[0]
|
||||
|
||||
def object_totals(self):
|
||||
"""
|
||||
Returns a dictionary with database object totals.
|
||||
|
|
|
|||
|
|
@ -136,6 +136,43 @@ class Object(models.Model):
|
|||
"""
|
||||
BEGIN COMMON METHODS
|
||||
"""
|
||||
def search_for_object(self, ostring, emit_to_obj=None, search_contents=True,
|
||||
search_location=True, dbref_only=False,
|
||||
limit_types=False, search_aliases=False):
|
||||
"""
|
||||
Perform a standard object search, handling multiple
|
||||
results and lack thereof gracefully.
|
||||
|
||||
source_object: (Object) The Object doing the searching
|
||||
ostring: (str) The string to match object names against.
|
||||
"""
|
||||
# This is the object that gets the duplicate/no match emits.
|
||||
if not emit_to_obj:
|
||||
emit_to_obj = self
|
||||
|
||||
if search_aliases:
|
||||
# If an alias match is found, get out of here and skip the rest.
|
||||
alias_results = Object.objects.player_alias_search(self, ostring)
|
||||
if alias_results:
|
||||
return alias_results[0]
|
||||
|
||||
results = Object.objects.local_and_global_search(self, ostring,
|
||||
search_contents=search_contents,
|
||||
search_location=search_location,
|
||||
dbref_only=dbref_only,
|
||||
limit_types=limit_types)
|
||||
|
||||
if len(results) > 1:
|
||||
emit_to_obj.emit_to("More than one match found (please narrow target):")
|
||||
for result in results:
|
||||
emit_to_obj.emit_to(" %s" % (result.get_name(),))
|
||||
return False
|
||||
elif len(results) == 0:
|
||||
emit_to_obj.emit_to("I don't see that here.")
|
||||
return False
|
||||
else:
|
||||
return results[0]
|
||||
|
||||
def get_sessions(self):
|
||||
"""
|
||||
Returns a list of sessions matching this object.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue