mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix debug dll assertions
+ cleanup/optimizations
This commit is contained in:
parent
b336b37025
commit
36a9c2779b
@ -5,26 +5,36 @@
|
||||
//=============================================================================//
|
||||
|
||||
#include "core/stdafx.h"
|
||||
#include "tier0/cvar.h"
|
||||
#include "engine/sys_utils.h"
|
||||
#include "engine/net.h"
|
||||
#include "engine/net_chan.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the netchannel name
|
||||
// Output : const char*
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CNetChan::GetName(void) const
|
||||
string CNetChan::GetName(void) const
|
||||
{
|
||||
// [0x1A8D + 0x1] (first char in array is a null character!).
|
||||
return this->m_Name + 1;
|
||||
const char* pszName = this->m_Name + 1;
|
||||
return string(pszName, NET_CHANNELNAME_MAXLEN);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the netchannel address
|
||||
// Output : const char*
|
||||
//-----------------------------------------------------------------------------
|
||||
const char* CNetChan::GetAddress(void) const
|
||||
string CNetChan::GetAddress(void) const
|
||||
{
|
||||
char szAdr[INET6_ADDRSTRLEN]{};
|
||||
inet_ntop(AF_INET6, &this->remote_address.adr, szAdr, INET6_ADDRSTRLEN);
|
||||
if (!inet_ntop(AF_INET6, &this->remote_address.adr, szAdr, INET6_ADDRSTRLEN))
|
||||
{
|
||||
if (sv_showconnecting->GetBool())
|
||||
{
|
||||
Warning(eDLL_T::ENGINE, "%s - Address conversion failed: %s", __FUNCTION__, NET_ErrorString(WSAGetLastError()));
|
||||
}
|
||||
}
|
||||
return szAdr;
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ enum EBufType
|
||||
class CNetChan
|
||||
{
|
||||
public:
|
||||
const char* GetName(void) const;
|
||||
const char* GetAddress(void) const;
|
||||
string GetName(void) const;
|
||||
string GetAddress(void) const;
|
||||
int GetDataRate(void) const;
|
||||
int GetBufferSize(void) const;
|
||||
|
||||
|
@ -113,7 +113,7 @@ void SHA256::final(unsigned char *digest)
|
||||
}
|
||||
}
|
||||
|
||||
std::string sha256(std::string input)
|
||||
string sha256(const string& input)
|
||||
{
|
||||
unsigned char digest[SHA256::DIGEST_SIZE];
|
||||
memset(digest, '\0', SHA256::DIGEST_SIZE);
|
||||
@ -124,10 +124,12 @@ std::string sha256(std::string input)
|
||||
(reinterpret_cast<const unsigned char*>(input.c_str())), input.length());
|
||||
ctx.final(digest);
|
||||
|
||||
char buf[2*SHA256::DIGEST_SIZE+1]{};
|
||||
buf[2*SHA256::DIGEST_SIZE] = 0;
|
||||
char buf[2*SHA256::DIGEST_SIZE+1];
|
||||
memset(buf, '\0', 2*SHA256::DIGEST_SIZE+1);
|
||||
|
||||
for (int i = 0; i < SHA256::DIGEST_SIZE; i++) {
|
||||
sprintf_s(buf + i * 2, sizeof(buf), "%02x", digest[i]);
|
||||
sprintf(buf + i * 2, "%02x", digest[i]);
|
||||
}
|
||||
return std::string(buf);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ protected:
|
||||
uint32 m_h[8];
|
||||
};
|
||||
|
||||
std::string sha256(std::string input);
|
||||
string sha256(const string& input);
|
||||
|
||||
#define SHA2_SHFR(x, n) (x >> n)
|
||||
#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
|
||||
|
@ -23,7 +23,7 @@ bool HIVEngineServer__PersistenceAvailable(void* entidx, int clientidx)
|
||||
{
|
||||
CNetChan* pNetChan = pClient->GetNetChan();
|
||||
|
||||
string svClientName(pNetChan->GetName(), NET_CHANNELNAME_MAXLEN);
|
||||
string svClientName = pNetChan->GetName();
|
||||
string svIpAddress = pNetChan->GetAddress();
|
||||
int64_t nOriginID = pClient->GetOriginID();
|
||||
|
||||
|
@ -74,7 +74,7 @@ void _Kick_f_CompletionFunc(const CCommand& args)
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string svClientName(pNetChan->GetName(), NET_CHANNELNAME_MAXLEN); // Get full name.
|
||||
std::string svClientName = pNetChan->GetName(); // Get full name.
|
||||
|
||||
if (svClientName.empty())
|
||||
{
|
||||
@ -179,7 +179,7 @@ void _Ban_f_CompletionFunc(const CCommand& args)
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string svClientName(pNetChan->GetName(), NET_CHANNELNAME_MAXLEN); // Get full name.
|
||||
std::string svClientName = pNetChan->GetName(); // Get full name.
|
||||
|
||||
if (svClientName.empty())
|
||||
{
|
||||
|
@ -14,7 +14,7 @@
|
||||
// Purpose: constructor (use this when string contains <[IP]:PORT>).
|
||||
// Input : svInAdr -
|
||||
//-----------------------------------------------------------------------------
|
||||
CNetAdr2::CNetAdr2(std::string svInAdr)
|
||||
CNetAdr2::CNetAdr2(string svInAdr)
|
||||
{
|
||||
SetIPAndPort(svInAdr);
|
||||
}
|
||||
@ -24,7 +24,7 @@ CNetAdr2::CNetAdr2(std::string svInAdr)
|
||||
// Input : svInAdr -
|
||||
// svInPort -
|
||||
//-----------------------------------------------------------------------------
|
||||
CNetAdr2::CNetAdr2(std::string svInAdr, std::string svInPort)
|
||||
CNetAdr2::CNetAdr2(string svInAdr, string svInPort)
|
||||
{
|
||||
SetType(netadrtype_t::NA_IP);
|
||||
|
||||
@ -66,7 +66,7 @@ CNetAdr2::~CNetAdr2(void)
|
||||
// Purpose: sets the IP address.
|
||||
// Input : *svInAdr -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CNetAdr2::SetIP(const std::string& svInAdr)
|
||||
void CNetAdr2::SetIP(const string& svInAdr)
|
||||
{
|
||||
m_svip = "[" + svInAdr + "]";
|
||||
}
|
||||
@ -75,7 +75,7 @@ void CNetAdr2::SetIP(const std::string& svInAdr)
|
||||
// Purpose: sets the port.
|
||||
// Input : *svInPort -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CNetAdr2::SetPort(const std::string& svInPort)
|
||||
void CNetAdr2::SetPort(const string& svInPort)
|
||||
{
|
||||
m_svip += ":" + svInPort;
|
||||
}
|
||||
@ -84,7 +84,7 @@ void CNetAdr2::SetPort(const std::string& svInPort)
|
||||
// Purpose: sets the IP address and port.
|
||||
// Input : *svInAdr -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CNetAdr2::SetIPAndPort(std::string svInAdr)
|
||||
void CNetAdr2::SetIPAndPort(string svInAdr)
|
||||
{
|
||||
SetType(netadrtype_t::NA_IP);
|
||||
if (strstr(svInAdr.c_str(), "loopback") || strstr(svInAdr.c_str(), "::1"))
|
||||
@ -115,7 +115,7 @@ void CNetAdr2::SetIPAndPort(std::string svInAdr)
|
||||
// Input : *svInAdr -
|
||||
// *svInPort -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CNetAdr2::SetIPAndPort(std::string svInAdr, std::string svInPort)
|
||||
void CNetAdr2::SetIPAndPort(string svInAdr, string svInPort)
|
||||
{
|
||||
SetType(netadrtype_t::NA_IP);
|
||||
|
||||
@ -223,9 +223,9 @@ bool CNetAdr2::SetFromSockadr(sockaddr_storage* s)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: removes brackets and port from IP address.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetBase(void) const
|
||||
string CNetAdr2::GetBase(void) const
|
||||
{
|
||||
std::string svIpAdr = m_svip;
|
||||
string svIpAdr = m_svip;
|
||||
static std::regex rx("\\].*");
|
||||
svIpAdr.erase(0, 1);
|
||||
svIpAdr = std::regex_replace(svIpAdr, rx, "");
|
||||
@ -237,7 +237,7 @@ std::string CNetAdr2::GetBase(void) const
|
||||
// Purpose: removes brackets and port from IP address.
|
||||
// Input : svInAdr -
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetBase(std::string svInAdr) const
|
||||
string CNetAdr2::GetBase(string svInAdr) const
|
||||
{
|
||||
static std::regex rx("\\].*");
|
||||
svInAdr.erase(0, 1);
|
||||
@ -250,7 +250,7 @@ std::string CNetAdr2::GetBase(std::string svInAdr) const
|
||||
// Purpose: gets the IP address.
|
||||
// Input : bBaseOnly -
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetIP(bool bBaseOnly = false) const
|
||||
string CNetAdr2::GetIP(bool bBaseOnly = false) const
|
||||
{
|
||||
if (GetType() == netadrtype_t::NA_LOOPBACK)
|
||||
{
|
||||
@ -276,9 +276,9 @@ std::string CNetAdr2::GetIP(bool bBaseOnly = false) const
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: removes brackets and IP address from port.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetPort(void) const
|
||||
string CNetAdr2::GetPort(void) const
|
||||
{
|
||||
std::string svport = m_svip;
|
||||
string svport = m_svip;
|
||||
static std::regex rx(".*\\]:");
|
||||
svport = std::regex_replace(svport, rx, "");
|
||||
|
||||
@ -293,7 +293,7 @@ std::string CNetAdr2::GetPort(void) const
|
||||
// Purpose: removes brackets and IP address from port.
|
||||
// Input : svInPort -
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetPort(std::string svInPort) const
|
||||
string CNetAdr2::GetPort(string svInPort) const
|
||||
{
|
||||
static std::regex rx(".*\\]:");
|
||||
svInPort = std::regex_replace(svInPort, rx, "");
|
||||
@ -308,7 +308,7 @@ std::string CNetAdr2::GetPort(std::string svInPort) const
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns the IP address and port.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::string CNetAdr2::GetIPAndPort(void) const
|
||||
string CNetAdr2::GetIPAndPort(void) const
|
||||
{
|
||||
return m_svip;
|
||||
}
|
||||
@ -333,9 +333,9 @@ netadrversion_t CNetAdr2::GetVersion(void) const
|
||||
// Purpose: splits IP address into parts by their delimiters.
|
||||
// Output : string vector containing IP parts.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::vector<std::string> CNetAdr2::GetParts(void) const
|
||||
vector<string> CNetAdr2::GetParts(void) const
|
||||
{
|
||||
std::vector<std::string> results;
|
||||
vector<string> results;
|
||||
|
||||
// Make sure we have a valid address.
|
||||
if (m_version == netadrversion_t::NA_INVALID || m_type != netadrtype_t::NA_IP)
|
||||
@ -344,8 +344,8 @@ std::vector<std::string> CNetAdr2::GetParts(void) const
|
||||
return results;
|
||||
}
|
||||
|
||||
std::string svIpAdr = m_svip, svDelim;
|
||||
std::string::size_type prev_pos = 0, curr_pos = 0;
|
||||
string svIpAdr = m_svip, svDelim;
|
||||
string::size_type prev_pos = 0, curr_pos = 0;
|
||||
|
||||
// 000.000.000.000 -> vparts.
|
||||
if (m_version == netadrversion_t::NA_V4)
|
||||
@ -359,9 +359,9 @@ std::vector<std::string> CNetAdr2::GetParts(void) const
|
||||
StringReplace(svIpAdr, "::", ":");
|
||||
}
|
||||
|
||||
while ((curr_pos = svIpAdr.find(svDelim, curr_pos)) != std::string::npos)
|
||||
while ((curr_pos = svIpAdr.find(svDelim, curr_pos)) != string::npos)
|
||||
{
|
||||
std::string substr(svIpAdr.substr(prev_pos, curr_pos - prev_pos));
|
||||
string substr(svIpAdr.substr(prev_pos, curr_pos - prev_pos));
|
||||
|
||||
results.push_back(substr);
|
||||
prev_pos = ++curr_pos;
|
||||
@ -494,7 +494,7 @@ void CNetAdr2::ToAdrinfo(addrinfo* pHint) const
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns true if this is a valid port string.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CNetAdr2::IsValidPort(const std::string& svInPort) const
|
||||
bool CNetAdr2::IsValidPort(const string& svInPort) const
|
||||
{
|
||||
for (char const& c : svInPort)
|
||||
{
|
||||
@ -534,7 +534,7 @@ bool CNetAdr2::IsReservedAdr(void) const
|
||||
|
||||
if (GetType() == netadrtype_t::NA_IP)
|
||||
{
|
||||
std::vector<std::string> ip_parts = GetParts();
|
||||
vector<string> ip_parts = GetParts();
|
||||
|
||||
int n0 = stoi(ip_parts[0]);
|
||||
int n1 = stoi(ip_parts[1]);
|
||||
@ -609,8 +609,8 @@ bool CNetAdr2::CompareClassBAdr(const CNetAdr2& netAdr2) const
|
||||
|
||||
if (GetType() == netadrtype_t::NA_IP)
|
||||
{
|
||||
std::vector<std::string> v0 = netAdr2.GetParts();
|
||||
std::vector<std::string> v1 = GetParts();
|
||||
vector<string> v0 = netAdr2.GetParts();
|
||||
vector<string> v1 = GetParts();
|
||||
|
||||
if (strcmp(v0[0].c_str(), v1[0].c_str()) == 0 &&
|
||||
strcmp(v0[1].c_str(), v1[1].c_str()) == 0)
|
||||
@ -646,8 +646,8 @@ bool CNetAdr2::CompareClassCAdr(const CNetAdr2& netAdr2) const
|
||||
|
||||
if (GetType() == netadrtype_t::NA_IP)
|
||||
{
|
||||
std::vector<std::string> v0 = netAdr2.GetParts();
|
||||
std::vector<std::string> v1 = GetParts();
|
||||
vector<string> v0 = netAdr2.GetParts();
|
||||
vector<string> v1 = GetParts();
|
||||
|
||||
if (strcmp(v0[0].c_str(), v1[0].c_str()) == 0 &&
|
||||
strcmp(v0[1].c_str(), v1[1].c_str()) == 0 &&
|
||||
|
@ -10,15 +10,15 @@ typedef struct __declspec(align(8)) netpacket_s
|
||||
char byte17;
|
||||
DWORD source;
|
||||
double received;
|
||||
std::uint8_t* data;
|
||||
std::uint64_t label;
|
||||
uint8_t* data;
|
||||
uint64_t label;
|
||||
BYTE byte38;
|
||||
std::uint64_t qword40;
|
||||
std::uint64_t qword48;
|
||||
uint64_t qword40;
|
||||
uint64_t qword48;
|
||||
BYTE gap50[8];
|
||||
std::uint64_t qword58;
|
||||
std::uint64_t qword60;
|
||||
std::uint64_t qword68;
|
||||
uint64_t qword58;
|
||||
uint64_t qword60;
|
||||
uint64_t qword68;
|
||||
int less_than_12;
|
||||
DWORD wiresize;
|
||||
BYTE gap78[8];
|
||||
@ -96,10 +96,11 @@ public:
|
||||
{
|
||||
return this->type;
|
||||
}
|
||||
inline const char* GetAddress(void) const
|
||||
inline string GetAddress(void) const
|
||||
{
|
||||
char szAdr[INET6_ADDRSTRLEN]{};
|
||||
inet_ntop(AF_INET6, &this->adr, szAdr, INET6_ADDRSTRLEN);
|
||||
|
||||
return szAdr;
|
||||
}
|
||||
inline uint16_t GetPort(void) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user