diff --git a/Server/mods/deathmatch/logic/CAccessControlListRight.cpp b/Server/mods/deathmatch/logic/CAccessControlListRight.cpp index e6bb72db18..331bd197d1 100644 --- a/Server/mods/deathmatch/logic/CAccessControlListRight.cpp +++ b/Server/mods/deathmatch/logic/CAccessControlListRight.cpp @@ -92,6 +92,6 @@ SString CAccessControlListRight::GetAttributeValue(const SString& strAttributeNa else { SString* pResult = MapFind(m_ExtraAttributeMap, strAttributeName); - return pResult ? *pResult : ""; + return pResult ? *pResult : SString{}; } } diff --git a/Server/mods/deathmatch/logic/CConsoleCommands.cpp b/Server/mods/deathmatch/logic/CConsoleCommands.cpp index 5f19e566f3..a2da7b28a4 100644 --- a/Server/mods/deathmatch/logic/CConsoleCommands.cpp +++ b/Server/mods/deathmatch/logic/CConsoleCommands.cpp @@ -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()); @@ -1587,9 +1587,9 @@ bool DoAclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient, std::vector 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"; @@ -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) @@ -1657,8 +1657,8 @@ bool CConsoleCommands::AuthorizeSerial(CConsole* pConsole, const char* szArgumen std::vector 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 == ""; diff --git a/Server/mods/deathmatch/logic/CDatabaseManager.cpp b/Server/mods/deathmatch/logic/CDatabaseManager.cpp index 1ccc1857b2..8fd2da471b 100644 --- a/Server/mods/deathmatch/logic/CDatabaseManager.cpp +++ b/Server/mods/deathmatch/logic/CDatabaseManager.cpp @@ -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); @@ -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); diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index d4efea393f..51dc656f21 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -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()); diff --git a/Server/mods/deathmatch/logic/CPerfStat.BandwidthUsage.cpp b/Server/mods/deathmatch/logic/CPerfStat.BandwidthUsage.cpp index 8659a5534c..7b442ab53a 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.BandwidthUsage.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.BandwidthUsage.cpp @@ -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); diff --git a/Server/mods/deathmatch/logic/CPerfStat.FunctionTiming.cpp b/Server/mods/deathmatch/logic/CPerfStat.FunctionTiming.cpp index 9928f432fa..59bd3f324f 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.FunctionTiming.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.FunctionTiming.cpp @@ -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); } @@ -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); } } diff --git a/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp b/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp index 0423cf7eea..93bbaff548 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp @@ -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 @@ -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); } } diff --git a/Server/mods/deathmatch/logic/CPerfStat.LuaTiming.cpp b/Server/mods/deathmatch/logic/CPerfStat.LuaTiming.cpp index 74b6eaad00..4c76a3cc9b 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.LuaTiming.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.LuaTiming.cpp @@ -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 ? "-" : ""; } diff --git a/Server/mods/deathmatch/logic/CPerfStat.PlayerPacketUsage.cpp b/Server/mods/deathmatch/logic/CPerfStat.PlayerPacketUsage.cpp index 8b7bf8bfae..194f9fb021 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.PlayerPacketUsage.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.PlayerPacketUsage.cpp @@ -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) : "-"; + row[c++] = value.uiBytesOutPerSec ? std::to_string(value.uiBytesOutPerSec) : "-"; row[c++] = value.strSerial; } row[c++] = value.strName; diff --git a/Server/mods/deathmatch/logic/CResourceManager.cpp b/Server/mods/deathmatch/logic/CResourceManager.cpp index b3b2d2f9c1..d3205ebc09 100644 --- a/Server/mods/deathmatch/logic/CResourceManager.cpp +++ b/Server/mods/deathmatch/logic/CResourceManager.cpp @@ -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{}); } } } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaDatabaseDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaDatabaseDefs.cpp index bb5a1d1d16..77d0dd2ff4 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaDatabaseDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaDatabaseDefs.cpp @@ -292,7 +292,7 @@ int CLuaDatabaseDefs::DbConnect(lua_State* luaVM) // Set default values if required GetOption(strOptions, "log", bLoggingEnabled, 1); GetOption(strOptions, "tag", strLogTag, "script"); - GetOption(strOptions, "queue", strQueueName, (strType == "mysql") ? strHost : DB_SQLITE_QUEUE_NAME_DEFAULT); + GetOption(strOptions, "queue", strQueueName, strType == "mysql" ? strHost : SString(DB_SQLITE_QUEUE_NAME_DEFAULT)); SetOption(strOptions, "log", bLoggingEnabled); SetOption(strOptions, "tag", strLogTag); SetOption(strOptions, "queue", strQueueName); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp index 8d8e3a3646..7cdbff863b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp @@ -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); } } diff --git a/Server/mods/deathmatch/premake5.lua b/Server/mods/deathmatch/premake5.lua index ddecdfb179..bd60d3409e 100644 --- a/Server/mods/deathmatch/premake5.lua +++ b/Server/mods/deathmatch/premake5.lua @@ -1,4 +1,5 @@ project "Deathmatch" + cppdialect "C++20" language "C++" kind "SharedLib" targetname "deathmatch" diff --git a/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp b/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp index 9226de9dfe..83e9c26fee 100644 --- a/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp +++ b/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp @@ -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) diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index 0b5847fa09..12c0515ca3 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -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; diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 00c57d0c1e..16ed7f0b0d 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -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 + 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, ...) { diff --git a/Shared/sdk/SharedUtil.Logging.hpp b/Shared/sdk/SharedUtil.Logging.hpp index f98b3bbdf6..5c34f3d1ec 100644 --- a/Shared/sdk/SharedUtil.Logging.hpp +++ b/Shared/sdk/SharedUtil.Logging.hpp @@ -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); diff --git a/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h b/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h index bac2b88235..9e49ec890f 100644 --- a/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h +++ b/vendor/sparsehash/src/sparsehash/internal/hashtable-common.h @@ -51,7 +51,7 @@ _START_GOOGLE_NAMESPACE_ template 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 {