stuff
This commit is contained in:
@@ -37,8 +37,6 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
UIController = uiController;
|
UIController = uiController;
|
||||||
OwnIP = getIP();
|
OwnIP = getIP();
|
||||||
loadChats();
|
|
||||||
//SaveChats("10", "{das ist ein test}");
|
|
||||||
Serve();
|
Serve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +72,7 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
Debug.WriteLine("--- initial packet received ---");
|
Debug.WriteLine("--- initial packet received ---");
|
||||||
string ForeignIp = data[0].ToString();
|
string ForeignIp = data[0].ToString();
|
||||||
|
|
||||||
Debug.WriteLine($"--- this ip was in the inital packet: {ForeignIp} ---");
|
Debug.WriteLine($"--- this ip was in the inital packet: {ForeignIp} ---");
|
||||||
if (isInConnections(ForeignIp))
|
if (isInConnections(ForeignIp))
|
||||||
{
|
{
|
||||||
@@ -171,6 +170,7 @@ namespace PolyChat
|
|||||||
/// <param name="ip"></param>
|
/// <param name="ip"></param>
|
||||||
public void loadChats()
|
public void loadChats()
|
||||||
{
|
{
|
||||||
|
//TODO: also load chatlogs when user tries to connect
|
||||||
//load dir and create if non existant
|
//load dir and create if non existant
|
||||||
if (Directory.Exists("U:\\PolyChat\\Saves"))
|
if (Directory.Exists("U:\\PolyChat\\Saves"))
|
||||||
{
|
{
|
||||||
@@ -200,9 +200,43 @@ namespace PolyChat
|
|||||||
UIController.OnIncomingMessages(ip, jsonArr);
|
UIController.OnIncomingMessages(ip, jsonArr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public void loadChat(String ip)
|
||||||
|
{
|
||||||
|
//TODO: also load chatlogs when user tries to connect
|
||||||
|
//load dir and create if non existant
|
||||||
|
if (Directory.Exists("U:\\PolyChat\\Saves"))
|
||||||
|
{
|
||||||
|
Debug.WriteLine("--Path exists.--");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory("U:\\PolyChat\\Saves");
|
||||||
|
Debug.WriteLine("--Path Created--.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//go through all files and send ip and json array to ui
|
||||||
|
String[] filepaths = Directory.GetFiles("U:\\PolyChat\\Saves");
|
||||||
|
if (filepaths.Length > 0)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("---Loading Saves");
|
||||||
|
foreach (String path in filepaths)
|
||||||
|
{
|
||||||
|
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(jsonArr);
|
||||||
|
Connect(ip);
|
||||||
|
UIController.OnIncomingConnection(ip);
|
||||||
|
UIController.OnIncomingMessages(ip, jsonArr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves incoming chat message to
|
/// Saves incoming chat message to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -215,39 +249,47 @@ namespace PolyChat
|
|||||||
//writing flag setzen oder auch in der datei selbst ne flag setzen
|
//writing flag setzen oder auch in der datei selbst ne flag setzen
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
//breaking if namechange
|
||||||
|
JObject obj = JObject.Parse(json);
|
||||||
|
if (!obj["type"].ToString().Equals("username"))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--File allready exists--");
|
//adding timestamp
|
||||||
//check for integraty of file
|
obj = JObject.Parse(json);
|
||||||
string output = File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt");
|
obj.Add(new JProperty("timestamp", timeStamp));
|
||||||
Debug.WriteLine($"---{output}---");
|
json = obj.ToString();
|
||||||
if (output.Substring(0, 1).Equals("[") && output.Substring(output.Length - 1, 1).Equals("]"))
|
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--adding new chatmessage--");
|
Debug.WriteLine("--File allready exists--");
|
||||||
//structure intact
|
//check for integraty of file
|
||||||
JObject obj = JObject.Parse(json);
|
string output = File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt");
|
||||||
//save new chat
|
Debug.WriteLine($"---{output}---");
|
||||||
String saved = output.Substring(0, output.Length - 1);
|
if (output.Substring(0, 1).Equals("[") && output.Substring(output.Length - 1, 1).Equals("]"))
|
||||||
output = saved + ", " + json + " ]";
|
{
|
||||||
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
Debug.WriteLine("--adding new chatmessage--");
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", output);
|
//structure intact
|
||||||
|
//save new chat
|
||||||
|
String saved = output.Substring(0, output.Length - 1);
|
||||||
|
output = saved + ", " + json + " ]";
|
||||||
|
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
||||||
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", output);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.WriteLine("--Structure not intact--");
|
||||||
|
Debug.WriteLine("--redoing file--");
|
||||||
|
//structure not intact
|
||||||
|
//redo file
|
||||||
|
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
||||||
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", $"[ {json} ]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--Structure not intact--");
|
Debug.WriteLine("--Creating new File--");
|
||||||
Debug.WriteLine("--redoing file--");
|
//setup file
|
||||||
//structure not intact
|
|
||||||
//redo file
|
|
||||||
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", $"[ {json} ]");
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", $"[ {json} ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.WriteLine("--Creating new File--");
|
|
||||||
//setup file
|
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", $"[ {json} ]");
|
|
||||||
}
|
|
||||||
}).Start();
|
}).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,8 +302,6 @@ namespace PolyChat
|
|||||||
rng.GetBytes(entropy);
|
rng.GetBytes(entropy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*byte[] ciphertext = ProtectedData.Protect(plaintext, entropy,
|
|
||||||
DataProtectionScope.CurrentUser);*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ namespace PolyChat
|
|||||||
new ChatMessage(
|
new ChatMessage(
|
||||||
origin,
|
origin,
|
||||||
item["type"].ToString(),
|
item["type"].ToString(),
|
||||||
item["content"].ToString(),
|
item["content"].ToString()//,
|
||||||
DateTime.Parse(item["timestamp"].ToString())
|
//DateTime.Parse(item["timestamp"].ToString())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,6 @@ 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>
|
||||||
|
|||||||
Reference in New Issue
Block a user