Exemplo n.º 1
0
    def parse(self, message):
        def need_to_resume(lines):
            if self.ignore_resume:
                return False
            for i in lines:
                if i.startswith(
                        'WARNING: You have a') and not 'unlimited' in i:
                    return True
            return False

        log.msg('#' * 80, logLevel=NOISY)
        log.msg('MESSAGE %s' % message, logLevel=NOISY)
        log.msg('#' * 80, logLevel=NOISY)  # WORK:00:
        self.reset_keepalive()
        lines = message.splitlines()
        while len(lines) > 0:
            first_line = lines[0]
            cmd_line = first_line.split()
            if len(cmd_line) == 0 or cmd_line[0] in \
                                        ('3', '4', '5', '6', '7', '8', '13'):
                del lines[0]
                continue
            log.msg('=' * 80, logLevel=logging.DEBUG)
            log.msg('COMMAND LINE %s' % cmd_line, logLevel=logging.DEBUG)
            log.msg('REQUEST %s' % self.requests, logLevel=logging.DEBUG)
            message_done = False

            if first_line.startswith('** '):
                # TODO hier gehört noch ein Abfangjäger für reichlich normale
                #      Meldungen rein (** Player helena has left the game...)
                log.msg('from server: %s' % first_line,
                        logLevel=logging.WARNING)

            for r in self.requests:
                if first_line.startswith(r):
                    log.msg('ICH CHECKE ----------- %s' % first_line,
                            logLevel=TRACE)
                    # TODO: das funktioniert noch nicht.
                    #       Versuch mal den bot auf 'away' zu setzen und dann zu starten
                    #       Er bekommt die "away"-message als erste Zeile
                    request = self.requests.pop(r)
                    log.msg('1 ################# %s' % len(lines),
                            logLevel=logging.DEBUG)
                    message_done = request.received(lines)
                    log.msg('2 ################# %s (%s)' %
                            (len(lines), message_done),
                            logLevel=logging.DEBUG)
                    break
            if not message_done and 'default' in self.requests:
                # TODO: schauen, ob man das noch braucht
                log.msg('IN DEFAULT ----------- %s' % first_line,
                        logLevel=TRACE)
                request = self.requests['default']
                log.msg('3 ################# %s' % len(lines),
                        logLevel=logging.DEBUG)
                message_done = request.received(lines)
                log.msg('4 ################# %s (%s)' %
                        (len(lines), message_done),
                        logLevel=logging.DEBUG)

            if not message_done:
                if first_line.startswith('12 '):
                    self.command(first_line[3:])
                elif len(cmd_line) > 3 and \
                                        ' '.join(cmd_line[1:3]) == "wants to":
                    opponent = cmd_line[0]
                    if cmd_line[3] == 'play':
                        ML = cmd_line[5]
                        if need_to_resume(lines):
                            msg = "tell %s We have a saved game. Please join " \
                                                "and let us finish that one :)."
                            self.send_server(msg % opponent)
                            invite(self, opponent, None)
                        elif ML == 'unlimited':
                            join(self, opponent, ML, type_of_invitation=1)
                            log.msg('joining an unlimited match with %s' % \
                                            opponent, logLevel=logging.INFO)
                        elif int(ML) > 0 and int(ML) <= MAX_MATCHLEN:
                            join(self, opponent, ML)
                            log.msg('joining a %s point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                        else:
                            msg = "tell %s I do not play matches greater " \
                                  "than ML %d. Sorry." % \
                                                    (opponent, MAX_MATCHLEN)
                            self.send_server(msg)
                            log.msg('turning down a %s point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                    else:
                        ML = None
                        log.msg('resuming a match with %s' % opponent,
                                logLevel=logging.INFO)
                        join(self, opponent, ML)
                elif 'HyperGammon.' in cmd_line:
                    bridge = self.protocol.factory.gnubg
                    if 'hyperbg' in bridge.gnubg:
                        self.current_gnubg = 'hyperbg'
                        log.msg("Set current_gnubg to 'hyperbg'")
                if len(lines) > 0:
                    log.msg('deleting command line: >%s<' % lines[0],
                            logLevel=logging.DEBUG)
                    del lines[0]

        if len(lines) > 0:
            log.msg('got from server/lines left: >%s<' % '\n'.join(lines),
                    logLevel=logging.DEBUG)
Exemplo n.º 2
0
    def parse(self, message):
        log.msg('#' * 80, logLevel=NOISY)
        log.msg('MESSAGE %s' % message, logLevel=NOISY)
        lines = message.splitlines()
        while len(lines) > 0:
            first_line = lines[0]
            cmd_line = first_line.split()
            if len(cmd_line) == 0 or cmd_line[0] in \
                                        ('3', '4', '5', '6', '7', '8', '13'):
                del lines[0]
                continue
            log.msg('=' * 80, logLevel=logging.DEBUG)
            log.msg('COMMAND LINE %s' % cmd_line, logLevel=logging.DEBUG)
            log.msg('REQUEST %s' % self.requests, logLevel=logging.DEBUG)
            message_done = False

            if first_line.startswith('** '):
                # TODO hier gehört noch ein Abfangjäger für reichlich normale
                #      Meldungen rein (** Player helena has left the game...)
                log.msg('from server: %s' % first_line,
                        logLevel=logging.WARNING)

            for r in self.requests:
                if first_line.startswith(r):
                    log.msg('ICH CHECKE ----------- %s' % first_line,
                            logLevel=TRACE)
                    # TODO: das funktioniert noch nicht.
                    #       Versuch mal den bot auf 'away' zu setzen und dann zu starten
                    #       Er bekommt die "away"-message als erste Zeile
                    request = self.requests.pop(r)
                    log.msg('1 ################# %s' % len(lines),
                            logLevel=logging.DEBUG)
                    message_done = request.received(lines)
                    log.msg('2 ################# %s (%s)' %
                            (len(lines), message_done),
                            logLevel=logging.DEBUG)
                    break
            if not message_done and 'default' in self.requests:
                # TODO: schauen, ob man das noch braucht
                log.msg('IN DEFAULT ----------- %s' % first_line,
                        logLevel=TRACE)
                request = self.requests['default']
                log.msg('3 ################# %s' % len(lines),
                        logLevel=logging.DEBUG)
                message_done = request.received(lines)
                log.msg('4 ################# %s (%s)' %
                        (len(lines), message_done),
                        logLevel=logging.DEBUG)

            if not message_done:
                if first_line.startswith('12 '):
                    self.command(first_line[3:])
                elif len(cmd_line) > 3 and \
                                        ' '.join(cmd_line[1:3]) == "wants to":
                    opponent = cmd_line[0]
                    if cmd_line[3] == 'play':
                        ML = int(cmd_line[5])
                        if ML > 0 and ML <= MAX_MATCHLEN:
                            join(opponent, ML)
                            log.msg('joining a %d point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                        else:
                            msg = "tell %s I do not as yet play matches " \
                                  "greater than ML %d or unlimited. Sorry." % \
                                                    (opponent, MAX_MATCHLEN)
                            self.send_server(msg)
                            log.msg('turning down a %d point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                    else:
                        ML = None
                        log.msg('resuming a match with %s' % opponent,
                                logLevel=logging.INFO)
                        join(opponent, ML)
                if len(lines) > 0:
                    del lines[0]

        if len(lines) > 0:
            log.msg('got from server/lines left: >%s<' % '\n'.join(lines),
                    logLevel=logging.DEBUG)
Exemplo n.º 3
0
    def parse(self, message):
        log.msg("#" * 80, logLevel=NOISY)
        log.msg("MESSAGE %s" % message, logLevel=NOISY)
        lines = message.splitlines()
        while len(lines) > 0:
            first_line = lines[0]
            cmd_line = first_line.split()
            if len(cmd_line) == 0 or cmd_line[0] in ("3", "4", "5", "6", "7", "8", "13"):
                del lines[0]
                continue
            log.msg("=" * 80, logLevel=logging.DEBUG)
            log.msg("COMMAND LINE %s" % cmd_line, logLevel=logging.DEBUG)
            log.msg("REQUEST %s" % self.requests, logLevel=logging.DEBUG)
            message_done = False

            if first_line.startswith("** "):
                # TODO hier gehört noch ein Abfangjäger für reichlich normale
                #      Meldungen rein (** Player helena has left the game...)
                log.msg("from server: %s" % first_line, logLevel=logging.WARNING)

            for r in self.requests:
                if first_line.startswith(r):
                    log.msg("ICH CHECKE ----------- %s" % first_line, logLevel=TRACE)
                    # TODO: das funktioniert noch nicht.
                    #       Versuch mal den bot auf 'away' zu setzen und dann zu starten
                    #       Er bekommt die "away"-message als erste Zeile
                    request = self.requests.pop(r)
                    log.msg("1 ################# %s" % len(lines), logLevel=logging.DEBUG)
                    message_done = request.received(lines)
                    log.msg("2 ################# %s (%s)" % (len(lines), message_done), logLevel=logging.DEBUG)
                    break
            if not message_done and "default" in self.requests:
                # TODO: schauen, ob man das noch braucht
                log.msg("IN DEFAULT ----------- %s" % first_line, logLevel=TRACE)
                request = self.requests["default"]
                log.msg("3 ################# %s" % len(lines), logLevel=logging.DEBUG)
                message_done = request.received(lines)
                log.msg("4 ################# %s (%s)" % (len(lines), message_done), logLevel=logging.DEBUG)

            if not message_done:
                if first_line.startswith("12 "):
                    self.command(first_line[3:])
                elif len(cmd_line) > 3 and " ".join(cmd_line[1:3]) == "wants to":
                    opponent = cmd_line[0]
                    if cmd_line[3] == "play":
                        ML = int(cmd_line[5])
                        if ML > 0 and ML <= MAX_MATCHLEN:
                            join(opponent, ML)
                            log.msg("joining a %d point match with %s" % (ML, opponent), logLevel=logging.INFO)
                        else:
                            msg = "tell %s I do not as yet play matches " "greater than ML %d or unlimited. Sorry." % (
                                opponent,
                                MAX_MATCHLEN,
                            )
                            self.send_server(msg)
                            log.msg("turning down a %d point match with %s" % (ML, opponent), logLevel=logging.INFO)
                    else:
                        ML = None
                        log.msg("resuming a match with %s" % opponent, logLevel=logging.INFO)
                        join(opponent, ML)
                if len(lines) > 0:
                    del lines[0]

        if len(lines) > 0:
            log.msg("got from server/lines left: >%s<" % "\n".join(lines), logLevel=logging.DEBUG)
Exemplo n.º 4
0
    def parse(self, message):
        def need_to_resume(lines):
            if self.ignore_resume:
                return False
            for i in lines:
                if i.startswith('WARNING: You have a') and not 'unlimited' in i:
                    return True
            return False
        log.msg('#'*80, logLevel=NOISY)
        log.msg('MESSAGE %s' % message, logLevel=NOISY)
        log.msg('#'*80, logLevel=NOISY)                     # WORK:00:
        self.reset_keepalive()
        lines = message.splitlines()
        while len(lines) > 0:
            first_line = lines[0]
            cmd_line = first_line.split()
            if len(cmd_line) == 0 or cmd_line[0] in \
                                        ('3', '4', '5', '6', '7', '8', '13'):
                del lines[0]
                continue
            log.msg('='*80, logLevel=logging.DEBUG)
            log.msg('COMMAND LINE %s' % cmd_line, logLevel=logging.DEBUG)
            log.msg('REQUEST %s' % self.requests, logLevel=logging.DEBUG)
            message_done = False

            if first_line.startswith('** '):
                # TODO hier gehört noch ein Abfangjäger für reichlich normale
                #      Meldungen rein (** Player helena has left the game...)
                log.msg('from server: %s' % first_line, logLevel=logging.WARNING)

            for r in self.requests:
                if first_line.startswith(r):
                    log.msg('ICH CHECKE ----------- %s' % first_line, logLevel=TRACE)
                    # TODO: das funktioniert noch nicht.
                    #       Versuch mal den bot auf 'away' zu setzen und dann zu starten
                    #       Er bekommt die "away"-message als erste Zeile
                    request = self.requests.pop(r)
                    log.msg('1 ################# %s' % len(lines), logLevel=logging.DEBUG)
                    message_done = request.received(lines)
                    log.msg('2 ################# %s (%s)' % (len(lines),message_done), logLevel=logging.DEBUG)
                    break
            if not message_done and 'default' in self.requests:
                # TODO: schauen, ob man das noch braucht
                log.msg('IN DEFAULT ----------- %s' % first_line, logLevel=TRACE)
                request = self.requests['default']
                log.msg('3 ################# %s' % len(lines), logLevel=logging.DEBUG)
                message_done = request.received(lines)
                log.msg('4 ################# %s (%s)' % (len(lines),message_done), logLevel=logging.DEBUG)

            if not message_done:
                if first_line.startswith('12 '):
                    self.command(first_line[3:])
                elif len(cmd_line) > 3 and \
                                        ' '.join(cmd_line[1:3]) == "wants to":
                    opponent = cmd_line[0]
                    if cmd_line[3] == 'play':
                        ML = cmd_line[5]
                        if need_to_resume(lines):
                            msg = "tell %s We have a saved game. Please join " \
                                                "and let us finish that one :)."
                            self.send_server(msg % opponent)
                            invite(self, opponent, None)
                        elif ML == 'unlimited':
                            join(self, opponent, ML, type_of_invitation=1)
                            log.msg('joining an unlimited match with %s' % \
                                            opponent, logLevel=logging.INFO)
                        elif int(ML) > 0 and int(ML) <= MAX_MATCHLEN:
                            join(self, opponent, ML)
                            log.msg('joining a %s point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                        else:
                            msg = "tell %s I do not play matches greater " \
                                  "than ML %d. Sorry." % \
                                                    (opponent, MAX_MATCHLEN)
                            self.send_server(msg)
                            log.msg('turning down a %s point match with %s' % \
                                        (ML, opponent), logLevel=logging.INFO)
                    else:
                        ML = None
                        log.msg('resuming a match with %s' % opponent,
                                logLevel=logging.INFO)
                        join(self, opponent, ML)
                elif 'HyperGammon.' in cmd_line:
                    bridge = self.protocol.factory.gnubg
                    if 'hyperbg' in bridge.gnubg:
                        self.current_gnubg = 'hyperbg'
                        log.msg("Set current_gnubg to 'hyperbg'")
                if len(lines) > 0:
                    log.msg('deleting command line: >%s<' % lines[0], logLevel=logging.DEBUG)
                    del lines[0]

        if len(lines) > 0:
            log.msg('got from server/lines left: >%s<' % '\n'.join(lines),
                                                logLevel=logging.DEBUG)