示例#1
0
void ClientConn::_HandleMsgData(CImPdu* pPdu)
{
    IM::Message::IMMsgData msg;
    uint32_t nSeqNo = pPdu->GetSeqNum();
    if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()))
    {
        play("message.wav");
        
        uint32_t nFromId = msg.from_user_id();
        uint32_t nToId = msg.to_session_id();
        uint32_t nMsgId = msg.msg_id();
        IM::BaseDefine::MsgType nMsgType = msg.msg_type();
        uint32_t nCreateTime = msg.create_time();
        string strMsg(msg.msg_data().c_str(), msg.msg_data().length());
        
        IM::BaseDefine::SessionType nSessionType;
        if(nMsgType == IM::BaseDefine::MSG_TYPE_SINGLE_TEXT)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_SINGLE;
        }
        else if(nMsgType == IM::BaseDefine::MSG_TYPE_SINGLE_AUDIO)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_SINGLE;
        }
        else if(nMsgType == IM::BaseDefine::MSG_TYPE_GROUP_TEXT)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_GROUP;
        }
        else if(nMsgType == IM::BaseDefine::MSG_TYPE_GROUP_AUDIO)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_GROUP;
        }
		
		if(nSessionType == IM::BaseDefine::SESSION_TYPE_SINGLE)
			sendMsgAck(nToId , nFromId , nSessionType, nMsgId);
        m_pCallback->onRecvMsg(nSeqNo, nFromId, nToId, nMsgId, nCreateTime, nMsgType, strMsg);
		sendMsgReadAck( nToId , nFromId , nSessionType, nMsgId);
    }
    else
    {
        m_pCallback->onError(nSeqNo, pPdu->GetCommandId(), "parse pb falied");
    }
}
示例#2
0
void ClientConn::_HandleMsgData(CImPdu* pPdu)
{
    IM::Message::IMMsgData msg;
    uint32_t nSeqNo = pPdu->GetSeqNum();
    if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()))
    {
        
        uint32_t nFromId = msg.from_user_id();
        uint32_t nToId = msg.to_session_id();
        uint32_t nMsgId = msg.msg_id();
        IM::BaseDefine::MsgType nMsgType = msg.msg_type();
        uint32_t nCreateTime = msg.create_time();
		
        //string strMsg(msg.msg_data().c_str(), msg.msg_data().length());
        string strMsg = "";
		//DecryptMsg
		char * pOutData=NULL;
		uint32_t nOutLen = 0;
		int retCode = DecryptMsg( msg.msg_data().c_str(), msg.msg_data().length(), &pOutData, nOutLen);
		if (retCode == 0 && nOutLen > 0 && pOutData != 0)
		{
			strMsg = std::string(pOutData, nOutLen);
			//delete pOutData;
			Free( pOutData);
			pOutData = NULL;			
		}
		else 
		{
			strMsg = std::string( msg.msg_data().c_str(), msg.msg_data().length());
			log("DecryptMsg error:%s\n", strMsg.c_str());			
		}
			
		//MSG_TYPE_ORDER_PUSH MSG_TYPE_ORDER_GRAB MSG_TYPE_ORDER_RESULT
        
        IM::BaseDefine::SessionType nSessionType;
        if(nMsgType == IM::BaseDefine::MSG_TYPE_SINGLE_TEXT 
			|| nMsgType == IM::BaseDefine::MSG_TYPE_SINGLE_AUDIO
			|| nMsgType == IM::BaseDefine::MSG_TYPE_ORDER_PUSH
			|| nMsgType == IM::BaseDefine::MSG_TYPE_ORDER_GRAB
			|| nMsgType == IM::BaseDefine::MSG_TYPE_ORDER_RESULT
			|| nMsgType == IM::BaseDefine::MSG_TYPE_LOCATION_SHARING
			|| nMsgType == IM::BaseDefine::MSG_TYPE_FILE_TRANSFER
			|| nMsgType== IM::BaseDefine::MSG_TYPE_ORDER_ENTRUST
			|| nMsgType== IM::BaseDefine::MSG_TYPE_ORDER_ACCEPT
			|| nMsgType== IM::BaseDefine::MSG_TYPE_ORDER_CANCEL
			|| nMsgType == IM::BaseDefine::MSG_TYPE_USER_CHECK 
			|| nMsgType == IM::BaseDefine::MSG_TYPE_ORDER_WAITPAYMENT
			|| nMsgType == IM::BaseDefine::MSG_TYPE_ORDER_ALLCANCEL
			|| nMsgType== IM::BaseDefine::MSG_TYPE_TOPUP_WITHDRAWAL)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_SINGLE;
        }
        else if(nMsgType == IM::BaseDefine::MSG_TYPE_GROUP_TEXT
			|| nMsgType == IM::BaseDefine::MSG_TYPE_GROUP_AUDIO)
        {
            nSessionType = IM::BaseDefine::SESSION_TYPE_GROUP;
        }
		
        sendMsgAck(nFromId, nToId, nSessionType, nMsgId);
        m_pCallback->onRecvMsg(nSeqNo, nFromId, nToId, nMsgId, nCreateTime, nMsgType, strMsg);
    }
    else
    {
        m_pCallback->onError(nSeqNo, pPdu->GetCommandId(), "parse pb falied");
    }
}