(d5505ed3d) Show the name of the server in the "connecting to..." popup instead of the IP address

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:52:07 +03:00
parent e633ecca69
commit c4584f7763
3 changed files with 20 additions and 13 deletions
@@ -43,7 +43,7 @@ namespace Barotrauma.Networking
private readonly List<Submarine> serverSubmarines = new List<Submarine>(); private readonly List<Submarine> serverSubmarines = new List<Submarine>();
private string serverIP; private string serverIP, serverName;
private bool needAuth; private bool needAuth;
private bool requiresPw; private bool requiresPw;
@@ -99,8 +99,8 @@ namespace Barotrauma.Networking
{ {
get { return ownerKey > 0; } 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? //TODO: gui stuff should probably not be here?
this.ownerKey = ownerKey; this.ownerKey = ownerKey;
@@ -211,7 +211,7 @@ namespace Barotrauma.Networking
serverSettings = new ServerSettings("Server", 0, 0, 0, false, false); serverSettings = new ServerSettings("Server", 0, 0, 0, false, false);
ConnectToServer(ip); ConnectToServer(ip, serverName);
//ServerLog = new ServerLog(""); //ServerLog = new ServerLog("");
@@ -219,7 +219,7 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen = new NetLobbyScreen(); GameMain.NetLobbyScreen = new NetLobbyScreen();
} }
private void ConnectToServer(string hostIP) private void ConnectToServer(string hostIP, string hostName)
{ {
chatBox.InputBox.Enabled = false; chatBox.InputBox.Enabled = false;
if (GameMain.NetLobbyScreen?.TextBox != null) if (GameMain.NetLobbyScreen?.TextBox != null)
@@ -227,6 +227,8 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.TextBox.Enabled = false; GameMain.NetLobbyScreen.TextBox.Enabled = false;
} }
serverName = hostName;
string[] address = hostIP.Split(':'); string[] address = hostIP.Split(':');
if (address.Length == 1) if (address.Length == 1)
{ {
@@ -301,7 +303,7 @@ namespace Barotrauma.Networking
private bool RetryConnection(GUIButton button, object obj) private bool RetryConnection(GUIButton button, object obj)
{ {
if (client != null) client.Shutdown(TextManager.Get("Disconnecting")); if (client != null) client.Shutdown(TextManager.Get("Disconnecting"));
ConnectToServer(serverIP); ConnectToServer(serverIP, serverName);
return true; return true;
} }
@@ -346,7 +348,10 @@ namespace Barotrauma.Networking
{ {
if (reconnectBox == null) 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 += (btn, userdata) => { CancelConnect(); return true; };
reconnectBox.Buttons[0].OnClicked += reconnectBox.Close; reconnectBox.Buttons[0].OnClicked += reconnectBox.Close;
} }
@@ -903,7 +908,7 @@ namespace Barotrauma.Networking
TextManager.Get("ConnectionLost"), TextManager.Get("ConnectionLost"),
msg, new string[0]); msg, new string[0]);
connected = false; connected = false;
ConnectToServer(serverIP); ConnectToServer(serverIP, serverName);
} }
else else
{ {
@@ -955,7 +960,7 @@ namespace Barotrauma.Networking
{ {
if (!CoroutineManager.IsCoroutineRunning("WaitForStartingInfo")) if (!CoroutineManager.IsCoroutineRunning("WaitForStartingInfo"))
{ {
ConnectToServer(serverIP); ConnectToServer(serverIP, serverName);
yield return new WaitForSeconds(2.0f); yield return new WaitForSeconds(2.0f);
} }
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
@@ -727,7 +727,7 @@ namespace Barotrauma
GameMain.ServerChildProcess = Process.Start(processInfo); GameMain.ServerChildProcess = Process.Start(processInfo);
Thread.Sleep(1000); //wait until the server is ready before connecting 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) catch (Exception e)
{ {
@@ -598,9 +598,11 @@ namespace Barotrauma
GameMain.Config.SaveNewPlayerConfig(); GameMain.Config.SaveNewPlayerConfig();
string ip = null; string ip = null;
string serverName = null;
if (ipBox.UserData is ServerInfo serverInfo) if (ipBox.UserData is ServerInfo serverInfo)
{ {
ip = serverInfo.IP + ":" + serverInfo.Port; ip = serverInfo.IP + ":" + serverInfo.Port;
serverName = serverInfo.ServerName;
} }
else if (!string.IsNullOrWhiteSpace(ipBox.Text)) else if (!string.IsNullOrWhiteSpace(ipBox.Text))
{ {
@@ -614,18 +616,18 @@ namespace Barotrauma
return false; return false;
} }
CoroutineManager.StartCoroutine(ConnectToServer(ip)); CoroutineManager.StartCoroutine(ConnectToServer(ip, serverName));
return true; return true;
} }
private IEnumerable<object> ConnectToServer(string ip) private IEnumerable<object> ConnectToServer(string ip, string serverName)
{ {
#if !DEBUG #if !DEBUG
try try
{ {
#endif #endif
GameMain.Client = new GameClient(clientNameBox.Text, ip); GameMain.Client = new GameClient(clientNameBox.Text, ip, serverName);
#if !DEBUG #if !DEBUG
} }
catch (Exception e) catch (Exception e)