From 04c0a028e84eaec31f5039c36f5f50944a97687a Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Mon, 21 Sep 2020 06:59:35 +0200 Subject: [PATCH] Basic client --- src/Impostor.Client/Forms/FrmMain.Designer.cs | 2 +- src/Impostor.Client/Forms/FrmMain.cs | 54 +++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Impostor.Client/Forms/FrmMain.Designer.cs b/src/Impostor.Client/Forms/FrmMain.Designer.cs index 9390372..c5511d8 100644 --- a/src/Impostor.Client/Forms/FrmMain.Designer.cs +++ b/src/Impostor.Client/Forms/FrmMain.Designer.cs @@ -61,7 +61,7 @@ this.buttonLaunch.Name = "buttonLaunch"; this.buttonLaunch.Size = new System.Drawing.Size(79, 23); this.buttonLaunch.TabIndex = 2; - this.buttonLaunch.Text = "Launch"; + this.buttonLaunch.Text = "Save"; this.buttonLaunch.UseVisualStyleBackColor = true; this.buttonLaunch.Click += new System.EventHandler(this.buttonLaunch_Click); // diff --git a/src/Impostor.Client/Forms/FrmMain.cs b/src/Impostor.Client/Forms/FrmMain.cs index 3fd6071..6b413b9 100644 --- a/src/Impostor.Client/Forms/FrmMain.cs +++ b/src/Impostor.Client/Forms/FrmMain.cs @@ -1,4 +1,9 @@ -using System.Windows.Forms; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Windows.Forms; +using Impostor.Shared.Innersloth; namespace Impostor.Client.Forms { @@ -9,14 +14,55 @@ namespace Impostor.Client.Forms InitializeComponent(); } - private void FrmMain_Load(object sender, System.EventArgs e) + private void FrmMain_Load(object sender, EventArgs e) { - + // TODO: Load old IP. } - private void buttonLaunch_Click(object sender, System.EventArgs e) + private void buttonLaunch_Click(object sender, EventArgs e) { + var ipText = textIp.Text; + + if (!IPAddress.TryParse(ipText, out var ipAddress)) + { + MessageBox.Show("Invalid IP Address entered", "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + + textIp.Text = string.Empty; + textIp.Focus(); + return; + } + if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) + { + MessageBox.Show("Invalid IP Address entered, only IPv4 is allowed.", "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + + textIp.Text = string.Empty; + textIp.Focus(); + return; + } + + // TODO: Clean up, move to somewhere else & error handling. + + var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "..\\LocalLow"); + var regionFile = Path.Combine(appData, "Innersloth", "Among Us", "regionInfo.dat"); + var region = new RegionInfo("Private", ipText, new [] + { + new ServerInfo("Private-Master-1", ipText, 22023) + }); + + using (var file = File.Open(regionFile, FileMode.Create, FileAccess.Write)) + using (var writer = new BinaryWriter(file)) + { + region.Serialize(writer); + } + + MessageBox.Show("The IP Address was saved, please (re)start Among Us.", "Success", + MessageBoxButtons.OK, + MessageBoxIcon.Information); } } } \ No newline at end of file -- 2.39.5