Esempio n. 1
0
 def command(self, cmd):
     a = cmd.split()
     user = a[0]
     command = a[1]
     cmd_string = ' '.join(a[1:])
     if command in COMMANDS and user in ADMINISTRATORS:
         log.msg('%s tells me to: %s' % \
                                 (user, cmd_string), logLevel=logging.INFO)
         if command in ('end', ):
             self.protocol.factory.stop()
             self.send_server('wave')
             self.send_server('wave')
         elif command == 'invite':
             if len(a) < 4:
                 invite(self, a[2], None)
             elif a[3] != 'unlimited' and int(a[3]) <= MAX_MATCHLEN:
                 invite(self, a[2], a[3])
             else:
                 log.msg('turning down a %s point invitation with %s' % \
                                         (a[3], a[2]), logLevel=logging.INFO)
         else:
             self.send_server(cmd_string)
     else:
         log.msg('%s says: %s' % (user, cmd_string), logLevel=logging.INFO)
         if command in ('info', ):
             self.user_commands[command](user)
         else:
             msg = "tell %s I am a bot. I don't know how to talk, yet. Sorry."
             if not user in self.told_opponent:
                 self.told_opponent[user] = True
                 self.send_server(msg % user)
                 reactor.callLater(300., self.delete_told_opponent, user)
Esempio n. 2
0
 def command(self, cmd):
     a = cmd.split()
     user = a[0]
     command = a[1]
     cmd_string = ' '.join(a[1:])
     if command in COMMANDS and user in ADMINISTRATORS:
         log.msg('%s tells me to: %s' % \
                                 (user, cmd_string), logLevel=logging.INFO)
         if command in ('end',):
             self.protocol.factory.stop()
             self.send_server('wave')
             self.send_server('wave')
         elif command == 'invite':
             if len(a) < 4:
                 invite(self, a[2], None)
             elif a[3] != 'unlimited' and int(a[3]) <= MAX_MATCHLEN:
                 invite(self, a[2], a[3])
             else:
                 log.msg('turning down a %s point invitation with %s' % \
                                         (a[3], a[2]), logLevel=logging.INFO)
         else:
             self.send_server(cmd_string)
     else:
         log.msg('%s says: %s' % (user, cmd_string), logLevel=logging.INFO)
         if command in ('info',):
             self.user_commands[command](user)
         else:
             msg = "tell %s I am a bot. I don't know how to talk, yet. Sorry."
             if not user in self.told_opponent:
                 self.told_opponent[user] = True
                 self.send_server(msg % user)
                 reactor.callLater(300., self.delete_told_opponent, user)
Esempio n. 3
0
 def invite_one(bots):
     ML = dispatch.get_invite_ML()
     opp = dispatch.get_invite_player()
     log.msg("invite_one in .....testbot %s %s" % (ML, opp))
     if opp in bots and ML is not None:
         invite(dispatch, opp, ML)
     else:
         dispatch.relax_hook()
Esempio n. 4
0
 def command(self, cmd):
     a = cmd.split()
     user = a[0]
     command = a[1]
     cmd_string = " ".join(a[1:])
     if command in COMMANDS and user in ADMINISTRATORS:
         if command in ("end",):
             self.protocol.factory.stop()
         elif command == "invite" and a[3] <= MAX_MATCHLEN:
             invite(a[2], a[3])
         else:
             self.send_server(cmd_string)
Esempio n. 5
0
 def command(self, cmd):
     a = cmd.split()
     user = a[0]
     command = a[1]
     cmd_string = ' '.join(a[1:])
     if command in COMMANDS and user in ADMINISTRATORS:
         if command in ('end', ):
             self.protocol.factory.stop()
         elif command == 'invite' and a[3] <= MAX_MATCHLEN:
             invite(a[2], a[3])
         else:
             self.send_server(cmd_string)
Esempio n. 6
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)
Esempio n. 7
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)