Merge branch 'ConnectionController' of https://sourcecode.socialcoding.bosch.com/scm/~hpl2fe/polychat into ConnectionController
This commit is contained in:
@@ -9,6 +9,8 @@ using System.IO;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System;
|
using System;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace PolyChat
|
namespace PolyChat
|
||||||
{
|
{
|
||||||
@@ -50,7 +52,10 @@ namespace PolyChat
|
|||||||
//Todo show error!
|
//Todo show error!
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Connections.Add(ip, new Connection(ip, PORT, Data => OnMessage(ip, Data), CloseChat));
|
Connections.Add(ip, new Connection(ip, PORT, Data => OnMessage(ip, Data), CloseChat));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Serve()
|
private void Serve()
|
||||||
@@ -181,15 +186,17 @@ namespace PolyChat
|
|||||||
String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves");
|
String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves");
|
||||||
if (filepaths.Length > 0)
|
if (filepaths.Length > 0)
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("---Loading Saves");
|
||||||
foreach (String path in filepaths)
|
foreach (String path in filepaths)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("---Loading Saves---");
|
Debug.WriteLine($"--{path}");
|
||||||
Debug.WriteLine("--" + path + "--");
|
|
||||||
String jsonArr = File.ReadAllText(path);
|
String jsonArr = File.ReadAllText(path);
|
||||||
String ip = Path.GetFileName(path);
|
String ip = Path.GetFileName(path);
|
||||||
ip = ip.Substring(0, ip.Length - 4);
|
ip = ip.Substring(0, ip.Length - 4);
|
||||||
Debug.WriteLine("-" + ip + "-");
|
Debug.WriteLine($"-{ip}");
|
||||||
Debug.WriteLine(jsonArr);
|
Debug.WriteLine(jsonArr);
|
||||||
|
Connect(ip);
|
||||||
|
UIController.OnIncomingConnection(ip);
|
||||||
UIController.OnIncomingMessages(ip, jsonArr);
|
UIController.OnIncomingMessages(ip, jsonArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +213,6 @@ namespace PolyChat
|
|||||||
//Vielleicht noch so machen dass die mit gleicher ip nacheinander gemacht
|
//Vielleicht noch so machen dass die mit gleicher ip nacheinander gemacht
|
||||||
//werden damit es nicht zu überschreibungen kommt vielleicth auch ganz oben oder am ende ne
|
//werden damit es nicht zu überschreibungen kommt vielleicth auch ganz oben oder am ende ne
|
||||||
//writing flag setzen oder auch in der datei selbst ne flag setzen
|
//writing flag setzen oder auch in der datei selbst ne flag setzen
|
||||||
//also save fils from myself
|
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
||||||
@@ -244,5 +250,18 @@ namespace PolyChat
|
|||||||
}
|
}
|
||||||
}).Start();
|
}).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);*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ namespace PolyChat.Models
|
|||||||
public DateTime TimeStamp;
|
public DateTime TimeStamp;
|
||||||
public readonly bool Foreign;
|
public readonly bool Foreign;
|
||||||
|
|
||||||
|
|
||||||
|
public ChatMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create own Message (directly sent)
|
/// Create own Message (directly sent)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -43,7 +48,7 @@ namespace PolyChat.Models
|
|||||||
Type = type;
|
Type = type;
|
||||||
Content = content;
|
Content = content;
|
||||||
Foreign = foreign;
|
Foreign = foreign;
|
||||||
Debug.WriteLine("Created Loaded Message: " + ToString());
|
Debug.WriteLine("Created Loaded Message: " + ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
|
|||||||
Reference in New Issue
Block a user