Skip to content

Commit

Permalink
Prep and dynamic host support
Browse files Browse the repository at this point in the history
  • Loading branch information
kwmx committed Sep 2, 2022
1 parent dca4914 commit e08e16e
Show file tree
Hide file tree
Showing 14 changed files with 1,441 additions and 39 deletions.
1 change: 1 addition & 0 deletions ZomboidRCON/ConnectionForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 35 additions & 7 deletions ZomboidRCON/ConnectionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ConnectionForm(Main MainForm)

private void connectBtn_Click(object sender, EventArgs e)
{
IPAddress? address = null;
if (!saveBox.Checked)
{
Properties.Settings.Default.ip = "";
Expand All @@ -38,15 +39,25 @@ private void connectBtn_Click(object sender, EventArgs e)
MessageBox.Show(this, "All fields must be filled", "ZomboidRCON");
return;
}
if (!IPAddress.TryParse(ipTxt.Text, out IPAddress address))
if (!IPAddress.TryParse(ipTxt.Text, out address))
{
MessageBox.Show(this, "Incorrect IP address", "ZomboidRCON");
return;

try
{
ipTxt.Text = ipTxt.Text.Replace("http://", "").Replace("https://", "").Replace("/", "");
address = GetAddressFromUrl(ipTxt.Text);
if (address == null) {
MessageBox.Show(this, "Couldn't find a valid IP for the provided URL", "ZomboidRCON");
return;
}
} catch (Exception exz) {
MessageBox.Show(this, "Incorrect IP address: " + exz.Message, "ZomboidRCON");
return;
}
}
if (address == null || address.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
{
MessageBox.Show(this, "Incorrect IP please enter an IPv4 address", "ZomboidRCON");
return;
}
if (!int.TryParse(portTxt.Text, out int port))
{
Expand All @@ -58,9 +69,9 @@ private void connectBtn_Click(object sender, EventArgs e)
passwordTxt.Enabled = false;
connectBtn.Enabled = false;
saveBox.Enabled = false;
_ = RconConnectAsync(address, port, passwordTxt.Text);
_ = RconConnectAsync(address, port, passwordTxt.Text, ipTxt.Text);
}
private async Task RconConnectAsync(IPAddress address, int port, string password)
private async Task RconConnectAsync(IPAddress address, int port, string password, string dbname)
{
RconClient client = RconClient.Create(address.ToString(), port);
try
Expand All @@ -77,7 +88,7 @@ private async Task RconConnectAsync(IPAddress address, int port, string password
Properties.Settings.Default.Save();
}

main.ResetConnection(client, address.ToString(), port);
main.ResetConnection(client, address.ToString(), port, dbname);
main.Show();
ok = true;
Close();
Expand All @@ -99,6 +110,18 @@ private async Task RconConnectAsync(IPAddress address, int port, string password
saveBox.Enabled = true;

}
private IPAddress? GetAddressFromUrl(string url)
{
if (Uri.CheckHostName(url) == UriHostNameType.Unknown) throw new Exception("Invalid URL");
Uri uri = new Uri("http://" + url);
IPHostEntry ihe = Dns.GetHostEntry(uri.Host);
if(ihe.AddressList.Length > 0)
foreach(IPAddress ipa in ihe.AddressList)
{
if (ipa.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return ipa;
}
return null;
}
private void ConnectionForm_Load(object sender, EventArgs e)
{
ipTxt.Text = String.IsNullOrWhiteSpace(Properties.Settings.Default.ip) ? "" : Properties.Settings.Default.ip;
Expand All @@ -111,5 +134,10 @@ private void ConnectionForm_FormClosed(object sender, FormClosedEventArgs e)
{
if(!ok) Application.Exit();
}

private void ipTxt_TextChanged(object sender, EventArgs e)
{

}
}
}
2 changes: 1 addition & 1 deletion ZomboidRCON/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace ZomboidRCON
internal class Constants
{
public const string RepoPath = "kwmx/ZomboidRCON";
public const string Version = "1.0.3";
public const string Version = "1.0.4";
public static string AssemblyVersionToSemver
{
get
Expand Down
101 changes: 101 additions & 0 deletions ZomboidRCON/ItemsPack/Forms/Items Pack Creator.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions ZomboidRCON/ItemsPack/Forms/Items Pack Creator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZomboidRCON.ItemsPack.Forms
{
public partial class ItemsPackCreator : Form
{
public ItemsPackCreator()
{
InitializeComponent();
}

private void ItemsPackCreator_Load(object sender, EventArgs e)
{

}
}
}
Loading

0 comments on commit e08e16e

Please sign in to comment.