예제 #1
0
    def on_icc_seek_add(self, data):
        log.debug("DG_SEEK_ADD %s" % data)
        # index name titles rating provisional-status wild rating-type time
        # inc rated color minrating maxrating autoaccept formula fancy-time-control
        # 195 Tinker {C} 2402 2 0 Blitz 5 3 1 -1 0 9999 1 1 {}

        parts = data.split(" ", 2)
        index = int(parts[0])
        player = self.connection.players.get(parts[1])

        titles_end = parts[2].find("}")
        titles = parts[2][1:titles_end]
        tit = set()
        for title in titles.split():
            tit.add(TITLES[title])
        player.titles |= tit

        parts = parts[2][titles_end + 1:].split()
        rating = int(parts[0])
        deviation = None  # parts[1]
        # wild = parts[2]
        try:
            gametype = GAME_TYPES[parts[3].lower()]
        except KeyError:
            return
        minutes = int(parts[4])
        increment = int(parts[5])
        rated = parts[6] == "1"
        color = parts[7]
        if color == "-1":
            color = None
        else:
            color = "white" if color == '1' else "black"
        rmin = int(parts[8])
        rmax = int(parts[9])
        automatic = parts[10] == "1"
        # formula = parts[11]
        # fancy_tc = parts[12]

        if gametype.variant_type in UNSUPPORTED:
            log.debug("!!! unsupported variant in seek: %s" % data)
            return

        if gametype.rating_type in RATING_TYPES and player.ratings[
                gametype.rating_type] != rating:
            player.ratings[gametype.rating_type] = rating
            player.deviations[gametype.rating_type] = deviation
            player.emit("ratings_changed", gametype.rating_type, player)

        seek = FICSSeek(index,
                        player,
                        minutes,
                        increment,
                        rated,
                        color,
                        gametype,
                        rmin=rmin,
                        rmax=rmax,
                        automatic=automatic)
        self.emit("addSeek", seek)
예제 #2
0
    def on_seek_add(self, match):
        # The <s> message looks like:
        # <s> index w=name_from ti=titles rt=rating t=time i=increment
        #     r=rated('r')/unrated('u') tp=type("wild/fr", "wild/4","blitz")
        #     c=color rr=rating_range(lower-upper) a=automatic?('t'/'f')
        #     f=formula_checked('t'/f')
        parts = match.groups()[0].split()
        seek = {}
        for key, value in [p.split("=") for p in parts[1:] if p]:
            seek[key] = value

        try:
            index = int(parts[0])
            player = self.connection.players.get(seek["w"])
            player.titles |= parse_title_hex(seek["ti"])
            rated = seek["r"] == "r"
            minutes = int(seek["t"])
            increment = int(seek["i"])
            rmin, rmax = [int(r) for r in seek["rr"].split("-")]
            rating = seek["rt"]
            if rating[-1] in (" ", "P", "E"):
                deviation = DEVIATION[rating[-1]]
                rating = rating[:-1]
            rating = int(rating)
            deviation = None
            automatic = seek["a"] == "t"
            color = None
            if seek["c"] == "W":
                color = "white"
            elif seek["c"] == "B":
                color = "black"
        except KeyError as e:
            log.warning("on_seek_add: KeyError: %s %s" % (repr(e), repr(seek)))
            return

        try:
            gametype = GAME_TYPES[seek["tp"]]
        except KeyError:
            if self.connection.FatICS and seek["tp"] == "chess":
                # TODO: remove when fixed in FatICS
                expected_time = minutes + increment * 2 / 3
                if expected_time == 0:
                    gametype = "untimed"
                elif expected_time < 3:
                    gametype = "lightning"
                elif expected_time < 15:
                    gametype = "blitz"
                else:
                    gametype = "standard"
                gametype = GAME_TYPES[gametype]
            else:
                return
        if gametype.variant_type in UNSUPPORTED:
            return

        if (gametype.rating_type in RATING_TYPES
                and player.ratings[gametype.rating_type] != rating):
            player.ratings[gametype.rating_type] = rating
            player.deviations[gametype.rating_type] = deviation
            player.emit("ratings_changed", gametype.rating_type, player)

        seek = FICSSeek(
            index,
            player,
            minutes,
            increment,
            rated,
            color,
            gametype,
            rmin=rmin,
            rmax=rmax,
            automatic=automatic,
        )
        self.emit("addSeek", seek)