r5sdk/r5dev/engine/net_chan.cpp
Kawe Mazidjatari 6feb41c285 Partial CNetChan class rebuild and implementation (see description)
* Adapt codebase to new class to reduce rune-like code.
* Fixed several bugs where the global CClient pointer was used instead of the instance in question to issue bans and display information about a certain client in CBanSystem and Pylon.
* Upgraded CBanSystem and Pylon to use IPv6 instead (including IPv4 mapped IPv6 addresses). This breaks all existing banlist files! All bans have to be re-issued or the existing file has to be updated to use IPv4 mapped IPv6 addresses and renamed to 'banlist.json', and moved to the root of the 'platform' folder.
2022-04-02 02:48:54 +02:00

183 lines
5.8 KiB
C++

//=============================================================================//
//
// Purpose: Netchannel system utilities
//
//=============================================================================//
#include "core/stdafx.h"
#include "engine/net_chan.h"
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel name
// Output : const char*
//-----------------------------------------------------------------------------
const char* CNetChan::GetName(void) const
{
// [0x1A8D + 0x1] (first char in array is a null character!).
return this->m_Name + 1;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel address
// Output : const char*
//-----------------------------------------------------------------------------
const char* CNetChan::GetAddress(void) const
{
char szAdr[INET6_ADDRSTRLEN]{};
inet_ntop(AF_INET6, &this->remote_address.adr, szAdr, INET6_ADDRSTRLEN);
return szAdr;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel data rate
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetDataRate(void) const
{
return this->m_Rate;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel buffer size (NET_FRAMES_BACKUP)
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetBufferSize(void) const
{
return NET_FRAMES_BACKUP;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel latency
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetLatency(int flow) const
{
return this->m_DataFlow[flow].latency;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel average choke
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetAvgChoke(int flow) const
{
return this->m_DataFlow[flow].avgchoke;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel average latency
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetAvgLatency(int flow) const
{
return this->m_DataFlow[flow].avglatency;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel average loss
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetAvgLoss(int flow) const
{
return this->m_DataFlow[flow].avgloss;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel average packets
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetAvgPackets(int flow) const
{
return this->m_DataFlow[flow].avgpacketspersec;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel average data
// Input : flow -
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetAvgData(int flow) const
{
return this->m_DataFlow[flow].avgbytespersec;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel total data
// Input : flow -
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetTotalData(int flow) const
{
return this->m_DataFlow[flow].totalbytes;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel total packets
// Input : flow -
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetTotalPackets(int flow) const
{
return this->m_DataFlow[flow].totalpackets;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel sequence number
// Input : flow -
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetSequenceNr(int flow) const
{
if (flow == FLOW_OUTGOING)
{
return this->m_nOutSequenceNr;
}
else if (flow == FLOW_INCOMING)
{
return this->m_nInSequenceNr;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel connect time
// Output : double
//-----------------------------------------------------------------------------
double CNetChan::GetConnectTime(void) const
{
return this->connect_time;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel timeout
// Output : float
//-----------------------------------------------------------------------------
float CNetChan::GetTimeoutSeconds(void) const
{
return this->m_Timeout;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel socket
// Output : int
//-----------------------------------------------------------------------------
int CNetChan::GetSocket(void) const
{
return this->m_Socket;
}
//-----------------------------------------------------------------------------
// Purpose: checks if the reliable stream is overflowed
// Output : true if overflowed, false otherwise
//-----------------------------------------------------------------------------
bool CNetChan::IsOverflowed(void) const
{
return this->m_StreamReliable.IsOverflowed();
}