diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index 1fabd3482..ac6ffc6fc 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -43,7 +43,7 @@ namespace Barotrauma.Networking private readonly List serverSubmarines = new List(); - private string serverIP; + private string serverIP, serverName; private bool needAuth; private bool requiresPw; @@ -99,8 +99,8 @@ namespace Barotrauma.Networking { get { return ownerKey > 0; } } - - public GameClient(string newName, string ip, int ownerKey=0) + + public GameClient(string newName, string ip, string serverName = null, int ownerKey = 0) { //TODO: gui stuff should probably not be here? this.ownerKey = ownerKey; @@ -211,7 +211,7 @@ namespace Barotrauma.Networking serverSettings = new ServerSettings("Server", 0, 0, 0, false, false); - ConnectToServer(ip); + ConnectToServer(ip, serverName); //ServerLog = new ServerLog(""); @@ -219,7 +219,7 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen = new NetLobbyScreen(); } - private void ConnectToServer(string hostIP) + private void ConnectToServer(string hostIP, string hostName) { chatBox.InputBox.Enabled = false; if (GameMain.NetLobbyScreen?.TextBox != null) @@ -227,6 +227,8 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen.TextBox.Enabled = false; } + serverName = hostName; + string[] address = hostIP.Split(':'); if (address.Length == 1) { @@ -301,7 +303,7 @@ namespace Barotrauma.Networking private bool RetryConnection(GUIButton button, object obj) { if (client != null) client.Shutdown(TextManager.Get("Disconnecting")); - ConnectToServer(serverIP); + ConnectToServer(serverIP, serverName); return true; } @@ -346,7 +348,10 @@ namespace Barotrauma.Networking { if (reconnectBox == null) { - reconnectBox = new GUIMessageBox(connectingText, TextManager.GetWithVariable("ConnectingTo", "[serverip]", serverIP), new string[] { TextManager.Get("Cancel") }); + reconnectBox = new GUIMessageBox( + connectingText, + TextManager.GetWithVariable("ConnectingTo", "[serverip]", string.IsNullOrEmpty(serverName) ? serverIP : serverName), + new string[] { TextManager.Get("Cancel") }); reconnectBox.Buttons[0].OnClicked += (btn, userdata) => { CancelConnect(); return true; }; reconnectBox.Buttons[0].OnClicked += reconnectBox.Close; } @@ -903,7 +908,7 @@ namespace Barotrauma.Networking TextManager.Get("ConnectionLost"), msg, new string[0]); connected = false; - ConnectToServer(serverIP); + ConnectToServer(serverIP, serverName); } else { @@ -955,7 +960,7 @@ namespace Barotrauma.Networking { if (!CoroutineManager.IsCoroutineRunning("WaitForStartingInfo")) { - ConnectToServer(serverIP); + ConnectToServer(serverIP, serverName); yield return new WaitForSeconds(2.0f); } yield return new WaitForSeconds(0.5f); diff --git a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs index 759ab39c1..d4bfe4bd2 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs @@ -727,7 +727,7 @@ namespace Barotrauma GameMain.ServerChildProcess = Process.Start(processInfo); Thread.Sleep(1000); //wait until the server is ready before connecting - GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(),ownerKey); + GameMain.Client = new GameClient(name, "127.0.0.1:" + port.ToString(), name, ownerKey); } catch (Exception e) { diff --git a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs index c8f44567d..223ab7bfe 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/ServerListScreen.cs @@ -598,9 +598,11 @@ namespace Barotrauma GameMain.Config.SaveNewPlayerConfig(); string ip = null; + string serverName = null; if (ipBox.UserData is ServerInfo serverInfo) { ip = serverInfo.IP + ":" + serverInfo.Port; + serverName = serverInfo.ServerName; } else if (!string.IsNullOrWhiteSpace(ipBox.Text)) { @@ -614,18 +616,18 @@ namespace Barotrauma return false; } - CoroutineManager.StartCoroutine(ConnectToServer(ip)); + CoroutineManager.StartCoroutine(ConnectToServer(ip, serverName)); return true; } - private IEnumerable ConnectToServer(string ip) + private IEnumerable ConnectToServer(string ip, string serverName) { #if !DEBUG try { #endif - GameMain.Client = new GameClient(clientNameBox.Text, ip); + GameMain.Client = new GameClient(clientNameBox.Text, ip, serverName); #if !DEBUG } catch (Exception e)