Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++20 support for Deathmatch project #3745

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CAccessControlListRight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ SString CAccessControlListRight::GetAttributeValue(const SString& strAttributeNa
else
{
SString* pResult = MapFind(m_ExtraAttributeMap, strAttributeName);
return pResult ? *pResult : "";
return pResult ? *pResult : SString{};
}
}
14 changes: 7 additions & 7 deletions Server/mods/deathmatch/logic/CConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern CGame* g_pGame;
static std::string GetAdminNameForLog(CClient* pClient)
{
std::string strName = pClient->GetNick();
std::string strAccountName = pClient->GetAccount() ? pClient->GetAccount()->GetName() : "no account";
std::string strAccountName = pClient->GetAccount() ? pClient->GetAccount()->GetName().c_str() : "no account";
if (strName == strAccountName)
return strName;
return SString("%s(%s)", strName.c_str(), strAccountName.c_str());
Expand Down Expand Up @@ -1587,9 +1587,9 @@ bool DoAclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient,

std::vector<SString> parts;
SStringX(szArguments).Split(" ", parts);
const SString& strAction = parts.size() > 0 ? parts[0] : "";
const SString& strResourceName = parts.size() > 1 ? parts[1] : "";
const SString& strRightName = parts.size() > 2 ? parts[2] : "";
const SString& strAction = parts.size() > 0 ? parts[0] : SString{};
const SString& strResourceName = parts.size() > 1 ? parts[1] : SString{};
const SString& strRightName = parts.size() > 2 ? parts[2] : SString{};

bool bList = strAction == "list";
bool bAllow = strAction == "allow";
Expand All @@ -1608,7 +1608,7 @@ bool DoAclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient,
pEchoClient->SendConsole("aclrequest: No loaded resources have any requests");
return true;
}
else if (bList | bAllow | bDeny)
else if (bList || bAllow || bDeny)
{
CResource* pResource = g_pGame->GetResourceManager()->GetResource(strResourceName);
if (!pResource)
Expand Down Expand Up @@ -1657,8 +1657,8 @@ bool CConsoleCommands::AuthorizeSerial(CConsole* pConsole, const char* szArgumen

std::vector<SString> parts;
SStringX(szArguments).Split(" ", parts);
const SString& strAccountName = parts.size() > 0 ? parts[0] : "";
const SString& strAction = parts.size() > 1 ? parts[1] : "";
const SString& strAccountName = parts.size() > 0 ? parts[0] : SString{};
const SString& strAction = parts.size() > 1 ? parts[1] : SString{};

bool bList = strAction == "list";
bool bAllow = strAction == "";
Expand Down
8 changes: 4 additions & 4 deletions Server/mods/deathmatch/logic/CDatabaseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ SString CDatabaseManagerImpl::InsertQueryArguments(SConnectionHandle hConnection
return strQuery;

// Determine connection type
SString* pstrType = MapFind(m_ConnectionTypeMap, hConnection);
SString strType = pstrType ? *pstrType : "";
std::string* pstrType = MapFind(m_ConnectionTypeMap, hConnection);
std::string strType = pstrType ? *pstrType : "";

if (strType == "sqlite")
return InsertQueryArgumentsSqlite(strQuery, pArgs);
Expand All @@ -607,8 +607,8 @@ SString CDatabaseManagerImpl::InsertQueryArguments(SConnectionHandle hConnection
SString CDatabaseManagerImpl::InsertQueryArguments(SConnectionHandle hConnection, const char* szQuery, va_list vl)
{
// Determine connection type
SString* pstrType = MapFind(m_ConnectionTypeMap, hConnection);
SString strType = pstrType ? *pstrType : "";
std::string* pstrType = MapFind(m_ConnectionTypeMap, hConnection);
std::string strType = pstrType ? *pstrType : "";

if (strType == "sqlite")
return InsertQueryArgumentsSqlite(szQuery, vl);
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ bool CGame::Start(int iArgumentCount, char* szArguments[])
if (m_pMainConfig->IsHTTPEnabled())
{
// Slight hack for internal HTTPD: Listen on all IPs if multiple IPs declared
SString strUseIP = (strServerIP == strServerIPList) ? strServerIP : "";
SString strUseIP = strServerIP == strServerIPList ? strServerIP : SString{};
if (!m_pHTTPD->StartHTTPD(strUseIP, m_pMainConfig->GetHTTPPort()))
{
CLogger::ErrorPrintf("Could not start HTTP server on interface '%s' and port '%u'!\n", strUseIP.c_str(), m_pMainConfig->GetHTTPPort());
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CPerfStat.BandwidthUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ void CPerfStatBandwidthUsageImpl::GetStats(CPerfStatResult* pResult, const std::
row[c++] = CPerfStatManager::GetScaledByteString(item.llGameRecv);
row[c++] = CPerfStatManager::GetScaledByteString(item.llGameSent);
if (bShowSentLoss[t])
row[c++] = item.llGameResent ? CPerfStatManager::GetPercentString(item.llGameResent, item.llGameSent) : "";
row[c++] = item.llGameResent ? CPerfStatManager::GetPercentString(item.llGameResent, item.llGameSent) : SString{};
row[c++] = CPerfStatManager::GetScaledByteString(item.llHttpSent);
if (bShowBlocked[t])
row[c++] = CPerfStatManager::GetScaledByteString(item.llGameRecvBlocked);
Expand Down
8 changes: 4 additions & 4 deletions Server/mods/deathmatch/logic/CPerfStat.FunctionTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ void CPerfStatFunctionTimingImpl::GetStats(CPerfStatResult* pResult, const std::
row[c++] = SString("%2.0f ms", prev5s.fPeakMs);
row[c++] = SString("%2.0f ms (%s)", prev5s.fResBiggestMs, *prev5s.strResBiggestMsName);

row[c++] = prev5s.uiTotalBytes < 10 ? "" : SString("%s", *CPerfStatManager::GetScaledByteString(prev5s.uiTotalBytes));
row[c++] = prev5s.uiTotalBytes < 10 ? SString{} : SString("%s", *CPerfStatManager::GetScaledByteString(prev5s.uiTotalBytes));
// row[c++] = prev5s.uiPeakBytes < 10 ? "" : SString ( "%s ", *CPerfStatManager::GetScaledByteString( prev5s.uiPeakBytes ) );
row[c++] = prev5s.uiResBiggestBytes < 10
? ""
? SString{}
: SString("%s (%s)", *CPerfStatManager::GetScaledByteString(prev5s.uiResBiggestBytes), *prev5s.strResBiggestBytesName);
}

Expand All @@ -434,10 +434,10 @@ void CPerfStatFunctionTimingImpl::GetStats(CPerfStatResult* pResult, const std::
row[c++] = SString("%2.0f ms", prev60s.fPeakMs);
row[c++] = SString("%2.0f ms (%s)", prev60s.fResBiggestMs, *prev60s.strResBiggestMsName);

row[c++] = prev60s.uiTotalBytes < 10 ? "" : SString("%s ", *CPerfStatManager::GetScaledByteString(prev60s.uiTotalBytes));
row[c++] = prev60s.uiTotalBytes < 10 ? SString{} : SString("%s ", *CPerfStatManager::GetScaledByteString(prev60s.uiTotalBytes));
// row[c++] = prev60s.uiPeakBytes < 10 ? "" : SString ( "%s ", *CPerfStatManager::GetScaledByteString( prev60s.uiPeakBytes ) );
row[c++] = prev60s.uiResBiggestBytes < 10
? ""
? SString{}
: SString("%s (%s)", *CPerfStatManager::GetScaledByteString(prev60s.uiResBiggestBytes), *prev60s.strResBiggestBytesName);
}
}
18 changes: 9 additions & 9 deletions Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ void CPerfStatLuaMemoryImpl::GetLuaMemoryStats(CPerfStatResult* pResult, const s

// Some extra 'all VM' things
c += 6;
row[c++] = !g_pStats->iDbJobDataCount ? "-" : SString("%d", g_pStats->iDbJobDataCount);
row[c++] = g_pStats->iDbConnectionCount - 2 == 0 ? "-" : SString("%d", g_pStats->iDbConnectionCount - 2);
row[c++] = !g_pStats->iDbJobDataCount ? "-" : std::to_string(g_pStats->iDbJobDataCount);
row[c++] = g_pStats->iDbConnectionCount - 2 == 0 ? "-" : std::to_string(g_pStats->iDbConnectionCount - 2);
}

// For each VM
Expand Down Expand Up @@ -321,12 +321,12 @@ void CPerfStatLuaMemoryImpl::GetLuaMemoryStats(CPerfStatResult* pResult, const s

row[c++] = SString("%d KB", LuaMainMemory.Current);
row[c++] = SString("%d KB", LuaMainMemory.Max);
row[c++] = !LuaMainMemory.OpenXMLFiles ? "-" : SString("%d", LuaMainMemory.OpenXMLFiles);
row[c++] = !LuaMainMemory.OpenFiles ? "-" : SString("%d", LuaMainMemory.OpenFiles);
row[c++] = !LuaMainMemory.Refs ? "-" : SString("%d", LuaMainMemory.Refs);
row[c++] = !LuaMainMemory.TimerCount ? "-" : SString("%d", LuaMainMemory.TimerCount);
row[c++] = !LuaMainMemory.ElementCount ? "-" : SString("%d", LuaMainMemory.ElementCount);
row[c++] = !LuaMainMemory.TextDisplayCount ? "-" : SString("%d", LuaMainMemory.TextDisplayCount);
row[c++] = !LuaMainMemory.TextItemCount ? "-" : SString("%d", LuaMainMemory.TextItemCount);
row[c++] = !LuaMainMemory.OpenXMLFiles ? SString{"-"} : SString("%d", LuaMainMemory.OpenXMLFiles);
row[c++] = !LuaMainMemory.OpenFiles ? SString{"-"} : SString("%d", LuaMainMemory.OpenFiles);
row[c++] = !LuaMainMemory.Refs ? SString{"-"} : SString("%d", LuaMainMemory.Refs);
row[c++] = !LuaMainMemory.TimerCount ? SString{"-"} : SString("%d", LuaMainMemory.TimerCount);
row[c++] = !LuaMainMemory.ElementCount ? SString{"-"} : SString("%d", LuaMainMemory.ElementCount);
row[c++] = !LuaMainMemory.TextDisplayCount ? SString{"-"} : SString("%d", LuaMainMemory.TextDisplayCount);
row[c++] = !LuaMainMemory.TextItemCount ? SString{"-"} : SString("%d", LuaMainMemory.TextItemCount);
}
}
6 changes: 3 additions & 3 deletions Server/mods/deathmatch/logic/CPerfStat.LuaTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ void CPerfStatLuaTimingImpl::OutputTimingBlock(CPerfStatResult* pResult, const C

double total_p = total_s / double(threshList[i]) * 100;

row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : "-";
row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : "-";
row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : "";
row[c++] = total_p > 0.005 ? SString("%2.2f%%", total_p) : SString{"-"};
row[c++] = total_s > 0.0005 ? SString("%2.3f", total_s) : SString{"-"};
row[c++] = p->prev.calls > 0 ? SString("%d", p->prev.calls) : SString{};
row[c++] = avg_s > 0.0005 ? SString("%2.3f", avg_s).c_str() : bSubBlock ? "-" : "";
row[c++] = max_s > 0.0005 ? SString("%2.3f", max_s).c_str() : bSubBlock ? "-" : "";
}
Expand Down
6 changes: 3 additions & 3 deletions Server/mods/deathmatch/logic/CPerfStat.PlayerPacketUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ void CPerfStatPlayerPacketUsageImpl::OutputTimeSpanBlock(CPerfStatResult* pResul
const CTimeSpan* p = timeSpanList[i];
const CTopValue& value = (p->prev.data[0].uiPktsPerSec > p->acc.data[0].uiPktsPerSec) ? p->prev.data[iTopPos] : p->acc.data[iTopPos];

row[c++] = value.uiPktsPerSec ? SString("%d", value.uiPktsPerSec) : "-";
row[c++] = value.uiPktsPerSec ? std::to_string(value.uiPktsPerSec) : "-";
if (bDetail)
{
row[c++] = value.uiBytesInPerSec ? SString("%d", value.uiBytesInPerSec) : "-";
row[c++] = value.uiBytesOutPerSec ? SString("%d", value.uiBytesOutPerSec) : "-";
row[c++] = value.uiBytesInPerSec ? std::to_string(value.uiBytesInPerSec) : "-";
TracerDS marked this conversation as resolved.
Show resolved Hide resolved
row[c++] = value.uiBytesOutPerSec ? std::to_string(value.uiBytesOutPerSec) : "-";
row[c++] = value.strSerial;
}
row[c++] = value.strName;
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,11 @@ void CResourceManager::ProcessQueue()
}
else if (sItem.eQueue == QUEUE_REFRESH)
{
Refresh(false, sItem.pResource ? sItem.pResource->GetName() : "");
Refresh(false, sItem.pResource ? sItem.pResource->GetName() : SString{});
}
else if (sItem.eQueue == QUEUE_REFRESHALL)
{
Refresh(true, sItem.pResource ? sItem.pResource->GetName() : "");
Refresh(true, sItem.pResource ? sItem.pResource->GetName() : SString{});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaDatabaseDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int CLuaDatabaseDefs::DbConnect(lua_State* luaVM)
// Set default values if required
GetOption<CDbOptionsMap>(strOptions, "log", bLoggingEnabled, 1);
GetOption<CDbOptionsMap>(strOptions, "tag", strLogTag, "script");
GetOption<CDbOptionsMap>(strOptions, "queue", strQueueName, (strType == "mysql") ? strHost : DB_SQLITE_QUEUE_NAME_DEFAULT);
GetOption<CDbOptionsMap>(strOptions, "queue", strQueueName, strType == "mysql" ? strHost : SString(DB_SQLITE_QUEUE_NAME_DEFAULT));
SetOption<CDbOptionsMap>(strOptions, "log", bLoggingEnabled);
SetOption<CDbOptionsMap>(strOptions, "tag", strLogTag);
SetOption<CDbOptionsMap>(strOptions, "queue", strQueueName);
Expand Down
5 changes: 3 additions & 2 deletions Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ void CLuaDefs::DidUseFunction(lua_CFunction f, lua_State* luaVM)
if (pFunction)
{
CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState(info.luaVM);
SString strResourceName = pResource ? pResource->GetName() : "unknown";
CPerfStatFunctionTiming::GetSingleton()->UpdateTiming(strResourceName, pFunction->GetName().c_str(), elapsedTime, uiDeltaBytes);
CPerfStatFunctionTiming::GetSingleton()->UpdateTiming(
pResource ? pResource->GetName() : SString{"unknown"},
pFunction->GetName().c_str(), elapsedTime, uiDeltaBytes);
}
}

Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
project "Deathmatch"
cppdialect "C++20"
language "C++"
kind "SharedLib"
targetname "deathmatch"
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/utils/CFunctionUseLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ void CFunctionUseLogger::OnFunctionUse(lua_State* luaVM, const char* szFunctionN
return;

CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState(luaVM);
SString strResourceName = pResource ? pResource->GetName() : "Unknown";
SString strResourceName = pResource ? pResource->GetName() : SString{"Unknown"};

SString strKey("%s-%s", szFunctionName, *strResourceName);
SString strKey("%s-%s", szFunctionName, strResourceName.c_str());

SFuncCallRecord* pItem = MapFind(m_FuncCallRecordMap, strKey);
if (!pItem)
Expand Down
2 changes: 1 addition & 1 deletion Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ int CLuaUtilDefs::GetUserdataType(lua_State* luaVM)
else if (iArgument == LUA_TUSERDATA)
strType = GetUserDataClassName(*((void**)lua_touserdata(luaVM, 1)), luaVM, false);

strType = strType.empty() ? "userdata" : strType;
strType = strType.empty() ? SString{"userdata"} : strType;

lua_pushstring(luaVM, strType.c_str());
return 1;
Expand Down
22 changes: 13 additions & 9 deletions Shared/sdk/SString.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ class SString : public std::string

SString(const char* szText) : std::string(szText ? szText : "") {}

explicit SString(const char* szFormat, ...) : std::string()
// A hacky way to force the compiler
// into properly recognizing varargs vs const char* constructor
template <int=0>
TracerDS marked this conversation as resolved.
Show resolved Hide resolved
explicit SString(const char* format, ...) : std::string()
{
if (szFormat)
{
va_list vl;
if (!format)
return;

va_start(vl, szFormat);
vFormat(szFormat, vl);
va_end(vl);
}
va_list vl;

va_start(vl, format);
vFormat(format, vl);
va_end(vl);
}

SString(const std::string& strText) : std::string(strText) {}
SString(const std::string& text) : std::string(text) {}
SString(std::string&& text) : std::string(std::move(text)) {}

SString& Format(const char* szFormat, ...)
{
Expand Down
4 changes: 2 additions & 2 deletions Shared/sdk/SharedUtil.Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ void SharedUtil::CycleFile(const SString& strPathFilename, uint uiCycleThreshKB,
// Rename older files .1 .2 etc
uint uiNew = uiNumBackups - 1 - i;
uint uiOld = uiNumBackups - i;
SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : "");
SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : "");
SString strFilenameNewer = strPathFilename + (uiNew ? SString(".%d", uiNew) : SString());
SString strFilenameOlder = strPathFilename + (uiOld ? SString(".%d", uiOld) : SString());

FileDelete(strFilenameOlder);
FileRename(strFilenameNewer, strFilenameOlder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _START_GOOGLE_NAMESPACE_

template <bool> struct SparsehashCompileAssert { };
#define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
__attribute__((unused)) typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
[[maybe_unused]] typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]

namespace sparsehash_internal {

Expand Down
Loading