Ejemplo n.º 1
0
oexBOOL CDataPacket::VerifyPacket()
{
	// Do we already know there is a valid packet?
	if ( m_bValidPacket ) 
        return oexTRUE;

	oexUINT uAvailable = 0;

	do
	{
		// Attempt to find a packet in the buffer
		if ( !FindPacket( &m_ph, &uAvailable ) )
			return oexFALSE;

		// Verify the length of the packet is available
		if ( m_ph.dwLength > uAvailable ) 
            return oexFALSE;

		// Enforce maximum packet size
		if ( m_ph.dwLength <= GetMaxSize() )
		{
			oexUCHAR    *pBuf = oexNULL;
			oexUINT     uSize = 0, uView = 0;

			// Initialize the check sum
			oexGUID csCur, csBuf;
            oss::CMd5 md5;

			// Calculate the md5 hash
			while ( GetReadView( uView++, 0, m_ph.dwLength - sizeof( oexGUID ), &pBuf, &uSize ) )

				// Update the md5 hash
				md5.Update( pBuf, uSize );

			// What is our calculated checksum?
            md5.Final( &csCur );

			// Read the checksum from the buffer
			Peek( &csBuf, sizeof( csBuf ), oexNULL, m_ph.dwLength - sizeof( oexGUID ) );

			// Do the checksums match?
            if ( guid::CmpGuid( &csCur, &csBuf ) )
			{	m_bValidPacket = oexTRUE;
				return oexTRUE;
			} // end if

		} // end if

	// Skip over the id
	} while ( AdvanceReadPtr( 4 ) );

	return oexFALSE;
}
void CServerKillCamForwarder::Update()
{
	CTimeValue now=gEnv->pTimer->GetCurrTime();
	const float k_timeout=2.0f;
	if (!m_forwarding.empty())
	{
		int maxCycles=m_forwarding.size();
		bool bSent=false;
		do 
		{
			SForwardingPacket &forward=m_forwarding.front();
			CActor::KillCamFPData* packet=FindPacket(forward.iterator, forward.pActor, forward.packetID);
			if (packet)
			{
				ForwardPacket(forward, packet);
				bSent=true;
				if (forward.m_sent>=forward.m_numPackets)
					m_forwarding.pop_front();
			}
			else
			{
				if (forward.m_sent!=forward.m_numPackets)
				{
					CryLog("Underflowed forwarding packetID %d from actor %s after sending %d packets\n", forward.packetID, forward.pActor->GetEntity()->GetName(), forward.m_sent);
					if (forward.m_lastPacketTime.GetDifferenceInSeconds(now)>=k_timeout)
					{
						CryLog("Underflowing packet timed out, did the client disconnect? Giving up :(\n");
					}
					else
					{
						// Re-add to the end of the list for trying later (forward packet can arrive before all source packets have arrived)
						m_forwarding.push_back(forward);
					}
				}
				m_forwarding.pop_front();
				maxCycles--;
			}
		} while (!bSent && maxCycles>0);
	}
}