Beispiel #1
0
	void ExpectFull(const unsigned char *pOutput, int OutputSize)
	{
		const ::testing::TestInfo *pTestInfo =
			::testing::UnitTest::GetInstance()->current_test_info();
		const char *pTestName = pTestInfo->name();

		if(m_Buffer.Error()
			|| m_Buffer.Size() != OutputSize
			|| mem_comp(m_Buffer.Data(), pOutput, OutputSize) != 0)
		{
			char aFilename[64];
			IOHANDLE File;

			str_format(aFilename, sizeof(aFilename), "%sGot.teehistorian", pTestName);
			File = io_open(aFilename, IOFLAG_WRITE);
			ASSERT_TRUE(File);
			io_write(File, m_Buffer.Data(), m_Buffer.Size());
			io_close(File);

			str_format(aFilename, sizeof(aFilename), "%sExpected.teehistorian", pTestName);
			File = io_open(aFilename, IOFLAG_WRITE);
			ASSERT_TRUE(File);
			io_write(File, pOutput, OutputSize);
			io_close(File);
		}

		ASSERT_FALSE(m_Buffer.Error());
		ASSERT_EQ(m_Buffer.Size(), OutputSize);
		ASSERT_TRUE(mem_comp(m_Buffer.Data(), pOutput, OutputSize) == 0);
	}
Beispiel #2
0
void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry)
{
	if(g_Config.m_Debug)
	{
		char aAddrStr[NETADDR_MAXSTRSIZE];
		net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
		char aBuf[256];
		str_format(aBuf, sizeof(aBuf),"requesting server info from %s", aAddrStr);
		m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
	}

	CPacker Packer;
	Packer.Reset();
	Packer.AddRaw(SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
	Packer.AddInt(pEntry ? pEntry->m_CurrentToken : m_CurrentLanToken);

	CNetChunk Packet;
	Packet.m_ClientID = -1;
	Packet.m_Address = Addr;
	Packet.m_Flags = NETSENDFLAG_CONNLESS;
	Packet.m_DataSize = Packer.Size();
	Packet.m_pData = Packer.Data();
	CSendCBData Data;
	Data.m_pfnCallback = CBFTrackPacket;
	Data.m_pCallbackUser = this;
	m_pNetClient->Send(&Packet, NET_TOKEN_NONE, &Data);
	pEntry->m_TrackID = Data.m_TrackID;

	if(pEntry)
	{
		pEntry->m_RequestTime = time_get();
		pEntry->m_InfoState = CServerEntry::STATE_PENDING;
	}
}
Beispiel #3
0
void CServerBrowser::Refresh(int RefreshFlags)
{
	m_RefreshFlags = RefreshFlags;

	if(RefreshFlags&IServerBrowser::REFRESHFLAG_LAN)
	{
		// clear out everything
		m_aServerlist[IServerBrowser::TYPE_LAN].Clear();
		if(m_ActServerlistType == IServerBrowser::TYPE_LAN)
			m_ServerBrowserFilter.Clear();

		// next token
		m_CurrentLanToken = GetNewToken();

		CPacker Packer;
		Packer.Reset();
		Packer.AddRaw(SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO));
		Packer.AddInt(m_CurrentLanToken);

		/* do the broadcast version */
		CNetChunk Packet;
		mem_zero(&Packet, sizeof(Packet));
		Packet.m_Address.type = m_pNetClient->NetType()|NETTYPE_LINK_BROADCAST;
		Packet.m_ClientID = -1;
		Packet.m_Flags = NETSENDFLAG_CONNLESS;
		Packet.m_DataSize = Packer.Size();
		Packet.m_pData = Packer.Data();
		m_BroadcastTime = time_get();

		for(int i = 8303; i <= 8310; i++)
		{
			Packet.m_Address.port = i;
			m_pNetClient->Send(&Packet);
		}

		if(g_Config.m_Debug)
			m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", "broadcasting for servers");
	}

	if(RefreshFlags&IServerBrowser::REFRESHFLAG_INTERNET)
	{
		// clear out everything
		for(CServerEntry *pEntry = m_pFirstReqServer; pEntry; pEntry = pEntry->m_pNextReq)
		{
			m_pNetClient->PurgeStoredPacket(pEntry->m_TrackID);
		}
		m_aServerlist[IServerBrowser::TYPE_INTERNET].Clear();
		if(m_ActServerlistType == IServerBrowser::TYPE_INTERNET)
			m_ServerBrowserFilter.Clear();
		m_pFirstReqServer = 0;
		m_pLastReqServer = 0;
		m_NumRequests = 0;

		m_NeedRefresh = 1;
		for(int i = 0; i < m_ServerBrowserFavorites.m_NumFavoriteServers; i++)
			if(m_ServerBrowserFavorites.m_aFavoriteServers[i].m_State >= CServerBrowserFavorites::FAVSTATE_ADDR)
				Set(m_ServerBrowserFavorites.m_aFavoriteServers[i].m_Addr, SET_FAV_ADD, -1, 0);
	}
}
Beispiel #4
0
void SendMessage( IPlugWay *way , int n , CPackFactory &factory)
{
    CPacker pack ;
    switch( n )
    {
    case 0:
    {
        CQueryCarDataReq req ;
        req._srcarea  = 10000 ;
        req._destarea = 10001 ;
        strtoBCD( "201206061428", (char*)req._time ) ;
        req._offset   = 0 ;
        req._count    = 10 ;
        factory.Pack( &req, pack ) ;
    }
    break ;
    case 1:
    {
        CSendScheduleRsp rsp ;
        rsp._result = 0 ;
        factory.Pack( &rsp, pack ) ;
    }
    break ;
    case 2:
    {
        CQueryScheduleReq req ;
        req._num = 10 ;
        factory.Pack( &req, pack ) ;
    }
    break ;
    case 3:
    {
        CUploadScheduleReq req ;
        safe_memncpy( (char*)req._scheduleid, "1", sizeof(req._scheduleid) ) ;
        req._matchstate = 0 ; 		//  UINT8	匹配状态(0成功,1失败)
        safe_memncpy( (char*)req._hangid, "1", sizeof(req._hangid));		//	String	挂车ID
        safe_memncpy( (char*)req._hangnum , "1", sizeof(req._hangnum));		//	String	挂车车牌号
        safe_memncpy( (char*)req._mtime , "201266" , sizeof(req._mtime)) ;			//  String	匹配时间
        req._info._alam  = 0 ;		//	4	UINT32	报警标志位
        req._info._state = 0 ;	//	4	UINT32	状态位
        req._info._lon   = 0 ;		//  4	UINT32	经度
        req._info._lat	 = 0 ;		//	4	UINT32	纬度
        req._info._height= 0 ;	//	2	UINT16	高程
        req._info._speed = 0 ;	//	2	UINT16	速度
        req._info._direction = 0 ;//	2	UINT16	方向
        safe_memncpy( (char*)req._info._time , "201266" , sizeof(req._info._time)) ;
        factory.Pack( &req, pack ) ;
    }
    break ;
    case 4:
    {
        CStateScheduleReq req ;

        safe_memncpy( (char*)req._scheduleid, "1", sizeof(req._scheduleid) ) ;
        req._action = 0 ; 		//  UINT8	匹配状态(0成功,1失败)
        safe_memncpy( (char*)req._hangid, "1", sizeof(req._hangid));		//	String	挂车ID
        safe_memncpy( (char*)req._hangnum , "1", sizeof(req._hangnum));		//	String	挂车车牌号

        req._info._alam  = 0 ;		//	4	UINT32	报警标志位
        req._info._state = 0 ;	//	4	UINT32	状态位
        req._info._lon   = 0 ;		//  4	UINT32	经度
        req._info._lat	 = 0 ;		//	4	UINT32	纬度
        req._info._height= 0 ;	//	2	UINT16	高程
        req._info._speed = 0 ;	//	2	UINT16	速度
        req._info._direction = 0 ;//	2	UINT16	方向
        safe_memncpy( (char*)req._info._time , "201266" , sizeof(req._info._time));

        factory.Pack( &req, pack);
    }
    break ;
    case 5:
    {
        CAlarmScheduleReq req ;
        safe_memncpy( (char*)req._scheduleid, "1", sizeof(req._scheduleid) ) ;
        req._alarmtype = 0 ; 		//  UINT8	匹配状态(0成功,1失败)
        safe_memncpy( (char*)req._hangid, "1", sizeof(req._hangid));		//	String	挂车ID
        safe_memncpy( (char*)req._hangnum , "1", sizeof(req._hangnum));		//	String	挂车车牌号

        req._info._alam  = 0 ;		//	4	UINT32	报警标志位
        req._info._state = 0 ;	//	4	UINT32	状态位
        req._info._lon   = 0 ;		//  4	UINT32	经度
        req._info._lat	 = 0 ;		//	4	UINT32	纬度
        req._info._height= 0 ;	//	2	UINT16	高程
        req._info._speed = 0 ;	//	2	UINT16	速度
        req._info._direction = 0 ;//	2	UINT16	方向
        safe_memncpy( (char*)req._info._time , "201266" , sizeof(req._info._time)) ;
        factory.Pack( &req, pack ) ;
    }
    break ;
    case 6:
    {
        CUpMsgDataScheduleReq req;
        req._code = 1;
        req._data = "1234567";
        factory.Pack( &req, pack);
    }
    break;
    case 7:
    {
        CAutoDataScheduleReq req;
        req._space = 1 ;
        req._state = 1 ;
        factory.Pack( &req, pack ) ;
    }
    break;
    case 8:
    {
        CErrorScheduleReq req;
        req._code = 1 ;
        req._desc = "bad message" ;
        factory.Pack(&req, pack);
    }
    break;
    case 9:
    {
        CQueryInfoReq req;
        req._ctype  = CQueryInfoReq::Area ;
        req._area_id = 1 ;
        factory.Pack(&req, pack);
    }
    break;
    case 10:
    {
        CResultScheduleReq req ;
        safe_memncpy( (char*)req._scheduleid, "1", sizeof(req._scheduleid) ) ;
        req._result = 0 ;
        factory.Pack( &req, pack ) ;
    }
    break ;
    case 11:
    {

    }
    break ;
    }

    way->Process( 1, pack.getBuffer(),pack.getLength(),0x1001, "4C54_15001088478");
    pack.resetBuf();
}
Beispiel #5
0
	void Expect(const unsigned char *pOutput, int OutputSize)
	{
		static CUuid TEEHISTORIAN_UUID = CalculateUuid("*****@*****.**");
		static const char PREFIX1[] = "{\"comment\":\"[email protected]\",\"version\":\"2\",\"game_uuid\":\"a1eb7182-796e-3b3e-941d-38ca71b2a4a8\",\"server_version\":\"DDNet test\",\"start_time\":\"";
		static const char PREFIX2[] = "\",\"server_name\":\"server name\",\"server_port\":\"8303\",\"game_type\":\"game type\",\"map_name\":\"Kobra 3 Solo\",\"map_size\":\"903514\",\"map_sha256\":\"0123456789012345678901234567890123456789012345678901234567890123\",\"map_crc\":\"eceaf25c\",\"config\":{},\"tuning\":{},\"uuids\":[";
		static const char PREFIX3[] = "]}";

		char aTimeBuf[64];
		str_timestamp_ex(m_GameInfo.m_StartTime, aTimeBuf, sizeof(aTimeBuf), "%Y-%m-%dT%H:%M:%S%z");

		CPacker Buffer;
		Buffer.Reset();
		Buffer.AddRaw(&TEEHISTORIAN_UUID, sizeof(TEEHISTORIAN_UUID));
		Buffer.AddRaw(PREFIX1, str_length(PREFIX1));
		Buffer.AddRaw(aTimeBuf, str_length(aTimeBuf));
		Buffer.AddRaw(PREFIX2, str_length(PREFIX2));
		for(int i = 0; i < m_UuidManager.NumUuids(); i++)
		{
			char aBuf[64];
			str_format(aBuf, sizeof(aBuf), "%s\"%s\"",
				i == 0 ? "" : ",",
				m_UuidManager.GetName(OFFSET_UUID + i));
			Buffer.AddRaw(aBuf, str_length(aBuf));
		}
		Buffer.AddRaw(PREFIX3, str_length(PREFIX3));
		Buffer.AddRaw("", 1);
		Buffer.AddRaw(pOutput, OutputSize);

		ASSERT_FALSE(Buffer.Error());

		ExpectFull(Buffer.Data(), Buffer.Size());
	}
Beispiel #6
0
	void Reset(const CTeeHistorian::CGameInfo *pGameInfo)
	{
		m_Buffer.Reset();
		m_TH.Reset(pGameInfo, Write, this);
		m_State = STATE_NONE;
	}
Beispiel #7
0
void CTcpView::OnLvnItemchangedEntrust(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	// TODO: Add your control notification handler code here
	POSITION pos = m_lsEntrust.GetFirstSelectedItemPosition();
	if (pos != NULL)
	{
		int nCurSel = m_lsEntrust.GetNextSelectedItem(pos);
		if (m_nLastIndex != nCurSel)
		{
			m_trData.DeleteAllItems();
			CTradePackData* pData = m_TradePackDataList.GetAt(nCurSel);
			CPacker Packer;
			if (Packer.ParseData(pData->m_pBuf, pData->m_nLen))
			{
				HTREEITEM hHeader = m_trData.InsertItem("Header");
				CString str;
				str.Format("phAction:%d", Packer.GetHeader(phAction));
				m_trData.InsertItem(str, hHeader);
				str.Format("phCellIndex:%d", Packer.GetHeader(phCellIndex));
				m_trData.InsertItem(str, hHeader);
				str.Format("phOnlineID:%d", Packer.GetHeader(phOnlineID));
				m_trData.InsertItem(str, hHeader);
				str.Format("phOnlineToken:%d", Packer.GetHeader(phOnlineToken));
				m_trData.InsertItem(str, hHeader);
				str.Format("phClientAddr:%d", Packer.GetHeader(phClientAddr));
				m_trData.InsertItem(str, hHeader);
				str.Format("phReturnCode:%d", Packer.GetHeader(phReturnCode));
				m_trData.InsertItem(str, hHeader);
				str.Format("phSenderID:%d", Packer.GetHeader(phSenderID));
				m_trData.InsertItem(str, hHeader);
				m_trData.Expand(hHeader, TVE_EXPAND);
				HTREEITEM hNVPack = m_trData.InsertItem("NVPack");
				for (int i = 0; i < Packer.GetNVCount(); i++)
				{
					int iType;
					CString sName;
					sName = Packer.GetNVNameByIndex(i, iType);
					if (ptNV == (EPacketType)iType)
					{
						str = sName + ":" + Packer.GetStr(sName);
						m_trData.InsertItem(str, hNVPack);
					}					
				}
				m_trData.Expand(hNVPack, TVE_EXPAND);
				HTREEITEM hArPack = m_trData.InsertItem("ArPack");
				int iDataLen = 0;	
				CString sName = "";
				if (0 == pData->m_nType)
				{
					sName = Packer.GetStr(S_BIN_REQ);
					if (sName.IsEmpty())
					{
						sName = S_BIN_DATA;
					}
				}
				else
				{
					sName = Packer.GetStr(S_BIN_ANS);
					if (sName.IsEmpty())
					{
						sName = S_BIN_DATA_ANS;
					}
				}
				
				char* pAr1Buf = NULL;
				pAr1Buf = Packer.GetData(sName.MakeLower(), iDataLen);
				if (iDataLen > 0)
				{
					CAr1UnPacker Ar1UnPacker;
					if (Ar1UnPacker.open(pAr1Buf, iDataLen))
					{
						HTREEITEM hArHeader = m_trData.InsertItem(sName, hArPack);
						AR1PacketHeader* pAR1PacketHeader = Ar1UnPacker.GetHeader();
						str.Format("HeaderVersion:%d", pAR1PacketHeader->HeaderVersion);
						m_trData.InsertItem(str, hArHeader);
						str.Format("PacketType:%d", pAR1PacketHeader->PacketType);
						m_trData.InsertItem(str, hArHeader);
						str.Format("Branch:%d", pAR1PacketHeader->Branch);
						m_trData.InsertItem(str, hArHeader);
						str.Format("FunctionNo:%d", pAR1PacketHeader->FunctionNo);
						m_trData.InsertItem(str, hArHeader);
						str.Format("SenderID:%d", pAR1PacketHeader->SenderID);
						m_trData.InsertItem(str, hArHeader);
						str.Format("AddressLevel:%d", pAR1PacketHeader->AddressLevel);
						m_trData.InsertItem(str, hArHeader);
						str.Format("DataLength:%d", pAR1PacketHeader->DataLength);
						m_trData.InsertItem(str, hArHeader);
						str.Format("ReturnCode:%d", pAR1PacketHeader->ReturnCode);
						m_trData.InsertItem(str, hArHeader);
						m_trData.Expand(hArHeader, TVE_EXPAND);
						HTREEITEM hSections = m_trData.InsertItem("Sections:0", hArHeader);
						str.Format("RecordCount:%d;FieldCount:%d", Ar1UnPacker.GetRowCount(), Ar1UnPacker.GetColCount());
						m_trData.InsertItem(str, hSections);
						m_trData.Expand(hSections, TVE_EXPAND);
						while(!Ar1UnPacker.isEof())
						{
							HTREEITEM hRecord = m_trData.InsertItem("Record", hSections);
							CMapStringToString* lpAr1Item = Ar1UnPacker.GetItem();
							if (lpAr1Item)
							{
								POSITION ipos = lpAr1Item->GetStartPosition();
								while(ipos)
								{
									CString sKey = "";
									CString sValue = "";
									lpAr1Item->GetNextAssoc(ipos,sKey,sValue);
									str.Format("%s:%s", sKey, sValue);
									m_trData.InsertItem(str, hRecord);
								}
							}		
							Ar1UnPacker.Next();
							m_trData.Expand(hRecord, TVE_EXPAND);
						}						
					}
					delete[] pAr1Buf;
				}
				m_trData.Expand(hArPack, TVE_EXPAND);
			}					
			m_nLastIndex = nCurSel;
		}
	}
	*pResult = 0;
}