From 8cc89063c85700ab703c3ade508f693d8ec176b1 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:18:30 +0200 Subject: [PATCH 1/7] Add C++20 support for Deathmatch project --- .../logic/CAccessControlListRight.cpp | 2 +- .../deathmatch/logic/CConsoleCommands.cpp | 16 +++++++++------- .../deathmatch/logic/CDatabaseManager.cpp | 8 ++++---- Server/mods/deathmatch/logic/CGame.cpp | 2 +- .../logic/CPerfStat.BandwidthUsage.cpp | 2 +- .../logic/CPerfStat.FunctionTiming.cpp | 8 ++++---- .../deathmatch/logic/CPerfStat.LuaMemory.cpp | 18 +++++++++--------- .../deathmatch/logic/CPerfStat.LuaTiming.cpp | 6 +++--- .../logic/CPerfStat.PlayerPacketUsage.cpp | 6 +++--- .../deathmatch/logic/CResourceManager.cpp | 4 ++-- .../logic/luadefs/CLuaAccountDefs.cpp | 19 +++++++++++++++++++ .../logic/luadefs/CLuaDatabaseDefs.cpp | 2 +- .../deathmatch/logic/luadefs/CLuaDefs.cpp | 5 +++-- Server/mods/deathmatch/premake5.lua | 1 + .../deathmatch/utils/CFunctionUseLogger.cpp | 4 ++-- .../deathmatch/logic/lua/CLuaFunctionParser.h | 17 ++++++++++------- .../deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 2 +- Shared/sdk/SString.h | 1 + Shared/sdk/SharedUtil.Logging.hpp | 4 ++-- .../sparsehash/internal/hashtable-common.h | 2 +- 20 files changed, 78 insertions(+), 51 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccessControlListRight.cpp b/Server/mods/deathmatch/logic/CAccessControlListRight.cpp index e6bb72db18..56d0e8e1e6 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..787ec194c6 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) @@ -1635,6 +1635,8 @@ bool DoAclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient, return false; } +#include + bool CConsoleCommands::AclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient) { BeginConsoleOutputCapture(pEchoClient); @@ -1657,8 +1659,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 58989394ec..b2ecae862b 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -708,7 +708,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..cdddb0e12e 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..e7035af71f 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..555b405604 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..aea831ef67 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..8ae34c59c1 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/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index 7af41f0e99..e01da3f3f4 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -14,9 +14,28 @@ #include "CStaticFunctionDefinitions.h" #include "CScriptArgReader.h" +class TestAbc +{ +public: + virtual int a() { return 123; } +}; + +class TestDef : public TestAbc +{ +public: + virtual int a() override { return 456; } +}; + +void abc(std::unordered_map>> map) +{ + throw LuaFunctionError("Hello, World"); +} + void CLuaAccountDefs::LoadFunctions() { constexpr static const std::pair functions[]{ + {"abc", ArgumentParser}, + // Log in/out funcs {"logIn", LogIn}, {"logOut", LogOut}, 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..d4bfb015bf 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..43bd8aa9b6 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/lua/CLuaFunctionParser.h b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h index fef13d708b..d15b5d1d02 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h @@ -46,20 +46,23 @@ struct CLuaFunctionParserBase // Translates a variant type to a list of names separated by slashes // std::variant => bool/int/float template - void TypeToNameVariant(SString& accumulator) + void TypeToNameVariant(std::string& accumulator) { - using param = typename is_variant::param1_t; + using variant_t = is_variant; + using rest_t = typename variant_t::rest_t; + static_assert(variant_t::value, "Not a variant!"); + if (accumulator.empty()) - accumulator = TypeToName(); + accumulator = TypeToName(); else - accumulator += "/" + TypeToName(); + accumulator += "/" + TypeToName(); - if constexpr (is_variant::count != 1) - return TypeToNameVariant::rest_t>(accumulator); + if constexpr (variant_t::count != 1) + return TypeToNameVariant(accumulator); } template - SString TypeToName() + std::string TypeToName() { if constexpr (std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v) return "string"; diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index 0b5847fa09..f80141ce49 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..106390a42e 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -30,6 +30,7 @@ class SString : public std::string SString(const char* szText) : std::string(szText ? szText : "") {} + template explicit SString(const char* szFormat, ...) : std::string() { if (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 { From dbe56a86978f431eecb983778b011e410c35f184 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:20:40 +0200 Subject: [PATCH 2/7] Removed test case --- .../logic/luadefs/CLuaAccountDefs.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp index e01da3f3f4..7af41f0e99 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaAccountDefs.cpp @@ -14,28 +14,9 @@ #include "CStaticFunctionDefinitions.h" #include "CScriptArgReader.h" -class TestAbc -{ -public: - virtual int a() { return 123; } -}; - -class TestDef : public TestAbc -{ -public: - virtual int a() override { return 456; } -}; - -void abc(std::unordered_map>> map) -{ - throw LuaFunctionError("Hello, World"); -} - void CLuaAccountDefs::LoadFunctions() { constexpr static const std::pair functions[]{ - {"abc", ArgumentParser}, - // Log in/out funcs {"logIn", LogIn}, {"logOut", LogOut}, From 2babeabecee2cba170847cb70890ac1a2654c563 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:22:17 +0200 Subject: [PATCH 3/7] Update CLuaFunctionParser.h --- .../deathmatch/logic/lua/CLuaFunctionParser.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h index d15b5d1d02..e6d98057c1 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h @@ -46,19 +46,16 @@ struct CLuaFunctionParserBase // Translates a variant type to a list of names separated by slashes // std::variant => bool/int/float template - void TypeToNameVariant(std::string& accumulator) + void TypeToNameVariant(SString& accumulator) { - using variant_t = is_variant; - using rest_t = typename variant_t::rest_t; - static_assert(variant_t::value, "Not a variant!"); - + using param = typename is_variant::param1_t; if (accumulator.empty()) - accumulator = TypeToName(); + accumulator = TypeToName(); else - accumulator += "/" + TypeToName(); - - if constexpr (variant_t::count != 1) - return TypeToNameVariant(accumulator); + accumulator += "/" + TypeToName(); + + if constexpr (is_variant::count != 1) + return TypeToNameVariant::rest_t>(accumulator); } template From b0d7d1573b3c16ce7176a91962f06213524fab6d Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:22:32 +0200 Subject: [PATCH 4/7] Update CLuaFunctionParser.h --- Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h index e6d98057c1..fef13d708b 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h +++ b/Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h @@ -53,13 +53,13 @@ struct CLuaFunctionParserBase accumulator = TypeToName(); else accumulator += "/" + TypeToName(); - + if constexpr (is_variant::count != 1) return TypeToNameVariant::rest_t>(accumulator); } template - std::string TypeToName() + SString TypeToName() { if constexpr (std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v) return "string"; From 6a5ca3a0301aaa34763a74eafb79effc0da40203 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:46:10 +0200 Subject: [PATCH 5/7] Update SString.h --- Shared/sdk/SString.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 106390a42e..22fc0277e4 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -31,19 +31,19 @@ class SString : public std::string SString(const char* szText) : std::string(szText ? szText : "") {} template - explicit SString(const char* szFormat, ...) : std::string() + 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& Format(const char* szFormat, ...) { From 7a6e88f4cc91bcb85fa6306fd3d156162e1a5ec8 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:46:50 +0200 Subject: [PATCH 6/7] Updated according to reviews --- Shared/sdk/SString.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Shared/sdk/SString.h b/Shared/sdk/SString.h index 22fc0277e4..16ed7f0b0d 100644 --- a/Shared/sdk/SString.h +++ b/Shared/sdk/SString.h @@ -30,6 +30,8 @@ class SString : public std::string SString(const char* szText) : std::string(szText ? szText : "") {} + // A hacky way to force the compiler + // into properly recognizing varargs vs const char* constructor template explicit SString(const char* format, ...) : std::string() { @@ -44,6 +46,7 @@ class SString : public std::string } SString(const std::string& text) : std::string(text) {} + SString(std::string&& text) : std::string(std::move(text)) {} SString& Format(const char* szFormat, ...) { From b0a5deb26ecaa1c47ca09dd3a99f974311885b78 Mon Sep 17 00:00:00 2001 From: Tracer <43095317+TracerDS@users.noreply.github.com> Date: Sun, 20 Oct 2024 21:55:46 +0200 Subject: [PATCH 7/7] Replaced SString() with SString{} --- .../deathmatch/logic/CAccessControlListRight.cpp | 2 +- Server/mods/deathmatch/logic/CConsoleCommands.cpp | 12 +++++------- Server/mods/deathmatch/logic/CGame.cpp | 2 +- .../deathmatch/logic/CPerfStat.BandwidthUsage.cpp | 2 +- .../deathmatch/logic/CPerfStat.FunctionTiming.cpp | 8 ++++---- .../mods/deathmatch/logic/CPerfStat.LuaMemory.cpp | 14 +++++++------- .../mods/deathmatch/logic/CPerfStat.LuaTiming.cpp | 6 +++--- Server/mods/deathmatch/logic/CResourceManager.cpp | 4 ++-- Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp | 2 +- .../mods/deathmatch/utils/CFunctionUseLogger.cpp | 2 +- .../mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 2 +- 11 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Server/mods/deathmatch/logic/CAccessControlListRight.cpp b/Server/mods/deathmatch/logic/CAccessControlListRight.cpp index 56d0e8e1e6..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 : SString(); + return pResult ? *pResult : SString{}; } } diff --git a/Server/mods/deathmatch/logic/CConsoleCommands.cpp b/Server/mods/deathmatch/logic/CConsoleCommands.cpp index 787ec194c6..a2da7b28a4 100644 --- a/Server/mods/deathmatch/logic/CConsoleCommands.cpp +++ b/Server/mods/deathmatch/logic/CConsoleCommands.cpp @@ -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] : SString(); - const SString& strResourceName = parts.size() > 1 ? parts[1] : SString(); - const SString& strRightName = parts.size() > 2 ? parts[2] : SString(); + 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"; @@ -1635,8 +1635,6 @@ bool DoAclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient, return false; } -#include - bool CConsoleCommands::AclRequest(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient) { BeginConsoleOutputCapture(pEchoClient); @@ -1659,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] : SString(); - const SString& strAction = parts.size() > 1 ? parts[1] : SString(); + 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/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index fc0301120c..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(""); + 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 cdddb0e12e..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) : SString(); + 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 e7035af71f..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() : 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{} : 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() : 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{} : 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 555b405604..93bbaff548 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.LuaMemory.cpp @@ -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("-") : 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); + 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 aea831ef67..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) : 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++] = 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/CResourceManager.cpp b/Server/mods/deathmatch/logic/CResourceManager.cpp index 8ae34c59c1..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() : SString()); + Refresh(false, sItem.pResource ? sItem.pResource->GetName() : SString{}); } else if (sItem.eQueue == QUEUE_REFRESHALL) { - Refresh(true, sItem.pResource ? sItem.pResource->GetName() : SString()); + Refresh(true, sItem.pResource ? sItem.pResource->GetName() : SString{}); } } } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp index d4bfb015bf..7cdbff863b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaDefs.cpp @@ -231,7 +231,7 @@ void CLuaDefs::DidUseFunction(lua_CFunction f, lua_State* luaVM) { CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState(info.luaVM); CPerfStatFunctionTiming::GetSingleton()->UpdateTiming( - pResource ? pResource->GetName() : SString("unknown"), + pResource ? pResource->GetName() : SString{"unknown"}, pFunction->GetName().c_str(), elapsedTime, uiDeltaBytes); } } diff --git a/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp b/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp index 43bd8aa9b6..83e9c26fee 100644 --- a/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp +++ b/Server/mods/deathmatch/utils/CFunctionUseLogger.cpp @@ -74,7 +74,7 @@ void CFunctionUseLogger::OnFunctionUse(lua_State* luaVM, const char* szFunctionN return; CResource* pResource = g_pGame->GetResourceManager()->GetResourceFromLuaState(luaVM); - SString strResourceName = pResource ? pResource->GetName() : SString("Unknown"); + SString strResourceName = pResource ? pResource->GetName() : SString{"Unknown"}; SString strKey("%s-%s", szFunctionName, strResourceName.c_str()); diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index f80141ce49..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() ? SString("userdata") : strType; + strType = strType.empty() ? SString{"userdata"} : strType; lua_pushstring(luaVM, strType.c_str()); return 1;