diff --git a/Client/core/CConnectManager.cpp b/Client/core/CConnectManager.cpp index c9e0edbb017..a054e5347a9 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 message; 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)); + message = mtasa::format(_("Reconnecting to {0}:{1} ..."), m_strHost, m_usPort); + else + 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)); return true; } diff --git a/Shared/sdk/SharedUtil.h b/Shared/sdk/SharedUtil.h index 3d4ff256dc6..225aad21b4d 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 + inline std::string format(const std::string_view fmt, _Types&&... _Args) + { + return std::vformat(fmt, std::make_format_args(_Args...)); + } +} + +#endif