Fixes, cleanups and bugfixes in various systems.
This commit is contained in:
parent
1565ac3a72
commit
8770a263ac
7 changed files with 33 additions and 39 deletions
|
|
@ -59,7 +59,7 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
|
||||||
if mindex.isdigit():
|
if mindex.isdigit():
|
||||||
mindex = int(mindex) - 1
|
mindex = int(mindex) - 1
|
||||||
# feed result back to parser iteratively
|
# feed result back to parser iteratively
|
||||||
return cmdparser(new_raw_string, cmdset, match_index=mindex)
|
return cmdparser(new_raw_string, cmdset, caller, match_index=mindex)
|
||||||
|
|
||||||
# only select command matches we are actually allowed to call.
|
# only select command matches we are actually allowed to call.
|
||||||
matches = [match for match in matches if match[2].access(caller, 'cmd')]
|
matches = [match for match in matches if match[2].access(caller, 'cmd')]
|
||||||
|
|
|
||||||
|
|
@ -1014,7 +1014,7 @@ class CmdOpen(ObjManipCommand):
|
||||||
@open - create new exit
|
@open - create new exit
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@open <new exit>[;alias;alias..][:typeclass] = <destination> [,<return exit>[;alias;..][:typeclass]]]
|
@open <new exit>[;alias;alias..][:typeclass] [,<return exit>[;alias;..][:typeclass]]] = <destination>
|
||||||
|
|
||||||
Handles the creation of exits. If a destination is given, the exit
|
Handles the creation of exits. If a destination is given, the exit
|
||||||
will point there. The <return exit> argument sets up an exit at the
|
will point there. The <return exit> argument sets up an exit at the
|
||||||
|
|
@ -1075,9 +1075,9 @@ class CmdOpen(ObjManipCommand):
|
||||||
if exit_obj:
|
if exit_obj:
|
||||||
# storing a destination is what makes it an exit!
|
# storing a destination is what makes it an exit!
|
||||||
exit_obj.destination = destination
|
exit_obj.destination = destination
|
||||||
string = "Created new Exit '%s' to %s (aliases: %s)." % (exit_name,
|
string = "Created new Exit '%s' from %s to %s (aliases: %s)." % (exit_name,location.name,
|
||||||
destination.name,
|
destination.name,
|
||||||
exit_aliases)
|
exit_aliases)
|
||||||
else:
|
else:
|
||||||
string = "Error: Exit '%s' not created." % (exit_name)
|
string = "Error: Exit '%s' not created." % (exit_name)
|
||||||
# emit results
|
# emit results
|
||||||
|
|
@ -1093,8 +1093,8 @@ class CmdOpen(ObjManipCommand):
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
|
||||||
if not self.args or not self.rhs:
|
if not self.args or not self.rhs:
|
||||||
string = "Usage: @open <new exit>[;alias;alias...][:typeclass] "
|
string = "Usage: @open <new exit>[;alias...][:typeclass][,<return exit>[;alias..][:typeclass]]] "
|
||||||
string += "= <destination [,<return exit>[;alias..][:typeclass]]]"
|
string += "= <destination>"
|
||||||
caller.msg(string)
|
caller.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -1109,33 +1109,25 @@ class CmdOpen(ObjManipCommand):
|
||||||
exit_name = self.lhs_objs[0]['name']
|
exit_name = self.lhs_objs[0]['name']
|
||||||
exit_aliases = self.lhs_objs[0]['aliases']
|
exit_aliases = self.lhs_objs[0]['aliases']
|
||||||
exit_typeclass = self.lhs_objs[0]['option']
|
exit_typeclass = self.lhs_objs[0]['option']
|
||||||
|
dest_name = self.rhs
|
||||||
dest_name = self.rhs_objs[0]['name']
|
|
||||||
|
|
||||||
# first, check so the destination exists.
|
# first, check so the destination exists.
|
||||||
destination = caller.search(dest_name, global_search=True)
|
destination = caller.search(dest_name, global_search=True)
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create exit
|
# Create exit
|
||||||
|
|
||||||
ok = self.create_exit(exit_name, location, destination, exit_aliases, exit_typeclass)
|
ok = self.create_exit(exit_name, location, destination, exit_aliases, exit_typeclass)
|
||||||
if not ok:
|
if not ok:
|
||||||
# an error; the exit was not created, so we quit.
|
# an error; the exit was not created, so we quit.
|
||||||
return
|
return
|
||||||
|
# Create back exit, if any
|
||||||
# We are done with exit creation. Check if we want a return-exit too.
|
if len(self.lhs_objs) > 1:
|
||||||
|
back_exit_name = self.lhs_objs[1]['name']
|
||||||
if len(self.rhs_objs) > 1:
|
back_exit_aliases = self.lhs_objs[1]['aliases']
|
||||||
back_exit_name = self.rhs_objs[1]['name']
|
back_exit_typeclass = self.lhs_objs[1]['option']
|
||||||
back_exit_aliases = self.rhs_objs[1]['name']
|
ok = self.create_exit(back_exit_name, destination, location, back_exit_aliases, back_exit_typeclass)
|
||||||
back_exit_typeclass = self.rhs_objs[1]['option']
|
|
||||||
|
|
||||||
# Create the back-exit
|
|
||||||
self.create_exit(back_exit_name, destination, location,
|
|
||||||
back_exit_aliases, back_exit_typeclass)
|
|
||||||
|
|
||||||
|
|
||||||
class CmdSetAttribute(ObjManipCommand):
|
class CmdSetAttribute(ObjManipCommand):
|
||||||
"""
|
"""
|
||||||
@set - set attributes
|
@set - set attributes
|
||||||
|
|
@ -1820,9 +1812,11 @@ class CmdTeleport(MuxCommand):
|
||||||
caller.msg("You can't teleport an object inside of itself!")
|
caller.msg("You can't teleport an object inside of itself!")
|
||||||
return
|
return
|
||||||
# try the teleport
|
# try the teleport
|
||||||
if obj_to_teleport.move_to(destination, quiet=tel_quietly,
|
if obj_to_teleport.move_to(destination, quiet=tel_quietly, emit_to_obj=caller):
|
||||||
emit_to_obj=caller):
|
if obj_to_teleport == caller:
|
||||||
caller.msg("Teleported.")
|
caller.msg("Teleported to %s." % destination.key)
|
||||||
|
else:
|
||||||
|
caller.msg("Teleported %s -> %s." % (obj_to_teleport, destination.key))
|
||||||
|
|
||||||
|
|
||||||
class CmdScript(MuxCommand):
|
class CmdScript(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ def attr(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
#print e
|
||||||
# this might happen if we try to compare two things that cannot be compared
|
# this might happen if we try to compare two things that cannot be compared
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -260,14 +260,13 @@ def attr(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
if hasattr(accessing_obj, attrname):
|
if hasattr(accessing_obj, attrname):
|
||||||
if value:
|
if value:
|
||||||
return valcompare(str(getattr(accessing_obj, attrname)), value, compare)
|
return valcompare(str(getattr(accessing_obj, attrname)), value, compare)
|
||||||
return getattr(accessing_obj, attrname) # will return Fail on False value etc
|
return bool(getattr(accessing_obj, attrname)) # will return Fail on False value etc
|
||||||
# check attributes, if they exist
|
# check attributes, if they exist
|
||||||
if (hasattr(accessing_obj, 'has_attribute')
|
if (hasattr(accessing_obj, 'has_attribute') and accessing_obj.has_attribute(attrname)):
|
||||||
and accessing_obj.has_attribute(attrname)):
|
|
||||||
if value:
|
if value:
|
||||||
return (hasattr(accessing_obj, 'get_attribute')
|
return (hasattr(accessing_obj, 'get_attribute')
|
||||||
and valcompare(accessing_obj.get_attribute(attrname), value, compare))
|
and valcompare(accessing_obj.get_attribute(attrname), value, compare))
|
||||||
return accessing_obj.get_attribute(attrname) # fails on False/None values
|
return bool(accessing_obj.get_attribute(attrname)) # fails on False/None values
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def objattr(accessing_obj, accessed_obj, *args, **kwargs):
|
def objattr(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
|
|
@ -358,7 +357,6 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
accessed_obj.location == accessing_obj), or if accessing_obj itself holds an
|
accessed_obj.location == accessing_obj), or if accessing_obj itself holds an
|
||||||
object matching the given key.
|
object matching the given key.
|
||||||
"""
|
"""
|
||||||
print "holds ..."
|
|
||||||
try:
|
try:
|
||||||
# commands and scripts don't have contents, so we are usually looking
|
# commands and scripts don't have contents, so we are usually looking
|
||||||
# for the contents of their .obj property instead (i.e. the object the
|
# for the contents of their .obj property instead (i.e. the object the
|
||||||
|
|
@ -369,7 +367,6 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
contents = accessing_obj.obj.contents
|
contents = accessing_obj.obj.contents
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
print "holds", contents, accessing_obj, accessed_obj
|
|
||||||
|
|
||||||
def check_holds(objid):
|
def check_holds(objid):
|
||||||
# helper function. Compares both dbrefs and keys/aliases.
|
# helper function. Compares both dbrefs and keys/aliases.
|
||||||
|
|
@ -386,11 +383,11 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if check_holds(accessed_obj.id):
|
if check_holds(accessed_obj.id):
|
||||||
print "holds: accessed_obj.id - True"
|
#print "holds: accessed_obj.id - True"
|
||||||
return True
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
print "holds: accessed_obj.obj.id -", hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.id)
|
#print "holds: accessed_obj.obj.id -", hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.id)
|
||||||
return hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.id)
|
return hasattr(accessed_obj, "obj") and check_holds(accessed_obj.obj.id)
|
||||||
|
|
||||||
def superuser(*args, **kwargs):
|
def superuser(*args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -330,9 +330,11 @@ class LockHandler(object):
|
||||||
# we have previously stored the function object and all the args/kwargs as list/dict,
|
# we have previously stored the function object and all the args/kwargs as list/dict,
|
||||||
# now we just execute them all in sequence. The result will be a list of True/False
|
# now we just execute them all in sequence. The result will be a list of True/False
|
||||||
# statements. Note that there is no eval here, these are normal command calls!
|
# statements. Note that there is no eval here, these are normal command calls!
|
||||||
true_false = (tup[0](accessing_obj, self.obj, *tup[1], **tup[2]) for tup in func_tup)
|
true_false = (bool(tup[0](accessing_obj, self.obj, *tup[1], **tup[2])) for tup in func_tup)
|
||||||
# we now input these True/False list into the evalstring, which combines them with
|
# we now input these True/False list into the evalstring, which combines them with
|
||||||
# AND/OR/NOT in order to get the final result
|
# AND/OR/NOT in order to get the final result
|
||||||
|
#true_false = tuple(true_false)
|
||||||
|
#print accessing_obj, self.obj, access_type, true_false, evalstring, func_tup, raw_string
|
||||||
return eval(evalstring % tuple(true_false))
|
return eval(evalstring % tuple(true_false))
|
||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
estring = "__iexact"
|
estring = "__iexact"
|
||||||
else:
|
else:
|
||||||
estring = "__istartswith"
|
estring = "__istartswith"
|
||||||
matches = eval("self.filter(db_key%s=ostring%s)" % (estring, lstring_key))
|
matches = eval("self.filter(db_key%s=ostring%s)" % (estring, lstring_key))
|
||||||
if not matches:
|
if not matches:
|
||||||
alias_matches = eval("self.model.alias_set.related.model.objects.filter(db_key%s=ostring%s)" % (estring, lstring_alias))
|
alias_matches = eval("self.model.alias_set.related.model.objects.filter(db_key%s=ostring%s)" % (estring, lstring_alias))
|
||||||
matches = [alias.db_obj for alias in alias_matches]
|
matches = [alias.db_obj for alias in alias_matches]
|
||||||
|
|
|
||||||
|
|
@ -715,7 +715,7 @@ class ObjectDB(TypedObject):
|
||||||
#emit_to_obj.msg(errtxt % "at_after_move()")
|
#emit_to_obj.msg(errtxt % "at_after_move()")
|
||||||
#logger.log_trace()
|
#logger.log_trace()
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
#
|
#
|
||||||
# Object Swap, Delete and Cleanup methods
|
# Object Swap, Delete and Cleanup methods
|
||||||
|
|
|
||||||
|
|
@ -464,6 +464,7 @@ class Exit(Object):
|
||||||
cmd.key = exidbobj.db_key.strip().lower()
|
cmd.key = exidbobj.db_key.strip().lower()
|
||||||
cmd.obj = exidbobj
|
cmd.obj = exidbobj
|
||||||
cmd.aliases = exidbobj.aliases
|
cmd.aliases = exidbobj.aliases
|
||||||
|
cmd.locks = str(exidbobj.locks)
|
||||||
cmd.destination = exidbobj.db_destination
|
cmd.destination = exidbobj.db_destination
|
||||||
# create a cmdset
|
# create a cmdset
|
||||||
exit_cmdset = cmdset.CmdSet(None)
|
exit_cmdset = cmdset.CmdSet(None)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue