void FileTransferSocket::onReceiveData(const char* data, UInt32 size)
{
	CImPdu* pPdu = 0;
	try
	{
		pPdu = CImPdu::ReadPdu((uchar_t*)data, (uint32_t)size);
		PTR_VOID(pPdu);
		if (IM_PDU_TYPE_HEARTBEAT == pPdu->GetCommandId() && SID_OTHER == pPdu->GetModuleId())
			return;
	}
	catch (CPduException e)
	{
		APP_LOG(LOG_ERROR, _T("FileTransferSocket onPacket CPduException serviceId:%d,commandId:%d,errCode:%d")
			, e.GetModuleId(), e.GetCommandId(), e.GetErrorCode());
		return;
	}
	catch (...)
	{
		APP_LOG(LOG_ERROR, _T("FileTransferSocket onPacket unknown exception"));
		return;
	}
	UInt16 ncmdid = pPdu->GetCommandId();
	switch (pPdu->GetCommandId())
	{
	case CID_FILE_LOGIN_RES:
		_fileLoginResponse(pPdu);
		break;
	case CID_FILE_PULL_DATA_REQ:
		_filePullDataReqResponse(pPdu);
		break;
	case CID_FILE_PULL_DATA_RSP:
		_filePullDataRspResponse(pPdu);
		break;
	case CID_FILE_STATE:
		_fileState(pPdu);
	default:
		break;
	}
	delete pPdu;
	pPdu = 0;
}
Example #2
0
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("100.0.0");
    cPdu.SetPBMsg(&msg);
    cPdu.SetServiceId(IM::BaseDefine::DFFX_SID_LOGIN);
    cPdu.SetCommandId(IM::BaseDefine::DFFX_CID_LOGIN_REQ_USERLOGIN);

	printf("login   %d\n",cPdu.GetCommandId());
	
    uint32_t nSeqNo = m_pSeqAlloctor->getSeq(ALLOCTOR_PACKET);
    cPdu.SetSeqNum(nSeqNo);
    SendPdu(&cPdu);
    return nSeqNo;
}
Example #3
0
void CDBServConn::_HandleDbRegisterResponse(CImPdu* pPdu)
{
    RUNTIME_TRACE;
    IM::Server::IMDbRegRes msgDb;
    CHECK_PB_PARSE_MSG(msgDb.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));

    string login_name = msgDb.user_name();
    CImUser* pImUser = CImUserManager::GetInstance()->GetImUserByLoginName(login_name);
    if (!pImUser) {
        log("ImUser for user_name=%s not exist", login_name.c_str());
        return;
    }
    
    CDbAttachData attach_data((uchar_t*)msgDb.attach_data().c_str(), msgDb.attach_data().length());

    auto pMsgConn = pImUser->GetUnValidateMsgConn(attach_data.GetHandle());
    if (!pMsgConn || pMsgConn->IsOpen()) {
        log("no such conn, user_name=%s", login_name.c_str());
        return;
    }
    
    IM::BaseDefine::UserInfo user_info = msgDb.user_info();
    uint32_t user_id = user_info.user_id();
    pImUser->SetUserId(user_id);
    pImUser->SetNickName(user_info.user_nick_name());
    pImUser->SetValidated();
    CImUserManager::GetInstance()->AddImUserById(user_id, pImUser);
    
    log("user_name: %s, uid: %d", login_name.c_str(), user_id);
    pMsgConn->SetUserId(user_id);
    pMsgConn->SetOpen();
    pMsgConn->SendUserStatusUpdate(IM::BaseDefine::USER_STATUS_ONLINE);
    pImUser->ValidateMsgConn(pMsgConn->GetHandle(), pMsgConn);
    
    IM::Login::IMRegisterRes msgRes;
    msgRes.set_user_name(login_name);
    msgRes.set_server_time(time(NULL));
    msgRes.set_result_code((IM::BaseDefine::ResultType)msgDb.result_code());
    msgRes.set_online_status((IM::BaseDefine::UserStatType)pMsgConn->GetOnlineStatus());
    msgRes.set_result_string(msgDb.result_string());
    
    IM::BaseDefine::UserInfo* user_info_tmp = msgRes.mutable_user_info();
    user_info_tmp->set_user_id(user_info.user_id());
    user_info_tmp->set_user_gender(user_info.user_gender());
    user_info_tmp->set_user_nick_name(user_info.user_nick_name());
    user_info_tmp->set_avatar_url(user_info.avatar_url());
    user_info_tmp->set_department_id(user_info.department_id());
    user_info_tmp->set_email(user_info.email());
    user_info_tmp->set_user_real_name(user_info.user_real_name());
    user_info_tmp->set_user_tel(user_info.user_tel());
    user_info_tmp->set_user_domain(user_info.user_domain());
    user_info_tmp->set_status(user_info.status());
    CImPdu pdu;
    pdu.SetPBMsg(&msgRes);
    pdu.SetServiceId(SID_LOGIN);
    pdu.SetCommandId(CID_LOGIN_RES_USERREG);
    pdu.SetSeqNum(pPdu->GetSeqNum());
    pMsgConn->SendPdu(&pdu);
    log("send pdu command id = %d", pdu.GetCommandId());
    if (msgDb.result_code())
        pMsgConn->Close();

}