void CGroupChat::HandleGroupMessageBroadcast(CImPdu *pPdu) { IM::Message::IMMsgData msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t from_user_id = msg.from_user_id(); uint32_t to_group_id = msg.to_session_id(); string msg_data = msg.msg_data(); uint32_t msg_id = msg.msg_id(); log("HandleGroupMessageBroadcast, %u->%u, msg id=%u. ", from_user_id, to_group_id, msg_id); // 服务器没有群的信息,向DB服务器请求群信息,并带上消息作为附件,返回时在发送该消息给其他群成员 //IM::BaseDefine::GroupVersionInfo group_version_info; CPduAttachData pduAttachData(ATTACH_TYPE_HANDLE_AND_PDU, 0, pPdu->GetBodyLength(), pPdu->GetBodyData()); IM::Group::IMGroupInfoListReq msg2; msg2.set_user_id(from_user_id); IM::BaseDefine::GroupVersionInfo* group_version_info = msg2.add_group_version_list(); group_version_info->set_group_id(to_group_id); group_version_info->set_version(0); msg2.set_attach_data(pduAttachData.GetBuffer(), pduAttachData.GetLength()); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_INFO_REQUEST); CDBServConn* pDbConn = get_db_serv_conn(); if(pDbConn) { pDbConn->SendPdu(&pdu); } }
void CRouteServConn::_HandleMsgData(CImPdu* pPdu) { IM::Message::IMMsgData msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); if (CHECK_MSG_TYPE_GROUP(msg.msg_type())) { s_group_chat->HandleGroupMessageBroadcast(pPdu); return; } uint32_t from_user_id = msg.from_user_id(); uint32_t to_user_id = msg.to_session_id(); uint32_t msg_id = msg.msg_id(); log("HandleMsgData, %u->%u, msg_id=%u. ", from_user_id, to_user_id, msg_id); CImUser* pFromImUser = CImUserManager::GetInstance()->GetImUserById(from_user_id); if (pFromImUser) { pFromImUser->BroadcastClientMsgData(pPdu, msg_id, NULL, from_user_id); } CImUser* pToImUser = CImUserManager::GetInstance()->GetImUserById(to_user_id); if (pToImUser) { pToImUser->BroadcastClientMsgData(pPdu, msg_id, NULL, from_user_id); } }
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); } } }
void CDBServConn::_HandleMsgData(CImPdu *pPdu) { IM::Message::IMMsgData msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); if (CHECK_MSG_TYPE_GROUP(msg.msg_type())) { s_group_chat->HandleGroupMessage(pPdu); return; } uint32_t from_user_id = msg.from_user_id(); uint32_t to_user_id = msg.to_session_id(); uint32_t msg_id = msg.msg_id(); if (msg_id == 0) { log("HandleMsgData, write db failed, %u->%u.", from_user_id, to_user_id); return; } uint8_t msg_type = msg.msg_type(); CDbAttachData attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length()); uint32_t handle = attach_data.GetHandle(); log("HandleMsgData, from_user_id=%u, to_user_id=%u, msg_id=%u.", from_user_id, to_user_id, msg_id); CMsgConn* pMsgConn = CImUserManager::GetInstance()->GetMsgConnByHandle(from_user_id, attach_data.GetHandle()); if (pMsgConn) { IM::Message::IMMsgDataAck msg2; msg2.set_user_id(from_user_id); msg2.set_msg_id(msg_id); msg2.set_session_id(to_user_id); msg2.set_session_type(::IM::BaseDefine::SESSION_TYPE_SINGLE); pMsgConn->SendPdu(SID_MSG, CID_MSG_DATA_ACK, msg2); } CRouteServConn* pRouteConn = get_route_serv_conn(); if (pRouteConn) { pRouteConn->SendPdu(pPdu); } msg.clear_attach_data(); pPdu->SetPBMsg(&msg); CImUser* pFromImUser = CImUserManager::GetInstance()->GetImUserById(from_user_id); CImUser* pToImUser = CImUserManager::GetInstance()->GetImUserById(to_user_id); pPdu->SetSeqNum(0); if (pFromImUser) { pFromImUser->BroadcastClientMsgData(pPdu, msg_id, pMsgConn, from_user_id); } if (pToImUser) { pToImUser->BroadcastClientMsgData(pPdu, msg_id, NULL, from_user_id); } IM::Server::IMGetDeviceTokenReq msg3; msg3.add_user_id(to_user_id); msg3.set_attach_data(pPdu->GetBodyData(), pPdu->GetBodyLength()); SendPdu(SID_OTHER, CID_OTHER_GET_DEVICE_TOKEN_REQ, msg3); }
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"); } }
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"); } }
void CGroupChat::HandleGroupMessage(CImPdu* pPdu) { IM::Message::IMMsgData msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t from_user_id = msg.from_user_id(); uint32_t to_group_id = msg.to_session_id(); string msg_data = msg.msg_data(); uint32_t msg_id = msg.msg_id(); if (msg_id == 0) { log("HandleGroupMsg, write db failed, %u->%u. ", from_user_id, to_group_id); return; } uint8_t msg_type = msg.msg_type(); CDbAttachData attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length()); log("HandleGroupMsg, %u->%u, msg id=%u. ", from_user_id, to_group_id, msg_id); CMsgConn* pFromConn = CImUserManager::GetInstance()->GetMsgConnByHandle(from_user_id, attach_data.GetHandle()); if (pFromConn) { //接收反馈 IM::Message::IMMsgDataAck msg2; msg2.set_user_id(from_user_id); msg2.set_session_id(to_group_id); msg2.set_msg_id(msg_id); msg2.set_session_type(::IM::BaseDefine::SESSION_TYPE_GROUP); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_MSG); pdu.SetCommandId(CID_MSG_DATA_ACK); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } CRouteServConn* pRouteConn = get_route_serv_conn(); if (pRouteConn) { pRouteConn->SendPdu(pPdu); } // 服务器没有群的信息,向DB服务器请求群信息,并带上消息作为附件,返回时在发送该消息给其他群成员 //IM::BaseDefine::GroupVersionInfo group_version_info; CPduAttachData pduAttachData(ATTACH_TYPE_HANDLE_AND_PDU, attach_data.GetHandle(), pPdu->GetBodyLength(), pPdu->GetBodyData()); IM::Group::IMGroupInfoListReq msg3; msg3.set_user_id(from_user_id); IM::BaseDefine::GroupVersionInfo* group_version_info = msg3.add_group_version_list(); group_version_info->set_group_id(to_group_id); group_version_info->set_version(0); msg3.set_attach_data(pduAttachData.GetBuffer(), pduAttachData.GetLength()); CImPdu pdu; pdu.SetPBMsg(&msg3); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_INFO_REQUEST); CDBServConn* pDbConn = get_db_serv_conn(); if(pDbConn) { pDbConn->SendPdu(&pdu); } }