<commit_before>/////////////////////////////////////////
//
//             OpenLieroX
//
//   work by JasonB
//   code under LGPL
//   enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Network Channel class
// Created 16/6/01
// <NAME>

#include <iostream>

#include "LieroX.h"
#include "CChannel.h"
#include "StringUtils.h"
#include "Timer.h"

using namespace std;

// default max size for UDP packets for windows is 1280
// only a size of 512 is guaranteed
#define MAX_PACKET_SIZE 512
#define RELIABLE_HEADER_LEN 8

///////////////////
// Setup the channel
void CChannel::Create(NetworkAddr *_adr, int _port, NetworkSocket _sock)
{
	RemoteAddr = *_adr;
	iPort = _port;
	fLastPckRecvd = tLX->fCurTime;
	Socket = _sock;
	Reliable.Clear();
	Messages.clear();
	iPacketsDropped=0;
	iPacketsGood=0;
	fLastSent = tLX->fCurTime-1;
	fLastPingSent = fLastSent;
	fIncomingClearTime = -9999;
	fOutgoingClearTime = -9999;
	fIncomingRate = 0;
	fOutgoingRate = 0;
	iCurrentIncomingBytes = 0;
	iCurrentOutgoingBytes = 0;
	iPongSequence = -1;
	iPing = 0;
	bNewReliablePacket = false;

	// Clear the sequences
	iIncomingSequence = 0;
	iIncomingAcknowledged = 0;
	iIncoming_ReliableAcknowledged = 0;
	iIncoming_ReliableSequence = 0;
	iOutgoingSequence = 0;
	iReliableSequence = 0;
	iLast_ReliableSequence = 0;
	iOutgoingBytes = 0;
	iIncomingBytes = 0;
}


////////////////////
// Adds a packet to reliable queue
void CChannel::AddReliablePacketToSend(CBytestream& bs)
{
	if (bs.GetLength() > MAX_PACKET_SIZE - RELIABLE_HEADER_LEN)  {
		printf("ERROR: trying to send a reliable packet of size " + itoa(bs.GetLength()) + 
			" which is bigger than allowed size (" + itoa(MAX_PACKET_SIZE - RELIABLE_HEADER_LEN) + 
			"), packet might not be sent at all!\n");
		Messages.push_back(bs); // Try to send it anyway, perhaps we're lucky...
		return;
	}

	// If no messages at all, add the first one
	if (Messages.size() == 0)  {
		Messages.push_back(bs);
		return;
	}

	// Some reliable messages already in queue, see if we should already split the packet
	if (bs.GetLength() + (Messages.rbegin()->GetLength()) > MAX_PACKET_SIZE)
		Messages.push_back(bs);
	else
		Messages.rbegin()->Append(&bs);
}<commit_msg>small cleanup<commit_after>/////////////////////////////////////////
//
//             OpenLieroX
//
//   work by JasonB
//   code under LGPL
//   enhanced by <NAME> and <NAME>
//
//
/////////////////////////////////////////


// Network Channel class
// Created 16/6/01
// <NAME>

#include <iostream>

#include "LieroX.h"
#include "CChannel.h"
#include "StringUtils.h"
#include "Timer.h"

using namespace std;

// default max size for UDP packets for windows is 1280
// only a size of 512 is guaranteed
#define MAX_PACKET_SIZE 512
#define RELIABLE_HEADER_LEN 8

///////////////////
// Setup the channel
void CChannel::Create(NetworkAddr *_adr, int _port, NetworkSocket _sock)
{
	RemoteAddr = *_adr;
	iPort = _port;
	fLastPckRecvd = tLX->fCurTime;
	Socket = _sock;
	Reliable.Clear();
	Messages.clear();
	iPacketsDropped=0;
	iPacketsGood=0;
	fLastSent = tLX->fCurTime-1;
	fLastPingSent = fLastSent;
	fIncomingClearTime = -9999;
	fOutgoingClearTime = -9999;
	fIncomingRate = 0;
	fOutgoingRate = 0;
	iCurrentIncomingBytes = 0;
	iCurrentOutgoingBytes = 0;
	iPongSequence = -1;
	iPing = 0;
	bNewReliablePacket = false;

	// Clear the sequences
	iIncomingSequence = 0;
	iIncomingAcknowledged = 0;
	iIncoming_ReliableAcknowledged = 0;
	iIncoming_ReliableSequence = 0;
	iOutgoingSequence = 0;
	iReliableSequence = 0;
	iLast_ReliableSequence = 0;
	iOutgoingBytes = 0;
	iIncomingBytes = 0;
}


////////////////////
// Adds a packet to reliable queue
void CChannel::AddReliablePacketToSend(CBytestream& bs)
{
	if (bs.GetLength() > MAX_PACKET_SIZE - RELIABLE_HEADER_LEN)  {
		cout
			<< "ERROR: trying to send a reliable packet of size " << bs.GetLength() 
			<< " which is bigger than allowed size (" << (MAX_PACKET_SIZE - RELIABLE_HEADER_LEN)
			<< "), packet might not be sent at all!" << endl;
		Messages.push_back(bs); // Try to send it anyway, perhaps we're lucky...
		return;
	}

	// If no messages at all, add the first one
	if (Messages.size() == 0)  {
		Messages.push_back(bs);
		return;
	}

	// Some reliable messages already in queue, see if we should already split the packet
	if (bs.GetLength() + (Messages.rbegin()->GetLength()) > MAX_PACKET_SIZE)
		Messages.push_back(bs);
	else
		Messages.rbegin()->Append(&bs);
}
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.019395579612088407, 'mean_word_length': 2.999098286744815, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '626646', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1513, 'n_words': 409}