Exemplo n.º 1
0
/////////// for server
void CFileHandler::HandleFileHasOfflineRes(CImPduFileHasOfflineRes* pPdu)
{
	uint32_t req_user_id = pPdu->GetReqUserId();
	uint32_t file_cnt = pPdu->GetFileCnt();
	offline_file_t* file_list = pPdu->GetFileList();
    CDbAttachData attach(pPdu->GetAttachData(), pPdu->GetAttachLen());
	log("HandleFileHasOfflineRes, req_id=%u, file_cnt=%u\n", req_user_id, file_cnt);

	CMsgConn* pConn = CImUserManager::GetInstance()->GetMsgConnByHandle(req_user_id,
                                                                        attach.GetHandle());
    CFileServConn* pFileConn = get_random_file_serv_conn();
    const list<ip_addr_t>* ip_list = NULL;
    if (pFileConn)
    {
        ip_list = pFileConn->GetFileServerIPList();
    }
    else
    {
        log("HandleFileHasOfflineRes, no file server.\n");
    }
    if (pConn) {
        
        CImPduClientFileHasOfflineRes pdu(file_cnt, file_list, ip_list);
        pdu.SetReserved(pPdu->GetReserved());
        pConn->SendPdu(&pdu);
    }
}
Exemplo n.º 2
0
void CFileHandler::HandleClientFileRequest(CMsgConn* pMsgConn, CImPduClientFileRequest* pPdu)
{
	string from_id_url(pPdu->GetFromId(), pPdu->GetFromIdLen());
	uint32_t from_id = urltoid(from_id_url.c_str());
	string to_id_url(pPdu->GetToId(), pPdu->GetToIdLen());
	uint32_t to_id = urltoid(to_id_url.c_str());
	string file_name(pPdu->GetFileName(), pPdu->GetFileNameLen());
	uint32_t file_size = pPdu->GetFileSize();
	log("HandleClientFileRequest, %u->%u, fileName: %s\n", from_id, to_id, file_name.c_str());

    CPduAttachData attach(ATTACH_TYPE_HANDLE, pMsgConn->GetHandle(), 0, NULL, 0);

    CImUser* pUser = CImUserManager::GetInstance()->GetImUserById(to_id);
    if (pUser)
    {
        uint32_t client_type_flag = pUser->GetClientTypeFlag();
        //to_user has pc_client in this msg_server
        if ((client_type_flag & CLIENT_TYPE_FLAG_BOTH) == CLIENT_TYPE_FLAG_PC)
        {
            CFileServConn* pFileConn = get_random_file_serv_conn();
            if (pFileConn)
            {
                CImPduMsgFileTransferReq pdu(from_id, to_id, file_name.c_str(), file_size,
                                    FILE_TYPE_ONLINE, attach.GetLength(), attach.GetBuffer());
                pdu.SetReserved(pPdu->GetReserved());
                pFileConn->SendPdu(&pdu);
            }
            else
            {
                log("HandleClientFileRequest, no file server.\n");
                CImPduClientFileResponse pdu2(REFUSE_REASON_NO_FILE_SERVER, from_id_url.c_str(),
                                              to_id_url.c_str(), file_name.c_str(), NULL, NULL, 0);
                pdu2.SetReserved(pPdu->GetReserved());
                pMsgConn->SendPdu(&pdu2);
            }
            return;
        }
    }
    else
    {
        //no pc_client in this msg_server, check it from route_server
        CRouteServConn* pConn = get_route_serv_conn();
        CPduAttachData pduAttachData(ATTACH_TYPE_HANDLE_AND_PDU, pMsgConn->GetHandle(),
                                     pPdu->GetLength(), pPdu->GetBuffer());
        CImPduUserClientTypeRequest pdu3(to_id, pduAttachData.GetLength(), pduAttachData.GetBuffer());
        pdu3.SetReserved(pPdu->GetReserved());
        pConn->SendPdu(&pdu3);
    }
}
Exemplo n.º 3
0
void CRouteServConn::_HandleUserClientTypeResponse(CImPduUserClientTypeResponse *pPdu)
{
    uint32_t client_type_flag = pPdu->GetClientTypeFlag();
    uint32_t attach_len = pPdu->GetAttachLen();
    uchar_t* attach_data = pPdu->GetAttachData();
    CPduAttachData pduAttachData(attach_data, attach_len);
    
    CImPduClientFileRequest pdu(pduAttachData.GetPdu(), pduAttachData.GetPduLength());
    string from_id_url(pdu.GetFromId(), pdu.GetFromIdLen());
	uint32_t from_id = urltoid(from_id_url.c_str());
	string to_id_url(pdu.GetToId(), pdu.GetToIdLen());
	uint32_t to_id = urltoid(to_id_url.c_str());
	string file_name(pdu.GetFileName(), pdu.GetFileNameLen());
	uint32_t file_size = pdu.GetFileSize();
    uint32_t handle = pduAttachData.GetHandle();
    
    log("HandleUserClientTypeResponse, from_user_id: %u, to_user_id: %u, file_name: %s\n",
        from_id, to_id, file_name.c_str());

    uint32_t trans_mode = FILE_TYPE_OFFLINE;
    if ((client_type_flag & CLIENT_TYPE_FLAG_BOTH) == CLIENT_TYPE_FLAG_PC)
    {
        trans_mode = FILE_TYPE_ONLINE;
    }

    CPduAttachData attach(ATTACH_TYPE_HANDLE, handle, 0, NULL, 0);
    CImPduMsgFileTransferReq pdu2(from_id, to_id, file_name.c_str(), file_size,
                                 trans_mode, attach.GetLength(), attach.GetBuffer());
    pdu2.SetReserved(pPdu->GetReserved());
    CFileServConn* pConn = get_random_file_serv_conn();
    if (pConn) {
        pConn->SendPdu(&pdu2);
    }
    else
    {
        log("HandleUserClientTypeResponse, no file server\n");
        CImPduClientFileResponse pdu3(REFUSE_REASON_NO_FILE_SERVER, from_id_url.c_str(), to_id_url.c_str(), file_name.c_str(), NULL, NULL, 0);
        pdu3.SetReserved(pPdu->GetReserved());
        CMsgConn* pMsgConn = CImUserManager::GetInstance()->GetMsgConnByHandle(from_id,handle);
        if (pMsgConn)
        {
            pMsgConn->SendPdu(&pdu3);
        }
    }
}
Exemplo n.º 4
0
void CRouteServConn::_HandleUsersStatusResponse(CImPdu* pPdu)
{
    IM::Buddy::IMUsersStatRsp msg;
    CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));

	uint32_t user_id = msg.user_id();
	uint32_t result_count = msg.user_stat_list_size();
	log("HandleUsersStatusResp, user_id=%u, query_count=%u ", user_id, result_count);
    
    CPduAttachData attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length());
    if (attach_data.GetType() == ATTACH_TYPE_HANDLE)
    {
        uint32_t handle = attach_data.GetHandle();
        CMsgConn* pConn = CImUserManager::GetInstance()->GetMsgConnByHandle(user_id, handle);
        if (pConn) {
            msg.clear_attach_data();
            pPdu->SetPBMsg(&msg);
            pConn->SendPdu(pPdu);
        }
    }
    else if (attach_data.GetType() == ATTACH_TYPE_PDU_FOR_PUSH)
    {
        IM::BaseDefine::UserStat user_stat = msg.user_stat_list(0);
        IM::Server::IMPushToUserReq msg2;
        CHECK_PB_PARSE_MSG(msg2.ParseFromArray(attach_data.GetPdu(), attach_data.GetPduLength()));
        IM::BaseDefine::UserTokenInfo* user_token = msg2.mutable_user_token_list(0);

        //pc client登录,则为勿打扰式推送
        if (user_stat.status() == IM::BaseDefine::USER_STATUS_ONLINE)
        {
            user_token->set_push_type(IM_PUSH_TYPE_SILENT);
            log("HandleUsersStatusResponse, user id: %d, push type: normal. ", user_stat.user_id());
        }
        else
        {
            user_token->set_push_type(IM_PUSH_TYPE_NORMAL);
            log("HandleUsersStatusResponse, user id: %d, push type: normal. ", user_stat.user_id());
        }
        CImPdu pdu;
        pdu.SetPBMsg(&msg2);
        pdu.SetServiceId(SID_OTHER);
        pdu.SetCommandId(CID_OTHER_PUSH_TO_USER_REQ);
        
        CPushServConn* PushConn = get_push_serv_conn();
        if (PushConn)
        {
            PushConn->SendPdu(&pdu);
        }
    }
    else if (attach_data.GetType() == ATTACH_TYPE_HANDLE_AND_PDU_FOR_FILE)
    {
        IM::BaseDefine::UserStat user_stat = msg.user_stat_list(0);
        IM::Server::IMFileTransferReq msg3;
        CHECK_PB_PARSE_MSG(msg3.ParseFromArray(attach_data.GetPdu(), attach_data.GetPduLength()));
        uint32_t handle = attach_data.GetHandle();
        
        IM::BaseDefine::FileType trans_mode = IM::BaseDefine::FILE_TYPE_OFFLINE;
        if (user_stat.status() == IM::BaseDefine::USER_STATUS_ONLINE)
        {
            trans_mode = IM::BaseDefine::FILE_TYPE_ONLINE;
        }
        msg3.set_trans_mode(trans_mode);
        CImPdu pdu;
        pdu.SetPBMsg(&msg3);
        pdu.SetServiceId(SID_OTHER);
        pdu.SetCommandId(CID_OTHER_FILE_TRANSFER_REQ);
        pdu.SetSeqNum(pPdu->GetSeqNum());
        CFileServConn* pConn = get_random_file_serv_conn();
        if (pConn) {
            pConn->SendPdu(&pdu);
        }
        else
        {
            log("no file server ");
            IM::File::IMFileRsp msg4;
            msg4.set_result_code(1);
            msg4.set_from_user_id(msg3.from_user_id());
            msg4.set_to_user_id(msg3.to_user_id());
            msg4.set_file_name(msg3.file_name());
            msg4.set_task_id("");
            msg4.set_trans_mode(msg3.trans_mode());
            CImPdu pdu2;
            pdu2.SetPBMsg(&msg4);
            pdu2.SetServiceId(SID_FILE);
            pdu2.SetCommandId(CID_FILE_RESPONSE);
            pdu2.SetSeqNum(pPdu->GetSeqNum());
            CMsgConn* pMsgConn = CImUserManager::GetInstance()->GetMsgConnByHandle(msg3.from_user_id(),handle);
            if (pMsgConn)
            {
                pMsgConn->SendPdu(&pdu2);
            }
        }
    }
}