Some command bugfixes. Added some more debug messages for pinning down issue101.
This commit is contained in:
parent
27b7570aab
commit
164eb5b89b
5 changed files with 89 additions and 69 deletions
|
|
@ -91,7 +91,6 @@ class DefaultCmdSet(CmdSet):
|
||||||
|
|
||||||
# Testing commands
|
# Testing commands
|
||||||
self.add(tests.CmdTest())
|
self.add(tests.CmdTest())
|
||||||
self.add(tests.CmdTestState())
|
|
||||||
self.add(tests.CmdTestPerms())
|
self.add(tests.CmdTestPerms())
|
||||||
self.add(tests.TestCom())
|
self.add(tests.TestCom())
|
||||||
self.add(tests.CmdDebug())
|
self.add(tests.CmdDebug())
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ from src.utils import create
|
||||||
from src.utils import debug
|
from src.utils import debug
|
||||||
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
||||||
|
|
||||||
|
from src.commands import cmdsethandler
|
||||||
|
|
||||||
|
|
||||||
# Test permissions
|
# Test permissions
|
||||||
|
|
||||||
|
|
@ -27,11 +29,19 @@ class CmdTest(MuxCommand):
|
||||||
|
|
||||||
key = "@test"
|
key = "@test"
|
||||||
aliases = ["@te", "@test all"]
|
aliases = ["@te", "@test all"]
|
||||||
permissions = "cmd:Immortals Wizards"
|
#permissions = "cmd:Immortals Wizards"
|
||||||
|
|
||||||
# the muxcommand class itself handles the display
|
# the muxcommand class itself handles the display
|
||||||
# so we just defer to it by not adding any function.
|
# so we just defer to it by not adding any function.
|
||||||
pass
|
|
||||||
|
def func(self):
|
||||||
|
cmdsetname = "game.gamesrc.commands.default.cmdset_default.DefaultCmdSet"
|
||||||
|
self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||||
|
cmdsethandler.import_cmdset(cmdsetname, self, self)
|
||||||
|
self.caller.msg("Imported %s" % cmdsetname)
|
||||||
|
self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CmdTestPerms(MuxCommand):
|
class CmdTestPerms(MuxCommand):
|
||||||
|
|
@ -52,105 +62,109 @@ class CmdTestPerms(MuxCommand):
|
||||||
key = "@testperm"
|
key = "@testperm"
|
||||||
permissions = "cmd:Immortals Wizards"
|
permissions = "cmd:Immortals Wizards"
|
||||||
|
|
||||||
def func(self, srcobj, inp):
|
def func(self):
|
||||||
"""
|
"""
|
||||||
Run tests
|
Run tests
|
||||||
"""
|
"""
|
||||||
if srcobj.user.is_superuser:
|
caller = self.caller
|
||||||
srcobj.msg("You are a superuser. Permission tests are pointless.")
|
|
||||||
|
if caller.user.is_superuser:
|
||||||
|
caller.msg("You are a superuser. Permission tests are pointless.")
|
||||||
return
|
return
|
||||||
# create a test object
|
# create a test object
|
||||||
obj = create.create_object(None, "accessed_object") # this will use default typeclass
|
obj = create.create_object(None, "accessed_object") # this will use default typeclass
|
||||||
obj_id = obj.id
|
obj_id = obj.id
|
||||||
srcobj.msg("obj_attr: %s" % obj.attr("testattr"))
|
caller.msg("obj_attr: %s" % obj.attr("testattr"))
|
||||||
|
|
||||||
# perms = ["has_permission", "has permission", "skey:has_permission",
|
# perms = ["has_permission", "has permission", "skey:has_permission",
|
||||||
# "has_id(%s)" % obj_id, "has_attr(testattr)",
|
# "has_id(%s)" % obj_id, "has_attr(testattr)",
|
||||||
# "has_attr(testattr, testattr_value)"]
|
# "has_attr(testattr, testattr_value)"]
|
||||||
|
|
||||||
# test setting permissions
|
# test setting permissions
|
||||||
uprofile = srcobj.user.get_profile()
|
uprofile = caller.user.get_profile()
|
||||||
# do testing
|
# do testing
|
||||||
srcobj.msg("----------------")
|
caller.msg("----------------")
|
||||||
|
|
||||||
permissions.set_perm(obj, "has_permission")
|
permissions.set_perm(obj, "has_permission")
|
||||||
permissions.add_perm(obj, "skey:has_permission")
|
permissions.add_perm(obj, "skey:has_permission")
|
||||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||||
srcobj.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
caller.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||||
srcobj.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
caller.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||||
|
|
||||||
permissions.set_perm(uprofile, "has_permission")
|
permissions.set_perm(uprofile, "has_permission")
|
||||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||||
srcobj.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
caller.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||||
srcobj.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
caller.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||||
|
|
||||||
# function tests
|
# function tests
|
||||||
permissions.set_perm(obj, "has_id(%s)" % (uprofile.id))
|
permissions.set_perm(obj, "has_id(%s)" % (uprofile.id))
|
||||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||||
srcobj.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
caller.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||||
|
|
||||||
uprofile.attr("testattr", "testattr_value")
|
uprofile.attr("testattr", "testattr_value")
|
||||||
permissions.set_perm(obj, "has_attr(testattr, testattr_value)")
|
permissions.set_perm(obj, "has_attr(testattr, testattr_value)")
|
||||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||||
srcobj.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
caller.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||||
|
|
||||||
# cleanup of test permissions
|
# cleanup of test permissions
|
||||||
permissions.del_perm(uprofile, "has_permission")
|
permissions.del_perm(uprofile, "has_permission")
|
||||||
srcobj.msg(" cleanup: keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
caller.msg(" cleanup: keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||||
obj.delete()
|
obj.delete()
|
||||||
uprofile.attr("testattr", delete=True)
|
uprofile.attr("testattr", delete=True)
|
||||||
|
|
||||||
|
|
||||||
# Add/remove states
|
# # Add/remove states (removed; not valid.)
|
||||||
|
|
||||||
EXAMPLE_STATE="game.gamesrc.commands.examples.example.EXAMPLESTATE"
|
# EXAMPLE_STATE="game.gamesrc.commands.examples.example.EXAMPLESTATE"
|
||||||
|
|
||||||
class CmdTestState(MuxCommand):
|
# class CmdTestState(MuxCommand):
|
||||||
"""
|
# """
|
||||||
Test command - add a state.
|
# Test command - add a state.
|
||||||
|
|
||||||
Usage:
|
# Usage:
|
||||||
@teststate[/switch] [<python path to state instance>]
|
# @teststate[/switch] [<python path to state instance>]
|
||||||
Switches:
|
# Switches:
|
||||||
add - add a state
|
# add - add a state
|
||||||
clear - remove all added states.
|
# clear - remove all added states.
|
||||||
list - view current state stack
|
# list - view current state stack
|
||||||
reload - reload current state stack
|
# reload - reload current state stack
|
||||||
|
|
||||||
If no python path is given, an example state will be added.
|
# If no python path is given, an example state will be added.
|
||||||
You will know it worked if you can use the commands '@testcommand'
|
# You will know it worked if you can use the commands '@testcommand'
|
||||||
and 'smile'.
|
# and 'smile'.
|
||||||
"""
|
# """
|
||||||
|
|
||||||
key = "@teststate"
|
# key = "@teststate"
|
||||||
alias = "@testingstate"
|
# alias = "@testingstate"
|
||||||
permissions = "cmd:Immortals Wizards"
|
# permissions = "cmd:Immortals Wizards"
|
||||||
|
|
||||||
def func(self, source_object, inp):
|
# def func(self):
|
||||||
"""
|
# """
|
||||||
inp is the dict returned from MuxCommand's parser.
|
# inp is the dict returned from MuxCommand's parser.
|
||||||
"""
|
# """
|
||||||
switches = inp["switches"]
|
# caller = self.caller
|
||||||
if not switches or switches[0] not in ["add", "clear", "list", "reload"]:
|
# switches = self.switches
|
||||||
string = "Usage: @teststate[/add|clear|list|reload] [<python path>]"
|
|
||||||
source_object.msg(string)
|
# if not switches or switches[0] not in ["add", "clear", "list", "reload"]:
|
||||||
elif "clear" in switches:
|
# string = "Usage: @teststate[/add|clear|list|reload] [<python path>]"
|
||||||
source_object.statehandler.clear()
|
# caller.msg(string)
|
||||||
source_object.msg("All states cleared.")
|
# elif "clear" in switches:
|
||||||
return
|
# caller.cmdset.clear()
|
||||||
elif "list" in switches:
|
# caller.msg("All cmdset cleared.")
|
||||||
string = "%s" % source_object.statehandler
|
# return
|
||||||
source_object.msg(string)
|
# elif "list" in switches:
|
||||||
elif "reload" in switches:
|
# string = "%s" % caller.cmdset
|
||||||
source_object.statehandler.load()
|
# caller.msg(string)
|
||||||
source_object.msg("States reloaded.")
|
# elif "reload" in switches:
|
||||||
else: #add
|
# caller.cmdset.load()
|
||||||
arg = inp["raw"]
|
# caller.msg("Cmdset reloaded.")
|
||||||
if not arg:
|
# else: #add
|
||||||
arg = EXAMPLE_STATE
|
# arg = inp["raw"]
|
||||||
source_object.statehandler.add(arg)
|
# if not arg:
|
||||||
string = "Added state '%s'." % source_object.statehandler.state.key
|
# arg = EXAMPLE_STATE
|
||||||
source_object.msg(string)
|
# caller.cmdset.add(arg)
|
||||||
|
# string = "Added state '%s'." % caller.cmdset.state.key
|
||||||
|
# caller.msg(string)
|
||||||
|
|
||||||
class TestCom(MuxCommand):
|
class TestCom(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
instance from a python module, given a python_path. It's usually accessed
|
instance from a python module, given a python_path. It's usually accessed
|
||||||
through the cmdsethandler's add() and add_default() methods.
|
through the cmdsethandler's add() and add_default() methods.
|
||||||
python_path - This is the full path to the cmdset object.
|
python_path - This is the full path to the cmdset object.
|
||||||
cmsetobj - the database object/typeclass on which this cmdset is to be assigned
|
cmdsetobj - the database object/typeclass on which this cmdset is to be assigned
|
||||||
(this can be also channels and exits, as well as players but there will
|
(this can be also channels and exits, as well as players but there will
|
||||||
always be such an object)
|
always be such an object)
|
||||||
emit_to_obj - if given, error is emitted to this object (in addition to logging)
|
emit_to_obj - if given, error is emitted to this object (in addition to logging)
|
||||||
|
|
@ -88,17 +88,18 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
|
print "importing %s: CACHED_CMDSETS=%s" % (python_path, CACHED_CMDSETS)
|
||||||
wanted_cache_key = python_path
|
wanted_cache_key = python_path
|
||||||
cmdsetclass = CACHED_CMDSETS.get(wanted_cache_key, None)
|
cmdsetclass = CACHED_CMDSETS.get(wanted_cache_key, None)
|
||||||
errstring = ""
|
errstring = ""
|
||||||
if not cmdsetclass:
|
if not cmdsetclass:
|
||||||
#print "cmdset %s not in cache. Reloading." % wanted_cache_key
|
print "cmdset %s not in cache. Reloading." % wanted_cache_key
|
||||||
# Not in cache. Reload from disk.
|
# Not in cache. Reload from disk.
|
||||||
modulepath, classname = python_path.rsplit('.', 1)
|
modulepath, classname = python_path.rsplit('.', 1)
|
||||||
module = __import__(modulepath, fromlist=[True])
|
module = __import__(modulepath, fromlist=[True])
|
||||||
cmdsetclass = module.__dict__[classname]
|
cmdsetclass = module.__dict__[classname]
|
||||||
CACHED_CMDSETS[wanted_cache_key] = cmdsetclass
|
CACHED_CMDSETS[wanted_cache_key] = cmdsetclass
|
||||||
#print "cmdset %s found." % wanted_cache_key
|
print "cmdset %s found." % wanted_cache_key
|
||||||
#instantiate the cmdset (and catch its errors)
|
#instantiate the cmdset (and catch its errors)
|
||||||
if callable(cmdsetclass):
|
if callable(cmdsetclass):
|
||||||
cmdsetclass = cmdsetclass(cmdsetobj)
|
cmdsetclass = cmdsetclass(cmdsetobj)
|
||||||
|
|
@ -118,6 +119,7 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
if errstring and not no_logging:
|
if errstring and not no_logging:
|
||||||
|
print errstring
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
if emit_to_obj:
|
if emit_to_obj:
|
||||||
emit_to_obj.msg(errstring)
|
emit_to_obj.msg(errstring)
|
||||||
|
|
|
||||||
|
|
@ -227,12 +227,13 @@ class CheckSessions(Script):
|
||||||
"Setup the script"
|
"Setup the script"
|
||||||
self.key = "sys_session_check"
|
self.key = "sys_session_check"
|
||||||
self.desc = "Checks sessions so they are live."
|
self.desc = "Checks sessions so they are live."
|
||||||
self.interval = 60 # repeat every 60 seconds
|
self.interval = 60 # repeat every 60 seconds
|
||||||
self.persistent = True
|
self.persistent = True
|
||||||
|
|
||||||
def at_repeat(self):
|
def at_repeat(self):
|
||||||
"called every 60 seconds"
|
"called every 60 seconds"
|
||||||
#print "session check!"
|
#print "session check!"
|
||||||
|
#print "ValidateSessions run"
|
||||||
sessionhandler.check_all_sessions()
|
sessionhandler.check_all_sessions()
|
||||||
|
|
||||||
class ValidateScripts(Script):
|
class ValidateScripts(Script):
|
||||||
|
|
@ -246,6 +247,7 @@ class ValidateScripts(Script):
|
||||||
|
|
||||||
def at_repeat(self):
|
def at_repeat(self):
|
||||||
"called every hour"
|
"called every hour"
|
||||||
|
print "ValidateScripts run."
|
||||||
ScriptDB.objects.validate()
|
ScriptDB.objects.validate()
|
||||||
|
|
||||||
class ValidateChannelHandler(Script):
|
class ValidateChannelHandler(Script):
|
||||||
|
|
@ -260,6 +262,7 @@ class ValidateChannelHandler(Script):
|
||||||
|
|
||||||
def at_repeat(self):
|
def at_repeat(self):
|
||||||
"called every hour+"
|
"called every hour+"
|
||||||
|
print "ValidateChannelHandler run."
|
||||||
channelhandler.CHANNELHANDLER.update()
|
channelhandler.CHANNELHANDLER.update()
|
||||||
|
|
||||||
class AddCmdSet(Script):
|
class AddCmdSet(Script):
|
||||||
|
|
@ -306,6 +309,8 @@ class AddCmdSet(Script):
|
||||||
This removes the cmdset when the script stops
|
This removes the cmdset when the script stops
|
||||||
"""
|
"""
|
||||||
cmdset = self.db.cmdset
|
cmdset = self.db.cmdset
|
||||||
|
|
||||||
|
print "AddCmdSets: at_stop() for %s called." % self.obj
|
||||||
if cmdset:
|
if cmdset:
|
||||||
if self.db.add_default:
|
if self.db.add_default:
|
||||||
self.obj.cmdset.delete_default()
|
self.obj.cmdset.delete_default()
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
attribute_model_name = "Attribute"
|
attribute_model_name = "Attribute"
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return other and self.id == other.id
|
return other and hasattr(other, 'id') and self.id == other.id
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return smart_str("%s" % self.key)
|
return smart_str("%s" % self.key)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue