From d2139e4beca2f0e4e92d16b3297667533baabcfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 28 Apr 2024 16:45:56 +0200 Subject: [PATCH 1/2] Use `net_addr_str` directly to format address including port --- src/engine/client/client.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 5a872fd22..f3d510c5c 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1585,11 +1585,10 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy) { return; } - char aAddr[128]; - char aIp[64]; + char aAddr[NETADDR_MAXSTRSIZE]; NETADDR ServerAddr = ServerAddress(); - net_addr_str(&ServerAddr, aIp, sizeof(aIp), 0); - str_format(aAddr, sizeof(aAddr), "%s:%d", aIp, RedirectPort); + ServerAddr.port = RedirectPort; + net_addr_str(&ServerAddr, aAddr, sizeof(aAddr), true); Connect(aAddr); } else if(Conn == CONN_MAIN && (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_RCON_CMD_ADD) From 938d264c4373d6f7625566c06ef22ff590fc4a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 28 Apr 2024 16:48:09 +0200 Subject: [PATCH 2/2] Fix wrong server address used in password popup when redirected Always use the server address from the network client to reconnect to the correct server after being disconnected due to wrong password. The password popup is only shown after being disconnected, so the server address of the network client should always the address of the server which the client should reconnect to with the password. Using `ui_server_address` was causing the wrong address to be used after being redirected to another server and if the config variable is changed while the password popup is open. Closes #8260. --- src/game/client/components/menus.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index e77e29242..3dd902c74 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1433,7 +1433,9 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen) static CButtonContainer s_ButtonTryAgain; if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || Ui()->ConsumeHotkey(CUi::HOTKEY_ENTER)) { - Client()->Connect(g_Config.m_UiServerAddress, g_Config.m_Password); + char aAddr[NETADDR_MAXSTRSIZE]; + net_addr_str(&Client()->ServerAddress(), aAddr, sizeof(aAddr), true); + Client()->Connect(aAddr, g_Config.m_Password); } Box.HSplitBottom(60.f, &Box, &Part);