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 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); } }