Esempio n. 1
0
def pushMsg(objPlayerData, objBetHisData):

    dictOnlineInfo = yield from classOnlineMgr.getInstance().getOnlineClient(
        objPlayerData.strAccountId)
    if dictOnlineInfo is not None:
        # 没在线,不用推送了
        objPushSSHead = classSSHead()
        objPushSSHead.strAccountId = objPlayerData.strAccountId
        objPushSSHead.strMsgId = pushGuessBetChangeResult
        objPushSSHead.strClientUdid = dictOnlineInfo['connectUid']

        objRsp = protoPushBetResultData()
        objHisItem = protoGuessHistoryItem(objBetHisData)
        objRsp.listGuessBetList.append(objHisItem)

        yield from classPushMgr.getInstance().push(dictOnlineInfo['host'],
                                                   dictOnlineInfo['groupId'],
                                                   objPushSSHead, objRsp)

        # 推送一下金钱
        objPushSSHead.strMsgId = pushPlayerCoin
        objRsp = protoPushCoinData()
        objRsp.iCoin = "%.2f" % round(objPlayerData.iGuessCoin / 100, 2)

        yield from classPushMgr.getInstance().push(dictOnlineInfo['host'],
                                                   dictOnlineInfo['groupId'],
                                                   objPushSSHead, objRsp)
Esempio n. 2
0
def broadCastGuessData(guessDataList: list, pubInsName: str = None):

    objPushSSHead = classSSHead()
    objPushSSHead.iBroadCast = 1
    objPushSSHead.strMsgId = pushGuessList

    objResp = protoPushGuessData()
    for var_guess in guessDataList:
        objNewGuessResp = protoGuessItem(var_guess)
        objResp.listGuessList.append(objNewGuessResp)

    yield from classPubMgr.getInstance(pubInsName).publish(
        objPushSSHead, objResp)
Esempio n. 3
0
def broadCastMatchBasicData(matchDataList: list, pubInsName: str = None):

    objPushSSHead = classSSHead()
    objPushSSHead.iBroadCast = 1
    objPushSSHead.strMsgId = pushMatchBasicList

    objResp = protoPushMatchBasicData()
    for var_match in matchDataList:
        objNewMatchResp = protoMatchItem(var_match)
        objResp.listMatchBasicList.append(objNewMatchResp)

    yield from classPubMgr.getInstance(pubInsName).publish(
        objPushSSHead, objResp)
Esempio n. 4
0
def pushPlayerMsg(accountId, msgId, pubInsName=None):
    dictOnlineInfo = yield from classOnlineMgr.getInstance().getOnlineClient(
        accountId)
    if dictOnlineInfo is not None:
        # 没在线,不用推送了
        objPushSSHead = classSSHead()
        objPushSSHead.strAccountId = accountId
        objPushSSHead.strMsgId = pushMessage

        objResp = protoPushPlayerMsg()
        objResp.accountId = accountId
        objResp.msgId = msgId

        yield from classPubMgr.getInstance(pubInsName).publish(
            objPushSSHead, objResp)
Esempio n. 5
0
def pushPinboRepairData(iEndTime,
                        iRepairFlag,
                        iSurplusTime,
                        iStartTime,
                        pubInsName=None):
    #推送pinbo维护状态信息
    objPushSSHead = classSSHead()
    objPushSSHead.iBroadCast = 1  # 全体
    objPushSSHead.strMsgId = pushPinboRepair

    objResp = protoPushPinboRepireData()
    objResp.end_time = iEndTime
    objResp.repairFlag = iRepairFlag
    objResp.surplus_time = iSurplusTime
    objResp.start_time = iStartTime

    yield from classPubMgr.getInstance(pubInsName).publish(
        objPushSSHead, objResp)
Esempio n. 6
0
def coroPushPlayerCoin(accountId: str, iCoin):

    dictOnlineInfo = yield from classOnlineMgr.getInstance().getOnlineClient(
        accountId)
    if dictOnlineInfo is not None:
        # 没在线,不用推送了
        objPushSSHead = classSSHead()
        objPushSSHead.strAccountId = accountId
        objPushSSHead.strMsgId = pushPlayerCoin
        objPushSSHead.strClientUdid = dictOnlineInfo['connectUid']

        objResp = protoPushPlayerCoin()
        objResp.strAccountId = accountId
        objResp.iCoin = "%.2f" % round(iCoin / 100, 2)

        yield from classPushMgr.getInstance().push(dictOnlineInfo['host'],
                                                   dictOnlineInfo['groupId'],
                                                   objPushSSHead, objResp)

    return iCoin
Esempio n. 7
0
def broadCastMatchData(matchDataList: list,
                       guessDataDict: dict,
                       pubInsName: str = None):

    objPushSSHead = classSSHead()
    objPushSSHead.iBroadCast = 1
    objPushSSHead.strMsgId = pushMatchList

    objResp = protoPushMatchData()
    for var_match in matchDataList:
        objNewMatchResp = protoMatchItem(var_match)
        for var_round, var_guess_id_list in var_match.dictGuess.item():
            for var_guess_id in var_guess_id_list:
                objGuessData = guessDataDict.get(var_guess_id, None)
                if objGuessData is not None:

                    objNewMatchResp.buildRoundGuess(var_round, objGuessData)
        objResp.listMatchList.append(objNewMatchResp)

    yield from classPubMgr.getInstance(pubInsName).publish(
        objPushSSHead, objResp)
Esempio n. 8
0
def handlerWebSocket(websocket, path):
    global g_dic_onlineFD

    #strThisAccountId = ""
    strThisUdid = str(uuid.uuid4())

    g_dic_onlineFD[strThisUdid] = websocket

    while True:
        try:
            bytesBuff = yield from websocket.recv()

            try:
                if bytesBuff is not None:
                    #TODO safe check
                    if len(bytesBuff) <= 0:
                        return

                    msgDict = clientSerialiser.loads(procVariable.debug,bytesBuff)

                    objSSHeader =  dataHeaderDefine.classSSHead()

                    objSSHeader.strMsgId = msgDict['head']['msgId']
                    objSSHeader.strAccountId = msgDict['head']['accountId']
                    objSSHeader.strClientUdid = strThisUdid
                    objSSHeader.strClientIp = websocket.remote_address[0]
                    objSSHeader.iClientPort = websocket.remote_address[1]
                    objSSHeader.strToken = msgDict['head']['token']

                    if objSSHeader.strMsgId == protocol.connect:
                        if len(objSSHeader.strAccountId) > 0:

                            #设置在线信息,如果是新连接,回发消息过来
                            yield from onlineMgr.classOnlineMgr.getInstance().setOnlineClient(objSSHeader.strAccountId,
                                                                                       procVariable.group_id,
                                                                                       procVariable.host,
                                                                                       strThisUdid)

                            dictSend = {"head": msgDict['head'], "body": {"ret":0,"reDes":""}}
                            # print(body_dict)
                            bytesSend = clientSerialiser.dumps(procVariable.debug, dictSend)
                            yield from websocket.send(bytesSend)

                        continue



                    logging.debug("recive msg [{}] ip[{}]".format(objSSHeader.strMsgId,objSSHeader.strClientIp))

                    #strThisAccountId = objSSHeader.strAccountId
                    bytesSSHead = pickle.dumps(objSSHeader)
                    bytesBody = pickle.dumps(msgDict['body'])

                    yield from fifoMgr.classFIFOMgr.getInstance().publish(bytesSSHead,bytesBody)

                else:
                    #TODO logging.error()
                    pass
            except Exception as inner:
                logging.error(repr(inner))

        except exceptionLogic as e:
            logging.error(repr(e))


        except ConnectionClosed as e:

            if strThisUdid != "":
                if strThisUdid in g_dic_onlineFD:
                    g_dic_onlineFD.pop(strThisUdid)

            logging.exception(e)
            #yield from websocket.close()
            #asyncio.Task.current_task().cancel()
            return
        except:
            return