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.
This commit is contained in:
Robert Müller 2024-08-08 18:50:07 +02:00
parent 00586a0c4a
commit 323ccf5a22

View file

@ -456,7 +456,6 @@ void CClient::Connect(const char *pAddress, const char *pPassword)
Disconnect(); Disconnect();
dbg_assert(m_State == IClient::STATE_OFFLINE, "Disconnect must ensure that client is offline"); dbg_assert(m_State == IClient::STATE_OFFLINE, "Disconnect must ensure that client is offline");
m_ConnectionId = RandomUuid();
if(pAddress != m_aConnectAddressStr) if(pAddress != m_aConnectAddressStr)
str_copy(m_aConnectAddressStr, pAddress); 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); str_format(aMsg, sizeof(aMsg), "connecting to '%s'", m_aConnectAddressStr);
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aMsg, gs_ClientNetworkPrintColor); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aMsg, gs_ClientNetworkPrintColor);
ServerInfoRequest();
int NumConnectAddrs = 0; int NumConnectAddrs = 0;
NETADDR aConnectAddrs[MAX_SERVER_ADDRESSES]; NETADDR aConnectAddrs[MAX_SERVER_ADDRESSES];
mem_zero(aConnectAddrs, sizeof(aConnectAddrs)); mem_zero(aConnectAddrs, sizeof(aConnectAddrs));
@ -502,11 +499,18 @@ void CClient::Connect(const char *pAddress, const char *pPassword)
if(NumConnectAddrs == 0) if(NumConnectAddrs == 0)
{ {
log_error("client", "could not find any connect address, defaulting to localhost for whatever reason..."); log_error("client", "could not find any connect address");
net_host_lookup("localhost", &aConnectAddrs[0], m_aNetClient[CONN_MAIN].NetType()); char aWarning[256];
NumConnectAddrs = 1; 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) if(m_SendPassword)
{ {
str_copy(m_aPassword, g_Config.m_Password); str_copy(m_aPassword, g_Config.m_Password);