void CImUser::BroadcastClientMsgData(CImPdu* pPdu, uint32_t msg_id, string msg_data, CMsgConn* pFromConn, uint32_t from_id) { IM::Message::IMMsgData msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); for (map<uint32_t, CMsgConn*>::iterator it = m_conn_map.begin(); it != m_conn_map.end(); it++) { CMsgConn* pConn = it->second; if (pConn != NULL && pConn != pFromConn) { if (pConn->GetCryptoFlag() == 1) { string tmp_msg_data = msg_data; if (pConn->EncryptMsgData(tmp_msg_data) == 0) { //log("BroadcastClientMsgData, from %u to %u data: %s", from_id, pConn->GetUserId(), tmp_msg_data.c_str()); //debug crypto msg.set_crypto_flag(1); msg.set_msg_data(tmp_msg_data); pPdu->SetPBMsg(&msg); } } pConn->SendPdu(pPdu); pConn->AddToSendList(msg_id, from_id); } } }
uint32_t ClientConn::sendMessage(uint32_t nFromId, uint32_t nToId, IM::BaseDefine::MsgType nType, const string& strMsgData) { CImPdu cPdu; IM::Message::IMMsgData msg; msg.set_from_user_id(nFromId); msg.set_to_session_id(nToId); msg.set_msg_id(0); msg.set_create_time(time(NULL)); msg.set_msg_type(nType); //msg.set_msg_data(strMsgData); //EncryptMsg char * pOutData=NULL; uint32_t nOutLen = 0; int retCode = EncryptMsg( strMsgData.c_str(), strMsgData.length(), &pOutData, nOutLen); if (retCode == 0 && nOutLen > 0 && pOutData != 0) { msg.set_msg_data( pOutData, nOutLen); //delete pOutData; Free(pOutData); pOutData = NULL; } else { log("EncryptMsg error:%s\n", strMsgData.c_str()); msg.set_msg_data( strMsgData); } cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::DFFX_SID_MSG); cPdu.SetCommandId(IM::BaseDefine::DFFX_CID_MSG_DATA); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
CImPdu sendMessage(uint32_t nFromId, uint32_t nToId, const string& strMsgData) { CImPdu cPdu; IM::Message::IMMsgData msg; msg.set_from_user_id(nFromId); msg.set_to_session_id(nToId); msg.set_msg_id(0); msg.set_create_time(time(NULL)); msg.set_msg_type(IM::BaseDefine::MSG_TYPE_SINGLE_TEXT); msg.set_msg_data(strMsgData); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_MSG); cPdu.SetCommandId(IM::BaseDefine::CID_MSG_DATA); cPdu.SetSeqNum(2); return cPdu; }
uint32_t ClientConn::sendMessage(uint32_t nFromId, uint32_t nToId, IM::BaseDefine::MsgType nType, const string& strMsgData) { CImPdu cPdu; IM::Message::IMMsgData msg; msg.set_from_user_id(nFromId); msg.set_to_session_id(nToId); msg.set_msg_id(0); msg.set_create_time(time(NULL)); msg.set_msg_type(nType); msg.set_msg_data(strMsgData); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_MSG); cPdu.SetCommandId(IM::BaseDefine::CID_MSG_DATA); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }