Skip to content

Commit

Permalink
Rectified conflicts
Browse files Browse the repository at this point in the history
Ready for merge
  • Loading branch information
AMacro committed Jul 14, 2024
1 parent 36db54a commit 24b6f58
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 286 deletions.
178 changes: 0 additions & 178 deletions Multiplayer/Components/MainMenu/MultiplayerPane.cs

This file was deleted.

This file was deleted.

67 changes: 61 additions & 6 deletions Multiplayer/Components/MainMenu/ServerBrowserPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Multiplayer.Networking.Data;
using DV;
using Multiplayer.Components.Networking.UI;
using System.Net;



Expand Down Expand Up @@ -60,7 +61,7 @@ public class ServerBrowserPane : MonoBehaviour
private const int REFRESH_MIN_TIME = 10; //Stop refresh spam

//connection parameters
private string ipAddress;
private string address;
private int portNumber;
string password = null;
bool direct = false;
Expand Down Expand Up @@ -325,7 +326,7 @@ private void JoinAction()
{
//not making a direct connection
direct = false;
ipAddress = selectedServer.ip;
address = selectedServer.ip;
portNumber = selectedServer.port;

ShowPasswordPopup();
Expand Down Expand Up @@ -413,7 +414,6 @@ private void UpdateDetailsPane()

private void ShowIpPopup()
{
Multiplayer.Log("In ShowIpPpopup");
var popup = MainMenuThingsAndStuff.Instance.ShowRenamePopup();
if (popup == null)
{
Expand All @@ -435,11 +435,46 @@ private void ShowIpPopup()

if (!IPv4Regex.IsMatch(result.data) && !IPv6Regex.IsMatch(result.data))
{
string inputUrl = result.data;

if (!inputUrl.StartsWith("http://") && !inputUrl.StartsWith("https://"))
{
inputUrl = "http://" + inputUrl;
}

bool isValidURL = Uri.TryCreate(inputUrl, UriKind.Absolute, out Uri uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

if (isValidURL)
{
string domainName = ExtractDomainName(result.data);
try
{
IPHostEntry hostEntry = Dns.GetHostEntry(domainName);
IPAddress[] addresses = hostEntry.AddressList;

if (addresses.Length > 0)
{
string address2 = addresses[0].ToString();

address = address2;
Multiplayer.Log(address);

ShowPortPopup();
return;
}
}
catch (Exception ex)
{
Multiplayer.LogError($"An error occurred: {ex.Message}");
}
}

ShowOkPopup(Locale.SERVER_BROWSER__IP_INVALID, ShowIpPopup);
}
else
{
ipAddress = result.data;
address = result.data;
ShowPortPopup();
}
};
Expand Down Expand Up @@ -514,13 +549,13 @@ private void ShowPasswordPopup()
if (direct)
{
//store params for later
Multiplayer.Settings.LastRemoteIP = ipAddress;
Multiplayer.Settings.LastRemoteIP = address;
Multiplayer.Settings.LastRemotePort = portNumber;
Multiplayer.Settings.LastRemotePassword = result.data;

}

SingletonBehaviour<NetworkLifecycle>.Instance.StartClient(ipAddress, portNumber, result.data, false);
SingletonBehaviour<NetworkLifecycle>.Instance.StartClient(address, portNumber, result.data, false);

//ShowConnectingPopup(); // Show a connecting message
//SingletonBehaviour<NetworkLifecycle>.Instance.ConnectionFailed += HandleConnectionFailed;
Expand Down Expand Up @@ -656,6 +691,26 @@ private void FillDummyServers()

gridView.SetModel(gridViewModel);
}

private string ExtractDomainName(string input)
{
if (input.StartsWith("http://"))
{
input = input.Substring(7);
}
else if (input.StartsWith("https://"))
{
input = input.Substring(8);
}

int portIndex = input.IndexOf(':');
if (portIndex != -1)
{
input = input.Substring(0, portIndex);
}

return input;
}
}


Expand Down
Loading

0 comments on commit 24b6f58

Please sign in to comment.