From f3409f067d388d42bc393adf0ab79900b4881227 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 24 Nov 2018 19:35:45 +0200 Subject: [PATCH] IPv6 fixes: - Fixed IPv6 addresses being clipped from the end in the server list screen because the IP textbox was too small to fit them. - Fixed clients parsing IPv6 addresses wrong because they assumed the first ":" in the address is the separator between the IP and port. --- .../Source/Networking/GameClient.cs | 18 ++++++++---------- .../Source/Screens/ServerListScreen.cs | 6 +++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 541c878df..8f769d797 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -122,25 +122,23 @@ namespace Barotrauma.Networking public void ConnectToServer(string hostIP) { string[] address = hostIP.Split(':'); - if (address.Length==1) + if (address.Length == 1) { serverIP = hostIP; Port = NetConfig.DefaultPort; } else { - serverIP = address[0]; - - int port = 0; - if (!int.TryParse(address[1], out port)) + serverIP = string.Join(":", address.Take(address.Length - 1)); + if (!int.TryParse(address[address.Length - 1], out int port)) { - DebugConsole.ThrowError("Invalid port: "+address[1]+"!"); + DebugConsole.ThrowError("Invalid port: " + address[address.Length - 1] + "!"); Port = NetConfig.DefaultPort; } else { Port = port; - } + } } myCharacter = Character.Controlled; @@ -172,7 +170,7 @@ namespace Barotrauma.Networking } catch { - new GUIMessageBox("Could not connect to server", "Failed to resolve address \""+serverIP+":"+Port+"\". Please make sure you have entered a valid IP address."); + new GUIMessageBox("Could not connect to server", "Failed to resolve address \"" + serverIP + ":" + Port + "\". Please make sure you have entered a valid IP address."); return; } @@ -186,13 +184,13 @@ namespace Barotrauma.Networking } catch (Exception e) { - DebugConsole.ThrowError("Couldn't connect to "+hostIP+". Error message: "+e.Message); + DebugConsole.ThrowError("Couldn't connect to " + hostIP + ". Error message: " + e.Message); Disconnect(); GameMain.ServerListScreen.Select(); return; } - + updateInterval = new TimeSpan(0, 0, 0, 0, 150); CoroutineManager.StartCoroutine(WaitForStartingInfo()); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs index 6a21849b5..04a119090 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs @@ -64,7 +64,11 @@ namespace Barotrauma clientNameBox.Text = GameMain.Config.DefaultPlayerName; new GUITextBlock(new Rectangle(0, 100, 0, 30), TextManager.Get("ServerIP"), "", menu); - ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), "", menu); + ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), "", menu) + { + //max IPv6 address length + port + MaxTextLength = 45 + 6 + }; int middleX = (int)(width * 0.35f);