From 4bcd5239b5f154e6d033cdf83354c15a632c89d2 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 30 Apr 2011 21:09:19 +0000 Subject: [PATCH] Mixed batch of minor bug fixes and cleanups. --- game/gamesrc/commands/basecommand.py | 4 ++-- src/commands/cmdhandler.py | 5 ++--- src/commands/cmdset.py | 7 +++---- src/commands/default/building.py | 2 ++ src/commands/default/cmdset_default.py | 1 + src/objects/exithandler.py | 5 ++--- src/objects/objects.py | 27 +++++++++++-------------- src/typeclasses/models.py | 28 +++++++++++++++----------- 8 files changed, 40 insertions(+), 39 deletions(-) diff --git a/game/gamesrc/commands/basecommand.py b/game/gamesrc/commands/basecommand.py index 5bf7392aa7..d5f1b51731 100644 --- a/game/gamesrc/commands/basecommand.py +++ b/game/gamesrc/commands/basecommand.py @@ -104,7 +104,7 @@ class Command(BaseCommand): used by Evennia to create the automatic help entry for the command, so make sure to document consistently here. """ - def access(self, srcobj): + def access(self, srcobj, access_type="cmd", default=False): """ This is called by the cmdhandler to determine if srcobj is allowed to execute this command. This @@ -113,7 +113,7 @@ class Command(BaseCommand): By default, We use checks of the 'cmd' type of lock to determine if the command should be run. """ - return super(Command, self).access(srcobj) + return super(Command, self).access(srcobj, access_type=access_type, default=default) def at_pre_cmd(self): """ diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index fd2d3df803..57437d86eb 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -120,13 +120,12 @@ def get_and_merge_cmdsets(caller): local_objects_cmdsets = [obj.cmdset.current for obj in local_objlist if obj.locks.check(caller, 'call', no_superuser_bypass=True)] - # Merge all command sets into one # (the order matters, the higher-prio cmdsets are merged last) cmdset = caller_cmdset for obj_cmdset in [obj_cmdset for obj_cmdset in local_objects_cmdsets if obj_cmdset]: # Here only, object cmdsets are merged with duplicates=True - # (or we would never be able to differentiate between objects) + # (or we would never be able to differentiate between same-prio objects) try: old_duplicate_flag = obj_cmdset.duplicates obj_cmdset.duplicates = True @@ -306,7 +305,7 @@ def cmdhandler(caller, raw_string, unloggedin=False, testing=False): raise ExecSystemCommand(syscmd, sysarg) # Parse the input string into command candidates - cmd_candidates = COMMAND_PARSER(raw_string) + cmd_candidates = COMMAND_PARSER(raw_string) #string ="Command candidates" #for cand in cmd_candidates: diff --git a/src/commands/cmdset.py b/src/commands/cmdset.py index f334f8c83d..47b334d9d9 100644 --- a/src/commands/cmdset.py +++ b/src/commands/cmdset.py @@ -131,10 +131,9 @@ class CmdSet(object): priority- All cmdsets are always merged in pairs of two so that the higher set's mergetype is applied to the - lower-priority cmdset. Evennia uses priorities from 0-10 - where 10 are used for high-priority things like comsys - channel names and 9 for exit names in order to give - these priority when the given command matches. + lower-priority cmdset. Default commands have priority 0, + high-priority ones like Exits and Channels have 10 and 9. Priorities + can be negative as well to give default commands preference. duplicates - determines what happens when two sets of equal priority merge. Default has the first of them in the diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 755fd4fec8..40953f0dbe 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -1018,6 +1018,8 @@ class CmdOpen(ObjManipCommand): else: # exit does not exist before. Create a new one. + if not typeclass: + typeclass = settings.BASE_EXIT_TYPECLASS exit_obj = create.create_object(typeclass, key=exit_name, location=location, aliases=exit_aliases) diff --git a/src/commands/default/cmdset_default.py b/src/commands/default/cmdset_default.py index 7ed73b6023..73fcc7298f 100644 --- a/src/commands/default/cmdset_default.py +++ b/src/commands/default/cmdset_default.py @@ -11,6 +11,7 @@ class DefaultCmdSet(CmdSet): Implements the default command set. """ key = "DefaultMUX" + priority = 0 def at_cmdset_creation(self): "Populates the cmdset" diff --git a/src/objects/exithandler.py b/src/objects/exithandler.py index 6b80bc3c77..f4b2c8eaf2 100644 --- a/src/objects/exithandler.py +++ b/src/objects/exithandler.py @@ -76,7 +76,7 @@ class ExitHandler(object): exit_cmdset.priority = 9 exit_cmdset.duplicates = True try: - location = srcobj.location + location = srcobj.location except Exception: location = None if not location: @@ -84,8 +84,7 @@ class ExitHandler(object): return exit_cmdset # use exits to create searchable "commands" for the cmdhandler - for exi in (exi for exi in location.contents - if exi.destination): + for exi in location.exits: if exi.id in self.cached_exit_cmds: # retrieve from cache exit_cmdset.add(self.cached_exit_cmds[exi.id]) diff --git a/src/objects/objects.py b/src/objects/objects.py index a2585ecc9b..f057dc27c2 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -16,6 +16,7 @@ they control by simply linking to a new object's user property. """ from src.typeclasses.typeclass import TypeClass +from src.commands import cmdset, command from src.objects.exithandler import EXITHANDLER @@ -347,7 +348,7 @@ class Character(Object): """ super(Character, self).basetype_setup() self.locks.add("get:false()") # noone can pick up the character - self.locks.add("call:false()") # no commands can be called on character + self.locks.add("call:false()") # no commands can be called on character from outside # add the default cmdset from settings import CMDSET_DEFAULT @@ -393,6 +394,11 @@ class Room(Object): super(Room, self).basetype_setup() self.location = None + +# +# Exits +# + class Exit(Object): """ This is the base exit object - it connects a location @@ -414,23 +420,14 @@ class Exit(Object): """ # the lock is open to all by default super(Exit, self).basetype_setup() + self.locks.add("puppet:false()") # would be weird to puppet an exit ... - self.locks.add("traverse:all()") # who can pass through exit + self.locks.add("traverse:all()") # who can pass through exit by default self.locks.add("get:false()") # noone can pick up the exit - def at_object_creation(self): - """ - An example just for show; the destination property - is usually set at creation time, not as part of the class - definition (unless you want an entire class of exits - all leadning to the same hard-coded place ...) - """ - # having destination != None is what makes it an exit - # (what's set here won't last) - if self.location: - self.destination = self.location - else: - self.destination = 2 # use limbo as a failsafe + # an exit should have a destination (this is replaced at creation time) + if self.dbobj.location: + self.destination = self.dbobj.location def at_object_delete(self): """ diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 304c86386d..14d51c2176 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -32,6 +32,7 @@ from django.conf import settings from django.utils.encoding import smart_str from django.contrib.contenttypes.models import ContentType from src.utils.idmapper.models import SharedMemoryModel +from src.server.models import ServerConfig from src.typeclasses import managers from src.locks.lockhandler import LockHandler from src.utils import logger, utils @@ -617,21 +618,24 @@ class TypedObject(SharedMemoryModel): Helper function to display error. """ infochan = None + cmessage = message try: from src.comms.models import Channel infochan = settings.CHANNEL_MUDINFO - infochan = Channel.objects.get_channel(infochan[0]) - except Exception, e: - print e - pass - if infochan: - cname = infochan.key - cmessage = "\n".join(["[%s]: %s" % (cname, line) for line in message.split('\n')]) - infochan.msg(message) - else: - # no mudinfo channel is found. Log instead. - cmessage = "\n".join(["[NO MUDINFO CHANNEL]: %s" % line for line in message.split('\n')]) - logger.log_errmsg(cmessage) + infochan = Channel.objects.get_channel(infochan[0]) + if infochan: + cname = infochan.key + cmessage = "\n".join(["[%s]: %s" % (cname, line) for line in message.split('\n')]) + infochan.msg(message) + else: + # no mudinfo channel is found. Log instead. + cmessage = "\n".join(["[NO MUDINFO CHANNEL]: %s" % line for line in message.split('\n')]) + logger.log_errmsg(cmessage) + except Exception, e: + if ServerConfig.objects.conf("server_starting_mode"): + print cmessage + else: + logger.log_trace(cmessage) #path = self.db_typeclass_path path = object.__getattribute__(self, 'db_typeclass_path')