Beispiel #1
0
def dispatchForever():
    # need to do this shit in a new thread
    while parsing:
        # If we have no commands to execute, f**k it
        if len(commandsToExecute) == 0:
            time.sleep(0)
        else:
            # get the next command in the queue and execute it
            args = commandsToExecute.pop()

            args = functionmapper.shorthandHandler(args)
            command = args.name

            if command in functionmapper.commandFunctions:
                try:
                    ret = functionmapper.commandFunctions[command](args)  # this calls the function
                    if not ret:
                        args.actor.sendMessage("What?")
                except:
                    print "Server: An error has occured."
                    print "-----------------------------"
                    print traceback.format_exc()
            else:
                args.actor.sendMessage("What?")

    print "Dispatcher: I am dead."
Beispiel #2
0
    def run(self):
        print "    Dispatcher: Running."
        self.dispatching = True
        # need to do this shit in a new thread
        while self.dispatching:
            # block until the flag is raised
            self.lock.wait()
            if not self.dispatching:
                break
            
            # get the next command in the queue and execute it
            args = self.queue.pop()
            args = functionmapper.shorthandHandler(args)
            command = args.name

            # handle the command if it exists
            if command in functionmapper.commandFunctions:
                try:
                    ret = functionmapper.commandFunctions[command](args)  # this calls the function
                    if not ret:
                        args.actor.sendMessage("What?")
                except:
                    print "Server: An error has occured."
                    print "-----------------------------"
                    print traceback.format_exc()
            # check to see if it's an alias
            elif command in args.actor.aliases:
                new_line = args.actor.aliases[command].strip()
                new_tokens = new_line.split(" ")
                new_args = CommandArgs(name=new_tokens[0], tokens=new_tokens, full=new_line, actor=args.actor)
                self.queue.append(new_args)
                self.lock.set()
            # check spectator
            elif (args.actor.spectator and 
                    args.name not in commands.commandFunctions and 
                    functionmapper.commandFunctions[args.name] not in commands.SPECTATORABLE):
                args.actor.sendMessage("Only actual players can use that command. Check help spectator for more info.")
            else:
                args.actor.sendMessage("What?")

            # if that was the last command, set the block again
            if len(self.queue) == 0:
                self.lock.clear()

        print "    Dispatcher: Done."