Esempio n. 1
0
 /**
  *  创建群组
  *
  *  @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");
     }
 }
Esempio n. 2
0
void CGroupChat::HandleClientGroupCreateRequest(CImPdu* pPdu, CMsgConn* pFromConn)
{
    IM::Group::IMGroupCreateReq msg;
    CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));

	uint32_t req_user_id = pFromConn->GetUserId();
    string group_name = msg.group_name();
    uint32_t group_type = msg.group_type();
    if (group_type == IM::BaseDefine::GROUP_TYPE_NORMAL) {
        log("HandleClientGroupCreateRequest, create normal group failed, req_id=%u, group_name=%s. ", req_user_id, group_name.c_str());
        return;
    }
	string group_avatar = msg.group_avatar();
	uint32_t user_cnt = msg.member_id_list_size();
	log("HandleClientGroupCreateRequest, req_id=%u, group_name=%s, avatar_url=%s, user_cnt=%u ",
			req_user_id, group_name.c_str(), group_avatar.c_str(), 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::IMGroupCreateRsp msg2;
        msg2.set_user_id(req_user_id);
        msg2.set_result_code(1);
        msg2.set_group_name(group_name);
        CImPdu pdu;
        pdu.SetPBMsg(&msg2);
        pdu.SetServiceId(SID_GROUP);
        pdu.SetCommandId(CID_GROUP_CREATE_RESPONSE);
		pdu.SetSeqNum(pPdu->GetSeqNum());
		pFromConn->SendPdu(&pdu);
	}
}