Ejemplo n.º 1
0
 def connectionMade(self):
     HistoricRecvLine.connectionMade(self)
     log.msg('{0} logged in'.format(self.username))
     self.terminal.write('Welcome! {0}'.format(self.username))
     self.terminal.nextLine()
     self.commands.do_help()
     self.show_prompt()
Ejemplo n.º 2
0
 def __init__(self, service, commandsClass=Commands):
     ReceiveLineProtocol.__init__(self)
     self.service = service
     self.inputLines = []
     self.commands = commandsClass(self)
     self.activeCommand = None
     self.emulate = "emacs"
Ejemplo n.º 3
0
    def connectionMade(self):
        ReceiveLineProtocol.connectionMade(self)

        self.keyHandlers['\x03'] = self.handle_INT  # Control-C
        self.keyHandlers['\x04'] = self.handle_EOF  # Control-D
        self.keyHandlers['\x1c'] = self.handle_QUIT  # Control-\
        self.keyHandlers['\x0c'] = self.handle_FF  # Control-L
        # self.keyHandlers['\t'  ] = self.handle_TAB   # Tab

        if self.emulate == "emacs":
            # EMACS key bindinds
            self.keyHandlers['\x10'] = self.handle_UP  # Control-P
            self.keyHandlers['\x0e'] = self.handle_DOWN  # Control-N
            self.keyHandlers['\x02'] = self.handle_LEFT  # Control-B
            self.keyHandlers['\x06'] = self.handle_RIGHT  # Control-F
            self.keyHandlers['\x01'] = self.handle_HOME  # Control-A
            self.keyHandlers['\x05'] = self.handle_END  # Control-E

        def observer(event):
            if not event["isError"]:
                return

            text = log.textFromEventDict(event)
            if text is None:
                return

            self.service.reactor.callFromThread(self.terminal.write, text)

        log.startLoggingWithObserver(observer)
Ejemplo n.º 4
0
 def __init__(self, service, commandsClass=Commands):
     ReceiveLineProtocol.__init__(self)
     self.service = service
     self.inputLines = []
     self.commands = commandsClass(self)
     self.activeCommand = None
     self.emulate = "emacs"
Ejemplo n.º 5
0
    def connectionMade(self):
        ReceiveLineProtocol.connectionMade(self)

        self.keyHandlers['\x03'] = self.handle_INT   # Control-C
        self.keyHandlers['\x04'] = self.handle_EOF   # Control-D
        self.keyHandlers['\x1c'] = self.handle_QUIT  # Control-\
        self.keyHandlers['\x0c'] = self.handle_FF    # Control-L
        #self.keyHandlers['\t'  ] = self.handle_TAB   # Tab

        if self.emulate == "emacs":
            # EMACS key bindinds
            self.keyHandlers['\x10'] = self.handle_UP     # Control-P
            self.keyHandlers['\x0e'] = self.handle_DOWN   # Control-N
            self.keyHandlers['\x02'] = self.handle_LEFT   # Control-B
            self.keyHandlers['\x06'] = self.handle_RIGHT  # Control-F
            self.keyHandlers['\x01'] = self.handle_HOME   # Control-A
            self.keyHandlers['\x05'] = self.handle_END    # Control-E

        def observer(event):
            if not event["isError"]:
                return

            text = log.textFromEventDict(event)
            if text is None:
                return

            self.service.reactor.callFromThread(self.terminal.write, text)

        log.startLoggingWithObserver(observer)
Ejemplo n.º 6
0
 def __init__(self, app):
     self.app = app
     self.handler = self.on_lobby_command
     self.nickname = None
     self.display_history = deque()
     self.tabchoices = []
     self.tabarg = None
     self.drawInput = False
     HistoricRecvLine.__init__(self)
Ejemplo n.º 7
0
 def connectionMade(self):
     HistoricRecvLine.connectionMade(self)
     self.keyHandlers.update({
         self.CTRL_D: lambda: self.handler.onEOF(self)})
     try:
         self.handler.onConnect(self)
     except AttributeError:
         pass
     self.showPrompt()
Ejemplo n.º 8
0
    def connectionMade(self):
        """ Create a PBClientFactory and connect to master when ConsoleClient
            connected to StandardIO. Prompt user for Username
        """
        HistoricRecvLine.connectionMade(self)
        self._factory = PBClientFactory()

        reactor.connectTCP(self._masterIP, self._console_port, self._factory) #@UndefinedVariable
        self.terminal.write("Username: ")
Ejemplo n.º 9
0
    def connectionMade(self):
        """ Create a PBClientFactory and connect to master when ConsoleClient
            connected to StandardIO. Prompt user for Username
        """
        HistoricRecvLine.connectionMade(self)
        self._factory = PBClientFactory()

        reactor.connectTCP(self._masterIP, self._console_port, self._factory)  #@UndefinedVariable
        self.terminal.write("Username: ")
Ejemplo n.º 10
0
 def connectionMade(self):
     """ Init connection. """
     HistoricRecvLine.connectionMade(self)
     self.write_to_terminal(GATEWAY_TERMINAL_WELCOME)
     self.terminal.nextLine()
     self.showPrompt()
Ejemplo n.º 11
0
    def handle_TAB(self):
        if self.nickname: # only tab once logged in
            parts = ''.join(self.lineBuffer).split(' ')
            player = self.app.players[self.nickname]
            comname = parts[0]
            
            if self.tabchoices and self.tabarg != None: # if queue, cycle
                self.tabchoices.append( self.tabchoices.pop(0) )
                choice = self.tabchoices[0]
                
                end = len(self.lineBuffer)
                diff = end - self.lineBufferIndex
                
                for x in xrange(diff):
                    self.handle_RIGHT()
                for x in range(end):
                    HistoricRecvLine.handle_BACKSPACE(self)
                    
                parts[self.tabarg] = choice
                newline = ' '.join(parts)
                end = len(' '.join(parts[:self.tabarg + 1]))
                 
                for c in newline:
                    HistoricRecvLine.characterReceived(self, c, None)
                
                diff = abs(end - self.lineBufferIndex)
                
                for x in xrange(diff):
                    self.handle_LEFT()
                    
            else: # determine tabchoices
                # complete commands
                if len(parts) == 1:
                    if '.' in parts[0]:
                        _parts = parts[0].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'] and command != 'exit':
                            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
                        context = ctxcls(self)
                        self.tabchoices = ["%s.%s" % (context_name, attribute[4:]) for attribute in dir(context) if attribute.startswith(contextual) and attribute != 'com_exit']
                        if self.tabchoices:
                            self.tabarg = 0
                            return self.handle_TAB()

                    elif isinstance(player.session.context,  contexts.get('battle')):
                        self.tabchoices = [move.selector.encode('utf8') for move in player.character.moves if move.selector.startswith(parts[0])]
                        callowed, cglobals = get_allowed(player)
                        self.tabchoices += [cname for cname in callowed if cname.startswith(parts[0])]
                        if self.tabchoices:
                            self.tabarg = 0
                            return self.handle_TAB()
                    else:
                        callowed, cglobals = get_allowed(player)
                        self.tabchoices = [cname for cname in callowed+cglobals if cname.startswith(parts[0])]
                        if self.tabchoices:
                            self.tabarg = 0
                            return self.handle_TAB()
                # complete arguments
                schema = None
                comobj = None
                callowed, cglobals = get_allowed(player)
                if len(parts) > 1:

                    if '.' in comname:
                        _parts = comname.split('.')
                        if len(_parts) == 2:
                            context_name, command = _parts
                            if context_name in ['build', 'admin'] and command != exit:
                                _context_name = {'build':'builder', 'admin':'administration'}[context_name] # convert to true name
                                ctxcls = contexts.get(_context_name)
                                if ctxcls:
                                    contextual = "com_%s" % command
                                    context = ctxcls(self)
                                    if hasattr(context, contextual):
                                        comobj = getattr(context, contextual)
                    # battle move arg
                    elif isinstance(player.session.context,  contexts.get('battle')) and len(parts) == 2:
                        moves = [move for move in player.character.moves if move.selector == comname]
                        if moves:
                            move = moves[0]
                            self.tabchoices = []
                            for fighter in self.app.game.fighters.itervalues():
                                try:
                                    self.app.game.validate_target(player, fighter, move)
                                except ValidationError: pass
                                else:
                                    self.tabchoices.append(fighter.nickname.encode('utf8'))
                            if self.tabchoices:
                                self.tabarg = 1
                                self.handle_TAB()
                    # contextual
                    elif comname in callowed:
                        contextual = "com_%s" % comname
                        if hasattr(player.session.context, contextual):
                            # get the command
                            comobj = getattr(player.session.context, contextual)
                    # global
                    elif comname in cglobals:
                        comobj = get(comname)
                    # do complete via exception
                    if comobj:
                        try:
                            data = v.command(self.app, comobj, parts[1:], player=player)
                        except v.ValidationError, e:
                            if e.choices:
                                self.tabchoices = [c.encode('utf8') for c in e.choices]
                                if self.tabchoices:
                                    self.tabarg = e.argnum
                                    self.handle_TAB()
Ejemplo n.º 12
0
 def handle_RETURN(self):
     self.reset_tab()
     if self.lineBuffer: # prevent empty submission
         self.sendLine(" ")
         return HistoricRecvLine.handle_RETURN(self)
Ejemplo n.º 13
0
 def handle_BACKSPACE(self):
     self.reset_tab()
     HistoricRecvLine.handle_BACKSPACE(self)
Ejemplo n.º 14
0
 def characterReceived(self, ch, moreCharactersComing):
     self.reset_tab()
     HistoricRecvLine.characterReceived(self, ch, moreCharactersComing)
Ejemplo n.º 15
0
 def connectionMade(self):
     HistoricRecvLine.connectionMade(self)
     self.keyHandlers.update({
         '\x03': self.handle_CTRL_C,
         '\x04': self.handle_CTRL_D,
     })
Ejemplo n.º 16
0
 def __init__(self, avatar=None):
     HistoricRecvLine.__init__(self)
     self.avatar = avatar