diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index 40a92e57e0..fc8d232474 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -229,11 +229,14 @@ def get_and_merge_cmdsets(caller, session, player, obj, cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority) # Merge all command sets into one, beginning with the lowest-prio one - cmdset = cmdsets.pop(0) - for merging_cmdset in cmdsets: + cmdset = cmdsets[0] + for merging_cmdset in cmdsets[1:]: #print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype, # cmdset.key, cmdset.priority, cmdset.mergetype) cmdset = yield merging_cmdset + cmdset + # store the full sets for diagnosis + cmdset.merged_from = cmdsets + # cache _CMDSET_MERGE_CACHE[mergehash] = cmdset else: cmdset = None diff --git a/src/commands/cmdset.py b/src/commands/cmdset.py index 8b964bf0e4..a8a0aabdf2 100644 --- a/src/commands/cmdset.py +++ b/src/commands/cmdset.py @@ -153,6 +153,10 @@ class CmdSet(object): self.system_commands = [] self.actual_mergetype = self.mergetype self.cmdsetobj = cmdsetobj + # this is set only on merged sets, in cmdhandler.py, in order to + # track, list and debug mergers correctly. + self.merged_from = [] + # initialize system self.at_cmdset_creation() self._contains_cache = {} diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 71e7562c78..08c373f337 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -1663,7 +1663,7 @@ class CmdExamine(ObjManipCommand): string += "\n{wLocation{n: %s" % obj.location if obj.location: string += " (#%s)" % obj.location.id - if hasattr(obj, "destination"): + if hasattr(obj, "destination") and obj.destination: string += "\n{wDestination{n: %s" % obj.destination if obj.destination: string += " (#%s)" % obj.destination.id @@ -1686,26 +1686,39 @@ class CmdExamine(ObjManipCommand): string += "\n{wLocks{n:%s" % locks_string if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"): - # list the current cmdsets - all_cmdsets = (obj.cmdset.all() + - (hasattr(obj, "player") and obj.player and - obj.player and obj.player.cmdset.all() or [])) - try: - # we have to protect this since many objects don't have player/sessions. - all_cmdsets += obj.player.get_session(obj.sessid).cmdset.all() - except (TypeError, AttributeError): - pass + stored_cmdsets = obj.cmdset.all() + stored_cmdsets.sort(key=lambda x: x.priority, reverse=True) + string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \ + (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) + for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET")) + + # this gets all components of the currently merged set + all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from] + # we always at least try to add player- and session sets since these are ignored + # if we merge on the object level. + if hasattr(obj, "player") and obj.player: + all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.cmdset.all()]) + if obj.sessid: + all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.get_session(obj.sessid).cmdset.all()]) + else: + try: + # we have to protect this since many objects don't have sessions. + all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessid).cmdset.all()]) + except (TypeError, AttributeError): + pass + all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()] all_cmdsets.sort(key=lambda x: x.priority, reverse=True) - string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (prio %s)" % \ - (cmdset.path, cmdset.key, cmdset.priority) + string += "\n{wMerged Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \ + (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) for cmdset in all_cmdsets)) + # list the commands available to this object avail_cmdset = sorted([cmd.key for cmd in avail_cmdset if cmd.access(obj, "cmd")]) cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2) - string += "\n{wCommands available to %s (all cmdsets + exits and external cmds){n:\n %s" % (obj.key, cmdsetstr) + string += "\n{wCommands available to %s (result of Merged CmdSets){n:\n %s" % (obj.key, cmdsetstr) if hasattr(obj, "scripts") and hasattr(obj.scripts, "all") and obj.scripts.all(): string += "\n{wScripts{n:\n %s" % obj.scripts @@ -1759,7 +1772,7 @@ class CmdExamine(ObjManipCommand): caller.execute_cmd('look %s' % obj.name) return # using callback for printing result whenever function returns. - get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback) + get_and_merge_cmdsets(obj, self.session, self.player, obj, "object").addCallback(get_cmdset_callback) else: self.msg("You need to supply a target to examine.") return @@ -1794,8 +1807,14 @@ class CmdExamine(ObjManipCommand): # we are only interested in specific attributes caller.msg(self.format_attributes(obj, attrname, crop=False)) else: + if obj.sessid: + mergemode = "session" + elif self.player_mode: + mergemode = "player" + else: + mergemode = "object" # using callback to print results whenever function returns. - get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback) + get_and_merge_cmdsets(obj, self.session, self.player, obj, mergemode).addCallback(get_cmdset_callback) class CmdFind(MuxCommand): diff --git a/src/commands/default/cmdset_session.py b/src/commands/default/cmdset_session.py index 46c038da15..cfaa83ffc2 100644 --- a/src/commands/default/cmdset_session.py +++ b/src/commands/default/cmdset_session.py @@ -9,7 +9,7 @@ class SessionCmdSet(CmdSet): Sets up the unlogged cmdset. """ key = "DefaultSession" - priority = 0 + priority = -7 def at_cmdset_creation(self): "Populate the cmdset" diff --git a/src/comms/channelhandler.py b/src/comms/channelhandler.py index fb65344c72..16b72b2925 100644 --- a/src/comms/channelhandler.py +++ b/src/comms/channelhandler.py @@ -44,7 +44,6 @@ class ChannelCommand(command.Command): is_channel = True key = "general" help_category = "Channel Names" - locks = "cmd:all()" obj = None def parse(self): @@ -129,7 +128,6 @@ class ChannelHandler(object): help_category="Channel names", obj=channel, is_channel=True) - cmd.__doc__ = self._format_help(channel) self.cached_channel_cmds.append(cmd) self.cached_cmdsets = {}