Exemplo n.º 1
0
def execute(userId, message, messageHandle):
    redis = gl.get_v("redis")
    if redis.exists(str(userId) + "_room"):
        roomNo = redis.get(str(userId) + "_room")
        redis.lock("lockroom_" + str(roomNo))
        try:
            room = redis.getobj("room_" + str(roomNo))
            if room.gameStatus != GameStatus.PLAYING:
                gl.get_v("serverlogger").logger.info("看牌失败状态不对")
                redis.unlock("lockroom_" + str(roomNo))
                return
            seat = room.getSeatByUserId(userId)
            if seat is not None and not seat.lookCard and not seat.end:
                seat.lookCard = True
                recExecuteAction = RecExecuteAction()
                recExecuteAction.playerId = seat.userId
                for s in room.seats:
                    lookCardAction = JinhuaLookCardAction()
                    if s.userId == userId:
                        lookCardAction.cards.extend(s.initialCards)
                        room.historyActions.append(
                            recExecuteAction.SerializeToString())
                    recExecuteAction.data = lookCardAction.SerializeToString()
                    messageHandle.send_to_gateway(EXECUTE_ACTION,
                                                  recExecuteAction, s.userId)
                room.save(redis)
        except:
            print traceback.print_exc()
        redis.unlock("lockroom_" + str(roomNo))
Exemplo n.º 2
0
 def executeAction(self, userId, actionType, data, messageHandle):
     recExecuteAction = RecExecuteAction()
     recExecuteAction.actionType = actionType
     recExecuteAction.playerId = userId
     if data is not None:
         recExecuteAction.data = data.SerializeToString()
     messageHandle.broadcast_seat_to_gateway(EXECUTE_ACTION,
                                             recExecuteAction, self)
     self.historyActions.append(recExecuteAction.SerializeToString())
Exemplo n.º 3
0
def execute(room, messageHandle):
    try:
        if room.gameStatus == GameStatus.WAITING:
            shuffleData = ShuffleData()
            conn = grpc.insecure_channel('127.0.0.1:50002')
            client = zhipai_pb2_grpc.ZhipaiStub(channel=conn)
            shuffleResult = client.shuffle(shuffleData)
            update_currency = []
            for seat in room.seats:
                seat.initialCards = []
                seat.initialCards.extend(
                    shuffleResult.cardlist[5 * seat.seatNo - 5:5 *
                                           seat.seatNo])
                seat.score -= int(0.5 * room.score)
                update_currency.append(
                    UpdateCurrency(-int(0.5 * room.score), seat.userId,
                                   room.roomNo))

            if 0 != len(update_currency):
                gl.get_v("update_currency").putall(update_currency)
            gl.get_v("serverlogger").logger.info("发牌完成")
        executeAction = RecExecuteAction()
        if room.gameStatus == GameStatus.PLAYING:
            for s in room.seats:
                dealCardAction = DouniuCardAction()
                if 0 != len(s.initialCards):
                    dealCardAction.cards.append(s.initialCards[4])
                else:
                    dealCardAction.cards.append(0)
                executeAction.data = dealCardAction.SerializeToString()
                messageHandle.send_to_gateway(EXECUTE_ACTION, executeAction,
                                              s.userId)
            room.gameStatus = GameStatus.OPENING
            room.executeAsk(messageHandle, 0, 3)
        else:
            for s in room.seats:
                dealCardAction = DouniuCardAction()
                if 0 != len(s.initialCards):
                    dealCardAction.cards.extend(s.initialCards[0:4])
                else:
                    dealCardAction.cards.extend([0, 0, 0, 0])
                executeAction.data = dealCardAction.SerializeToString()
                messageHandle.send_to_gateway(EXECUTE_ACTION, executeAction,
                                              s.userId)
            room.gameStatus = GameStatus.GRABING
            room.executeAsk(messageHandle, 0, 1)
        room.historyActions.append(executeAction.SerializeToString())
    except:
        print traceback.print_exc()
Exemplo n.º 4
0
def execute(room, messageHandle):
    try:
        if room.gameStatus == GameStatus.WAITING:
            shuffleData = ShuffleData()
            conn = grpc.insecure_channel('127.0.0.1:50011')
            client = zhipai_pb2_grpc.ZhipaiStub(channel=conn)
            shuffleResult = client.shuffle(shuffleData)
            cardlist = shuffleResult.cardlist
            room.positions[0].cards.append(cardlist[0])
            room.positions[1].cards.append(cardlist[1])
            room.startDate = int(time.time())
        if room.gameStatus == GameStatus.PLAYING:
            gameover_cmd.execute(room, messageHandle)
        else:
            executeAction = RecExecuteAction()
            executeAction.actionType = 0
            messageHandle.broadcast_watch_to_gateway(EXECUTE_ACTION,
                                                     executeAction, room)
            room.gameStatus = GameStatus.PLAYING
            room.historyActions.append(executeAction.SerializeToString())
            room.executeAsk(messageHandle, 0, 2)
            threading.Thread(target=play_timeout.execute,
                             args=(
                                 room.roomNo,
                                 messageHandle,
                                 room.gameCount,
                             ),
                             name='play_timeout').start()  # 线程对象.
            gl.get_v("serverlogger").logger.info("开始下注")
            playHandle = PlayScoreHandle(str(room.roomNo), TestQueue())
            gl.get_v("play-handle")[str(room.roomNo)] = playHandle
            threading.Thread(target=playHandle.execute,
                             name='playthread').start()  # 线程对象.

            if gl.get_v(str(room.roomNo) + "sendthread") is None:
                e = SendScores(room.roomNo, messageHandle)
                threading.Thread(target=e.execute,
                                 name='sendthread').start()  # 线程对象.
                gl.set_v(str(room.roomNo) + "sendthread", e)
    except:
        print traceback.print_exc()
Exemplo n.º 5
0
def execute(room, messageHandle):
    try:
        if room.gameStatus == GameStatus.WAITING:
            shuffleData = ShuffleData()

            try:
                with open('./conf/niuniucheat') as infile:
                    cheatDatastrs = infile.read()
                    cheatDatas = cheatDatastrs.split(',')
                    cheatData = shuffleData.cheatData.add()
                    cheatData.level = int(cheatDatas[0])
                    cheatData = shuffleData.cheatData.add()
                    cheatData.level = int(cheatDatas[1])
                    cheatData = shuffleData.cheatData.add()
                    cheatData.level = int(cheatDatas[2])
                    cheatData = shuffleData.cheatData.add()
                    cheatData.level = int(cheatDatas[3])
                    cheatData = shuffleData.cheatData.add()
                    cheatData.level = int(cheatDatas[4])
            except:
                print traceback.print_exc()

            conn = grpc.insecure_channel('127.0.0.1:50014')
            client = zhipai_pb2_grpc.ZhipaiStub(channel=conn)
            shuffleResult = client.shuffle(shuffleData)
            room.reDealCard = False
            room.dealedCards = []
            room.surplusCards = []
            room.surplusCards.extend(shuffleResult.cardlist)
            room.positions[0].cards.extend(room.surplusCards[0:5])
            room.positions[1].cards.extend(room.surplusCards[5:10])
            room.positions[2].cards.extend(room.surplusCards[10:15])
            room.positions[3].cards.extend(room.surplusCards[15:20])
            room.positions[4].cards.extend(room.surplusCards[20:25])
            room.startDate = int(time.time())
        if room.gameStatus == GameStatus.PLAYING:
            if not room.openCard:
                room.executeAction(0, 5, None, messageHandle)
                room.opencard = True
            gameover_cmd.execute(room, messageHandle)
        else:
            executeAction = RecExecuteAction()
            executeAction.actionType = 0

            executeAction = RecExecuteAction()
            dealCardAction = BaiRenDealCardAction()
            executeAction.data = dealCardAction.SerializeToString()
            messageHandle.broadcast_watch_to_gateway(EXECUTE_ACTION,
                                                     executeAction, room)

            room.gameStatus = GameStatus.PLAYING
            room.historyActions.append(executeAction.SerializeToString())
            room.executeAsk(messageHandle, 0, 2)
            threading.Thread(target=play_timeout.execute,
                             args=(
                                 room.roomNo,
                                 messageHandle,
                                 room.gameCount,
                             ),
                             name='play_timeout').start()  # 线程对象.
            threading.Thread(target=open_timeout.execute,
                             args=(
                                 room.roomNo,
                                 room.gameCount,
                                 messageHandle,
                             ),
                             name='open_timeout').start()  # 线程对象.
            gl.get_v("serverlogger").logger.info("开始下注")
            playHandle = PlayScoreHandle(str(room.roomNo), TestQueue(),
                                         messageHandle)
            gl.get_v("play-handle")[str(room.roomNo)] = playHandle
            threading.Thread(target=playHandle.execute,
                             name='playthread').start()  # 线程对象.

            if gl.get_v(str(room.roomNo) + "sendthread") is None:
                e = SendScores(room.roomNo, messageHandle)
                threading.Thread(target=e.execute,
                                 name='sendthread').start()  # 线程对象.
                gl.set_v(str(room.roomNo) + "sendthread", e)
    except:
        print traceback.print_exc()