示例#1
0
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);
    }
}
示例#2
0
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);
    }
}
示例#3
0
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);
	}
}
示例#4
0
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);
	}
}
示例#5
0
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);
    }
}
示例#6
0
// get a random db server connection in the range [start_pos, stop_pos)
static CDBServConn* get_db_server_conn_in_range(uint32_t start_pos, uint32_t stop_pos)
{
	uint32_t i = 0;
	CDBServConn* pDbConn = NULL;

	// determine if there is a valid DB server connection
	for (i = start_pos; i < stop_pos; i++) {
		pDbConn = (CDBServConn*)g_db_server_list[i].serv_conn;
		if (pDbConn && pDbConn->IsOpen()) {
			break;
		}
	}

	// no valid DB server connection
	if (i == stop_pos) {
		return NULL;
	}

	// return a random valid DB server connection
	while (true) {
		int i = rand() % (stop_pos - start_pos) + start_pos;
		pDbConn = (CDBServConn*)g_db_server_list[i].serv_conn;
		if (pDbConn && pDbConn->IsOpen()) {
			break;
		}
	}

	return pDbConn;
}
示例#7
0
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);
    }
}
示例#8
0
// 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);
	}
}
示例#9
0
void CFileHandler::HandleClientFileDelOfflineReq(CImPduClientFileDelOfflineReq* pPdu)
{
	string from_id_url(pPdu->GetFromId(), pPdu->GetFromIdLen());
	string to_id_url(pPdu->GetToId(), pPdu->GetToIdLen());
	uint32_t from_id = urltoid(from_id_url.c_str());
	uint32_t to_id = urltoid(to_id_url.c_str());
    string task_id(pPdu->GetTaskId(), pPdu->GetTaskIdLen());
	log("HandleClientFileDelOfflineReq, %u->%u, task_id=%s\n", from_id, to_id, task_id.c_str());

	CDBServConn* pDbConn = get_db_serv_conn();
	if (pDbConn) {
		CImPduFileDelOfflineReq pdu(to_id, from_id, to_id, task_id.c_str());
		pDbConn->SendPdu(&pdu);
	}
}
示例#10
0
void CFileHandler::HandleClientFileAddOfflineReq(CImPduClientFileAddOfflineReq* pPdu)
{
	string from_id_url(pPdu->GetFromId(), pPdu->GetFromIdLen());
	string to_id_url(pPdu->GetToId(), pPdu->GetToIdLen());
    string task_id(pPdu->GetTaskId(), pPdu->GetTaskIdLen());
	string file_name(pPdu->GetFileName(), pPdu->GetFileNameLen());
	uint32_t file_size = pPdu->GetFileSize();
	uint32_t from_id = urltoid(from_id_url.c_str());
	uint32_t to_id = urltoid(to_id_url.c_str());
	log("HandleClientFileAddOfflineReq, %u->%u, task_id: %s, file_name: %s, size: %u \n",
			from_id, to_id, task_id.c_str(), file_name.c_str(), file_size);

	CDBServConn* pDbConn = get_db_serv_conn();
	if (pDbConn) {
		CImPduFileAddOfflineReq pdu(from_id, from_id, to_id, task_id.c_str(), file_name.c_str(), file_size);
		pDbConn->SendPdu(&pdu);
	}
}
示例#11
0
void CFileHandler::HandleClientFileHasOfflineReq(CMsgConn* pMsgConn, CImPduClientFileHasOfflineReq* pPdu)
{
	uint32_t req_user_id = pMsgConn->GetUserId();
	log("HandleClientFileHasOfflineReq, req_id=%u\n", req_user_id);

    CDbAttachData attach_data(ATTACH_TYPE_HANDLE, pMsgConn->GetHandle(), 0);
	CDBServConn* pDbConn = get_db_serv_conn();
	if (pDbConn) {
		CImPduFileHasOfflineReq pdu(req_user_id, attach_data.GetLength(), attach_data.GetBuffer());
		pdu.SetReserved(pPdu->GetReserved());
		pDbConn->SendPdu(&pdu);
	} else {
		log("warning no DB connection available\n");
		CImPduClientFileHasOfflineRes pdu;
		pdu.SetReserved(pPdu->GetReserved());
		pMsgConn->SendPdu(&pdu);
	}
}
示例#12
0
static void db_server_conn_timer_callback(void* callback_data, uint8_t msg, uint32_t handle, void* pParam)
{
	ConnMap_t::iterator it_old;
	CDBServConn* pConn = NULL;
	uint64_t cur_time = get_tick_count();

	for (ConnMap_t::iterator it = g_db_server_conn_map.begin(); it != g_db_server_conn_map.end(); ) {
		it_old = it;
		it++;

		pConn = (CDBServConn*)it_old->second;
		if (pConn->IsOpen()) {
			pConn->OnTimer(cur_time);
		}
	}

	// reconnect DB Storage Server
	// will reconnect in 4s, 8s, 16s, 32s, 64s, 4s 8s ...
	serv_check_reconnect<CDBServConn>(g_db_server_list, g_db_server_count);
}
示例#13
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);
	}
}
示例#14
0
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);
    }
}
示例#15
0
void CGroupChat::HandleGroupInfoResponse(CImPdu* pPdu)
{
    IM::Group::IMGroupInfoListRsp msg;
    CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));

    uint32_t user_id = msg.user_id();
    uint32_t group_cnt = msg.group_info_list_size();
    CPduAttachData pduAttachData((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length());
    
    log("HandleGroupInfoResponse, user_id=%u, group_cnt=%u. ", user_id, group_cnt);

    //此处是查询成员时使用,主要用于群消息从数据库获得msg_id后进行发送,一般此时group_cnt = 1
    if (pduAttachData.GetPduLength() > 0 && group_cnt > 0)
    {
        IM::BaseDefine::GroupInfo group_info = msg.group_info_list(0);
        uint32_t group_id = group_info.group_id();
        log("GroupInfoRequest is send by server, group_id=%u ", group_id);
        
        std::set<uint32_t> group_member_set;
        for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
        {
            uint32_t member_user_id = group_info.group_member_list(i);
            group_member_set.insert(member_user_id);
        }
        if (group_member_set.find(user_id) == group_member_set.end())
        {
            log("user_id=%u is not in group, group_id=%u. ", user_id, group_id);
            return;
        }
        
        IM::Message::IMMsgData msg2;
        CHECK_PB_PARSE_MSG(msg2.ParseFromArray(pduAttachData.GetPdu(), pduAttachData.GetPduLength()));
        CImPdu pdu;
        pdu.SetPBMsg(&msg2);
        pdu.SetServiceId(SID_MSG);
        pdu.SetCommandId(CID_MSG_DATA);
        
        //Push相关
        IM::Server::IMGroupGetShieldReq msg3;
        msg3.set_group_id(group_id);
        msg3.set_attach_data(pdu.GetBodyData(), pdu.GetBodyLength());
        for (uint32_t i = 0; i < group_info.group_member_list_size(); i++)
        {
            uint32_t member_user_id = group_info.group_member_list(i);
            
            msg3.add_user_id(member_user_id);
            
            CImUser* pToImUser = CImUserManager::GetInstance()->GetImUserById(member_user_id);
            if (pToImUser)
            {
                CMsgConn* pFromConn = NULL;
                if( member_user_id == user_id )
                {
                    uint32_t reqHandle = pduAttachData.GetHandle();
                    if(reqHandle != 0)
                        pFromConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, reqHandle);
                }
                
                pToImUser->BroadcastData(pdu.GetBuffer(), pdu.GetLength(), pFromConn);
            }
        }
        
        CImPdu pdu2;
        pdu2.SetPBMsg(&msg3);
        pdu2.SetServiceId(SID_OTHER);
        pdu2.SetCommandId(CID_OTHER_GET_SHIELD_REQ);
        CDBServConn* pDbConn = get_db_serv_conn();
        if (pDbConn)
        {
            pDbConn->SendPdu(&pdu2);
        }
    }
    else if (pduAttachData.GetPduLength() == 0)
    {
        //正常获取群信息的返回
        CMsgConn* pConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, pduAttachData.GetHandle());
        if (pConn)
        {
            msg.clear_attach_data();
            pPdu->SetPBMsg(&msg);
            pConn->SendPdu(pPdu);
        }
    }
}