(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

View File

@@ -43,7 +43,7 @@ namespace Barotrauma.Networking
private readonly List<Submarine> serverSubmarines = new List<Submarine>();
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);

View File

@@ -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)
{

View File

@@ -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<object> ConnectToServer(string ip)
private IEnumerable<object> 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)