Exemplo n.º 1
0
std::string Entity::Identify(Player* mob)
{
    std::stringstream st;
    st << BaseObject::Identify(mob);
    st << "UUID: " << GetUuid() << std::endl;
    return st.str();
}
Exemplo n.º 2
0
void autobots_toutiao::initialDevices()
{
	for (size_t i = 0; i < 10; i++)
	{
		DeviceParam dev;
		dev._uuid = GetUuid();
		dev._did = GetDid();
		dev._useragent = "Mozilla / 5.0 (iPhone; CPU iPhone OS 9_3_5 like Mac OS X) AppleWebKit / 601.1.46 (KHTML, like Gecko) Mobile / 13G36 NewsArticle / 5.8.3.2 JsSdk / 2.0 NetType / WIFI(News 5.8.3 9.300000)";
		dev._device_type = GetDeviceType();
		m_devices_list.push_back(dev);
	}
}
Exemplo n.º 3
0
void DataManager::Export(DRef& dref, QDataStream& out)
{
    Data* pData = dref.m_pData;

    if (pData != NULL)
    {
        out << (qint32)BOI_STD_D_VERSION;
        out << (qint32)pData->Type();
        out << GetUuid(pData->Type());

        /*
         * Do not write the Data object directly to the
         * stream. This will allow implementations to
         * correctly skip over any unknown types. For
         * example, given the following stream:
         *
         *      out << QString << DRef << QString;
         * 
         * If the DRef data object was directly written
         * to the stream and then imported on a different
         * version of the system which does not support the
         * particular DRef type, the import would not be able
         * to read in the data and advance the stream to the
         * correct position to read the final QString.
         * Using a QByteArray avoids this situation because
         * the Import routine will always just read in a byte
         * array and thus advance the stream to the next
         * appropriate position (regardless of whether or not
         * the system supports the data type).
         */

        QByteArray byteArray;
        QBuffer buffer(&byteArray);
        buffer.open(QIODevice::WriteOnly);

        QDataStream tempOut(&buffer);
        pData->Export(tempOut);

        buffer.close();

        out << byteArray;
    }
    else
    {
        out << (qint32)BOI_STD_D_VERSION;
        out << (qint32)BOI_STD_D(Invalid);
    }
}
Exemplo n.º 4
0
/**
 * A Synchronous send with a blocking receive.
 * 
 * @param command
 *   A string to send
 * @return 
 *   The reply received
 */
std::string BoomStick::Send(const std::string& command) {
   const std::string uuid = GetUuid();
   if (mUtilizedThread == 0) {
      mUtilizedThread = pthread_self();
   } else {
      CHECK(mUtilizedThread == pthread_self());
   }
   if (!SendAsync(uuid, command)) {
      return
      {
      };
   }
   std::string returnString;
   if (!GetAsyncReply(uuid, 30000, returnString)) {
      return
      {
      };
   }
   return returnString;
}
Exemplo n.º 5
0
int CMp4DownloadClient::DataRequest(unsigned int startpos, unsigned int endpos, unsigned int* pactualfinishpos, 
									ResponseCallBack cb, ProgressCallBack data_progresscb, void* customparam,
									EMediaDataRequestSource eTryResoure)
{
	if (cb == NULL || pactualfinishpos == NULL || m_sequence_ptr == NULL || m_info_ptr == NULL || m_cdnInfolist_ptr == NULL || startpos >= endpos)
		return -1;

	bool bresult = false;

	_uint32_t startclipnum = 0;
	_uint32_t endclipnum = 0;
	bresult = m_sequence_ptr->TranslateSectionRange(startpos, endpos, &startclipnum, &endclipnum);
	if (!bresult)
		return -1;

	printf("section %d - %d data request...\n", startclipnum, endclipnum);

	NPT_LOG_FATAL_2("section %d - %d data request...\n", startclipnum, endclipnum);

	SectionDataInfo startsectioninfo;
	m_sequence_ptr->getSectionDataInfoByIndex(startclipnum, &startsectioninfo);

	SectionDataInfo endsectioninfo;
	m_sequence_ptr->getSectionDataInfoByIndex(endclipnum, &endsectioninfo);

	ClipOfRangeInfo sClipInfo;
	m_sequence_ptr->getSectionInfoByIndex(startclipnum, &sClipInfo);

	//for switch
	m_eResoureType = eTryResoure;

	if (m_eResoureType == P2P_Local_RequestSource)
	{
		SHVideoInfo* video = m_info_ptr;

		unsigned int index = startclipnum;
		CString strUrl;
		CString strUid;
		strUid.Format(_T("%s_%d"),GetUuid().c_str(), index);

		SHVideoRequestParam param;
		param.index		= index;
		param.start			= 0;
		param.startpos	= sClipInfo.StartOffset;
		param.dnum		= index;
		param.pnum		= index;
		param.ptime		= 0;
		param.dtime		= 100000;
		param.cdnNum   = 1;
		param.shdtype   = SHDType_ClientPlay;

		int cdnNum = param.cdnNum > 0 ? param.cdnNum : video->tn;
		strUrl.Format(_T("http://127.0.0.1:8828/%s/%s?start=%d&vid=%d&hashid=%s&key=%s&num=%d&pnum=%d")
			_T("&dnum=%d&ptime=%d&dtime=%d&p2pflag=%d&size=%d&cdn=%d&new=%s&fname=%s&startpos=%d&r=%d&shdtype=%d&duration=%d&rld=%d&uid=%s&rip=%s")
			_T("&plat=%s&ch=%s&catcode=%s"),
			video->allot,video->sections[param.index].url,param.start,video->vid,video->sections[param.index].hashId,
			video->sections[param.index].key,param.index,param.pnum,param.dnum,param.ptime,param.dtime,param.p2pflag,
			video->sections[param.index].size,cdnNum,video->sections[param.index].newAddress,video->name,param.startpos,
			GetTickCount(),param.shdtype,param.duration,param.reportLocalData,strUid,video->reserveIp,
			_T("ifox"),video->ch,video->catcode);

		printf("Index %d: Range [%d-]\n", index, sClipInfo.StartOffset);

		NPT_LOG_FATAL_2("Index %d: Range [%d-]\n", index, sClipInfo.StartOffset);

		USES_CONVERSION;
		const char* pRequest = W2A((LPCTSTR)strUrl);
		CMultiRequest data_client(Response_Partial_DataType);
		bresult = data_client.AddRequest(pRequest, startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - sClipInfo.StartOffset,
			cb, data_progresscb, NULL, customparam);
		if (!bresult)
			return -1;

		CURLcode resultcode = data_client.Perform();
		if (resultcode > CURLE_OK)
		{
// 			if (resultcode == CURLE_COULDNT_CONNECT)
// 			{
// 				data_client.Done();
// 				printf("p2p request timeout, try to connect cdn directly!\n");
// 
// 				NPT_LOG_FATAL("p2p request timeout, try to connect cdn directly!\n");
// 				goto cdn_lable;
// 			}
// 			else if (resultcode == CURLE_RECV_ERROR)
// 			{
// 				printf("p2p request forbidden, try to connect cdn directly!\n");
// 				data_client.Done();
// 
// 				NPT_LOG_FATAL("p2p request forbidden, try to connect cdn directly!\n");
// 				goto cdn_lable;
// 			}
// 			else
// 			{
// 				NPT_LOG_FATAL("not p2p not cdn request!!\n");
// 				return -1;
// 			}

			NPT_LOG_FATAL("p2p request failed, try to connect cdn directly!\n");
			data_client.Done();
			goto cdn_lable;
		}

		unsigned int response_data_size = data_client.GetResponseDataSizeByIndex(0);
		if (response_data_size > 0)
		{		
			assert(response_data_size <= (startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - sClipInfo.StartOffset));
		}

		for (_uint32_t j = startclipnum + 1; j <= endclipnum; j++)
		{
			SectionDataInfo sectioninfo;
			m_sequence_ptr->getSectionDataInfoByIndex(j, &sectioninfo);

			index = j;
			strUid.Format(_T("%s_%d"),GetUuid().c_str(), index);

			param.index		= index;
			param.startpos	= sectioninfo.ui32DataOffset;
			param.dnum		= index;
			param.pnum		= index;

			cdnNum = param.cdnNum > 0 ? param.cdnNum : video->tn;
			strUrl.Format(_T("http://127.0.0.1:8828/%s/%s?start=%d&vid=%d&hashid=%s&key=%s&num=%d&pnum=%d")
				_T("&dnum=%d&ptime=%d&dtime=%d&p2pflag=%d&size=%d&cdn=%d&new=%s&fname=%s&startpos=%d&r=%d&shdtype=%d&duration=%d&rld=%d&uid=%s&rip=%s")
				_T("&plat=%s&ch=%s&catcode=%s"),
				video->allot,video->sections[param.index].url,param.start,video->vid,video->sections[param.index].hashId,
				video->sections[param.index].key,param.index,param.pnum,param.dnum,param.ptime,param.dtime,param.p2pflag,
				video->sections[param.index].size,cdnNum,video->sections[param.index].newAddress,video->name,param.startpos,
				GetTickCount(),param.shdtype,param.duration,param.reportLocalData,strUid,video->reserveIp,
				_T("ifox"),video->ch,video->catcode);

			printf("Index %d: Range [%d-]\n", index, sectioninfo.ui32DataOffset);

			NPT_LOG_FATAL_2("Index %d: Range [%d-]\n", index, sectioninfo.ui32DataOffset);

			pRequest = W2A((LPCTSTR)strUrl);
			CMultiRequest data_client_ex(Response_Partial_DataType);
			bresult = data_client_ex.AddRequest(pRequest, sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - sectioninfo.ui32DataOffset,
				cb, data_progresscb, NULL, customparam);
			if (!bresult)
			{
				NPT_LOG_FATAL_2("Index %d: Range [%d-] failed\n", index, sectioninfo.ui32DataOffset);
				return -1;
			}

			NPT_LOG_FATAL_2("Index %d: Range [%d-] success\n", index, sectioninfo.ui32DataOffset);

			resultcode = data_client_ex.Perform();
			if (resultcode > CURLE_OK)
			{
// 				if (resultcode == CURLE_COULDNT_CONNECT)
// 				{
// 					data_client.Done();
// 					printf("p2p request timeout, try to connect cdn directly!\n");
// 
// 					startclipnum = j;
// 
// 					NPT_LOG_FATAL("p2p request timeout, try to connect cdn directly!\n");
// 					goto cdn_lable;
// 				}
// 				else if (resultcode == CURLE_RECV_ERROR)
// 				{
// 					printf("p2p request forbidden, try to connect cdn directly!\n");
// 					data_client.Done();
// 
// 					startclipnum = j;
// 
// 					NPT_LOG_FATAL("p2p request forbidden, try to connect cdn directly!\n");
// 					goto cdn_lable;
// 				}
// 				else
// 					return -1;
				NPT_LOG_FATAL("p2p request failed, try to connect cdn directly!\n");
				data_client.Done();
				startclipnum = j;
				goto cdn_lable;
			}

			unsigned int response_data_size_ex = data_client_ex.GetResponseDataSizeByIndex(0);
			assert(response_data_size_ex <= (sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - sectioninfo.ui32DataOffset));
		}
	}
	else
	{
cdn_lable:
		m_eResoureType = CDN_Remote_RequestSource;

		wostringstream stream;
		stream<<L"http://"<<(LPCTSTR)(*m_cdnInfolist_ptr)[startclipnum].ip.c_str()<<(LPCTSTR)(*m_cdnInfolist_ptr)[startclipnum].url.c_str()<<"?key="<<(LPCTSTR)(*m_cdnInfolist_ptr)[startclipnum].key.c_str()<<"plat=ifox"<<
			"&ch="<<(LPCTSTR)m_info_ptr->ch<<"&catcode="<<(LPCTSTR)m_info_ptr->catcode<<"&start=0"<<"&rs=1";

		wstring wstream = stream.str();

		CMultiRequest data_client(Response_Partial_DataType);

		vector<pair<CURLoption, const char*> > vDataHeader;
		char strRange[100];
		sprintf(strRange, "Range:bytes=%d-%d", sClipInfo.StartOffset, startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - 1);
		printf("Index %d: Range [%d-%d]\n", startclipnum, sClipInfo.StartOffset, startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - 1);
		NPT_LOG_FATAL_3("Index %d: Range [%d-%d]\n", startclipnum, sClipInfo.StartOffset, startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - 1);
		
		vDataHeader.push_back(pair<CURLoption, const char*>(CURLOPT_HTTPHEADER, strRange));

		USES_CONVERSION;
		const char* pRequest = W2A((LPCTSTR)wstream.c_str());
		bresult = data_client.AddRequest(pRequest, startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - sClipInfo.StartOffset,
			cb, data_progresscb, &vDataHeader, customparam);
		if (!bresult)
			return -1;

		CURLcode resultcode = data_client.Perform();
		if (resultcode > CURLE_OK)
			return -1;

		unsigned int response_data_size = data_client.GetResponseDataSizeByIndex(0);
		assert(response_data_size <= (startsectioninfo.ui32DataOffset + startsectioninfo.ui32DataSize - sClipInfo.StartOffset));

		for (_uint32_t j = startclipnum + 1; j <= endclipnum; j++)
		{
			SectionDataInfo sectioninfo;
			m_sequence_ptr->getSectionDataInfoByIndex(j, &sectioninfo);

			wostringstream stream;
			stream<<L"http://"<<(LPCTSTR)(*m_cdnInfolist_ptr)[j].ip.c_str()<<(LPCTSTR)(*m_cdnInfolist_ptr)[j].url.c_str()<<"?key="<<(LPCTSTR)(*m_cdnInfolist_ptr)[j].key.c_str()<<"plat=ifox"<<
				"&ch="<<(LPCTSTR)m_info_ptr->ch<<"&catcode="<<(LPCTSTR)m_info_ptr->catcode<<"&start=0"<<"&rs=1";

			wstring wstream = stream.str();

			CMultiRequest data_client_ex(Response_Partial_DataType);

			char strRange[100];
			sprintf(strRange, "Range:bytes=%d-%d", sectioninfo.ui32DataOffset, sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - 1);
			printf("Index %d: Range [%d-%d]\n", j, sectioninfo.ui32DataOffset, sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - 1);

			NPT_LOG_FATAL_3("Index %d: Range [%d-%d]\n", j, sectioninfo.ui32DataOffset, sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - 1);
			vDataHeader.push_back(pair<CURLoption, const char*>(CURLOPT_HTTPHEADER, strRange));

			USES_CONVERSION;
			const char* pRequest = W2A((LPCTSTR)wstream.c_str());
			bool bresult = data_client_ex.AddRequest(pRequest, sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - sectioninfo.ui32DataOffset,
				cb, data_progresscb, &vDataHeader, customparam);
			if (!bresult)
				return -1;

			resultcode = data_client_ex.Perform();
			if (resultcode > CURLE_OK)
				return -1;

			unsigned int response_data_size_ex = data_client_ex.GetResponseDataSizeByIndex(0);
			if (response_data_size_ex > 0)
				assert(response_data_size_ex <= (sectioninfo.ui32DataOffset + sectioninfo.ui32DataSize - sectioninfo.ui32DataOffset));
			else
				return -1;
		}
	}

	if (pactualfinishpos)
		*pactualfinishpos = endsectioninfo.ui32AbsoluteDataOffset + endsectioninfo.ui32DataSize;

	return 0;
}