diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index 0bcfb8e0..d2364428 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -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; } diff --git a/r5dev/engine/net_chan.h b/r5dev/engine/net_chan.h index 791a33b9..9c92b58d 100644 --- a/r5dev/engine/net_chan.h +++ b/r5dev/engine/net_chan.h @@ -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; diff --git a/r5dev/mathlib/sha256.cpp b/r5dev/mathlib/sha256.cpp index 32d4bde4..794b2f0b 100644 --- a/r5dev/mathlib/sha256.cpp +++ b/r5dev/mathlib/sha256.cpp @@ -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(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; } diff --git a/r5dev/mathlib/sha256.h b/r5dev/mathlib/sha256.h index b6ef8bc1..acfaa42c 100644 --- a/r5dev/mathlib/sha256.h +++ b/r5dev/mathlib/sha256.h @@ -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))) diff --git a/r5dev/server/vengineserver_impl.cpp b/r5dev/server/vengineserver_impl.cpp index 0d34d53e..55e53d71 100644 --- a/r5dev/server/vengineserver_impl.cpp +++ b/r5dev/server/vengineserver_impl.cpp @@ -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(); diff --git a/r5dev/tier0/completion.cpp b/r5dev/tier0/completion.cpp index b83b88ca..134ff38e 100644 --- a/r5dev/tier0/completion.cpp +++ b/r5dev/tier0/completion.cpp @@ -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()) { diff --git a/r5dev/tier1/NetAdr2.cpp b/r5dev/tier1/NetAdr2.cpp index 8dd475e8..af6725d8 100644 --- a/r5dev/tier1/NetAdr2.cpp +++ b/r5dev/tier1/NetAdr2.cpp @@ -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 CNetAdr2::GetParts(void) const +vector CNetAdr2::GetParts(void) const { - std::vector results; + vector 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 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 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 ip_parts = GetParts(); + vector 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 v0 = netAdr2.GetParts(); - std::vector v1 = GetParts(); + vector v0 = netAdr2.GetParts(); + vector 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 v0 = netAdr2.GetParts(); - std::vector v1 = GetParts(); + vector v0 = netAdr2.GetParts(); + vector v1 = GetParts(); if (strcmp(v0[0].c_str(), v1[0].c_str()) == 0 && strcmp(v0[1].c_str(), v1[1].c_str()) == 0 && diff --git a/r5dev/tier1/NetAdr2.h b/r5dev/tier1/NetAdr2.h index 2521b953..175b139c 100644 --- a/r5dev/tier1/NetAdr2.h +++ b/r5dev/tier1/NetAdr2.h @@ -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