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.
|
# If an argument is provided with the command, search for the object.
|
||||||
# else look at the current room.
|
# else look at the current room.
|
||||||
if command.command_argument:
|
if command.command_argument:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument)
|
||||||
command.command_argument)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
@ -151,10 +150,9 @@ def cmd_get(command):
|
||||||
source_object.emit_to("Get what?")
|
source_object.emit_to("Get what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument,
|
||||||
command.command_argument,
|
search_contents=False)
|
||||||
search_contents=False)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -193,10 +191,9 @@ def cmd_drop(command):
|
||||||
source_object.emit_to("Drop what?")
|
source_object.emit_to("Drop what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument,
|
||||||
command.command_argument,
|
search_location=False)
|
||||||
search_location=False)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -248,9 +245,8 @@ def cmd_examine(command):
|
||||||
obj_searchstr = command.command_argument
|
obj_searchstr = command.command_argument
|
||||||
|
|
||||||
# Resolve the target object.
|
# Resolve the target object.
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(obj_searchstr)
|
||||||
obj_searchstr)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ def cmd_teleport(command):
|
||||||
# a direct teleport, @tel <destination>.
|
# a direct teleport, @tel <destination>.
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
# Equal sign teleport.
|
# Equal sign teleport.
|
||||||
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
victim = source_object.search_for_object(eq_args[0])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not victim:
|
if not victim:
|
||||||
return
|
return
|
||||||
|
|
||||||
destination = Object.objects.standard_objsearch(source_object, eq_args[1])
|
destination = source_object.search_for_object(eq_args[1])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -50,9 +50,8 @@ def cmd_teleport(command):
|
||||||
victim.move_to(destination, quiet=tel_quietly)
|
victim.move_to(destination, quiet=tel_quietly)
|
||||||
else:
|
else:
|
||||||
# Direct teleport (no equal sign)
|
# Direct teleport (no equal sign)
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument)
|
||||||
command.command_argument)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -83,11 +82,15 @@ def cmd_alias(command):
|
||||||
new_alias = eq_args[1]
|
new_alias = eq_args[1]
|
||||||
|
|
||||||
# An Object instance for the victim.
|
# An Object instance for the victim.
|
||||||
target = Object.objects.standard_objsearch(source_object, target_string)
|
target = source_object.search_for_object(target_string)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target:
|
if not target:
|
||||||
source_object.emit_to("I can't find that player.")
|
source_object.emit_to("I can't find that player.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not new_alias.isalnum():
|
||||||
|
source_object.emit_to("Aliases must be alphanumeric.")
|
||||||
|
return
|
||||||
|
|
||||||
old_alias = target.get_attribute_value('ALIAS')
|
old_alias = target.get_attribute_value('ALIAS')
|
||||||
duplicates = Object.objects.player_alias_search(source_object, new_alias)
|
duplicates = Object.objects.player_alias_search(source_object, new_alias)
|
||||||
|
|
@ -130,8 +133,8 @@ def cmd_wipe(command):
|
||||||
else:
|
else:
|
||||||
searchstr = command.command_argument
|
searchstr = command.command_argument
|
||||||
|
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, attr_split[0])
|
target_obj = source_object.search_for_object(attr_split[0])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -173,8 +176,8 @@ def cmd_set(command):
|
||||||
source_object.emit_to("Set what?")
|
source_object.emit_to("Set what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
victim = source_object.search_for_object(eq_args[0])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not victim:
|
if not victim:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -297,7 +300,7 @@ def cmd_cpattr(command):
|
||||||
source_attr_string = source[1].strip().upper()
|
source_attr_string = source[1].strip().upper()
|
||||||
|
|
||||||
# Check whether src_obj exists
|
# 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:
|
if not src_obj:
|
||||||
source_object.emit_to("Source object does not exist.")
|
source_object.emit_to("Source object does not exist.")
|
||||||
|
|
@ -319,7 +322,7 @@ def cmd_cpattr(command):
|
||||||
tar_string = tar[0].strip()
|
tar_string = tar[0].strip()
|
||||||
tar_attr_string = tar[1].strip().upper()
|
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?
|
# Does target exist?
|
||||||
if not tar_obj:
|
if not tar_obj:
|
||||||
|
|
@ -372,9 +375,8 @@ def cmd_open(command):
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
||||||
comma_split = eq_args[1].split(',', 1)
|
comma_split = eq_args[1].split(',', 1)
|
||||||
destination = Object.objects.standard_objsearch(source_object,
|
destination = source_object.search_for_object(comma_split[0])
|
||||||
comma_split[0])
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -438,8 +440,8 @@ def cmd_chown(command):
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
target_obj = source_object.search_for_object(target_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -447,8 +449,8 @@ def cmd_chown(command):
|
||||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
owner_obj = Object.objects.standard_objsearch(source_object, owner_name)
|
owner_obj = source_object.search_for_object(owner_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not owner_obj:
|
if not owner_obj:
|
||||||
return
|
return
|
||||||
if not owner_obj.is_player():
|
if not owner_obj.is_player():
|
||||||
|
|
@ -488,8 +490,8 @@ def cmd_chzone(command):
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
target_obj = source_object.search_for_object(target_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -503,8 +505,8 @@ def cmd_chzone(command):
|
||||||
source_object.emit_to("%s is no longer zoned." % (target_obj))
|
source_object.emit_to("%s is no longer zoned." % (target_obj))
|
||||||
return
|
return
|
||||||
|
|
||||||
zone_obj = Object.objects.standard_objsearch(source_object, zone_name)
|
zone_obj = source_object.search_for_object(zone_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not zone_obj:
|
if not zone_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -538,8 +540,8 @@ def cmd_link(command):
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
target_obj = source_object.search_for_object(target_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -553,8 +555,8 @@ def cmd_link(command):
|
||||||
source_object.emit_to("You have unlinked %s." % (target_obj,))
|
source_object.emit_to("You have unlinked %s." % (target_obj,))
|
||||||
return
|
return
|
||||||
|
|
||||||
destination = Object.objects.standard_objsearch(source_object, dest_name)
|
destination = source_object.search_for_object(dest_name)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -578,9 +580,8 @@ def cmd_unlink(command):
|
||||||
source_object.emit_to("Unlink what?")
|
source_object.emit_to("Unlink what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument)
|
||||||
command.command_argument)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -637,8 +638,8 @@ def cmd_name(command):
|
||||||
if len(eq_args) < 2 or eq_args[1] == '':
|
if len(eq_args) < 2 or eq_args[1] == '':
|
||||||
source_object.emit_to("What would you like to name that object?")
|
source_object.emit_to("What would you like to name that object?")
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
|
target_obj = source_object.search_for_object(eq_args[0])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -663,8 +664,8 @@ def cmd_description(command):
|
||||||
source_object.emit_to("How would you like to describe that object?")
|
source_object.emit_to("How would you like to describe that object?")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
|
target_obj = source_object.search_for_object(eq_args[0])
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -695,9 +696,8 @@ def cmd_destroy(command):
|
||||||
if "override" in command.command_switches:
|
if "override" in command.command_switches:
|
||||||
switch_override = True
|
switch_override = True
|
||||||
|
|
||||||
target_obj = Object.objects.standard_objsearch(source_object,
|
target_obj = source_object.search_for_object(command.command_argument)
|
||||||
command.command_argument)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@ def cmd_newpassword(command):
|
||||||
source_object.emit_to("You must supply a new password.")
|
source_object.emit_to("You must supply a new password.")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj = Object.objects.standard_objsearch(source_object, searchstring)
|
target_obj = source_object.search_for_object(searchstring)
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
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
|
# Look up an Object matching the player search query
|
||||||
if search_player:
|
if search_player:
|
||||||
# Replace the string variable with an Object reference
|
# Replace the string variable with an Object reference
|
||||||
search_player = Object.objects.standard_objsearch(source_object,
|
search_player = source_object.search_for_object(search_player)
|
||||||
search_player)
|
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results
|
# Use standard_objsearch to handle duplicate/nonexistant results
|
||||||
if not search_player:
|
if not search_player:
|
||||||
return None
|
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,
|
search_query = search_query.filter(name__icontains=search_restriction,
|
||||||
type=defines_global.OTYPE_PLAYER)
|
type=defines_global.OTYPE_PLAYER)
|
||||||
elif search_type == "zone":
|
elif search_type == "zone":
|
||||||
zone_obj = Object.objects.standard_objsearch(source_object,
|
zone_obj = source_object.search_for_object(search_restriction)
|
||||||
search_restriction)
|
# Use search_for_object to handle duplicate/nonexistant results.
|
||||||
# Use standard_objsearch to handle duplicate/nonexistant results.
|
|
||||||
if not zone_obj:
|
if not zone_obj:
|
||||||
return None
|
return None
|
||||||
search_query = search_query.filter(zone=zone_obj)
|
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:
|
else:
|
||||||
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
|
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):
|
def object_totals(self):
|
||||||
"""
|
"""
|
||||||
Returns a dictionary with database object totals.
|
Returns a dictionary with database object totals.
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,43 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
BEGIN COMMON METHODS
|
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):
|
def get_sessions(self):
|
||||||
"""
|
"""
|
||||||
Returns a list of sessions matching this object.
|
Returns a list of sessions matching this object.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue