Many small code improvements and optimizations

* Use c++ methods as much as possible.
* Use enum types for accessing NavMesh objects from array.
* Use size_t for for loops when testing against size types.
* Don't compute strlen twice of more on the same string.
* Don't use unnecessary c string casts if there is a method with a std::string overload.
* Don't create string objects from string pointers if we could use them directly.
* Don't initialize RCON password twice on each change, and don't set if the new password equals the old.
This commit is contained in:
Kawe Mazidjatari 2022-08-11 11:07:45 +02:00
parent ab097126ff
commit 88b3336758
26 changed files with 146 additions and 128 deletions

View File

@ -26,7 +26,7 @@ void R5Dev_Init()
g_svCmdLine = LoadConfigFile(SDK_DEFAULT_CFG);
}
#ifndef DEDICATED
if (strstr(g_svCmdLine.c_str(), "-wconsole"))
if (g_svCmdLine.find("-wconsole") != std::string::npos)
{
Console_Init();
}
@ -38,7 +38,7 @@ void R5Dev_Init()
for (size_t i = 0; i < SDK_ARRAYSIZE(R5R_EMBLEM); i++)
{
std::string svEscaped = StringEscape(R5R_EMBLEM[i]);
spdlog::info("{:s}{:s}{:s}\n", g_svRedF.c_str(), svEscaped.c_str(), g_svReset.c_str());
spdlog::info("{:s}{:s}{:s}\n", g_svRedF, svEscaped, g_svReset);
}
spdlog::info("\n");

View File

@ -31,7 +31,7 @@ void SpdLog_Init(void)
auto wconsole = spdlog::stdout_logger_mt("win_console");
// Determine if user wants ansi-color logging in the terminal.
if (strstr(g_svCmdLine.c_str(), "-ansiclr"))
if (g_svCmdLine.find("-ansiclr") != string::npos)
{
wconsole->set_pattern("[0.000] %v\u001b[0m");
g_bSpdLog_UseAnsiClr = true;
@ -71,7 +71,7 @@ void SpdLog_PostInit()
iconsole->set_pattern("%v");
if (strstr(g_svCmdLine.c_str(), "-ansiclr"))
if (g_svCmdLine.find("-ansiclr") != string::npos)
{
wconsole->set_pattern("%v\u001b[0m");
g_bSpdLog_UseAnsiClr = true;

View File

@ -39,12 +39,12 @@ studiohdr_t* CMDLCache::FindMDL(CMDLCache* cache, MDLHandle_t handle, void* a3)
if (pStudioHDR)
{
string svStudio = ConvertToUnixPath(string(pStudioHDR->name));
if (svStudio.compare(ERROR_MODEL) == 0)
if (svStudio.compare(ERROR_MODEL) == NULL)
{
g_pMDLFallback->m_pErrorHDR = pStudioHDR;
g_pMDLFallback->m_hErrorMDL = handle;
}
if (svStudio.compare(EMPTY_MODEL) == 0)
if (svStudio.compare(EMPTY_MODEL) == NULL)
{
g_pMDLFallback->m_pEmptyHDR = pStudioHDR;
g_pMDLFallback->m_hEmptyMDL = handle;

View File

@ -66,9 +66,10 @@ void CRConClient::Shutdown(void)
//-----------------------------------------------------------------------------
bool CRConClient::SetPassword(const char* pszPassword)
{
if (std::strlen(pszPassword) < 8)
size_t nLen = std::strlen(pszPassword);
if (nLen < 8)
{
if (std::strlen(pszPassword) > 0)
if (nLen > 0)
{
DevMsg(eDLL_T::CLIENT, "Remote server access requires a password of at least 8 characters\n");
}
@ -119,7 +120,7 @@ bool CRConClient::Connect(void)
//-----------------------------------------------------------------------------
bool CRConClient::Connect(const std::string& svInAdr, const std::string& svInPort)
{
if (svInAdr.size() > 0 && svInPort.size() > 0)
if (!svInAdr.empty() && !svInPort.empty())
{
// Default is [127.0.0.1]:37015
m_pNetAdr2->SetIPAndPort(svInAdr, svInPort);

View File

@ -44,7 +44,7 @@ void MOD_GetAllInstalledMaps()
std::string svFileName = dEntry.path().u8string();
std::regex_search(svFileName, smRegexMatches, rgArchiveRegex);
if (smRegexMatches.size() > 0)
if (!smRegexMatches.empty())
{
if (smRegexMatches[1].str().compare("frontend") == 0)
{

View File

@ -13,25 +13,31 @@
// Purpose: gets the netchannel name
// Output : const char*
//-----------------------------------------------------------------------------
string CNetChan::GetName(void) const
const char* CNetChan::GetName(void) const
{
// [0x1A8D + 0x1] (first char in array is a null character!).
const char* pszName = this->m_Name + 1;
return string(pszName, NET_CHANNELNAME_MAXLEN);
return this->m_Name;
}
//-----------------------------------------------------------------------------
// Purpose: gets the netchannel address
// Output : const char*
//-----------------------------------------------------------------------------
string CNetChan::GetAddress(void) const
const char* CNetChan::GetAddress(void) const
{
char szAdr[INET6_ADDRSTRLEN]{};
if (!inet_ntop(AF_INET6, &this->remote_address.adr, szAdr, INET6_ADDRSTRLEN))
// Select a static buffer
static char s[4][INET6_ADDRSTRLEN];
static int slot = 0;
int useSlot = (slot++) % 4;
// Render into it
if (!inet_ntop(AF_INET6, &this->remote_address.adr, s[useSlot], sizeof(s[0])))
{
Warning(eDLL_T::ENGINE, "%s - Address conversion failed: %s", __FUNCTION__, NET_ErrorString(WSAGetLastError()));
}
return szAdr;
// Pray the caller uses it before it gets clobbered
return s[useSlot];
}
//-----------------------------------------------------------------------------

View File

@ -79,8 +79,8 @@ enum EBufType
class CNetChan
{
public:
string GetName(void) const;
string GetAddress(void) const;
const char* GetName(void) const;
const char* GetAddress(void) const;
int GetDataRate(void) const;
int GetBufferSize(void) const;
@ -162,6 +162,7 @@ private:
int m_nSequencesSkipped_MAYBE;
int m_nSessionRecvs;
uint32_t m_nLiftimeRecvs;
bool m_bPad;
char m_Name[NET_CHANNELNAME_MAXLEN];
uint8_t m_bRetrySendLong;
v_netadr_t remote_address;

View File

@ -114,15 +114,18 @@ bool CRConServer::SetPassword(const char* pszPassword)
m_bInitialized = false;
m_pSocket->CloseAllAcceptedSockets();
if (std::strlen(pszPassword) < 8)
size_t nLen = std::strlen(pszPassword);
if (nLen < 8)
{
if (std::strlen(pszPassword) > 0)
if (nLen > 0)
{
Warning(eDLL_T::SERVER, "Remote server access requires a password of at least 8 characters\n");
}
this->Shutdown();
return false;
}
m_svPasswordHash = sha256(pszPassword);
DevMsg(eDLL_T::SERVER, "Password hash ('%s')\n", m_svPasswordHash.c_str());
@ -569,6 +572,16 @@ void CRConServer::CloseNonAuthConnection(void)
}
}
}
//-----------------------------------------------------------------------------
// Purpose: checks if server rcon is initialized
// Output : true if initialized, false otherwise
//-----------------------------------------------------------------------------
bool CRConServer::IsInitialized(void) const
{
return m_bInitialized;
}
///////////////////////////////////////////////////////////////////////////////
CRConServer* g_pRConServer = new CRConServer();
CRConServer* RCONServer()

View File

@ -41,6 +41,8 @@ public:
void CloseConnection(void);
void CloseNonAuthConnection(void);
bool IsInitialized(void) const;
private:
bool m_bInitialized;

View File

@ -34,7 +34,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
const string svMeshDir = "maps\\navmesh\\";
const string svGraphDir = "maps\\graphs\\";
fs::path fsMeshPath(svMeshDir + g_pHostState->m_levelName + "_" + SHULL_SIZE[3] + ".nm");
fs::path fsMeshPath(svMeshDir + g_pHostState->m_levelName + "_" + SHULL_SIZE[EHULL_SIZE::LARGE] + ".nm");
fs::path fsGraphPath(svGraphDir + g_pHostState->m_levelName + ".ain");
CFastTimer masterTimer;
@ -69,7 +69,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
}
else
{
Warning(eDLL_T::SERVER, "%s - No %s NavMesh found. Unable to calculate CRC for AI Network.\n", __FUNCTION__, SHULL_SIZE[3].c_str());
Warning(eDLL_T::SERVER, "%s - No %s NavMesh found. Unable to calculate CRC for AI Network.\n", __FUNCTION__, SHULL_SIZE[EHULL_SIZE::LARGE].c_str());
}
// Large NavMesh CRC.
@ -169,7 +169,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
// Don't know what this is, it's likely a block from tf1 that got deprecated? should just be 1 int per node.
DevMsg(eDLL_T::SERVER, " |-- Writing '%d' bytes for node block at '0x%zX'\n", pNetwork->m_iNumNodes * sizeof(uint32_t), writer.GetPosition());
if (static_cast<int>(pNetwork->m_iNumNodes) > 0)
if (pNetwork->m_iNumNodes > 0)
{
uint32_t* unkNodeBlock = new uint32_t[pNetwork->m_iNumNodes];
memset(&unkNodeBlock, '\0', pNetwork->m_iNumNodes * sizeof(uint32_t));
@ -179,7 +179,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork)
// TODO: This is traverse nodes i think? these aren't used in r2 ains so we can get away with just writing count=0 and skipping
// but ideally should actually dump these.
DevMsg(eDLL_T::SERVER, " |-- Writing '%d' traversal nodes at '0x%zX'\n", 0, static_cast<size_t>(writer.GetPosition()));
DevMsg(eDLL_T::SERVER, " |-- Writing '%d' traversal nodes at '0x%zX'\n", 0, writer.GetPosition());
short traverseNodeCount = 0; // Only write count since count=0 means we don't have to actually do anything here.
writer.Write(&traverseNodeCount, sizeof(short));
@ -293,7 +293,7 @@ void CAI_NetworkManager::LoadNetworkGraph(CAI_NetworkManager* pAINetworkManager,
string svMeshDir = "maps\\navmesh\\";
string svGraphDir = "maps\\graphs\\";
fs::path fsMeshPath(svMeshDir + g_pHostState->m_levelName + "_" + SHULL_SIZE[3] + ".nm");
fs::path fsMeshPath(svMeshDir + g_pHostState->m_levelName + "_" + SHULL_SIZE[EHULL_SIZE::LARGE] + ".nm");
fs::path fsGraphPath(svGraphDir + g_pHostState->m_levelName + ".ain");
int nAiNetVersion = NULL;

View File

@ -249,7 +249,7 @@ void CConsole::BasePanel(void)
{
// Remove the default value from ConVar before assigning it to the input buffer.
string svConVar = m_vSuggest[m_nSuggestPos].m_svName.substr(0, m_vSuggest[m_nSuggestPos].m_svName.find(' ')) + ' ';
memmove(m_szInputBuf, svConVar.c_str(), svConVar.size() + 1);
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
ResetAutoComplete();
BuildSummary(svConVar);
@ -366,7 +366,7 @@ void CConsole::SuggestPanel(void)
// Remove the default value from ConVar before assigning it to the input buffer.
string svConVar = m_vSuggest[i].m_svName.substr(0, m_vSuggest[i].m_svName.find(' ')) + ' ';
memmove(m_szInputBuf, svConVar.c_str(), svConVar.size() + 1);
memmove(m_szInputBuf, svConVar.data(), svConVar.size() + 1);
ResetAutoComplete();
BuildSummary(svConVar);

View File

@ -64,7 +64,7 @@ bool CModAppSystemGroup::Create(CModAppSystemGroup* pModAppSystemGroup)
for (auto& map : g_pCVar->DumpToMap())
{
g_pConsole->m_vsvCommandBases.push_back(
CSuggest(map.first.c_str(), map.second->GetFlags()));
CSuggest(map.first, map.second->GetFlags()));
}
#endif // !DEDICATED
if (pModAppSystemGroup->IsServerOnly())

View File

@ -125,7 +125,7 @@ void ParseAndApplyConfigFile(const string& svConfig)
stringstream ss(svConfig);
string svInput;
if (strlen(svConfig.c_str()) > 0)
if (!svConfig.empty())
{
while (std::getline(ss, svInput, '\n'))
{

View File

@ -29,10 +29,10 @@ void StreamDB_Init(const char* pszLevelName)
if (!jsIn.is_null())
{
if (!jsIn["stbsp"].is_null())
if (!jsIn[STREAM_DB_EXT].is_null())
{
string svStreamDBFile = jsIn["stbsp"].get<string>();
DevMsg(eDLL_T::MS, "%s: Loading override STBSP file '%s.stbsp'\n", __FUNCTION__, svStreamDBFile.c_str());
string svStreamDBFile = jsIn[STREAM_DB_EXT].get<string>();
DevMsg(eDLL_T::MS, "%s: Loading override STBSP file '%s.%s'\n", __FUNCTION__, svStreamDBFile.c_str(), STREAM_DB_EXT);
v_StreamDB_Init(svStreamDBFile.c_str());
return;
}
@ -43,7 +43,7 @@ void StreamDB_Init(const char* pszLevelName)
Warning(eDLL_T::MS, "%s: Exception while parsing STBSP override: '%s'\n", __FUNCTION__, ex.what());
}
}
DevMsg(eDLL_T::MS, "%s: Loading STBSP file '%s.stbsp'\n", __FUNCTION__, pszLevelName);
DevMsg(eDLL_T::MS, "%s: Loading STBSP file '%s.%s'\n", __FUNCTION__, pszLevelName, STREAM_DB_EXT);
v_StreamDB_Init(pszLevelName);
}

View File

@ -1,5 +1,7 @@
#pragma once
#define STREAM_DB_EXT "stbsp"
/* ==== MATERIALSYSTEM ================================================================================================================================================== */
inline CMemory p_CMaterialSystem__Init;
inline auto CMaterialSystem__Init = p_CMaterialSystem__Init.RCast<void* (*)(void* thisptr)>();

View File

@ -109,7 +109,7 @@ std::string SHA1::final()
std::string SHA1::from_file(const std::string &filename)
{
std::ifstream stream(filename.c_str(), std::ios::binary);
std::ifstream stream(filename, std::ios::binary);
SHA1 checksum;
checksum.update(stream);
return checksum.final();

View File

@ -234,7 +234,7 @@ bool CNetCon::ShouldQuit(void) const
//-----------------------------------------------------------------------------
bool CNetCon::Connect(const std::string& svInAdr, const std::string& svInPort)
{
if (svInAdr.size() > 0 && svInPort.size() > 0)
if (!svInAdr.empty() && !svInPort.empty())
{
// Default is [127.0.0.1]:37015
m_pNetAdr2->SetIPAndPort(svInAdr, svInPort);

View File

@ -186,7 +186,7 @@ void CBanSystem::BanListCheck(void)
Warning(eDLL_T::SERVER, "Connection rejected for '%s' ('%llu' is banned from this server!)\n", svIpAddress.c_str(), pClient->GetOriginID());
AddEntry(svIpAddress, pClient->GetOriginID());
Save(); // Save banlist to file.
NET_DisconnectClient(pClient, c, m_vRefuseList[i].first.c_str(), false, true);
NET_DisconnectClient(pClient, c, m_vRefuseList[i].first.c_str(), 0, true);
}
}
}

View File

@ -40,7 +40,7 @@ void CMemory::Patch(const vector<uint8_t> vOpcodeArray) const
SIZE_T dwSize = vOpcodeArray.size();
VirtualProtect(reinterpret_cast<void*>(ptr), dwSize, PAGE_EXECUTE_READWRITE, &oldProt); // Patch page to be able to read and write to it.
for (int i = 0; i < vOpcodeArray.size(); i++)
for (size_t i = 0; i < vOpcodeArray.size(); i++)
{
*reinterpret_cast<uint8_t*>(ptr + i) = vOpcodeArray[i]; // Write opcodes to Address.
}
@ -62,7 +62,7 @@ void CMemory::PatchString(const string& svString) const
VirtualProtect(reinterpret_cast<void*>(ptr), dwSize, PAGE_EXECUTE_READWRITE, &oldProt); // Patch page to be able to read and write to it.
for (int i = 0; i < svString.size(); i++)
for (size_t i = 0; i < svString.size(); i++)
{
*reinterpret_cast<uint8_t*>(ptr + i) = bytes[i]; // Write string to Address.
}

View File

@ -646,7 +646,7 @@ int32_t RTech::OpenFile(const char* szFilePath, void* unused, int64_t* fileSizeO
//-----------------------------------------------------------------------------
RPakLoadedInfo_t* RTech::GetPakLoadedInfo(int nPakId)
{
for (int i = 0; i < *s_pLoadedPakCount; ++i)
for (int16_t i = 0; i < *s_pLoadedPakCount; ++i)
{
RPakLoadedInfo_t* info = &g_pLoadedPakInfo[i];
if (!info)
@ -667,7 +667,7 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(int nPakId)
//-----------------------------------------------------------------------------
RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName)
{
for (int i = 0; i < *s_pLoadedPakCount; ++i)
for (int16_t i = 0; i < *s_pLoadedPakCount; ++i)
{
RPakLoadedInfo_t* info = &g_pLoadedPakInfo[i];
if (!info)

View File

@ -3,6 +3,8 @@
#define PAK_PARAM_SIZE 0xB0
#define DCMP_BUF_SIZE 0x400000
#define RPAKHEADER (('k'<<24)+('a'<<16)+('P'<<8)+'R')
/*unk_141313180*/
// LUT_0 redacted now, split LUT into multiple parts.
#pragma warning( push )

View File

@ -555,7 +555,7 @@ void CUIBaseSurface::ParseMaps()
std::string svFileName = dEntry.path().string();
std::regex_search(svFileName, smRegexMatches, rgArchiveRegex);
if (smRegexMatches.size() > 0)
if (!smRegexMatches.empty())
{
if (smRegexMatches[1].str().compare("frontend") == 0)
{

View File

@ -136,7 +136,7 @@ void CNetAdr2::SetVersion(void)
{
if (inet_pton(reinterpret_cast<sockaddr_in*>(&m_sadr)->sin_family,
GetBase().c_str(), &reinterpret_cast<sockaddr_in*>(m_sadr)->sin_addr) &&
!strstr(GetBase().c_str(), "::"))
GetBase().find("::") == string::npos)
{
m_version = netadrversion_t::NA_V4;
return;
@ -203,13 +203,13 @@ string CNetAdr2::GetBase(void) const
std::smatch smRegexMatches;
std::regex_search(m_svip, smRegexMatches, rx);
if (smRegexMatches.size() > 0)
if (smRegexMatches.empty())
{
return smRegexMatches[1].str();
return "127.0.0.1";
}
else
{
return "127.0.0.1";
return smRegexMatches[1].str();
}
}
@ -223,13 +223,13 @@ string CNetAdr2::GetBase(const string& svInAdr) const
std::smatch smRegexMatches;
std::regex_search(svInAdr, smRegexMatches, rx);
if (smRegexMatches.size() > 0)
if (smRegexMatches.empty())
{
return smRegexMatches[1].str();
return "127.0.0.1";
}
else
{
return "127.0.0.1";
return smRegexMatches[1].str();
}
}
@ -498,7 +498,7 @@ bool CNetAdr2::IsValidPort(const string& svInPort) const
//-----------------------------------------------------------------------------
bool CNetAdr2::IsLocalhost(void) const
{
return (strcmp(GetBase().c_str(), "127.0.0.1") == 0);
return (GetBase().compare("127.0.0.1") == NULL);
}
//-----------------------------------------------------------------------------
@ -506,7 +506,7 @@ bool CNetAdr2::IsLocalhost(void) const
//-----------------------------------------------------------------------------
bool CNetAdr2::IsLoopback(void) const
{
return GetType() == netadrtype_t::NA_LOOPBACK;
return (GetType() == netadrtype_t::NA_LOOPBACK);
}
//-----------------------------------------------------------------------------
@ -558,12 +558,12 @@ bool CNetAdr2::CompareAdr(const CNetAdr2& netAdr2, bool bBaseOnly) const
if (GetType() == netadrtype_t::NA_IP)
{
if (!bBaseOnly &&
(strcmp(netAdr2.GetPort().c_str(), GetPort().c_str()) != 0))
(netAdr2.GetPort().compare(GetPort()) != NULL))
{
return false;
}
if (strcmp(netAdr2.GetBase().c_str(), GetBase().c_str()) == 0)
if (netAdr2.GetBase().compare(GetBase()) == NULL)
{
return true;
}
@ -599,8 +599,8 @@ bool CNetAdr2::CompareClassBAdr(const CNetAdr2& netAdr2) const
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)
if (v0[0].compare(v1[0]) == NULL &&
v0[1].compare(v1[1]) == NULL)
{
return true;
}
@ -636,9 +636,9 @@ bool CNetAdr2::CompareClassCAdr(const CNetAdr2& netAdr2) const
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 &&
strcmp(v0[2].c_str(), v1[2].c_str()) == 0)
if (v0[0].compare(v1[0]) == NULL &&
v0[1].compare(v1[1]) == NULL &&
v0[2].compare(v1[2]) == NULL)
{
return true;
}
@ -655,5 +655,5 @@ void CNetAdr2::Clear(void)
m_svip.clear();
m_type = netadrtype_t::NA_NULL;
m_version = netadrversion_t::NA_INVALID;
m_sadr = {};
m_sadr = nullptr;
}

View File

@ -60,9 +60,9 @@ public:
private:
string m_svip;
netadrtype_t m_type{};
netadrversion_t m_version{};
sockaddr_storage* m_sadr{};
netadrtype_t m_type;
netadrversion_t m_version;
sockaddr_storage* m_sadr;
};
class v_netadr_t // !TODO: Move this to 'NetAdr.h' instead and adjust existing class to new system.
@ -74,10 +74,16 @@ public:
}
inline string GetAddress(void) const
{
char szAdr[INET6_ADDRSTRLEN]{};
inet_ntop(AF_INET6, &this->adr, szAdr, INET6_ADDRSTRLEN);
// Select a static buffer
static char s[4][INET6_ADDRSTRLEN];
static int slot = 0;
int useSlot = (slot++) % 4;
return szAdr;
// Render into it
inet_ntop(AF_INET6, &this->adr, s[useSlot], sizeof(s[0]));
// Pray the caller uses it before it gets clobbered
return s[useSlot];
}
inline uint16_t GetPort(void) const
{

View File

@ -93,27 +93,19 @@ void Host_Kick_f(const CCommand& args)
for (int i = 0; i < MAX_PLAYERS; i++)
{
CClient* pClient = g_pClient->GetClient(i);
if (!pClient)
continue;
CNetChan* pNetChan = pClient->GetNetChan();
if (!pNetChan)
continue;
string svClientName = pNetChan->GetName(); // Get full name.
if (svClientName.empty())
if (CClient* pClient = g_pClient->GetClient(i))
{
continue;
if (CNetChan* pNetChan = pClient->GetNetChan())
{
if (strlen(pNetChan->GetName()) > 0)
{
if (strcmp(args.Arg(1), pNetChan->GetName()) == NULL) // Our wanted name?
{
NET_DisconnectClient(pClient, i, "Kicked from server", 0, true);
}
}
}
}
if (strcmp(args.Arg(1), svClientName.c_str()) != 0) // Our wanted name?
{
continue;
}
NET_DisconnectClient(pClient, i, "Kicked from server", 0, 1);
}
}
#ifndef CLIENT_DLL
@ -142,8 +134,6 @@ void Host_KickID_f(const CCommand& args)
if (!pNetChan)
continue;
string svIpAddress = pNetChan->GetAddress(); // If this stays null they modified the packet somehow.
if (bOnlyDigits)
{
uint64_t nTargetID = static_cast<uint64_t>(std::stoll(args.Arg(1)));
@ -164,16 +154,16 @@ void Host_KickID_f(const CCommand& args)
}
}
NET_DisconnectClient(pClient, i, "Kicked from server", 0, 1);
NET_DisconnectClient(pClient, i, "Kicked from server", 0, true);
}
else
{
if (string(args.Arg(1)).compare(svIpAddress) != NULL)
if (strcmp(args.Arg(1), pNetChan->GetAddress()) != NULL)
{
continue;
}
NET_DisconnectClient(pClient, i, "Kicked from server", 0, 1);
NET_DisconnectClient(pClient, i, "Kicked from server", 0, true);
}
}
}
@ -198,31 +188,21 @@ void Host_Ban_f(const CCommand& args)
for (int i = 0; i < MAX_PLAYERS; i++)
{
CClient* pClient = g_pClient->GetClient(i);
if (!pClient)
continue;
CNetChan* pNetChan = pClient->GetNetChan();
if (!pNetChan)
continue;
string svClientName = pNetChan->GetName(); // Get full name.
if (svClientName.empty())
if (CClient* pClient = g_pClient->GetClient(i))
{
continue;
if (CNetChan* pNetChan = pClient->GetNetChan())
{
if (strlen(pNetChan->GetName()) > 0)
{
if (strcmp(args.Arg(1), pNetChan->GetName()) == NULL) // Our wanted name?
{
g_pBanSystem->AddEntry(pNetChan->GetAddress(), pClient->GetOriginID());
g_pBanSystem->Save();
NET_DisconnectClient(pClient, i, "Banned from server", 0, true);
}
}
}
}
if (strcmp(args.Arg(1), svClientName.c_str()) != 0)
{
continue;
}
string svIpAddress = pNetChan->GetAddress(); // If this stays empty they modified the packet somehow.
g_pBanSystem->AddEntry(svIpAddress, pClient->GetOriginID());
g_pBanSystem->Save();
NET_DisconnectClient(pClient, i, "Banned from server", 0, 1);
}
}
@ -251,8 +231,6 @@ void Host_BanID_f(const CCommand& args)
if (!pNetChan)
continue;
string svIpAddress = pNetChan->GetAddress(); // If this stays empty they modified the packet somehow.
if (bOnlyDigits)
{
uint64_t nTargetID = static_cast<uint64_t>(std::stoll(args.Arg(1)));
@ -273,20 +251,20 @@ void Host_BanID_f(const CCommand& args)
}
}
g_pBanSystem->AddEntry(svIpAddress, pClient->GetOriginID());
g_pBanSystem->AddEntry(pNetChan->GetAddress(), pClient->GetOriginID());
g_pBanSystem->Save();
NET_DisconnectClient(pClient, i, "Banned from server", 0, 1);
NET_DisconnectClient(pClient, i, "Banned from server", 0, true);
}
else
{
if (string(args.Arg(1)).compare(svIpAddress) != NULL)
if (strcmp(args.Arg(1), pNetChan->GetAddress()) != NULL)
{
continue;
}
g_pBanSystem->AddEntry(svIpAddress, pClient->GetOriginID());
g_pBanSystem->AddEntry(pNetChan->GetAddress(), pClient->GetOriginID());
g_pBanSystem->Save();
NET_DisconnectClient(pClient, i, "Banned from server", 0, 1);
NET_DisconnectClient(pClient, i, "Banned from server", 0, true);
}
}
}
@ -439,9 +417,9 @@ void Pak_Swap_f(const CCommand& args)
{
try
{
string pakName;
RPakHandle_t nPakId = 0;
RPakLoadedInfo_t* pakInfo = nullptr;
string pakName = std::string();
if (args.HasOnlyDigits(1))
{
@ -551,7 +529,7 @@ void RTech_Decompress_f(const CCommand& args)
DevMsg(eDLL_T::RTECH, " | | |-- Size decp: '%llu'\n", rheader.m_nSizeMemory);
DevMsg(eDLL_T::RTECH, " | | |-- Ratio : '%.02f'\n", (rheader.m_nSizeDisk * 100.f) / rheader.m_nSizeMemory);
if (rheader.m_nMagic != 'kaPR')
if (rheader.m_nMagic != RPAKHEADER)
{
Error(eDLL_T::RTECH, "%s - pak file '%s' has invalid magic!\n", __FUNCTION__, pakNameIn.c_str());
return;
@ -821,12 +799,19 @@ void RCON_PasswordChanged_f(IConVar* pConVar, const char* pOldString, float flOl
{
if (ConVar* pConVarRef = g_pCVar->FindVar(pConVar->GetName()))
{
if (strcmp(pOldString, pConVarRef->GetString()) == NULL)
return; // Same password.
#ifndef DEDICATED
RCONClient()->SetPassword(pConVarRef->GetString());
RCONClient()->Init();
#elif DEDICATED
RCONServer()->SetPassword(pConVarRef->GetString());
RCONServer()->Init();
if (RCONClient()->IsInitialized())
RCONClient()->SetPassword(pConVarRef->GetString());
else
RCONClient()->Init(); // Initialize first.
#elif DEDICATED
if (RCONServer()->IsInitialized())
RCONServer()->SetPassword(pConVarRef->GetString());
else
RCONServer()->Init(); // Initialize first.
#endif // DEDICATED
}
}

View File

@ -98,7 +98,7 @@ void Console_Init()
CloseHandle(hThread);
}
if (strstr(g_svCmdLine.c_str(), "-ansiclr"))
if (g_svCmdLine.find("-ansiclr") != string::npos)
{
GetConsoleMode(hOutput, &dwMode);
dwMode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;