Пример #1
0
    def ShowResultAll(self, nWinnerPos):
        import proto.show_result_pb2 as show_result_pb2
        rsp = show_result_pb2.show_result_all_rsp()
        rsp.room_id = self.m_roomObj.GetRoomID()
        rsp.cur_round = self.m_nCurJu
        rsp.total_round = self.GetMaxJuNum()

        nRoomMaster = self.m_roomObj.GetRoomMaster()
        rsp.room_master_pos = self.m_roomObj.GetMemberPos(nRoomMaster)
        rsp.winner_pos = nWinnerPos

        import entity.entity_mgr as entity_mgr
        for nMember in self.m_roomObj.GetMemberList():
            allData = rsp.list_data.add()

            Player = entity_mgr.GetEntity(nMember)
            assert Player is not None
            allData.player_id = nMember
            allData.pos = self.m_roomObj.GetMemberPos(nMember)
            allData.wecaht_info = Player.GetWeChatInfo().encode("utf-8")

            dictData = self.m_dictTotalCount[allData.pos]
            allData.hu_num = dictData.get("hu_num", 0)
            allData.dan_you_num = dictData.get("dan_you_num", 0)
            allData.shuang_you_num = dictData.get("shuang_you_num", 0)
            allData.sam_you_num = dictData.get("sam_you_num", 0)
            allData.kai_gang_num = dictData.get("kai_gang_num", 0)
            allData.total_score = dictData.get("total_score", 0)

        for nMember in self.m_roomObj.GetMemberList():
            ffext.send_msg_session(nMember, rpc_def.Gas2GacRetShowResultAll,
                                   rsp.SerializeToString())
Пример #2
0
    def SynCardInfoByType2All(self, nPos, nType):
        rsp = common_info_pb2.syn_card_list_by_type()
        rsp.pos = nPos
        rsp.type = nType
        tmp = rsp.card_list.add()

        print("SynCardInfoByType2All ", self.m_roomObj.GetMemberIDByPos(nPos),
              nType)

        nSynCardHave = True if nType == common_info_pb2.card_list_type.Value(
            "eTypeHave") else False
        self.GetMemberAllCardInfo(nPos, tmp, nSynCardHave)

        # if nType == common_info_pb2.card_list_type.Value("eTypeHave"):
        #     rsp.card_list.append(self.SerialList2Str(self.m_dictPosCarList[nPos]))
        # elif nType == common_info_pb2.card_list_type.Value("eTypeShow"):
        #     rsp.card_list.append(self.SerialTouchEventData(nPos))
        # elif nType == common_info_pb2.card_list_type.Value("eTypeHist"):
        #     listTmp = []
        #     for tInfo in self.m_dictPosHistory[nPos]:
        #         _, nCard = tInfo
        #         listTmp.append(nCard)
        #     rsp.card_list.append(self.SerialList2Str(listTmp))
        # else:
        #     assert False

        szRspSerial = rsp.SerializeToString()
        for nMember in self.m_roomObj.GetMemberList():
            ffext.send_msg_session(nMember,
                                   rpc_def.Gas2GacRetSynCardListByType,
                                   szRspSerial)
Пример #3
0
def process_test(session_id, msg):
    ffext.send_msg_session(session_id, 1, '<font color="#ff0000">测试单播接口 cmd=2!'\
                                 '</font>')
    player = ffext.singleton(player_mgr_t).get(session_id)
    player.inc_chat_times()
    if player.get_chat_times() > 30:
        ffext.close_session(session_id)
Пример #4
0
def Gac2GasEnterRoom(nPlayerGID, reqObj):
    nRoomID = reqObj.room_id
    bRet = _roomMgr.EnterRoom(nPlayerGID, nRoomID)
    nMsgID = 0 if bRet is True else 10004

    rsp = enter_room_pb2.enter_room_rsp()
    rsp.ret = nMsgID
    ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRetEnterRoom,
                           rsp.SerializeToString())
Пример #5
0
def my_session_enter(session_id, from_scene, extra_data):
    #单播接口
    ffext.send_msg_session(session_id, 1, '<font color="#ff0000">测试单播接口!欢迎你!'\
                                 '</font>')
    content = '<font color="#ff0000">[%s %s] online </font>' % (session_id,
                                                                GetNowTime())
    ffext.broadcast_msg_session(1, content)
    player = player_t(session_id)
    ffext.singleton(player_mgr_t).add(session_id, player)
    ffext.broadcast_msg_session(1, '<font color="#ff0000">当前在线:</font>')
    ffext.broadcast_msg_session(1, ffext.singleton(player_mgr_t).idlist())
Пример #6
0
    def SynOrder(self):
        import proto.opt_pb2 as opt_pb2
        rsp = opt_pb2.syn_game_order()
        rsp.room_id = self.m_roomObj.GetRoomID()
        rsp.cur_game_num = self.GetMaxJuNum()
        rsp.cur_round = self.m_nCurJu
        rsp.cur_turn = self.m_nCurTurn
        rsp.remain_card_num = len(
            self.m_listGlobalCard) - self.m_nNextCardIndex
        rsp.opt_pos = self.m_nCurOptMemberPos

        listMember = self.m_roomObj.GetMemberList()
        for nMember in listMember:
            ffext.send_msg_session(nMember, rpc_def.Gac2GasSynGameOrder,
                                   rsp.SerializeToString())
Пример #7
0
def Gcc2GasRetGetRoomScene(dictData):
    szRoomGasID = dictData["gas_id"]
    nPlayerGID = dictData["player_id"]
    nRoomID = dictData["room_id"]
    if nRoomID == 0:
        return
    Player = entity_mgr.GetEntity(nPlayerGID)
    if Player is None:
        return

    rsp = query_room_scene_pb2.query_room_scene_rsp()
    rsp.ret = 0
    rsp.room_id = nRoomID
    rsp.scene_name = szRoomGasID.encode('utf-8')
    ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacretQueryRoomScene,
                           rsp.SerializeToString())
Пример #8
0
    def SerialEventList2Client(self):
        print("SerialEventList2Client")
        import proto.common_info_pb2 as common_info_pb2
        for nPos, listEvent in self.m_dictEventNoticePool.iteritems():
            if 0 == len(listEvent):
                continue
            nMember = self.m_roomObj.GetMemberIDByPos(nPos)
            rsp = common_info_pb2.on_touch_event()
            for eventObj in listEvent:
                evCli = rsp.event_list.add()
                eventObj.Serial2Client(evCli)
                print("syn ev ", self.m_roomObj.GetMemberIDByPos(nPos),
                      eventObj.GetStr())
            ffext.send_msg_session(nMember, rpc_def.Gas2GacOnTouchGameEvent,
                                   rsp.SerializeToString())

        self.ResetEventNoticePool()
Пример #9
0
    def _cb(err, data):
        rsp = gm_config_pb2.opt_config_rsp()
        rsp.opt_type = data["opt_type"]
        if data["conf_name"] is None:
            rsp.cur_use_conf = ""
        else:
            rsp.cur_use_conf = data["conf_name"].encode("utf-8")

            data = data["dict_data"]
            rsp.ret_data.config_name = data["config_name"].encode("utf-8")
            rsp.ret_data.pos_1_card = data["pos_1_card"].encode("utf-8")
            rsp.ret_data.pos_2_card = data["pos_2_card"].encode("utf-8")
            rsp.ret_data.pos_3_card = data["pos_3_card"].encode("utf-8")
            rsp.ret_data.pos_4_card = data["pos_4_card"].encode("utf-8")
            rsp.ret_data.card_order = data["card_order"].encode("utf-8")

        ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRetModifyConfig, rsp.SerializeToString())
Пример #10
0
    def ShowResultOne(self, nWinnerPos):
        import proto.show_result_pb2 as show_result_pb2
        rsp = show_result_pb2.show_result_one_rsp()
        rsp.room_id = self.m_roomObj.GetRoomID()
        rsp.cur_round = self.m_nCurJu
        rsp.total_round = self.GetMaxJuNum()
        rsp.master_pos = self.m_roomObj.GetMemberPos(self.m_nZhuang)
        rsp.winner_pos = nWinnerPos
        rsp.golden_card_list = self.SerialList2Str(self.m_listJinPai)
        rsp.hu_type = EMjEvent.ev_liu_ju if nWinnerPos == 0 else check_hu.GetHuType(
            self.m_dictPosCarList[nWinnerPos], self.m_listJinPai)

        import check_hu as check_hu_mgr
        import entity.entity_mgr as entity_mgr
        for nMember in self.m_roomObj.GetMemberList():
            dataInfo = rsp.list_data.add()

            nPos = self.m_roomObj.GetMemberPos(nMember)
            Player = entity_mgr.GetEntity(nMember)
            dataInfo.wecaht_info = Player.GetWeChatInfo().encode('utf-8')
            dataInfo.player_id = nMember
            dataInfo.pos = nPos

            tmpCardList = self.m_dictPosCarList[nPos]
            tmpCardList.extend(self.m_dictPosCarListEx[nPos])
            dataInfo.card_list = self.SerialList2Str(tmpCardList)

            listHuaPai = []
            for tupleInfo in self.m_dictPosHistory[nPos]:
                _, nCard = tupleInfo
                if check_hu_mgr.IsHuaPai(nCard) is False:
                    continue
                listHuaPai.append(nCard)
            dataInfo.hua_list = self.SerialList2Str(listHuaPai)

            self.GetMemberAllCardInfo(nPos,
                                      dataInfo.card_info,
                                      bSynHaveCard=True)
            dataInfo.event_list = self.GetEventStr()
            dataInfo.total_score = self.GetScore(nPos)

        for nMember in self.m_roomObj.GetMemberList():
            ffext.send_msg_session(nMember, rpc_def.Gas2GacRetShowResultOne,
                                   rsp.SerializeToString())
Пример #11
0
    def _cb(err, dictData):
        rsp = gm_config_pb2.syn_all_gm_config_rsp()
        rsp.ret = 0
        if dictData["g_szCurConfigName"] is None:
            rsp.cur_use_conf = ""
        else:
            rsp.cur_use_conf = dictData["g_szCurConfigName"].encode("utf-8")
        dictData.pop("g_szCurConfigName")
        for szName, dictTmp in dictData.iteritems():
            confObj = rsp.config_arr.add()
            confObj.config_name = szName.encode("utf-8")
            confObj.pos_1_card = SerialList2String(dictTmp["pos_1_card"])
            confObj.pos_2_card = SerialList2String(dictTmp["pos_2_card"])
            confObj.pos_3_card = SerialList2String(dictTmp["pos_3_card"])
            confObj.pos_4_card = SerialList2String(dictTmp["pos_4_card"])
            confObj.card_order = SerialList2String(dictTmp["card_order"])

        print("rsp.SerializeToString() ", rsp.SerializeToString())
        ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacSynAllConfig, rsp.SerializeToString())
Пример #12
0
    def NoticeMemberEvent(self, ev, nModMember):
        # notice other members
        import proto.common_info_pb2 as common_info_pb2
        rsp = common_info_pb2.on_touch_event_member()
        rsp.ev_type = ev

        inf = rsp.list_member.add()
        inf.pos = self.GetMemberPos(nModMember)
        inf.state = self.GetMemberState(nModMember)
        inf.total_score = self.m_gameRuleObj.GetScore(inf.pos)
        Player = entity_mgr.GetEntity(nModMember)
        Player.Serial2Client(inf)

        for nMemberOther, dictData in self.m_dictMember.iteritems():
            if nMemberOther == nModMember:
                continue
            if self.IsMemberLoaded(nMemberOther) is False:
                continue
            print("ffext.send_msg_session ", nMemberOther)
            ffext.send_msg_session(nMemberOther, rpc_def.Gas2GacOnTouchMemberEvent, rsp.SerializeToString())
Пример #13
0
    def OnGetRoomIDRet(self, nRoomID, nPlayerGID, dictCfg):
        print("start room with config ", dictCfg)
        ffext.LOGINFO(
            "FFSCENE_PYTHON",
            " GasRoomMgr.OnGetRoomIDRet {0}, {1}".format(nRoomID, nPlayerGID))
        roomObj = gas_room_obj.RoomObj(nRoomID, nPlayerGID, self, dictCfg)
        self.m_dictRoomID2Room[nRoomID] = roomObj

        rsp = create_room_pb2.create_room_rsp()
        rsp.ret = 0
        rsp.game_type = 1
        rsp.room_id = nRoomID
        rsp.pos = roomObj.GetMemberPos(nPlayerGID)
        rsp.cfg.member_num = dictCfg["member_num"]
        rsp.cfg.multi = dictCfg["multi"]
        rsp.cfg.total_start_game_num = dictCfg["total_start_game_num"]
        rsp.cfg.avg = dictCfg["avg"]
        rsp.cfg.opt = dictCfg["opt"]
        ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRetCreateRoom,
                               rsp.SerializeToString())
Пример #14
0
    def SynGameInfo(self, nPlayerGID, bSynAll=False):
        import proto.common_info_pb2 as common_info_pb2
        rsp = common_info_pb2.syn_game_info()
        rsp.room_id = self.GetRoomID()
        rsp.cur_game_num = 0 #
        rsp.cur_round = self.m_gameRuleObj.GetCurJu()
        rsp.cur_turn = self.m_gameRuleObj.GetCurTurn()
        rsp.remain_card_num = self.m_gameRuleObj.GetCardRemain()
        rsp.room_state = EStatusInRoom.eWaiting if self.m_sm.IsInState(room_state_running.RoomStateRunning) is False else EStatusInRoom.eRunning
        self.GetGameCfg(rsp.cfg)

        nZhuang = self.m_gameRuleObj.GetZhuang()
        rsp.zhuang_pos = nZhuang if nZhuang == 0 else self.GetMemberPos(nZhuang)
        rsp.room_master_pos = self.GetMemberPos(self.m_nMaster)

        listJinPai = self.m_gameRuleObj.GetJinPaiList()
        for nJin in listJinPai:
            rsp.list_gold_card.append(nJin)

        rsp.pos_owner = self.GetMemberPos(nPlayerGID)
        rsp.opt_pos = self.m_gameRuleObj.GetCurOptMemberPos()

        for nMember, listVal in self.m_dictMember.iteritems():
            nPos = listVal[RoomMemberProperty.ePos]
            tmp = rsp.card_info.add()
            self.m_gameRuleObj.GetMemberAllCardInfo(nPos, tmp, True if nPlayerGID == nMember else False)

        if bSynAll is True:
            for nMember in self.m_dictMember.iterkeys():
                tmp = rsp.list_members.add()
                tmp.pos = self.GetMemberPos(nMember)
                tmp.state = self.GetMemberState(nMember)
                tmp.total_score = self.m_gameRuleObj.GetScore(tmp.pos)
                Player = entity_mgr.GetEntity(nMember)
                assert Player is not None
                Player.Serial2Client(tmp)

        if self.IsMemberLoaded(nPlayerGID) is True:
            ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRspSynGameData, rsp.SerializeToString())
Пример #15
0
def Gac2GasGameReady(nPlayerGID, reqObj):
    _roomMgr.MemberReady(nPlayerGID)
    rsp = opt_pb2.game_ready_rsp()
    rsp.ret = 0
    ffext.send_msg_session(nPlayerGID, rpc_def.Gac2GasRetGameReady,
                           rsp.SerializeToString())
Пример #16
0
def Gac2GasGameReady(nPlayerGID, reqObj):
    _roomMgr.OnMemberExit(nPlayerGID)
    rsp = exit_room_pb2.exit_room_rsp()
    rsp.ret = 0
    ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRetExitRoom,
                           rsp.SerializeToString())
Пример #17
0
    def GacOpt(self, nPlayerGID, reqObj):
        nPos = self.m_roomObj.GetMemberPos(nPlayerGID)
        nOptType = reqObj.opt_type
        print("GacOpt ", nOptType, reqObj.opt_data_str,
              self.GetCurOptMemberPos(), nPos)
        if nOptType == EMjEvent.ev_peng:
            if self.GetCurEventOptMember() != nPlayerGID:
                return
            nTargetMember, nCardID = map(int, reqObj.opt_data_str.split(","))
            self.RequestPeng([nPlayerGID, nTargetMember, nCardID])

        elif nOptType in (EMjEvent.ev_gang_all, EMjEvent.ev_gang_other,
                          EMjEvent.ev_gang_with_peng):
            if self.GetCurEventOptMember() != nPlayerGID:
                return
            nTargetMember, nCardID = map(int, reqObj.opt_data_str.split(","))
            self.RequestGang([nPlayerGID, nTargetMember, nCardID])

        elif nOptType == EMjEvent.ev_pass:
            if self.GetCurEventOptMember() != nPlayerGID:
                return
            self.StopEventTick()
            self.NextTurn()

        elif nOptType == EMjEvent.ev_hu_normal:
            if self.GetCurOptMemberPos() != nPos:
                return
            self.RequestHu(nPlayerGID)

        elif nOptType in (EMjEvent.ev_be_qi_pai, EMjEvent.ev_qi_pai):
            if self.GetCurOptMemberPos() != nPos:
                return
            nCardID, nCardPos = map(int, reqObj.opt_data_str.split(","))
            self.OptQiPai(nPos, nCardID, nCardPos)

        elif nOptType == EMjEvent.ev_dan_you:
            if self.GetCurOptMemberPos() != nPos:
                return
            self.RequestDanYou(nPlayerGID)

        else:
            return

        import proto.opt_pb2 as opt_pb2
        rsp = opt_pb2.opt_rsp()
        rsp.ret = 0
        rsp.opt_type = nOptType

        if nOptType not in (EMjEvent.ev_pass, EMjEvent.ev_hu_normal):
            listCard = self.m_dictPosCarList[nPos]
            print("ret listCard ", len(listCard), listCard)
            for nCard in listCard:
                rsp.owner_card_list.append(nCard)

        if nOptType in (EMjEvent.ev_be_qi_pai, EMjEvent.ev_qi_pai):
            listListenCard = check_hu.getTingArr(self.m_dictPosCarList[nPos],
                                                 self.GetJinPaiList())
            print("listListenCard ", listListenCard)
            for nCard in listListenCard:
                rsp.listen_card.append(nCard)

        ffext.send_msg_session(nPlayerGID, rpc_def.Gas2GacRspOpt,
                               rsp.SerializeToString())
        self.SerialEventList2Client()
Пример #18
0
 def send_error(self, error_code_, error_msg_=''):
     msg = msg_def.error_code_ret_t()
     msg.error_code = error_code_
     msg.error_msg = error_msg_
     return ffext.send_msg_session(self.get_socket_id(),
                                   msg_def.server_cmd_e.ERROR_CODE_RET, msg)
Пример #19
0
 def send(self, cmd_, msg_):
     return ffext.send_msg_session(self.get_socket_id(), cmd_, msg_)
Пример #20
0
 def send_error(self, error_code_, error_msg_ = ''):
     msg = msg_def.error_code_ret_t()
     msg.error_code = error_code_
     msg.error_msg = error_msg_
     return ffext.send_msg_session(self.get_socket_id(), msg_def.server_cmd_e.ERROR_CODE_RET, msg)
Пример #21
0
 def send(self, cmd_, msg_):
     return ffext.send_msg_session(self.get_socket_id(),cmd_, msg_)