diff --git a/contrib/misc_commands.py b/contrib/misc_commands.py new file mode 100644 index 0000000000..7874c58d49 --- /dev/null +++ b/contrib/misc_commands.py @@ -0,0 +1,80 @@ +""" +Evennia misc commands + +Contribution - Griatch 2011 + +This module offers some miscellaneous commands that may be useful +depending on the game you run or the style of administration you +prefer. Alternatively they can be looked at for inspiration. + +To make available in the game, import this module to +game.gamesrc.commands.basecmdset.py (or your own equivalent) and add +the command class(es) you want to the default command set. You need to +reload the server to make them recognized. +""" + +from django.conf import settings +from src.commands.default.muxcommand import MuxCommand + +PERMISSION_HIERARCHY = settings.PERMISSION_HIERARCHY +PERMISSION_HIERARCHY_LOWER = [perm.lower() for perm in PERMISSION_HIERARCHY] + +class CmdQuell(MuxCommand): + """ + Quelling permissions + + Usage: + quell [=permission level] + + This is an admin command that allows to execute another command as + another (lower) permission level than what you currently + have. This is useful for testing. Also superuser flag will be + deactivated by this command. If no permission level is given, + the command will be executed as the lowest level available in + settings.PERMISSION_HIERARCHY. + """ + + key = "quell" + locks = "cmd:perm(all)" + help_category = "General" + + def func(self): + "Perform the command" + + if not self.args: + self.caller.msg("Usage: quell [=permission level]") + return + + cmd = self.lhs + perm = self.rhs + + if not PERMISSION_HIERARCHY: + self.caller.msg("settings.PERMISSION_HIERARCHY is not defined. Add a hierarchy to use this command.") + return + if perm: + if not perm.lower() in PERMISSION_HIERARCHY_LOWER: + self.caller.msg("Unknown permission. Permission hierarchy is: [%s]" % ", ".join(PERMISSION_HIERARCHY)) + return + if not self.caller.locks.check_lockstring(self.caller, "dummy:perm(%s)" % perm): + self.caller.msg("You cannot use a permission higher than the one you have.") + return + else: + perm = PERMISSION_HIERARCHY_LOWER[0] + + # replace permission + oldperm = self.caller.permissions + old_superuser = self.caller.player.user.is_superuser + newperm = [perm] + [perm for perm in oldperm if perm not in PERMISSION_HIERARCHY_LOWER] + self.caller.permissions = newperm + self.caller.player.user.is_superuser = False + self.caller.player.user.save() + + try: + ret = self.caller.execute_cmd(cmd) + except Exception, e: + self.caller.msg(str(e)) + + self.caller.permissions = oldperm + self.caller.player.user.is_superuser = old_superuser + self.caller.player.user.save() + return ret diff --git a/game/gamesrc/commands/basecmdset.py b/game/gamesrc/commands/basecmdset.py index 35331993aa..2e56e379c0 100644 --- a/game/gamesrc/commands/basecmdset.py +++ b/game/gamesrc/commands/basecmdset.py @@ -22,7 +22,8 @@ from src.commands.cmdset import CmdSet from src.commands.default import cmdset_default, cmdset_unloggedin, cmdset_ooc from game.gamesrc.commands.basecommand import Command -from contrib import menusystem, lineeditor +#from contrib import menusystem, lineeditor +from contrib import misc_commands class DefaultCmdSet(cmdset_default.DefaultCmdSet): """ @@ -48,7 +49,7 @@ class DefaultCmdSet(cmdset_default.DefaultCmdSet): # #self.add(menusystem.CmdMenuTest()) #self.add(lineeditor.CmdEditor()) - + self.add(misc_commands.CmdQuell()) class UnloggedinCmdSet(cmdset_unloggedin.UnloggedinCmdSet): """ diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index f9b3cd6c22..dfa77729cb 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -1,11 +1,16 @@ -from weakref import WeakValueDictionary, ref +""" +This is mostly unmodified from the original idmapper. + +Evennia changes: + The cache mechanism was changed from a WeakValueDictionary to a + normal dictionary. The old way caused very hard-to-diagnose bugs + over long periods of time (which Evennia requires) + +""" from django.db.models.base import Model, ModelBase - from manager import SharedMemoryManager -TCACHE = {} # test cache, for debugging /Griatch - class SharedMemoryModelBase(ModelBase): #def __new__(cls, name, bases, attrs): # super_new = super(ModelBase, cls).__new__ @@ -120,7 +125,6 @@ class SharedMemoryModel(Model): """ cls._flush_cached_by_key(instance._get_pk_val()) #key = "%s-%s" % (cls, instance.pk) - #del TCACHE[key] #print "uncached: %s (%s: %s) (total cached: %s)" % (instance, cls.__name__, len(cls.__instance_cache__), len(TCACHE)) flush_cached_instance = classmethod(flush_cached_instance)