From 59630cc137d71657073daf94dd330f1b0929826c Mon Sep 17 00:00:00 2001 From: SCM6WE Date: Thu, 23 Sep 2021 11:29:54 +0200 Subject: [PATCH] quick --- PolyChat/Controller.cs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index e390a9e..1f3315b 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -9,6 +9,8 @@ using System.IO; using System.Threading; using System; using System.Text.Json; +using System.Text; +using System.Security.Cryptography; namespace PolyChat { @@ -50,7 +52,10 @@ namespace PolyChat //Todo show error! } else + { Connections.Add(ip, new Connection(ip, PORT, Data => OnMessage(ip, Data), CloseChat)); + } + } private void Serve() @@ -164,8 +169,6 @@ namespace PolyChat /// public void loadChats() { - - //load dir and create if non existant if (Directory.Exists("U:\\PolyChat\\Saves")) { @@ -181,16 +184,17 @@ namespace PolyChat String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves"); if (filepaths.Length > 0) { + Debug.WriteLine("---Loading Saves"); foreach (String path in filepaths) { - Debug.WriteLine("---Loading Saves---"); - Debug.WriteLine("--" + path + "--"); + Debug.WriteLine($"--{path}"); String jsonArr = File.ReadAllText(path); String ip = Path.GetFileName(path); ip = ip.Substring(0, ip.Length - 4); - Debug.WriteLine("-" + ip + "-"); + Debug.WriteLine($"-{ip}"); Debug.WriteLine(jsonArr); Connect(ip); + UIController.OnIncomingConnection(ip); UIController.OnIncomingMessages(ip, jsonArr); } } @@ -207,7 +211,6 @@ namespace PolyChat //Vielleicht noch so machen dass die mit gleicher ip nacheinander gemacht //werden damit es ncith zu überschreibungen kommt vielleicth auch ganz oben oder am ende ne //writing flag setzen oder auch in der datei selbst ne flag setzen - //also save fils from myself new Thread(() => { if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt")) @@ -244,5 +247,18 @@ namespace PolyChat } }).Start(); } + + private void encode(string json) + { + byte[] plaintext = Encoding.UTF8.GetBytes(json); + byte[] entropy = new byte[20]; + using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) + { + rng.GetBytes(entropy); + } + + /*byte[] ciphertext = ProtectedData.Protect(plaintext, entropy, + DataProtectionScope.CurrentUser);*/ + } } }