From 766a8171f00fa053078650cce6b04fc3c6b9567a Mon Sep 17 00:00:00 2001 From: SCM6WE Date: Thu, 23 Sep 2021 11:09:43 +0200 Subject: [PATCH 1/3] fix connection establishment when loading files --- PolyChat/Controller.cs | 3 +++ PolyChat/MainPage.xaml.cs | 5 +++++ PolyChat/Models/ChatMessage.cs | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index 61793fb..e390a9e 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -164,6 +164,8 @@ namespace PolyChat /// public void loadChats() { + + //load dir and create if non existant if (Directory.Exists("U:\\PolyChat\\Saves")) { @@ -188,6 +190,7 @@ namespace PolyChat ip = ip.Substring(0, ip.Length - 4); Debug.WriteLine("-" + ip + "-"); Debug.WriteLine(jsonArr); + Connect(ip); UIController.OnIncomingMessages(ip, jsonArr); } } diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 7cc022e..245e679 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -156,8 +156,13 @@ namespace PolyChat new ChatMessage( origin, item["type"].ToString(), +<<<<<<< Updated upstream item["content"].ToString()//, //DateTime.Parse(item["timestamp"].ToString()) +======= + item["content"].ToString(), + DateTime.Parse(item["timestamp"].ToString()) +>>>>>>> Stashed changes ) ); } diff --git a/PolyChat/Models/ChatMessage.cs b/PolyChat/Models/ChatMessage.cs index 5757702..55c593a 100644 --- a/PolyChat/Models/ChatMessage.cs +++ b/PolyChat/Models/ChatMessage.cs @@ -12,6 +12,11 @@ namespace PolyChat.Models public DateTime TimeStamp; public readonly bool Foreign; + + public ChatMessage() + { + + } /// /// Create own Message (directly sent) /// @@ -43,7 +48,7 @@ namespace PolyChat.Models Type = type; Content = content; Foreign = foreign; - Debug.WriteLine("Created Loaded Message: " + ToString()); + Debug.WriteLine("Created Loaded Message: " + ToString()); } override From 51ada88313d0c604fc94fa556132ff87acf2e21d Mon Sep 17 00:00:00 2001 From: SCM6WE Date: Thu, 23 Sep 2021 11:09:58 +0200 Subject: [PATCH 2/3] merge --- PolyChat/MainPage.xaml.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 245e679..b91a0bb 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -156,13 +156,8 @@ namespace PolyChat new ChatMessage( origin, item["type"].ToString(), -<<<<<<< Updated upstream - item["content"].ToString()//, - //DateTime.Parse(item["timestamp"].ToString()) -======= item["content"].ToString(), DateTime.Parse(item["timestamp"].ToString()) ->>>>>>> Stashed changes ) ); } From 59630cc137d71657073daf94dd330f1b0929826c Mon Sep 17 00:00:00 2001 From: SCM6WE Date: Thu, 23 Sep 2021 11:29:54 +0200 Subject: [PATCH 3/3] 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);*/ + } } }