示例#1
0
 def do_command(self, nickname, command, args):
     player = self.players[nickname]
     # inter-context commands
     if '.' in command:
         parts = command.split('.')
         if len(parts) != 2:
             player.tell("Inter-context commands take the form: context.command arg1 ... argN")
             return
         context_name, command = parts
         if context_name not in ['build', 'admin']:
             player.tell("Context must be one of: build, admin")
             return
         context_name = {'build':'builder', 'admin':'administration'}[context_name] # convert to true name
         ctxcls = contexts.get(context_name)
         if not ctxcls:
             player.tell("The %s context could not be loaded remotely." % context_name)
             return
         contextual = "com_%s" % command
         if not hasattr(ctxcls, contextual) or contextual == "com_exit":
             player.tell("The %s context has no %s command." % (context_name, command))
             return
         context = ctxcls(self)
         contextual = getattr(context, contextual)
         # run validation
         try:
             data = validation.command(self, contextual, args)
             # run if valid
             contextual(player.session, data)
             db.commit()
             return
         except validation.ValidationError, e:
             self.tell(player, e.message)
             return
         except Exception, e:
             self.tell(player, "Sorry, that command resulted in an error on the server.")
             return    
示例#2
0
            try:
                data = validation.command(self, contextual, args)
                # run if valid
                contextual(player.session, data)
                db.commit()
                return
            except validation.ValidationError, e:
                self.tell(player, e.message)
                return
            except Exception, e:
                self.tell(player, "Sorry, that command resulted in an error on the server.")
                return    

        # Let context handle input if it wants
        if player.session.context.on_input(player.session, command, args):
            db.commit()
            return
        # determine the usable commands for this player
        clocals, cglobals = commands.get_allowed(player)
        if command in clocals+cglobals: # only respond to allowed commands
            # format for context based commands
            contextual = "com_%s" % command
            # session contextual command
            if hasattr(player.session.context, contextual):
                # get the command
                contextual = getattr(player.session.context, contextual)
                # validate passed arguments against schema
                try: 
                    data = validation.command(self, contextual, args)
                    # run the comand if validated
                    contextual(player.session, data)