Ejemplo n.º 1
0
void CHLTVDemoRecorder::WriteMessages( unsigned char cmd, bf_write &message )
{
	int len = message.GetNumBytesWritten();

	if (len <= 0)
		return;

	// fill last bits in last byte with NOP if necessary
	int nRemainingBits = message.GetNumBitsWritten() % 8;
	if ( nRemainingBits > 0 &&  nRemainingBits <= (8-NETMSG_TYPE_BITS) )
	{
		message.WriteUBitLong( net_NOP, NETMSG_TYPE_BITS );
	}

	Assert( len < NET_MAX_MESSAGE );

	// if signondata read as fast as possible, no rewind
	// and wait for packet time
	// byte cmd = (m_pDemoFileHeader != NULL)  ? dem_signon : dem_packet;

	if ( cmd == dem_packet )
	{
		m_nFrameCount++;
	}

	// write command & time
	m_DemoFile.WriteCmdHeader( cmd, GetRecordingTick() ); 
	
	// write NULL democmdinfo just to keep same format as client demos
	democmdinfo_t info;
	Q_memset( &info, 0, sizeof( info ) );
	m_DemoFile.WriteCmdInfo( info );

	// write continously increasing sequence numbers
	m_DemoFile.WriteSequenceInfo( m_SequenceInfo, m_SequenceInfo );
	m_SequenceInfo++;
	
	// Output the buffer.  Skip the network packet stuff.
	m_DemoFile.WriteRawData( (char*)message.GetBasePointer(), len );
	
	if ( tv_debug.GetInt() > 1 )
	{
		Msg( "Writing SourceTV demo message %i bytes at file pos %i\n", len, m_DemoFile.GetCurPos( false ) );
	}
}
Ejemplo n.º 2
0
void GenerateLeyFile(const char *file, const char *txt)
{


	printf("OUTGOING: %i\n", netchan->m_nOutSequenceNr);


	int nCheckSumStart = senddata.GetNumBytesWritten();

	senddata.WriteUBitLong(netchan->m_nInReliableState, 3);//m_nInReliableState
	senddata.WriteOneBit(1);//subchannel
	senddata.WriteOneBit(1); // data follows( if 0 = singleblock )
	senddata.WriteUBitLong(0, MAX_FILE_SIZE_BITS - FRAGMENT_BITS);// startFragment
	senddata.WriteUBitLong(BYTES2FRAGMENTS(strlen(txt)), 3);//number of fragments
	senddata.WriteOneBit(1);//is it a file?

	senddata.WriteUBitLong(0xFF, 32);//transferid

	senddata.WriteString(file);//filename
	senddata.WriteOneBit(0);//compressed?
	senddata.WriteUBitLong(strlen(txt), MAX_FILE_SIZE_BITS);//number of bytes of the file
	senddata.WriteString(txt);

}
Ejemplo n.º 3
0
inline bool NET_SendDatagram(bool subchans = false)
{
	if (senddata.GetNumBytesWritten() == 0)
	{
		return false;
	}
	unsigned char flags = 0;

	netdatagram.WriteLong(netchan->m_nOutSequenceNr); // outgoing sequence
	netdatagram.WriteLong(netchan->m_nInSequenceNr); // incoming sequence

	bf_write flagpos = netdatagram;

	netdatagram.WriteByte(0); // flags
	netdatagram.WriteWord(0); // crc16

	int nCheckSumStart = netdatagram.GetNumBytesWritten();



	netdatagram.WriteByte(netchan->m_nInReliableState);


	if (subchans)
	{
		flags |= PACKET_FLAG_RELIABLE;
	}



	netdatagram.WriteBits(senddata.GetData(), senddata.GetNumBitsWritten()); // Data

	int nMinRoutablePayload = MIN_ROUTABLE_PAYLOAD;


	while ((netdatagram.GetNumBytesWritten() < MIN_ROUTABLE_PAYLOAD&&netdatagram.GetNumBitsWritten() % 8 != 0))
	{
		netdatagram.WriteUBitLong(0, NETMSG_TYPE_BITS);
	}

	flagpos.WriteByte(flags);

	void *pvData = datagram + nCheckSumStart;

	if (pvData)
	{


		int nCheckSumBytes = netdatagram.GetNumBytesWritten() - nCheckSumStart;
		if (nCheckSumBytes > 0)
		{

			unsigned short usCheckSum = BufferToShortChecksum(pvData, nCheckSumBytes);
			flagpos.WriteUBitLong(usCheckSum, 16);

			netchan->m_nOutSequenceNr++;

			net.SendTo(serverip, serverport, datagram, netdatagram.GetNumBytesWritten());
		}
	}

	NET_ResetDatagram();

	return true;
}