Esempio n. 1
0
    def update(self):
        if self.update_recursion:
            self.log.warn("unexpected recursion (ignored)", exc_info=1)
            return "recurse"
        self.update_recursion = True
        if not self.isValid():
            return "not valid"
        
        history = self.game.historyGet()
        history_len = len(history)
        history_tail = history[self.history_index:]

        try:
            self.updateTimers(history_tail)
            packets, self.previous_dealer, errors = history2packets(history_tail, self.game.id, self.previous_dealer, self.cache)
            for error in errors: self.log.warn("%s", error)
            self.syncDatabase()
            self.delayedActions()
            if len(packets) > 0:
                self.broadcast(packets)
            self.tourneyEndTurn()
            if self.isValid():
                self.cashGame_kickPlayerSittingOutTooLong(history_tail)
                self.scheduleAutoDeal()
        finally:
            if history_len != len(history):
                self.log.error("%s length changed from %d to %d (i.e. %s was added)",
                    history,
                    history_len,
                    len(history),
                    history[history_len:]
                )
            if self.game.historyCanBeReduced():
                try:
                    self.game.historyReduce()
                except Exception:
                    self.log.error('history reduce error', exc_info=1)
            self.history_index = len(self.game.historyGet())
            self.update_recursion = False
        return "ok"
Esempio n. 2
0
 def handReplay(self, avatar, hand):
     history = self.factory.loadHand(hand)
     if not history:
         return
     event_type, level, hand_serial, hands_count, time, variant, betting_structure, player_list, dealer, serial2chips = history[0]  # @UnusedVariable
     for player in self.game.playersAll():
         avatar.sendPacketVerbose(PacketPokerPlayerLeave(
             game_id = self.game.id,
             serial = player.serial,
             seat = player.seat
         ))
     self.game.reset()
     self.game.name = "*REPLAY*"
     self.game.setVariant(variant)
     self.game.setBettingStructure(betting_structure)
     self.game.setTime(time)
     self.game.setHandsCount(hands_count)
     self.game.setLevel(level)
     self.game.hand_serial = hand
     for serial in player_list:
         self.game.addPlayer(serial)
         self.game.getPlayer(serial).money = serial2chips[serial]
         self.game.sit(serial)
     if self.isJoined(avatar):
         avatar.join(self, reason=PacketPokerTable.REASON_HAND_REPLAY)
     else:
         self.joinPlayer(avatar, avatar.getSerial(), reason = PacketPokerTable.REASON_HAND_REPLAY)
     serial = avatar.getSerial()
     cache = createCache()
     packets, previous_dealer, errors = history2packets(history, self.game.id, -1, cache) #@UnusedVariable
     for packet in packets:
         if packet.type == PACKET_POKER_PLAYER_CARDS and packet.serial == serial:
             packet.cards = cache["pockets"][serial].toRawList()
         if packet.type == PACKET_POKER_PLAYER_LEAVE:
             continue
         avatar.sendPacketVerbose(packet)