From 4ac91fbf8a3103821387890b2d4e3934cb0f96a3 Mon Sep 17 00:00:00 2001 From: G-Moris Date: Sat, 30 Aug 2025 09:36:53 +0300 Subject: [PATCH 1/5] Update --- Client/core/CConnectManager.cpp | 11 +++++++---- Shared/sdk/SharedUtil.h | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Client/core/CConnectManager.cpp b/Client/core/CConnectManager.cpp index c9e0edbb017..bd50d4f6778 100644 --- a/Client/core/CConnectManager.cpp +++ b/Client/core/CConnectManager.cpp @@ -150,11 +150,14 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c OpenServerFirewall(m_Address, CServerBrowser::GetSingletonPtr()->FindServerHttpPort(m_strHost, m_usPort), true); // Display the status box - SString strBuffer(_("Connecting to %s:%u ..."), m_strHost.c_str(), m_usPort); + std::string formatConnecting; if (m_bReconnect) - strBuffer = SString(_("Reconnecting to %s:%u ..."), m_strHost.c_str(), m_usPort); - CCore::GetSingleton().ShowMessageBox(_("CONNECTING"), strBuffer, MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick); - WriteDebugEvent(SString("Connecting to %s:%u ...", m_strHost.c_str(), m_usPort)); + formatConnecting = mtasa::format(_("Reconnecting to {}:{} ..."), m_strHost, m_usPort); + else + formatConnecting = mtasa::format(_("Connecting to {}:{} ..."), m_strHost, m_usPort); + + CCore::GetSingleton().ShowMessageBox(_("CONNECTING"), formatConnecting.c_str(), MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick); + WriteDebugEvent(std::format("Connecting to {}:{} ...", m_strHost, m_usPort)); return true; } diff --git a/Shared/sdk/SharedUtil.h b/Shared/sdk/SharedUtil.h index 3d4ff256dc6..88cfc3419b4 100644 --- a/Shared/sdk/SharedUtil.h +++ b/Shared/sdk/SharedUtil.h @@ -85,3 +85,21 @@ #define strnicmp strncasecmp #endif #endif + +// Ensure that the C++ version is at least C++20 +#if __cplusplus >= 202002L + +/* + The function prevents a compilation error caused by using non-constant format strings and + correctly forwards the arguments to std::format for formatting +*/ +namespace mtasa +{ + template + __forceinline std::string format(const std::string_view fmt, _Types&&... _Args) + { + return std::vformat(fmt, std::make_format_args(_Args...)); + } +} + +#endif From 18a1273f26ae05f93e8e0d4e8fa707a9b56b258d Mon Sep 17 00:00:00 2001 From: G-Moris Date: Sat, 30 Aug 2025 09:38:12 +0300 Subject: [PATCH 2/5] Update 2 --- Client/core/CConnectManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Client/core/CConnectManager.cpp b/Client/core/CConnectManager.cpp index bd50d4f6778..979e9929c66 100644 --- a/Client/core/CConnectManager.cpp +++ b/Client/core/CConnectManager.cpp @@ -150,13 +150,13 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c OpenServerFirewall(m_Address, CServerBrowser::GetSingletonPtr()->FindServerHttpPort(m_strHost, m_usPort), true); // Display the status box - std::string formatConnecting; + std::string message; if (m_bReconnect) - formatConnecting = mtasa::format(_("Reconnecting to {}:{} ..."), m_strHost, m_usPort); + message = mtasa::format(_("Reconnecting to {}:{} ..."), m_strHost, m_usPort); else - formatConnecting = mtasa::format(_("Connecting to {}:{} ..."), m_strHost, m_usPort); + message = mtasa::format(_("Connecting to {}:{} ..."), m_strHost, m_usPort); - CCore::GetSingleton().ShowMessageBox(_("CONNECTING"), formatConnecting.c_str(), MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick); + CCore::GetSingleton().ShowMessageBox(_("CONNECTING"), message.c_str(), MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick); WriteDebugEvent(std::format("Connecting to {}:{} ...", m_strHost, m_usPort)); return true; From b43eaa5b06822bdda08420721d206837036d0bf7 Mon Sep 17 00:00:00 2001 From: G-Moris Date: Sat, 30 Aug 2025 09:52:20 +0300 Subject: [PATCH 3/5] constexpr --- Shared/sdk/SharedUtil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/sdk/SharedUtil.h b/Shared/sdk/SharedUtil.h index 88cfc3419b4..1e97597f21e 100644 --- a/Shared/sdk/SharedUtil.h +++ b/Shared/sdk/SharedUtil.h @@ -96,7 +96,7 @@ namespace mtasa { template - __forceinline std::string format(const std::string_view fmt, _Types&&... _Args) + constexpr std::string format(const std::string_view fmt, _Types&&... _Args) { return std::vformat(fmt, std::make_format_args(_Args...)); } From c60a2b9d21afd783da13a14a99959f9053588173 Mon Sep 17 00:00:00 2001 From: G-Moris Date: Sat, 30 Aug 2025 09:57:16 +0300 Subject: [PATCH 4/5] inline --- Shared/sdk/SharedUtil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/sdk/SharedUtil.h b/Shared/sdk/SharedUtil.h index 1e97597f21e..225aad21b4d 100644 --- a/Shared/sdk/SharedUtil.h +++ b/Shared/sdk/SharedUtil.h @@ -96,7 +96,7 @@ namespace mtasa { template - constexpr std::string format(const std::string_view fmt, _Types&&... _Args) + inline std::string format(const std::string_view fmt, _Types&&... _Args) { return std::vformat(fmt, std::make_format_args(_Args...)); } From 9848e0b2388faa45c0b5ba382313b5eb08d3990f Mon Sep 17 00:00:00 2001 From: G-Moris Date: Sat, 30 Aug 2025 20:17:25 +0300 Subject: [PATCH 5/5] Recommended changes --- Client/core/CConnectManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/core/CConnectManager.cpp b/Client/core/CConnectManager.cpp index 979e9929c66..a054e5347a9 100644 --- a/Client/core/CConnectManager.cpp +++ b/Client/core/CConnectManager.cpp @@ -152,9 +152,9 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c // Display the status box std::string message; if (m_bReconnect) - message = mtasa::format(_("Reconnecting to {}:{} ..."), m_strHost, m_usPort); + message = mtasa::format(_("Reconnecting to {0}:{1} ..."), m_strHost, m_usPort); else - message = mtasa::format(_("Connecting to {}:{} ..."), m_strHost, m_usPort); + message = mtasa::format(_("Connecting to {0}:{1} ..."), m_strHost, m_usPort); CCore::GetSingleton().ShowMessageBox(_("CONNECTING"), message.c_str(), MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick); WriteDebugEvent(std::format("Connecting to {}:{} ...", m_strHost, m_usPort));