]> git.deb.at Git - rhonda/impostor.git/commitdiff
Basic client
authorAeonLucid <aeonlucid@gmail.com>
Mon, 21 Sep 2020 04:59:35 +0000 (06:59 +0200)
committerAeonLucid <aeonlucid@gmail.com>
Mon, 21 Sep 2020 04:59:35 +0000 (06:59 +0200)
src/Impostor.Client/Forms/FrmMain.Designer.cs
src/Impostor.Client/Forms/FrmMain.cs

index 93903723d076d08d79a011ce38432393843e1869..c5511d881250e8900afb14c1dceeb725ac02f8d9 100644 (file)
@@ -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);
             // 
index 3fd60718d83a9f5fb5dc3d6ffc1d0f544bfcb6f6..6b413b957d603992f4c1509b04e14c6255b1aebd 100644 (file)
@@ -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