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
|
|
@ -11,6 +11,8 @@ from src.utils import create
|
|||
from src.utils import debug
|
||||
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
||||
|
||||
from src.commands import cmdsethandler
|
||||
|
||||
|
||||
# Test permissions
|
||||
|
||||
|
|
@ -27,11 +29,19 @@ class CmdTest(MuxCommand):
|
|||
|
||||
key = "@test"
|
||||
aliases = ["@te", "@test all"]
|
||||
permissions = "cmd:Immortals Wizards"
|
||||
#permissions = "cmd:Immortals Wizards"
|
||||
|
||||
# the muxcommand class itself handles the display
|
||||
# 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):
|
||||
|
|
@ -52,105 +62,109 @@ class CmdTestPerms(MuxCommand):
|
|||
key = "@testperm"
|
||||
permissions = "cmd:Immortals Wizards"
|
||||
|
||||
def func(self, srcobj, inp):
|
||||
def func(self):
|
||||
"""
|
||||
Run tests
|
||||
"""
|
||||
if srcobj.user.is_superuser:
|
||||
srcobj.msg("You are a superuser. Permission tests are pointless.")
|
||||
caller = self.caller
|
||||
|
||||
if caller.user.is_superuser:
|
||||
caller.msg("You are a superuser. Permission tests are pointless.")
|
||||
return
|
||||
# create a test object
|
||||
obj = create.create_object(None, "accessed_object") # this will use default typeclass
|
||||
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",
|
||||
# "has_id(%s)" % obj_id, "has_attr(testattr)",
|
||||
# "has_attr(testattr, testattr_value)"]
|
||||
|
||||
# test setting permissions
|
||||
uprofile = srcobj.user.get_profile()
|
||||
uprofile = caller.user.get_profile()
|
||||
# do testing
|
||||
srcobj.msg("----------------")
|
||||
caller.msg("----------------")
|
||||
|
||||
permissions.set_perm(obj, "has_permission")
|
||||
permissions.add_perm(obj, "skey:has_permission")
|
||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
srcobj.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||
srcobj.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
caller.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||
caller.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||
|
||||
permissions.set_perm(uprofile, "has_permission")
|
||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
srcobj.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||
srcobj.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
caller.msg("normal permtest: %s" % permissions.has_perm(uprofile, obj))
|
||||
caller.msg("skey permtest: %s" % permissions.has_perm(uprofile, obj, 'skey'))
|
||||
|
||||
# function tests
|
||||
permissions.set_perm(obj, "has_id(%s)" % (uprofile.id))
|
||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
srcobj.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
caller.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||
|
||||
uprofile.attr("testattr", "testattr_value")
|
||||
permissions.set_perm(obj, "has_attr(testattr, testattr_value)")
|
||||
srcobj.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
srcobj.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||
caller.msg(" keys:[%s] locks:[%s]" % (uprofile.permissions, obj.permissions))
|
||||
caller.msg("functest: %s" % permissions.has_perm(uprofile, obj))
|
||||
|
||||
# cleanup of test permissions
|
||||
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()
|
||||
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):
|
||||
"""
|
||||
Test command - add a state.
|
||||
# class CmdTestState(MuxCommand):
|
||||
# """
|
||||
# Test command - add a state.
|
||||
|
||||
Usage:
|
||||
@teststate[/switch] [<python path to state instance>]
|
||||
Switches:
|
||||
add - add a state
|
||||
clear - remove all added states.
|
||||
list - view current state stack
|
||||
reload - reload current state stack
|
||||
# Usage:
|
||||
# @teststate[/switch] [<python path to state instance>]
|
||||
# Switches:
|
||||
# add - add a state
|
||||
# clear - remove all added states.
|
||||
# list - view current state stack
|
||||
# reload - reload current state stack
|
||||
|
||||
If no python path is given, an example state will be added.
|
||||
You will know it worked if you can use the commands '@testcommand'
|
||||
and 'smile'.
|
||||
"""
|
||||
# If no python path is given, an example state will be added.
|
||||
# You will know it worked if you can use the commands '@testcommand'
|
||||
# and 'smile'.
|
||||
# """
|
||||
|
||||
key = "@teststate"
|
||||
alias = "@testingstate"
|
||||
permissions = "cmd:Immortals Wizards"
|
||||
# key = "@teststate"
|
||||
# alias = "@testingstate"
|
||||
# permissions = "cmd:Immortals Wizards"
|
||||
|
||||
def func(self, source_object, inp):
|
||||
"""
|
||||
inp is the dict returned from MuxCommand's parser.
|
||||
"""
|
||||
switches = inp["switches"]
|
||||
if not switches or switches[0] not in ["add", "clear", "list", "reload"]:
|
||||
string = "Usage: @teststate[/add|clear|list|reload] [<python path>]"
|
||||
source_object.msg(string)
|
||||
elif "clear" in switches:
|
||||
source_object.statehandler.clear()
|
||||
source_object.msg("All states cleared.")
|
||||
return
|
||||
elif "list" in switches:
|
||||
string = "%s" % source_object.statehandler
|
||||
source_object.msg(string)
|
||||
elif "reload" in switches:
|
||||
source_object.statehandler.load()
|
||||
source_object.msg("States reloaded.")
|
||||
else: #add
|
||||
arg = inp["raw"]
|
||||
if not arg:
|
||||
arg = EXAMPLE_STATE
|
||||
source_object.statehandler.add(arg)
|
||||
string = "Added state '%s'." % source_object.statehandler.state.key
|
||||
source_object.msg(string)
|
||||
# def func(self):
|
||||
# """
|
||||
# inp is the dict returned from MuxCommand's parser.
|
||||
# """
|
||||
# caller = self.caller
|
||||
# switches = self.switches
|
||||
|
||||
# if not switches or switches[0] not in ["add", "clear", "list", "reload"]:
|
||||
# string = "Usage: @teststate[/add|clear|list|reload] [<python path>]"
|
||||
# caller.msg(string)
|
||||
# elif "clear" in switches:
|
||||
# caller.cmdset.clear()
|
||||
# caller.msg("All cmdset cleared.")
|
||||
# return
|
||||
# elif "list" in switches:
|
||||
# string = "%s" % caller.cmdset
|
||||
# caller.msg(string)
|
||||
# elif "reload" in switches:
|
||||
# caller.cmdset.load()
|
||||
# caller.msg("Cmdset reloaded.")
|
||||
# else: #add
|
||||
# arg = inp["raw"]
|
||||
# if not arg:
|
||||
# arg = EXAMPLE_STATE
|
||||
# caller.cmdset.add(arg)
|
||||
# string = "Added state '%s'." % caller.cmdset.state.key
|
||||
# caller.msg(string)
|
||||
|
||||
class TestCom(MuxCommand):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue