From 323ccf5a2298eb21397363f102df954b0e8f5bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 8 Aug 2024 18:50:07 +0200 Subject: [PATCH] Show warning when connect address cannot be resolved Show warning and disconnect instead of falling back to connecting to `localhost` when the connect address cannot be resolved. --- src/engine/client/client.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 8155b7104..abdf0f9b5 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -456,7 +456,6 @@ void CClient::Connect(const char *pAddress, const char *pPassword) Disconnect(); dbg_assert(m_State == IClient::STATE_OFFLINE, "Disconnect must ensure that client is offline"); - m_ConnectionId = RandomUuid(); if(pAddress != m_aConnectAddressStr) str_copy(m_aConnectAddressStr, pAddress); @@ -464,8 +463,6 @@ void CClient::Connect(const char *pAddress, const char *pPassword) str_format(aMsg, sizeof(aMsg), "connecting to '%s'", m_aConnectAddressStr); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aMsg, gs_ClientNetworkPrintColor); - ServerInfoRequest(); - int NumConnectAddrs = 0; NETADDR aConnectAddrs[MAX_SERVER_ADDRESSES]; mem_zero(aConnectAddrs, sizeof(aConnectAddrs)); @@ -502,11 +499,18 @@ void CClient::Connect(const char *pAddress, const char *pPassword) if(NumConnectAddrs == 0) { - log_error("client", "could not find any connect address, defaulting to localhost for whatever reason..."); - net_host_lookup("localhost", &aConnectAddrs[0], m_aNetClient[CONN_MAIN].NetType()); - NumConnectAddrs = 1; + log_error("client", "could not find any connect address"); + char aWarning[256]; + str_format(aWarning, sizeof(aWarning), Localize("Could not resolve connect address '%s'. See local console for details."), m_aConnectAddressStr); + SWarning Warning(Localize("Connect address error"), aWarning); + Warning.m_AutoHide = false; + AddWarning(Warning); + return; } + m_ConnectionId = RandomUuid(); + ServerInfoRequest(); + if(m_SendPassword) { str_copy(m_aPassword, g_Config.m_Password);