Exemplo n.º 1
0
    def __onJournalResponseYES(self, matchlist):
        # Journal for User:
        #     White         Rating  Black         Rating  Type         ECO End Result
        # %01: tentacle      2291    larsa         2050    [ lr  1   2] D35 Rep 1/2-1/2
        # %02: larsa         2045    tentacle      2296    [ lr  1   2] A46 Res 0-1
        journal = []
        self.connection.journal_owner = matchlist[0].groups()[0]
        for match in matchlist[2:]:
            # print(match.groups())
            journal_no = match.groups()[0]
            result = match.groups()[10]
            result = reprResult.index(result)
            white = match.groups()[1]
            wrating = match.groups()[2]
            black = match.groups()[3]
            brating = match.groups()[4]
            game_type = match.groups()[5]
            minutes, gain = match.groups()[6:8]
            reason = reasons_dict[match.groups()[9]]
            private = game_type[0] == "p"
            rated = game_type[2] == "r"
            gametype = GAME_TYPES_BY_SHORT_FICS_NAME[game_type[1]]
            minutes = int(minutes)
            gain = int(gain)

            wplayer = self.connection.players.get(
                FICSPlayer(white,
                           status=IC_STATUS_OFFLINE))
            bplayer = self.connection.players.get(
                FICSPlayer(black,
                           status=IC_STATUS_OFFLINE))
            game = FICSJournalGame(wplayer,
                                   bplayer,
                                   game_type=gametype,
                                   rated=rated,
                                   minutes=minutes,
                                   inc=gain,
                                   private=private,
                                   wrating=wrating,
                                   brating=brating,
                                   reason=reason,
                                   journal_no=journal_no,
                                   result=result)

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

        self.emit("onJournalList", journal)
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)