/** * 获取正式群列表 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void getNormalGroupList(CImPdu* pPdu, uint32_t conn_uuid) { IM::Group::IMNormalGroupListReq msg; IM::Group::IMNormalGroupListRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t nUserId = msg.user_id(); list<IM::BaseDefine::GroupVersionInfo> lsGroup; CGroupModel::getInstance()->getUserGroup(nUserId, lsGroup, IM::BaseDefine::GROUP_TYPE_NORMAL); msgResp.set_user_id(nUserId); for(auto it=lsGroup.begin(); it!=lsGroup.end(); ++it) { IM::BaseDefine::GroupVersionInfo* pGroupVersion = msgResp.add_group_version_list(); pGroupVersion->set_group_id(it->group_id()); pGroupVersion->set_version(it->version()); } log("getNormalGroupList. userId=%u, count=%d", nUserId, msgResp.group_version_list_size()); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_GROUP); pPduRes->SetCommandId(IM::BaseDefine::CID_GROUP_NORMAL_LIST_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("parse pb failed"); } }
void CLoginConn::OnTimer(uint64_t curr_tick) { log("enter[%s]", __FUNCTION__); if (m_conn_type == LOGIN_CONN_TYPE_CLIENT) { if (curr_tick > m_last_recv_tick + CLIENT_TIMEOUT) { Close();//超过2min则断开,指的是客户端的短连接2min中内没有新的数据到达,就断开??? } } else { if (curr_tick > m_last_send_tick + SERVER_HEARTBEAT_INTERVAL) {//每隔5s就给msg_server发送一个心跳包 IM::Other::IMHeartBeat msg; CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_HEARTBEAT); log("Send HeartBeat To MsgServer"); SendPdu(&pdu); } //30s内没有收到msg-server的数据,则判断MsgServer断开了 if (curr_tick > m_last_recv_tick + SERVER_TIMEOUT) { log("connection to MsgServer timeout "); Close(); } } log("leave[%s]", __FUNCTION__); }
// friend online/off-line notify void CRouteServConn::_HandleStatusNotify(CImPdu* pPdu) { IM::Buddy::IMUserStatNotify msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); IM::BaseDefine::UserStat user_stat = msg.user_stat(); log("HandleFriendStatusNotify, user_id=%u, status=%u ", user_stat.user_id(), user_stat.status()); // send friend online message to client //CImUserManager::GetInstance()->BroadcastPdu(pPdu, CLIENT_TYPE_FLAG_PC); //send to db CDBServConn* pDBConn = get_db_serv_conn(); //CImUser* pImUser = CImUserManager::GetInstance()->GetImUserById( user_stat.user_id()); if(pDBConn) //pImUser && { IM::Server::IMGetFriendsidReq msgReq; msgReq.set_user_id(user_stat.user_id()); CImPdu dbPdu; //CDbAttachData dbAttachData(pPdu->GetBodyData(), pPdu->GetBodyLength()); //msgReq.set_attach_data(dbAttachData.GetBuffer(), dbAttachData.GetLength()); msgReq.set_attach_data(pPdu->GetBodyData(), pPdu->GetBodyLength()); dbPdu.SetPBMsg( &msgReq); dbPdu.SetServiceId(DFFX_SID_OTHER); dbPdu.SetCommandId(DFFX_CID_OTHER_GETFRIENDSID_REQ); dbPdu.SetSeqNum(pPdu->GetSeqNum()); pDBConn->SendPdu( &dbPdu); } }
void CGroupChat::HandleClientGroupChangeMemberRequest(CImPdu* pPdu, CMsgConn* pFromConn) { IM::Group::IMGroupChangeMemberReq msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t change_type = msg.change_type(); uint32_t req_user_id = pFromConn->GetUserId(); uint32_t group_id = msg.group_id(); uint32_t user_cnt = msg.member_id_list_size(); log("HandleClientChangeMemberReq, change_type=%u, req_id=%u, group_id=%u, user_cnt=%u ", change_type, req_user_id, group_id, user_cnt); CDBServConn* pDbConn = get_db_serv_conn(); if (pDbConn) { CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pFromConn->GetHandle(), 0); msg.set_user_id(req_user_id); msg.set_attach_data(attach_data.GetBuffer(), attach_data.GetLength()); pPdu->SetPBMsg(&msg); pDbConn->SendPdu(pPdu); } else { log("no DB connection "); IM::Group::IMGroupChangeMemberRsp msg2; msg2.set_user_id(req_user_id); msg2.set_change_type((IM::BaseDefine::GroupModifyType)change_type); msg2.set_result_code(1); msg2.set_group_id(group_id); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_CHANGE_MEMBER_RESPONSE); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } }
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 CGroupChat::HandleClientGroupShieldGroupRequest(CImPdu *pPdu, CMsgConn *pFromConn) { IM::Group::IMGroupShieldReq msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t shield_status = msg.shield_status(); uint32_t group_id = msg.group_id(); uint32_t user_id = pFromConn->GetUserId(); log("HandleClientGroupShieldGroupRequest, user_id: %u, group_id: %u, shield_status: %u. ", user_id, group_id, shield_status); CDBServConn* pDbConn = get_db_serv_conn(); if (pDbConn) { CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pFromConn->GetHandle(), 0); msg.set_user_id(user_id); msg.set_attach_data(attach_data.GetBuffer(), attach_data.GetLength()); pPdu->SetPBMsg(&msg); pDbConn->SendPdu(pPdu); } else { log("no DB connection "); IM::Group::IMGroupShieldRsp msg2; msg2.set_user_id(user_id); msg2.set_result_code(1); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_SHIELD_GROUP_RESPONSE); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } }
void CGroupChat::HandleClientGroupInfoRequest(CImPdu *pPdu, CMsgConn* pFromConn) { IM::Group::IMGroupInfoListReq msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t user_id = pFromConn->GetUserId(); uint32_t group_cnt = msg.group_version_list_size(); log("HandleClientGroupInfoRequest, user_id=%u, group_cnt=%u. ", user_id, group_cnt); CPduAttachData attach_data(ATTACH_TYPE_HANDLE, pFromConn->GetHandle(), 0, NULL); CDBServConn* pDBConn = get_db_serv_conn(); if (pDBConn) { msg.set_user_id(user_id); msg.set_attach_data(attach_data.GetBuffer(), attach_data.GetLength()); pPdu->SetPBMsg(&msg); pDBConn->SendPdu(pPdu); } else { log("no db connection. "); IM::Group::IMGroupInfoListRsp msg2; msg2.set_user_id(user_id); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_INFO_RESPONSE); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } }
void CGroupChat::HandleGroupGetShieldByGroupResponse(CImPdu *pPdu) { IM::Server::IMGroupGetShieldRsp msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t shield_status_list_cnt = msg.shield_status_list_size(); log("HandleGroupGetShieldByGroupResponse, shield_status_list_cnt: %u. ", shield_status_list_cnt); IM::Server::IMGetDeviceTokenReq msg2; msg2.set_attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length()); for (uint32_t i = 0; i < shield_status_list_cnt; i++) { IM::BaseDefine::ShieldStatus shield_status = msg.shield_status_list(i); if (shield_status.shield_status() == 0) { msg2.add_user_id(shield_status.user_id()); } else { log("user_id: %u shield group, group id: %u. ", shield_status.user_id(), shield_status.group_id()); } } CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_GET_DEVICE_TOKEN_REQ); CDBServConn* pDbConn = get_db_serv_conn(); if (pDbConn) { pDbConn->SendPdu(&pdu); } }
/** * 创建群组 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void createGroup(CImPdu* pPdu, uint32_t conn_uuid) { IM::Group::IMGroupCreateReq msg; IM::Group::IMGroupCreateRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t nUserId = msg.user_id(); string strGroupName = msg.group_name(); IM::BaseDefine::GroupType nGroupType = msg.group_type(); if(IM::BaseDefine::GroupType_IsValid(nGroupType)) { string strGroupAvatar = msg.group_avatar(); set<uint32_t> setMember; uint32_t nMemberCnt = msg.member_id_list_size(); for(uint32_t i=0; i<nMemberCnt; ++i) { uint32_t nUserId = msg.member_id_list(i); setMember.insert(nUserId); } log("createGroup.%d create %s, userCnt=%u", nUserId, strGroupName.c_str(), setMember.size()); uint32_t nGroupId = CGroupModel::getInstance()->createGroup(nUserId, strGroupName, strGroupAvatar, nGroupType, setMember); msgResp.set_user_id(nUserId); msgResp.set_group_name(strGroupName); for(auto it=setMember.begin(); it!=setMember.end();++it) { msgResp.add_user_id_list(*it); } if(nGroupId != INVALID_VALUE) { msgResp.set_result_code(0); msgResp.set_group_id(nGroupId); } else { msgResp.set_result_code(1); } log("createGroup.%d create %s, userCnt=%u, result:%d", nUserId, strGroupName.c_str(), setMember.size(), msgResp.result_code()); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_GROUP); pPduRes->SetCommandId(IM::BaseDefine::CID_GROUP_CREATE_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("invalid group type.userId=%u, groupType=%u, groupName=%s", nUserId, nGroupType, strGroupName.c_str()); } } else { log("parse pb failed"); } }
void CRouteServConn::_HandlePCLoginStatusNotify(CImPdu *pPdu) { IM::Server::IMServerPCLoginStatusNotify msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t user_id = msg.user_id(); uint32_t login_status = msg.login_status(); log("HandlePCLoginStatusNotify, user_id=%u, login_status=%u ", user_id, login_status); CImUser* pUser = CImUserManager::GetInstance()->GetImUserById(user_id); if (pUser) { pUser->SetPCLoginStatus(login_status); IM::Buddy::IMPCLoginStatusNotify msg2; msg2.set_user_id(user_id); if (IM_PC_LOGIN_STATUS_ON == login_status) { msg2.set_login_stat(::IM::BaseDefine::USER_STATUS_ONLINE); } else { msg2.set_login_stat(::IM::BaseDefine::USER_STATUS_OFFLINE); } CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); pdu.SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_PC_LOGIN_STATUS_NOTIFY); pUser->BroadcastPduToMobile(&pdu); } }
void CRouteServConn::OnConfirm() { log("connect to route server success "); m_bOpen = true; m_connect_time = get_tick_count(); g_route_server_list[m_serv_idx].reconnect_cnt = MIN_RECONNECT_CNT / 2; if (!g_master_rs_conn) { update_master_route_serv_conn(); } list<user_stat_t> online_user_list; CImUserManager::GetInstance()->GetOnlineUserInfo(&online_user_list); IM::Server::IMOnlineUserInfo msg; for (list<user_stat_t>::iterator it = online_user_list.begin(); it != online_user_list.end(); it++) { user_stat_t user_stat = *it; IM::BaseDefine::ServerUserStat* server_user_stat = msg.add_user_stat_list(); server_user_stat->set_user_id(user_stat.user_id); server_user_stat->set_status((::IM::BaseDefine::UserStatType)user_stat.status); server_user_stat->set_client_type((::IM::BaseDefine::ClientType)user_stat.client_type); } CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_ONLINE_USER_INFO); SendPdu(&pdu); }
void update_master_route_serv_conn() { uint64_t oldest_connect_time = (uint64_t)-1; // CRouteServConn* pOldestConn = NULL; shared_ptr<CRouteServConn> pOldestConn; // CRouteServConn* pConn = NULL; shared_ptr<CRouteServConn> pConn; for (uint32_t i = 0; i < g_route_server_count; i++) { pConn = g_route_server_list[i].serv_conn; if (pConn && pConn->IsOpen() && (pConn->GetConnectTime() < oldest_connect_time) ){ pOldestConn = pConn; oldest_connect_time = pConn->GetConnectTime(); } } g_master_rs_conn = pOldestConn; if (g_master_rs_conn) { IM::Server::IMRoleSet msg; msg.set_master(1); CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_ROLE_SET); g_master_rs_conn->SendPdu(&pdu); } }
void CGroupChat::HandleClientGroupNormalRequest(CImPdu* pPdu, CMsgConn* pFromConn) { IM::Group::IMNormalGroupListReq msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t user_id = pFromConn->GetUserId(); log("HandleClientGroupNormalRequest, user_id=%u. ", user_id); CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pFromConn->GetHandle(), 0); CDBServConn* pDBConn = get_db_serv_conn(); if (pDBConn) { msg.set_user_id(user_id); msg.set_attach_data((uchar_t*)attach_data.GetBuffer(), attach_data.GetLength()); pPdu->SetPBMsg(&msg); pDBConn->SendPdu(pPdu); } else { log("no db connection. "); IM::Group::IMNormalGroupListRsp msg2; msg.set_user_id(user_id); CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_NORMAL_LIST_RESPONSE); pdu.SetSeqNum(pPdu->GetSeqNum()); pFromConn->SendPdu(&pdu); } }
/** * 修改群成员,增加或删除 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void modifyMember(CImPdu* pPdu, uint32_t conn_uuid) { IM::Group::IMGroupChangeMemberReq msg; IM::Group::IMGroupChangeMemberRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { uint32_t nUserId = msg.user_id(); uint32_t nGroupId = msg.group_id(); IM::BaseDefine::GroupModifyType nType = msg.change_type(); if (IM::BaseDefine::GroupModifyType_IsValid(nType) && CGroupModel::getInstance()->isValidateGroupId(nGroupId)) { CImPdu* pPduRes = new CImPdu; uint32_t nCnt = msg.member_id_list_size(); set<uint32_t> setUserId; for(uint32_t i=0; i<nCnt;++i) { setUserId.insert(msg.member_id_list(i)); } list<uint32_t> lsCurUserId; bool bRet = CGroupModel::getInstance()->modifyGroupMember(nUserId, nGroupId, nType, setUserId, lsCurUserId); msgResp.set_user_id(nUserId); msgResp.set_group_id(nGroupId); msgResp.set_change_type(nType); msgResp.set_result_code(bRet?0:1); if(bRet) { for(auto it=setUserId.begin(); it!=setUserId.end(); ++it) { msgResp.add_chg_user_id_list(*it); } for(auto it=lsCurUserId.begin(); it!=lsCurUserId.end(); ++it) { msgResp.add_cur_user_id_list(*it); } } log("userId=%u, groupId=%u, result=%u, changeCount:%u, currentCount=%u",nUserId, nGroupId, bRet?0:1, msgResp.chg_user_id_list_size(), msgResp.cur_user_id_list_size()); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_GROUP); pPduRes->SetCommandId(IM::BaseDefine::CID_GROUP_CHANGE_MEMBER_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("invalid groupModifyType or groupId. userId=%u, groupId=%u, groupModifyType=%u", nUserId, nGroupId, nType); } } else { log("parse pb failed"); } }
/** * 获取群信息 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void getGroupInfo(CImPdu* pPdu, uint32_t conn_uuid) { IM::Group::IMGroupInfoListReq msg; IM::Group::IMGroupInfoListRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t nUserId = msg.user_id(); uint32_t nGroupCnt = msg.group_version_list_size(); map<uint32_t, IM::BaseDefine::GroupVersionInfo> mapGroupId; for(uint32_t i=0; i<nGroupCnt; ++i) { IM::BaseDefine::GroupVersionInfo groupInfo = msg.group_version_list(i); if(CGroupModel::getInstance()->isValidateGroupId(groupInfo.group_id())) { mapGroupId[groupInfo.group_id()] = groupInfo; } } list<IM::BaseDefine::GroupInfo> lsGroupInfo; CGroupModel::getInstance()->getGroupInfo(mapGroupId, lsGroupInfo); msgResp.set_user_id(nUserId); for(auto it=lsGroupInfo.begin(); it!=lsGroupInfo.end(); ++it) { IM::BaseDefine::GroupInfo* pGroupInfo = msgResp.add_group_info_list(); // *pGroupInfo = *it; pGroupInfo->set_group_id(it->group_id()); pGroupInfo->set_version(it->version()); pGroupInfo->set_group_name(it->group_name()); pGroupInfo->set_group_avatar(it->group_avatar()); pGroupInfo->set_group_creator_id(it->group_creator_id()); pGroupInfo->set_group_type(it->group_type()); pGroupInfo->set_shield_status(it->shield_status()); uint32_t nGroupMemberCnt = it->group_member_list_size(); for (uint32_t i=0; i<nGroupMemberCnt; ++i) { uint32_t userId = it->group_member_list(i); pGroupInfo->add_group_member_list(userId); } } log("userId=%u, requestCount=%u", nUserId, nGroupCnt); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_GROUP); pPduRes->SetCommandId(IM::BaseDefine::CID_GROUP_INFO_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("parse pb failed"); } }
void CGroupChat::HandleGroupChangeMemberResponse(CImPdu* pPdu) { IM::Group::IMGroupChangeMemberRsp msg; CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())); uint32_t change_type = msg.change_type(); uint32_t user_id = msg.user_id(); uint32_t result = msg.result_code(); uint32_t group_id = msg.group_id(); uint32_t chg_user_cnt = msg.chg_user_id_list_size(); uint32_t cur_user_cnt = msg.cur_user_id_list_size(); log("HandleChangeMemberResp, change_type=%u, req_id=%u, group_id=%u, result=%u, chg_usr_cnt=%u, cur_user_cnt=%u. ", change_type, user_id, group_id, result, chg_user_cnt, cur_user_cnt); CDbAttachData attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length()); CMsgConn* pFromConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, attach_data.GetHandle()); if (pFromConn) { msg.clear_attach_data(); pPdu->SetPBMsg(&msg); pFromConn->SendPdu(pPdu); } if (!result) { IM::Group::IMGroupChangeMemberNotify msg2; msg2.set_user_id(user_id); msg2.set_change_type((::IM::BaseDefine::GroupModifyType)change_type); msg2.set_group_id(group_id); for (uint32_t i = 0; i < chg_user_cnt; i++) { msg2.add_chg_user_id_list(msg.chg_user_id_list(i)); } for (uint32_t i = 0; i < cur_user_cnt; i++) { msg2.add_cur_user_id_list(msg.cur_user_id_list(i)); } CImPdu pdu; pdu.SetPBMsg(&msg2); pdu.SetServiceId(SID_GROUP); pdu.SetCommandId(CID_GROUP_CHANGE_MEMBER_NOTIFY); CRouteServConn* pRouteConn = get_route_serv_conn(); if (pRouteConn) { pRouteConn->SendPdu(&pdu); } for (uint32_t i = 0; i < chg_user_cnt; i++) { uint32_t to_user_id = msg.chg_user_id_list(i); _SendPduToUser(&pdu, to_user_id, pFromConn); } for (uint32_t i = 0; i < cur_user_cnt; i++) { uint32_t to_user_id = msg.cur_user_id_list(i); _SendPduToUser(&pdu, to_user_id, pFromConn); } } }
void getChangedUser(CImPdu* pPdu, uint32_t conn_uuid) { IM::Buddy::IMAllUserReq msg; IM::Buddy::IMAllUserRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t nReqId = msg.user_id(); uint32_t nLastTime = msg.latest_update_time(); uint32_t nLastUpdate = CSyncCenter::getInstance()->getLastUpdate(); list<IM::BaseDefine::UserInfo> lsUsers; if( nLastUpdate > nLastTime) { list<uint32_t> lsIds; CUserModel::getInstance()->getChangedId(nLastTime, lsIds); CUserModel::getInstance()->getUsers(lsIds, lsUsers); } msgResp.set_user_id(nReqId); msgResp.set_latest_update_time(nLastTime); for (list<IM::BaseDefine::UserInfo>::iterator it=lsUsers.begin(); it!=lsUsers.end(); ++it) { IM::BaseDefine::UserInfo* pUser = msgResp.add_user_list(); // *pUser = *it; pUser->set_user_id(it->user_id()); pUser->set_user_gender(it->user_gender()); pUser->set_user_nick_name(it->user_nick_name()); pUser->set_avatar_url(it->avatar_url()); pUser->set_sign_info(it->sign_info()); pUser->set_department_id(it->department_id()); pUser->set_email(it->email()); pUser->set_user_real_name(it->user_real_name()); pUser->set_user_tel(it->user_tel()); pUser->set_user_domain(it->user_domain()); pUser->set_status(it->status()); } log("userId=%u,nLastUpdate=%u, last_time=%u, userCnt=%u", nReqId,nLastUpdate, nLastTime, msgResp.user_list_size()); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); pPduRes->SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_ALL_USER_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("parse pb failed"); } }
uint32_t ClientConn::getUnreadMsgCnt(uint32_t nUserId) { CImPdu cPdu; IM::Message::IMUnreadMsgCntReq msg; msg.set_user_id(nUserId); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_MSG); cPdu.SetCommandId(IM::BaseDefine::CID_MSG_UNREAD_CNT_REQUEST); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
uint32_t ClientConn::getGroupList(uint32_t nUserId) { CImPdu cPdu; IM::Group::IMNormalGroupListReq msg; msg.set_user_id(nUserId); printf("%d\n" , nUserId); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_GROUP); cPdu.SetCommandId(IM::BaseDefine::CID_GROUP_NORMAL_LIST_REQUEST); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
void getUserInfo(CImPdu* pPdu, uint32_t conn_uuid) { IM::Buddy::IMUsersInfoReq msg; IM::Buddy::IMUsersInfoRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { CImPdu* pPduRes = new CImPdu; uint32_t from_user_id = msg.user_id(); uint32_t userCount = msg.user_id_list_size(); std::list<uint32_t> idList; for(uint32_t i = 0; i < userCount;++i) { idList.push_back(msg.user_id_list(i)); } std::list<IM::BaseDefine::UserInfo> lsUser; CUserModel::getInstance()->getUsers(idList, lsUser); msgResp.set_user_id(from_user_id); for(list<IM::BaseDefine::UserInfo>::iterator it=lsUser.begin(); it!=lsUser.end(); ++it) { IM::BaseDefine::UserInfo* pUser = msgResp.add_user_info_list(); // *pUser = *it; pUser->set_user_id(it->user_id()); pUser->set_user_gender(it->user_gender()); pUser->set_user_nick_name(it->user_nick_name()); pUser->set_avatar_url(it->avatar_url()); pUser->set_sign_info(it->sign_info()); pUser->set_department_id(it->department_id()); pUser->set_email(it->email()); pUser->set_user_real_name(it->user_real_name()); pUser->set_user_tel(it->user_tel()); pUser->set_user_domain(it->user_domain()); pUser->set_status(it->status()); pUser->set_user_type(it->user_type()); } log("userId=%u, userCnt=%u", from_user_id, userCount); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); pPduRes->SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_USER_INFO_RESPONSE); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("parse pb failed"); } }
uint32_t ClientConn::getRecentSession(uint32_t nUserId, uint32_t nLastTime) { CImPdu cPdu; IM::Buddy::IMRecentContactSessionReq msg; msg.set_user_id(nUserId); msg.set_latest_update_time(nLastTime); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); cPdu.SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_RECENT_CONTACT_SESSION_REQUEST); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
uint32_t ClientConn::getUser(uint32_t nUserId, uint32_t nTime) { CImPdu cPdu; IM::Buddy::IMAllUserReq msg; msg.set_user_id(nUserId); msg.set_latest_update_time(nTime); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); cPdu.SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_ALL_USER_REQUEST); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
CImPdu login(const string &strName, const string &strPass) { CImPdu cPdu; IM::Login::IMLoginReq msg; msg.set_user_name(strName); msg.set_password(strPass); msg.set_online_status(IM::BaseDefine::USER_STATUS_ONLINE); msg.set_client_type(IM::BaseDefine::CLIENT_TYPE_WINDOWS); msg.set_client_version("1.0"); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_LOGIN); cPdu.SetCommandId(IM::BaseDefine::CID_LOGIN_REQ_USERLOGIN); cPdu.SetSeqNum(1); return cPdu; }
void CFileConn::_HandleGetServerAddressReq(CImPdu* pPdu) { IM::Server::IMFileServerIPRsp msg; for (auto ip_addr_tmp : g_addr) { auto ip_addr = msg.add_ip_addr_list(); *ip_addr = ip_addr_tmp; } CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_FILE_SERVER_IP_RSP); pdu.SetSeqNum(pPdu->GetSeqNum()); SendPdu(&pdu); return; }
uint32_t ClientConn::getUserInfo(uint32_t nUserId, list<uint32_t>& lsUserId) { CImPdu cPdu; IM::Buddy::IMUsersInfoReq msg; msg.set_user_id(nUserId); for (auto it=lsUserId.begin(); it!=lsUserId.end(); ++it) { msg.add_user_id_list(*it); } cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_BUDDY_LIST); cPdu.SetCommandId(IM::BaseDefine::CID_BUDDY_LIST_USER_INFO_REQUEST); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
uint32_t ClientConn::sendMsgAck(uint32_t nUserId, uint32_t nPeerId, IM::BaseDefine::SessionType nType, uint32_t nMsgId) { CImPdu cPdu; IM::Message::IMMsgDataAck msg; msg.set_user_id(nUserId); msg.set_session_id(nPeerId); msg.set_session_type(nType); msg.set_msg_id(nMsgId); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::DFFX_SID_MSG); cPdu.SetCommandId(IM::BaseDefine::DFFX_CID_MSG_READ_ACK); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }
void CDBServConn::OnTimer(uint64_t curr_tick) { if (curr_tick > m_last_send_tick + SERVER_HEARTBEAT_INTERVAL) { IM::Other::IMHeartBeat msg; CImPdu pdu; pdu.SetPBMsg(&msg); pdu.SetServiceId(SID_OTHER); pdu.SetCommandId(CID_OTHER_HEARTBEAT); SendPdu(&pdu); } if (curr_tick > m_last_recv_tick + SERVER_TIMEOUT) { log("conn to db server timeout"); Close(); } }
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; }
/** * 获取一个群的推送设置 * * @param pPdu 收到的packet包指针 * @param conn_uuid 该包过来的socket 描述符 */ void getGroupPush(CImPdu* pPdu, uint32_t conn_uuid) { IM::Server::IMGroupGetShieldReq msg; IM::Server::IMGroupGetShieldRsp msgResp; if(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength())) { uint32_t nGroupId = msg.group_id(); uint32_t nUserCnt = msg.user_id_size(); if(CGroupModel::getInstance()->isValidateGroupId(nGroupId)) { CImPdu* pPduRes = new CImPdu; list<uint32_t> lsUser; for(uint32_t i=0; i<nUserCnt; ++i) { lsUser.push_back(msg.user_id(i)); } list<IM::BaseDefine::ShieldStatus> lsPush; CGroupModel::getInstance()->getPush(nGroupId, lsUser, lsPush); msgResp.set_group_id(nGroupId); for (auto it=lsPush.begin(); it!=lsPush.end(); ++it) { IM::BaseDefine::ShieldStatus* pStatus = msgResp.add_shield_status_list(); // *pStatus = *it; pStatus->set_user_id(it->user_id()); pStatus->set_group_id(it->group_id()); pStatus->set_shield_status(it->shield_status()); } log("groupId=%u, count=%u", nGroupId, nUserCnt); msgResp.set_attach_data(msg.attach_data()); pPduRes->SetPBMsg(&msgResp); pPduRes->SetSeqNum(pPdu->GetSeqNum()); pPduRes->SetServiceId(IM::BaseDefine::SID_OTHER); pPduRes->SetCommandId(IM::BaseDefine::CID_OTHER_GET_SHIELD_RSP); CProxyConn::AddResponsePdu(conn_uuid, pPduRes); } else { log("Invalid groupId. nGroupId=%u", nGroupId); } } else { log("parse pb failed"); } }
uint32_t ClientConn::login(const string &strName, const string &strPass) { CImPdu cPdu; IM::Login::IMLoginReq msg; msg.set_user_name(strName); msg.set_password(strPass); msg.set_online_status(IM::BaseDefine::USER_STATUS_ONLINE); msg.set_client_type(IM::BaseDefine::CLIENT_TYPE_WINDOWS); msg.set_client_version("1.0"); cPdu.SetPBMsg(&msg); cPdu.SetServiceId(IM::BaseDefine::SID_LOGIN); cPdu.SetCommandId(IM::BaseDefine::CID_LOGIN_REQ_USERLOGIN); uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET); cPdu.SetSeqNum(nSeqNo); SendPdu(&cPdu); return nSeqNo; }