Exemplo n.º 1
0
    def __onStoredResponseYES(self, matchlist):
        #Stored games for User:
        #     C Opponent     On Type          Str  M    ECO Date
        #  1: W TheDane       N [ br  2  12]  0-0  B2   ??? Sun Nov 23,  6:14 CST 1997
        #  2: W PyChess       Y [psu  2  12] 39-39 W3   C20 Sun Jan 11, 17:40 ??? 2009
        #  3: B cjavad        N [ wr  2   2] 31-31 W18  --- Wed Dec 23, 06:58 PST 2009
        self.connection.stored_owner = matchlist[0].groups()[0]
        adjournments = []
        for match in matchlist[2:]:
            our_color = match.groups()[0]
            opponent_name, opponent_online = match.groups()[1:3]
            game_type = match.groups()[3]
            minutes, gain = match.groups()[4:6]
            str_white, str_black = match.groups()[6:8]
            next_color = match.groups()[8]
            move_num = match.groups()[9]
            eco = match.groups()[10]
            week, month, day, hour, minute, timezone, year = match.groups(
            )[11:18]
            gametime = datetime.datetime(int(year),
                                         months.index(month) + 1, int(day),
                                         int(hour), int(minute))
            private = game_type[0] == "p"
            rated = game_type[2] == "r"
            gametype = GAME_TYPES_BY_SHORT_FICS_NAME[game_type[1]]
            our_color = our_color == "B" and BLACK or WHITE
            minutes = int(minutes)
            gain = int(gain)
            length = (int(move_num) - 1) * 2
            if next_color == "B": length += 1

            user = self.connection.players.get(
                FICSPlayer(self.connection.stored_owner))
            opponent = FICSPlayer(opponent_name, status=IC_STATUS_OFFLINE)
            opponent = self.connection.players.get(opponent)
            wplayer, bplayer = (user, opponent) if our_color == WHITE \
                                                else (opponent, user)
            game = FICSAdjournedGame(wplayer,
                                     bplayer,
                                     game_type=gametype,
                                     rated=rated,
                                     our_color=our_color,
                                     length=length,
                                     time=gametime,
                                     minutes=minutes,
                                     inc=gain,
                                     private=private)
            if game.opponent.adjournment != True:
                game.opponent.adjournment = True

            if game not in self.connection.games:
                game = self.connection.games.get(game, emit=False)
                self.emit("adjournedGameAdded", game)
            adjournments.append(game)

        self.emit("onAdjournmentsList", adjournments)
Exemplo n.º 2
0
    def on_icc_gamelist_item(self, data):
        # index id event date time white-name white-rating black-name black-rating rated rating-type
        # wild init-time-W inc-W init-time-B inc-B eco status color mode {note} here
        # status: 0=win 1=draw 2=adjourned 3=abort
        # rating_type: 0=wild, 1=blitz, 2=standard, bullet, 4=bughouse see DG_RATING_TYPE_KEY
        # 99 1731753309 ? 2016.12.08 15:07:53 gbtami 1538 konechno 1644 1 11 0 3 0 3 0 A00 0 1 1 {} 0
        # 98 1731751094 ? 2016.12.08 14:34:37 gbtami 1550 espilva 1484 1 11 0 3 0 3 0 A00 1 0 5 {} 0
        idx, gid, event, date, time, wname, wrating, bname, brating, rated, rating_type, \
            wild, wtime, winc, btime, binc, eco, status, color, mode, rest = data.split(" ", 20)

        if status == "0":
            result = WHITEWON if color == "0" else BLACKWON
        elif status == "1":
            result = DRAW
        elif status == "2":
            result = ADJOURNED
        else:
            result = ABORTED

        white = wname
        black = bname
        wrating = wrating
        brating = brating

        if status == "0":
            reason = won_reasons_dict[mode]
        elif status == "1":
            reason = draw_reasons_dict[mode]
        else:
            reason = UNKNOWN_REASON

        year, month, day = date.split(".")
        hour, minute, sec = time.split(":")
        gametime = datetime.datetime(int(year), int(month), int(day),
                                     int(hour), int(minute), int(sec))
        rated = rated == "1"
        fics_name = self.RATING_TYPES[rating_type]
        gametype = GAME_TYPES_BY_FICS_NAME[fics_name]

        minutes = int(wtime)
        gain = int(winc)

        wplayer = self.connection.players.get(white)
        bplayer = self.connection.players.get(black)

        if self.gamelist_command == "stored":
            game = FICSAdjournedGame(wplayer,
                                     bplayer,
                                     game_type=gametype,
                                     rated=rated,
                                     our_color=WHITE if wname
                                     == self.connection.username else BLACK,
                                     minutes=minutes,
                                     inc=gain)

            if game.opponent.adjournment is False:
                game.opponent.adjournment = True

        elif self.gamelist_command == "history":
            game = FICSHistoryGame(wplayer,
                                   bplayer,
                                   game_type=gametype,
                                   rated=rated,
                                   minutes=minutes,
                                   inc=gain,
                                   wrating=wrating,
                                   brating=brating,
                                   time=gametime,
                                   reason=reason,
                                   history_no=idx,
                                   result=result)

        elif self.gamelist_command == "liblist":
            game = FICSJournalGame(wplayer,
                                   bplayer,
                                   game_type=gametype,
                                   rated=rated,
                                   minutes=minutes,
                                   inc=gain,
                                   wrating=wrating,
                                   brating=brating,
                                   time=gametime,
                                   reason=reason,
                                   journal_no=idx,
                                   result=result)

        if game not in self.connection.games:
            game = self.connection.games.get(game, emit=False)
            if self.gamelist_command == "stored":
                self.emit("adjournedGameAdded", game)
            elif self.gamelist_command == "history":
                self.emit("historyGameAdded", game)
            elif self.gamelist_command == "liblist":
                self.emit("journalGameAdded", game)