Compare commits
56 Commits
a5dd048f07
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e75385a69b | ||
|
|
f5030c55c5 | ||
|
|
2718864b5c | ||
|
|
61cbd7fe74 | ||
|
|
c00e4c6a01 | ||
|
|
125c908ef8 | ||
|
|
ebaf831be7 | ||
|
|
1daaa52c36 | ||
|
|
ba4d0b619e | ||
|
|
31ffe86f04 | ||
|
|
fd5cb984e2 | ||
|
|
f55c4a2b70 | ||
|
|
ac67ff38c6 | ||
|
|
5c4b4373d6 | ||
|
|
4c0413e7d8 | ||
|
|
5ce1316245 | ||
|
|
c3daaf8b00 | ||
|
|
9141efd55a | ||
|
|
179ce2b1bb | ||
|
|
59d4827965 | ||
|
|
0d76ec30e2 | ||
|
|
a8a07f44c3 | ||
|
|
3cf0197672 | ||
|
|
43d8b2919c | ||
|
|
7286b211bf | ||
|
|
c00a7ff379 | ||
|
|
b12d3f3f4f | ||
|
|
e27141e013 | ||
|
|
a953d34122 | ||
|
|
eeea238398 | ||
|
|
7e5883d761 | ||
|
|
fb098db63d | ||
|
|
1b3d133657 | ||
|
|
e1ea49bf71 | ||
|
|
92bc795aff | ||
|
|
55bd72b467 | ||
|
|
ea81547540 | ||
|
|
e2de9f5917 | ||
|
|
6f2c442e94 | ||
|
|
b42a2f9728 | ||
|
|
05e3e9e0c4 | ||
|
|
e6e5bee4ef | ||
|
|
0f305a216e | ||
|
|
7135486810 | ||
|
|
0ef2158859 | ||
|
|
badbaf0b40 | ||
|
|
072e12d427 | ||
|
|
f0d785cb13 | ||
|
|
0ca78d7861 | ||
|
|
323f4d5b5b | ||
|
|
3b4ca6caa3 | ||
|
|
0a1ff66e38 | ||
|
|
88e5d3a329 | ||
|
|
de2d135fdf | ||
|
|
15679951bc | ||
|
|
08325b1c65 |
82
PolyChat/Assets/polychat_logo.svg
Normal file
82
PolyChat/Assets/polychat_logo.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 12 KiB |
@@ -5,18 +5,10 @@ using System.Net;
|
|||||||
using SocketIOSharp.Server;
|
using SocketIOSharp.Server;
|
||||||
using SocketIOSharp.Server.Client;
|
using SocketIOSharp.Server.Client;
|
||||||
using PolyChat.Models;
|
using PolyChat.Models;
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using Windows.Security.Cryptography.Core;
|
|
||||||
using Windows.Security.Cryptography;
|
|
||||||
using Windows.Storage.Streams;
|
|
||||||
|
|
||||||
namespace PolyChat
|
namespace PolyChat
|
||||||
{
|
{
|
||||||
|
|
||||||
// 10.1.211.26 Marc
|
// 10.1.211.26 Marc
|
||||||
// 10.1.218.90 Felix
|
// 10.1.218.90 Felix
|
||||||
// 10.4.141.77 Pat
|
// 10.4.141.77 Pat
|
||||||
@@ -37,13 +29,13 @@ namespace PolyChat
|
|||||||
public Controller(MainPage uiController)
|
public Controller(MainPage uiController)
|
||||||
{
|
{
|
||||||
UIController = uiController;
|
UIController = uiController;
|
||||||
fileManager = new FileManager(uiController);
|
fileManager = new FileManager(this);
|
||||||
fileManager.loadChats();
|
fileManager.loadChats();
|
||||||
Serve();
|
Serve();
|
||||||
|
|
||||||
// test
|
// test
|
||||||
/*
|
/*
|
||||||
UIController.OnIncomingConnection("1.1.1.1");
|
UIController.OnIncomingConnection("localhost");
|
||||||
UIController.OnIncomingConnection("1.2.3.4");
|
UIController.OnIncomingConnection("1.2.3.4");
|
||||||
UIController.OnIncomingConnection("1.2.4.8");
|
UIController.OnIncomingConnection("1.2.4.8");
|
||||||
*/
|
*/
|
||||||
@@ -65,6 +57,9 @@ namespace PolyChat
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// starts server for clients to connect to
|
||||||
|
/// </summary>
|
||||||
private void Serve()
|
private void Serve()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--- Controller.Serve ---");
|
Debug.WriteLine("--- Controller.Serve ---");
|
||||||
@@ -107,6 +102,12 @@ namespace PolyChat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends message to given ip
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="content"></param>
|
||||||
public void SendMessage(string ip, string type, string content)
|
public void SendMessage(string ip, string type, string content)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--- Controller.SendMessage ---");
|
Debug.WriteLine("--- Controller.SendMessage ---");
|
||||||
@@ -122,6 +123,11 @@ namespace PolyChat
|
|||||||
fileManager.saveChats(ip, json.ToString(), DateTime.Now);
|
fileManager.saveChats(ip, json.ToString(), DateTime.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// if We recieve a message this method gets triggert
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip">ip from sender</param>
|
||||||
|
/// <param name="data">String that is send</param>
|
||||||
private void OnMessage(string ip, JToken[] data)
|
private void OnMessage(string ip, JToken[] data)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--- Controller.OnMessage ---");
|
Debug.WriteLine("--- Controller.OnMessage ---");
|
||||||
@@ -135,6 +141,12 @@ namespace PolyChat
|
|||||||
else Debug.WriteLine("Undefined: " + data);
|
else Debug.WriteLine("Undefined: " + data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes chat connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="IP">ip of user to be closed</param>
|
||||||
|
/// <param name="wasConnected"></param>
|
||||||
|
/// <param name="delete"></param>
|
||||||
public void CloseChat(string IP, bool wasConnected = true, bool delete = false)
|
public void CloseChat(string IP, bool wasConnected = true, bool delete = false)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Deleting connection with IP:{IP}");
|
Debug.WriteLine($"Deleting connection with IP:{IP}");
|
||||||
@@ -149,6 +161,17 @@ namespace PolyChat
|
|||||||
fileManager.deleteChat(IP);
|
fileManager.deleteChat(IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sends incoming message to ui
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip">ip of client that send the message</param>
|
||||||
|
/// <param name="jsonArr">the json array that is ti be displayed in th gui</param>
|
||||||
|
public void SendIncomingMessageUI(String ip, String jsonArr)
|
||||||
|
{
|
||||||
|
UIController.OnIncomingConnection(ip);
|
||||||
|
UIController.OnIncomingMessages(ip, jsonArr);
|
||||||
|
}
|
||||||
|
|
||||||
private void CloseChatUI(string IP, bool wasConnected = true, bool delete = false)
|
private void CloseChatUI(string IP, bool wasConnected = true, bool delete = false)
|
||||||
{
|
{
|
||||||
UIController.OnChatPartnerDeleted(IP);
|
UIController.OnChatPartnerDeleted(IP);
|
||||||
@@ -166,6 +189,10 @@ namespace PolyChat
|
|||||||
return Connections.ContainsKey(ip) && Connections[ip].IsConnected();
|
return Connections.ContainsKey(ip) && Connections[ip].IsConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// returns your own ip that starts with 10. becuase that is our subnet
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public static string getIP()
|
public static string getIP()
|
||||||
{
|
{
|
||||||
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
|
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
|
||||||
@@ -180,11 +207,5 @@ namespace PolyChat
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encode(string json)
|
|
||||||
{
|
|
||||||
String ecryptetText = FileManager.encrypt(json);
|
|
||||||
Debug.WriteLine(ecryptetText);
|
|
||||||
Debug.WriteLine(FileManager.decrypt(ecryptetText));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,17 +6,18 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:models="using:PolyChat.Models"
|
xmlns:models="using:PolyChat.Models"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark">
|
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="224"/>
|
<ColumnDefinition Width="224"/>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<!-- LEFT SIDE -->
|
<!-- LEFT SIDE -->
|
||||||
<Grid Grid.Column="0" Margin="16">
|
<Grid Grid.Column="0" Padding="16" Background="{ThemeResource SystemChromeMediumColor}">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<!-- CONNECTION HEADER -->
|
<!-- CONNECTION HEADER -->
|
||||||
<StackPanel HorizontalAlignment="Stretch" Spacing="8" Margin="0 0 0 8">
|
<StackPanel HorizontalAlignment="Stretch" Spacing="8" Margin="0 0 0 8">
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
<TextBlock Text="Connect to" Foreground="{ThemeResource SystemColorDisabledTextColor}"/>
|
<TextBlock Text="Connect to" Foreground="{ThemeResource SystemColorDisabledTextColor}"/>
|
||||||
<TextBlock x:Name="ipAddress" Grid.Column="1"/>
|
<TextBlock x:Name="ipAddress" Grid.Column="1"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Border BorderThickness="1" BorderBrush="{ThemeResource AppBarBorderThemeBrush}"/>
|
<Border BorderThickness="1" BorderBrush="{ThemeResource SystemControlBackgroundListLowBrush}"/>
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
@@ -55,12 +56,8 @@
|
|||||||
<DataTemplate x:DataType="models:ChatPartner">
|
<DataTemplate x:DataType="models:ChatPartner">
|
||||||
<RadioButton GroupName="chatSelect" Tag="{x:Bind Code}" HorizontalAlignment="Stretch" Height="64" Click="OnChatPartnerSelected">
|
<RadioButton GroupName="chatSelect" Tag="{x:Bind Code}" HorizontalAlignment="Stretch" Height="64" Click="OnChatPartnerSelected">
|
||||||
<StackPanel x:Name="ChatPartner" VerticalAlignment="Center" HorizontalAlignment="Stretch">
|
<StackPanel x:Name="ChatPartner" VerticalAlignment="Center" HorizontalAlignment="Stretch">
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/>
|
||||||
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Name}"/>
|
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
|
||||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=" ("/>
|
|
||||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text="{x:Bind Code}"/>
|
|
||||||
<TextBlock Foreground="{ThemeResource SystemColorDisabledTextColor}" Text=")"/>
|
|
||||||
</StackPanel>
|
|
||||||
<!--
|
<!--
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
|
||||||
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Messages.Last().toString()}"/>
|
<TextBlock HorizontalAlignment="Stretch" Text="{x:Bind Messages.Last().toString()}"/>
|
||||||
@@ -73,6 +70,7 @@
|
|||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
</ListView>
|
</ListView>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
<Button Grid.Row="2" Click="OnToggleTheme" Content="Toggle Theme"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<TextBlock x:Name="textNoChatSelected" Grid.Column="1" Text="No Chat Selected" Foreground="{ThemeResource SystemColorDisabledTextColor}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
<TextBlock x:Name="textNoChatSelected" Grid.Column="1" Text="No Chat Selected" Foreground="{ThemeResource SystemColorDisabledTextColor}" FontSize="24" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
||||||
<!-- RIGHT SIDE -->
|
<!-- RIGHT SIDE -->
|
||||||
@@ -98,12 +96,16 @@
|
|||||||
<!-- CHAT -->
|
<!-- CHAT -->
|
||||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
|
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
|
||||||
<ListView x:Name="listViewMessages" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4 16">
|
<ListView x:Name="listViewMessages" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4 16">
|
||||||
|
<ListView.ItemContainerStyle>
|
||||||
|
<Style TargetType="ListViewItem">
|
||||||
|
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||||
|
</Style>
|
||||||
|
</ListView.ItemContainerStyle>
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate x:DataType="models:ChatMessage">
|
<DataTemplate x:DataType="models:ChatMessage">
|
||||||
<StackPanel x:Name="Message" MaxWidth="320" Margin="0 4" Padding="16 8" CornerRadius="4" Background="{ThemeResource SystemAccentColor}">
|
<StackPanel HorizontalAlignment="{x:Bind Align}" x:Name="Message" MaxWidth="320" Margin="0 4" Padding="16 8" CornerRadius="4" Background="{ThemeResource SystemAccentColor}">
|
||||||
<TextBlock Text="{x:Bind Content}" Foreground="{ThemeResource SystemAltHighColor}" TextWrapping="WrapWholeWords" FontSize="14"/>
|
<TextBlock Text="{x:Bind Content}" Foreground="{ThemeResource SystemAltHighColor}" TextWrapping="WrapWholeWords" FontSize="14"/>
|
||||||
<TextBlock Text="{x:Bind TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/>
|
<TextBlock Text="{x:Bind TimeStamp.ToString()}" Foreground="{ThemeResource SystemAltMediumColor}"/>
|
||||||
<TextBlock Text="{x:Bind Foreign}" Foreground="{ThemeResource SystemAltMediumLowColor}" FontStyle="Italic" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace PolyChat
|
|||||||
private ObservableCollection<ChatPartner> Partners;
|
private ObservableCollection<ChatPartner> Partners;
|
||||||
private ChatPartner selectedPartner = null;
|
private ChatPartner selectedPartner = null;
|
||||||
private string username;
|
private string username;
|
||||||
|
private static ElementTheme Theme = ElementTheme.Light;
|
||||||
|
|
||||||
public MainPage()
|
public MainPage()
|
||||||
{
|
{
|
||||||
@@ -35,6 +36,9 @@ namespace PolyChat
|
|||||||
// ui variables
|
// ui variables
|
||||||
ipAddress.Text = IP.GetCodeFromIP(Controller.getIP());
|
ipAddress.Text = IP.GetCodeFromIP(Controller.getIP());
|
||||||
Partners = new ObservableCollection<ChatPartner>();
|
Partners = new ObservableCollection<ChatPartner>();
|
||||||
|
// theming
|
||||||
|
RequestedTheme = Theme;
|
||||||
|
// updated placeholder
|
||||||
updateNoChatsPlaceholder();
|
updateNoChatsPlaceholder();
|
||||||
updateNoUsernamePlaceholder();
|
updateNoUsernamePlaceholder();
|
||||||
updateNoChatSelected();
|
updateNoChatSelected();
|
||||||
@@ -74,7 +78,7 @@ namespace PolyChat
|
|||||||
|
|
||||||
public void OnSendMessage(object sender = null, RoutedEventArgs e = null)
|
public void OnSendMessage(object sender = null, RoutedEventArgs e = null)
|
||||||
{
|
{
|
||||||
selectedPartner.AddMessage(new ChatMessage(username, "message", inputSend.Text));
|
selectedPartner.AddMessage(new ChatMessage(username, "message", inputSend.Text, DateTime.Now, false));
|
||||||
Controller.SendMessage(selectedPartner.Code, "message", inputSend.Text);
|
Controller.SendMessage(selectedPartner.Code, "message", inputSend.Text);
|
||||||
// clear input
|
// clear input
|
||||||
inputSend.Text = "";
|
inputSend.Text = "";
|
||||||
@@ -85,10 +89,10 @@ namespace PolyChat
|
|||||||
// test
|
// test
|
||||||
/*
|
/*
|
||||||
OnIncomingMessage(
|
OnIncomingMessage(
|
||||||
"1.1.1.1",
|
"localhost",
|
||||||
new JObject(
|
new JObject(
|
||||||
new JProperty("type", "username"),
|
new JProperty("type", "message"),
|
||||||
new JProperty("content", "Cloudflare")
|
new JProperty("content", "Test")
|
||||||
).ToString(),
|
).ToString(),
|
||||||
DateTime.Now
|
DateTime.Now
|
||||||
);
|
);
|
||||||
@@ -159,7 +163,7 @@ namespace PolyChat
|
|||||||
Partners.Insert(index, sendingPartner);
|
Partners.Insert(index, sendingPartner);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp));
|
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp, true));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -176,15 +180,15 @@ 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()),
|
||||||
|
false // TODO: FIX !!!!
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
|
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
|
||||||
{
|
{
|
||||||
Controller.CloseChat(selectedPartner.Code,delete: true);
|
Controller.CloseChat(selectedPartner.Code,delete: true);
|
||||||
@@ -213,35 +217,31 @@ namespace PolyChat
|
|||||||
if (!Controller.IsConnected(code)) Controller.Connect(code);
|
if (!Controller.IsConnected(code)) Controller.Connect(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnToggleTheme(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Theme = Theme == ElementTheme.Light ? ElementTheme.Dark : ElementTheme.Light;
|
||||||
|
RequestedTheme = Theme;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
|
private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
updateSendButtonEnabled();
|
updateSendButtonEnabled();
|
||||||
if (e.Key == Windows.System.VirtualKey.Enter)
|
if (buttonSend.IsEnabled && e.Key == Windows.System.VirtualKey.Enter)
|
||||||
{
|
{
|
||||||
OnSendMessage();
|
OnSendMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(Dialog d)
|
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(ContentDialog d)
|
||||||
{
|
{
|
||||||
if(VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
if(VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
||||||
return d.ShowAsync();
|
return d.ShowAsync();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(NewChatDialog d)
|
// GETTERS
|
||||||
{
|
|
||||||
if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
|
||||||
return d.ShowAsync();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IAsyncOperation<ContentDialogResult> SafelyOpenDialog(EditUsernameDialog d)
|
public static ElementTheme GetTheme() => Theme;
|
||||||
{
|
|
||||||
if (VisualTreeHelper.GetOpenPopups(Window.Current).Count == 0)
|
|
||||||
return d.ShowAsync();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UPDATE FUNCTIONS FOR UI PLACEHOLDERS
|
// UPDATE FUNCTIONS FOR UI PLACEHOLDERS
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
|
||||||
namespace PolyChat.Models
|
namespace PolyChat.Models
|
||||||
{
|
{
|
||||||
@@ -10,38 +11,23 @@ namespace PolyChat.Models
|
|||||||
public string Type;
|
public string Type;
|
||||||
public string Content;
|
public string Content;
|
||||||
public DateTime TimeStamp;
|
public DateTime TimeStamp;
|
||||||
public readonly bool Foreign;
|
public HorizontalAlignment Align;
|
||||||
|
private bool Foreign;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create own Message (directly sent)
|
/// Create Message
|
||||||
/// </summary>
|
|
||||||
/// <param name="origin">My IP</param>
|
|
||||||
/// <param name="type">Message Type</param>
|
|
||||||
/// <param name="content">Message Content (not JSON)</param>
|
|
||||||
public ChatMessage(string origin, string type, string content)
|
|
||||||
{
|
|
||||||
Origin = origin;
|
|
||||||
TimeStamp = DateTime.Now;
|
|
||||||
Type = type;
|
|
||||||
Content = content;
|
|
||||||
// TODO
|
|
||||||
Foreign = false;
|
|
||||||
Debug.WriteLine("Created Message: " + ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create Message loaded with timestamp
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="origin">Origin IP</param>
|
/// <param name="origin">Origin IP</param>
|
||||||
/// <param name="type">Message Type, usually "message"</param>
|
/// <param name="type">Message Type, usually "message"</param>
|
||||||
/// <param name="content">Message Content, usually plain text</param>
|
/// <param name="content">Message Content, usually plain text</param>
|
||||||
/// <param name="timeStamp">Parsed DateTime</param>
|
/// <param name="timeStamp">Parsed DateTime</param>
|
||||||
public ChatMessage(string origin, string type, string content, DateTime timeStamp, bool foreign = false)
|
public ChatMessage(string origin, string type, string content, DateTime timeStamp, bool foreign)
|
||||||
{
|
{
|
||||||
Origin = origin;
|
Origin = origin;
|
||||||
TimeStamp = timeStamp;
|
TimeStamp = timeStamp;
|
||||||
Type = type;
|
Type = type;
|
||||||
Content = content;
|
Content = content;
|
||||||
|
Align = foreign ? HorizontalAlignment.Right : HorizontalAlignment.Left;
|
||||||
Foreign = foreign;
|
Foreign = foreign;
|
||||||
Debug.WriteLine("Created Loaded Message: " + ToString());
|
Debug.WriteLine("Created Loaded Message: " + ToString());
|
||||||
}
|
}
|
||||||
|
|||||||
156
PolyChat/Models/Client.cs
Normal file
156
PolyChat/Models/Client.cs
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
using System;
|
||||||
|
using SocketIOSharp.Common;
|
||||||
|
using SocketIOSharp.Client;
|
||||||
|
using SocketIOSharp.Server.Client;
|
||||||
|
using Json.Net;
|
||||||
|
using System.Threading;
|
||||||
|
using PolyChat.Models.Exceptions;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace PolyChat.Models
|
||||||
|
{
|
||||||
|
class Client
|
||||||
|
{
|
||||||
|
private SocketIOClient connection_client = null;
|
||||||
|
private SocketIOSocket connection_server = null;
|
||||||
|
private Boolean connected = true;
|
||||||
|
private String ipSelf;
|
||||||
|
|
||||||
|
public Client(SocketIOClient connection, String ip, MainPage uiController)
|
||||||
|
{
|
||||||
|
this.ipSelf = ip;
|
||||||
|
this.connection_client = connection;
|
||||||
|
InitEventHandlers(this, connection, uiController);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when socket accepts client
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connection"></param>
|
||||||
|
/// <param name="ip"></param>
|
||||||
|
/// <param name="uiController"></param>
|
||||||
|
public Client(SocketIOSocket connection, String ip, MainPage uiController)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("New Client Saved!!!!(Clinent[34])");
|
||||||
|
this.ipSelf = ip;
|
||||||
|
this.connection_server = connection;
|
||||||
|
InitEventHandlers(this, connection, uiController);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sending
|
||||||
|
//===================================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// converts String message into json file and sends it to the server.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// gets called by gui if someone wants to send Message
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="sender">Sender of Message</param>
|
||||||
|
/// <param name="chatMessage">the accual text the user wants to send</param>
|
||||||
|
/// <param name="timestamp">current time</param>
|
||||||
|
public void sendMessage(SendCode code, String chatMessage)
|
||||||
|
{
|
||||||
|
new Thread(() =>
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"connected is {connected}");
|
||||||
|
//create msg
|
||||||
|
Message msg = new Message(chatMessage, false, ipSelf);
|
||||||
|
|
||||||
|
//convert msg
|
||||||
|
String petJson = JsonNet.Serialize(msg);
|
||||||
|
|
||||||
|
//wait if not connected and send msg
|
||||||
|
int i=0;
|
||||||
|
int sleeptimer = 2000;
|
||||||
|
while(!this.connected)
|
||||||
|
{
|
||||||
|
Thread.Sleep(sleeptimer);
|
||||||
|
i++;
|
||||||
|
if(i>=10)
|
||||||
|
{
|
||||||
|
throw new MessageTimedOutException(i*sleeptimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (connection_client != null)
|
||||||
|
{
|
||||||
|
connection_client.Emit(code.ToString(), petJson);
|
||||||
|
}else if (connection_server != null)
|
||||||
|
{
|
||||||
|
connection_server.Emit(code.ToString(), petJson);
|
||||||
|
}
|
||||||
|
}).Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
//==================================================================================
|
||||||
|
//EventHandeling
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// handles all events of client
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">self</param>
|
||||||
|
/// <param name="connection"></param>
|
||||||
|
private static void InitEventHandlers(Client client, SocketIOClient connection, MainPage uiController)
|
||||||
|
{
|
||||||
|
connection.On(SendCode.Message.ToString(), (Data) =>
|
||||||
|
{
|
||||||
|
//Message msg = new Message(Data[0]);
|
||||||
|
Debug.WriteLine("Normal Message Recieved!!!!");
|
||||||
|
Message msg = JsonNet.Deserialize<Message>(Data[0].ToString());
|
||||||
|
uiController.OnIncomingMessage(msg);
|
||||||
|
|
||||||
|
//TODO: send message to GUI
|
||||||
|
});
|
||||||
|
|
||||||
|
connection.On(SendCode.Command.ToString(), (Data) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("Command recieved!" + Data[0]);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
connection.On(SocketIOEvent.CONNECTION, () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
client.connected = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// handles all events of server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">self</param>
|
||||||
|
/// <param name="connection"></param>
|
||||||
|
private static void InitEventHandlers(Client client, SocketIOSocket connection, MainPage uiController)
|
||||||
|
{
|
||||||
|
connection.On(SendCode.Message.ToString(), (Data) =>
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Normal Message Recieved!!!!");
|
||||||
|
Message msg = JsonNet.Deserialize<Message>(Data[0].ToString());
|
||||||
|
//Message msg = new Message(Data[0]);
|
||||||
|
uiController.OnIncomingMessage(msg);
|
||||||
|
//TODO: send message to GUI
|
||||||
|
});
|
||||||
|
|
||||||
|
connection.On(SendCode.Command.ToString(), (Data) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("Command recieved!" + Data[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.connected = true;
|
||||||
|
}
|
||||||
|
//==================================================================================
|
||||||
|
//Getter and Setter
|
||||||
|
//==================================================================================
|
||||||
|
|
||||||
|
public String getIP()
|
||||||
|
{
|
||||||
|
return this.ipSelf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isConnected()
|
||||||
|
{
|
||||||
|
return this.connected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,13 +14,21 @@ namespace PolyChat.Models
|
|||||||
class FileManager
|
class FileManager
|
||||||
{
|
{
|
||||||
// Controller
|
// Controller
|
||||||
private readonly MainPage UIController;
|
private readonly Controller controller;
|
||||||
|
|
||||||
public FileManager(MainPage uiController)
|
|
||||||
|
//===============================================================================================================================================
|
||||||
|
//Constructor
|
||||||
|
//===============================================================================================================================================
|
||||||
|
public FileManager(Controller controller)
|
||||||
{
|
{
|
||||||
UIController = uiController;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===============================================================================================================================================
|
||||||
|
// editing save files
|
||||||
|
//===============================================================================================================================================
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// deletes chatlog of one speciffic user
|
/// deletes chatlog of one speciffic user
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,14 +67,13 @@ namespace PolyChat.Models
|
|||||||
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
||||||
{
|
{
|
||||||
String jsonArr = decrypt(File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt"));
|
String jsonArr = decrypt(File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt"));
|
||||||
UIController.OnIncomingConnection(ip);
|
controller.SendIncomingMessageUI(ip, jsonArr);
|
||||||
UIController.OnIncomingMessages(ip, jsonArr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// sends chatlogs as json array to uiController wit corrosponding ip
|
/// sends chatlogs as json array to uiController with corrosponding ip
|
||||||
///
|
///
|
||||||
/// in ui when chat is clicked connection gets established
|
/// in ui when chat is clicked connection gets established
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -97,22 +104,18 @@ namespace PolyChat.Models
|
|||||||
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);
|
||||||
UIController.OnIncomingConnection(ip);
|
controller.SendIncomingMessageUI(ip, jsonArr);
|
||||||
UIController.OnIncomingMessages(ip, jsonArr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves incoming chat message to
|
/// Saves incoming chat message to U:\PolyChat\Saves\ip.txt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ip"></param>
|
/// <param name="ip"></param>
|
||||||
/// <param name="json"></param>
|
/// <param name="json"></param>
|
||||||
public void saveChats(string ip, string json, DateTime timeStamp)
|
public void saveChats(string ip, string json, DateTime timeStamp)
|
||||||
{
|
{
|
||||||
//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
|
|
||||||
//writing flag setzen oder auch in der datei selbst ne flag setzen
|
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
//breaking if namechange
|
//breaking if namechange
|
||||||
@@ -120,39 +123,39 @@ namespace PolyChat.Models
|
|||||||
if (!obj["type"].ToString().Equals("username"))
|
if (!obj["type"].ToString().Equals("username"))
|
||||||
{
|
{
|
||||||
//adding timestamp
|
//adding timestamp
|
||||||
obj = JObject.Parse(json);
|
|
||||||
obj.Add(new JProperty("timestamp", timeStamp));
|
obj.Add(new JProperty("timestamp", timeStamp));
|
||||||
json = obj.ToString();
|
json = obj.ToString();
|
||||||
|
|
||||||
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
if (File.Exists($"U:\\PolyChat\\Saves\\{ip}.txt"))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--File allready exists--");
|
Debug.WriteLine("--File allready exists--");
|
||||||
|
|
||||||
//check for integraty of file
|
//check for integraty of file
|
||||||
string output = decrypt(File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt"));
|
string output = decrypt(File.ReadAllText($"U:\\PolyChat\\Saves\\{ip}.txt"));
|
||||||
Debug.WriteLine($"---{output}---");
|
Debug.WriteLine($"---{output}---");
|
||||||
if (output.Substring(0, 1).Equals("[") && output.Substring(output.Length - 1, 1).Equals("]"))
|
if (output.Substring(0, 1).Equals("[") && output.Substring(output.Length - 1, 1).Equals("]"))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--adding new chatmessage--");
|
|
||||||
//structure intact
|
//structure intact
|
||||||
//save new chat
|
//save new chat
|
||||||
String saved = output.Substring(0, output.Length - 1);
|
Debug.WriteLine("--adding new chatmessage--");
|
||||||
output = saved + ", " + json + " ]";
|
output = output.Substring(0, output.Length - 1) + ", " + json + " ]"; //rip appart and put file back together
|
||||||
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt(output));
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt(output)); //encrypt and save to textfile
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--Structure not intact--");
|
|
||||||
Debug.WriteLine("--redoing file--");
|
|
||||||
//structure not intact
|
//structure not intact
|
||||||
//redo file
|
//redo file
|
||||||
|
Debug.WriteLine("--Structure not intact--");
|
||||||
|
Debug.WriteLine("--redoing file--");
|
||||||
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
File.Delete($"U:\\PolyChat\\Saves\\{ip}.txt");
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt($"[ {json} ]"));
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt($"[ {json} ]")); //encrypt and write to file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--Creating new File--");
|
|
||||||
//setup file
|
//setup file
|
||||||
|
Debug.WriteLine("--Creating new File--");
|
||||||
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt($"[ {json} ]"));
|
File.WriteAllText($"U:\\PolyChat\\Saves\\{ip}.txt", encrypt($"[ {json} ]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,28 +163,35 @@ namespace PolyChat.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------
|
//===============================================================================================================================================
|
||||||
//security
|
// Encryption
|
||||||
//---------------------------------------------------------------------------------------------------
|
//===============================================================================================================================================
|
||||||
private void genKeys()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// generates keypair [public, privte] (100% secure, trust me)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private String[] genKeys()
|
||||||
|
{
|
||||||
|
return new String[] {"12345678", "12345678" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// does exactly what it says. XD
|
/// does exactly what it says. XD
|
||||||
|
///
|
||||||
|
/// encrypts given string and returns unreadable string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="toEncrypt"></param>
|
/// <param name="toEncrypt"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static String encrypt(String toEncrypt)
|
private String encrypt(String toEncrypt)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string textToEncrypt = toEncrypt;
|
string textToEncrypt = toEncrypt;
|
||||||
string ToReturn = "";
|
string ToReturn = "";
|
||||||
string publickey = "santhosh";
|
string publickey = genKeys()[0];
|
||||||
string secretkey = "engineer";
|
string secretkey = genKeys()[1];
|
||||||
byte[] secretkeyByte = { };
|
byte[] secretkeyByte = { };
|
||||||
secretkeyByte = System.Text.Encoding.UTF8.GetBytes(secretkey);
|
secretkeyByte = System.Text.Encoding.UTF8.GetBytes(secretkey);
|
||||||
byte[] publickeybyte = { };
|
byte[] publickeybyte = { };
|
||||||
@@ -203,22 +213,23 @@ namespace PolyChat.Models
|
|||||||
{
|
{
|
||||||
throw new Exception(ex.Message, ex.InnerException);
|
throw new Exception(ex.Message, ex.InnerException);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// does exactly what it says. XD
|
/// does exactly what it says. XD
|
||||||
|
///
|
||||||
|
/// takes in unreadable string and returns infirmation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="toEncrypt"></param>
|
/// <param name="toEncrypt"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static String decrypt(String toDecrypt)
|
private String decrypt(String toDecrypt)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string textToDecrypt = toDecrypt;
|
string textToDecrypt = toDecrypt;
|
||||||
string ToReturn = "";
|
string ToReturn = "";
|
||||||
string publickey = "santhosh";
|
string publickey = genKeys()[0];
|
||||||
string privatekey = "engineer";
|
string privatekey = genKeys()[1];
|
||||||
byte[] privatekeyByte = { };
|
byte[] privatekeyByte = { };
|
||||||
privatekeyByte = System.Text.Encoding.UTF8.GetBytes(privatekey);
|
privatekeyByte = System.Text.Encoding.UTF8.GetBytes(privatekey);
|
||||||
byte[] publickeybyte = { };
|
byte[] publickeybyte = { };
|
||||||
@@ -244,10 +255,4 @@ namespace PolyChat.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
62
PolyChat/Models/Message.cs
Normal file
62
PolyChat/Models/Message.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Json.Net;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace PolyChat.Models
|
||||||
|
{
|
||||||
|
public class Message
|
||||||
|
{
|
||||||
|
public readonly string Sender;
|
||||||
|
public readonly DateTime Timestamp = new DateTime(1970, 01, 01);
|
||||||
|
public readonly string Msg = "empty";
|
||||||
|
public readonly string Ip;
|
||||||
|
public readonly bool Foreign;
|
||||||
|
public readonly string StringTimeStamp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// create new Message object from parameters
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Msg"></param>
|
||||||
|
/// <param name="Foreign"></param>
|
||||||
|
/// <param name="Sender"></param>
|
||||||
|
/// <param name="Ip"></param>
|
||||||
|
public Message(string Msg = "", bool Foreign = true, string Sender= "Unknown", string Ip = "127.0.0.1")
|
||||||
|
{
|
||||||
|
this.Sender = Sender;
|
||||||
|
this.Timestamp = DateTime.Now;
|
||||||
|
StringTimeStamp = Timestamp.ToString();
|
||||||
|
this.Msg = Msg;
|
||||||
|
this.Foreign = Foreign;
|
||||||
|
this.Ip = Ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// create new Message object from JToken (json)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public Message(JToken data)
|
||||||
|
{
|
||||||
|
|
||||||
|
Message m = (Message) data.ToObject<Message>();
|
||||||
|
Sender = m.Sender;
|
||||||
|
Timestamp = m.Timestamp;
|
||||||
|
StringTimeStamp = Timestamp.ToString();
|
||||||
|
Msg = m.Msg;
|
||||||
|
Ip = m.Ip;
|
||||||
|
Foreign = m.Foreign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override
|
||||||
|
public string ToString()
|
||||||
|
{
|
||||||
|
string prefix = Foreign ? "Other" : "Me";
|
||||||
|
return $"{prefix}: {Msg}({Sender})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
127
PolyChat/Models/NetworkingController.cs
Normal file
127
PolyChat/Models/NetworkingController.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using SocketIOSharp.Client;
|
||||||
|
using EngineIOSharp.Common.Enum;
|
||||||
|
using System.Net;
|
||||||
|
using PolyChat.Models.Exceptions;
|
||||||
|
|
||||||
|
//dependencies for server functionality
|
||||||
|
using SocketIOSharp.Server;
|
||||||
|
using SocketIOSharp.Server.Client;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using Json.Net;
|
||||||
|
|
||||||
|
namespace PolyChat.Models
|
||||||
|
{
|
||||||
|
class NetworkingController
|
||||||
|
{
|
||||||
|
public List<Client> clients = new List<Client>();
|
||||||
|
private String ownName = "";
|
||||||
|
private IPAddress ownIP;
|
||||||
|
private readonly ushort Port;
|
||||||
|
private SocketIOServer Server;
|
||||||
|
private readonly MainPage uiController;
|
||||||
|
|
||||||
|
public NetworkingController (MainPage uiController, ushort Port = 8050)
|
||||||
|
{
|
||||||
|
this.uiController = uiController;
|
||||||
|
this.Port = Port;
|
||||||
|
ownIP = getIP();
|
||||||
|
startServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//EXTERNAL METHODS
|
||||||
|
//=========================================================================================================================================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// connects self to server with given ip
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip"> server to connect to </param>
|
||||||
|
public void connectNewClient(String ip)
|
||||||
|
{
|
||||||
|
SocketIOClient connection = new SocketIOClient(new SocketIOClientOption(EngineIOScheme.http, ip, 8050));
|
||||||
|
connection.Connect();
|
||||||
|
clients.Add(new Client(connection, ip, uiController));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// handle incomming connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip"> server to connect to </param>
|
||||||
|
private void connectNewClient(SocketIOSocket socket)
|
||||||
|
{
|
||||||
|
socket.On(SendCode.Initial.ToString(), (JToken[] Data) =>
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Client connected and Initial Message Recieved!!!!!!!!!!!!!!!!!");
|
||||||
|
Message msg = JsonNet.Deserialize<Message>(Data[0].ToString());
|
||||||
|
clients.Add(new Client(socket,msg.Ip, uiController));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sends Message to given ip
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip"> partner to send to </param>
|
||||||
|
/// <param name="msg"> to send </param>
|
||||||
|
public void sendMessage(String ip, String msg)
|
||||||
|
{
|
||||||
|
this.getClient(ip).sendMessage(SendCode.Message, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// returns own ip adress
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IPAddress getIP()
|
||||||
|
{
|
||||||
|
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
|
||||||
|
IPAddress[] addrList = ipEntry.AddressList;
|
||||||
|
|
||||||
|
for (short i = 0; i < addrList.Length; i++)
|
||||||
|
{
|
||||||
|
if (addrList[i].ToString().Substring(0, 3).Equals("10."))
|
||||||
|
{
|
||||||
|
return addrList[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainPage getUIController()
|
||||||
|
{
|
||||||
|
return this.uiController;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//=========================================================================================================================================================================================
|
||||||
|
//INTERNAL METHODS
|
||||||
|
//=========================================================================================================================================================================================
|
||||||
|
private void startServer()
|
||||||
|
{
|
||||||
|
Server = new SocketIOServer(new SocketIOServerOption(Port));
|
||||||
|
Server.OnConnection((socket) => connectNewClient(socket));
|
||||||
|
Server.Start();
|
||||||
|
Debug.WriteLine($"Your ip is: {ownIP}");
|
||||||
|
Debug.WriteLine($"Server started, binding to port {Port}, waiting for connection...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// returns client that fit to ip address
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ip"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Client getClient(String ip)
|
||||||
|
{
|
||||||
|
foreach (Client cl in clients)
|
||||||
|
{
|
||||||
|
if (cl.getIP().Equals(ip))
|
||||||
|
{
|
||||||
|
return cl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,11 @@
|
|||||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||||
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
|
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
|
||||||
IgnorableNamespaces="uap mp uap3">
|
xmlns:uap6="http://schemas.microsoft.com/appx/manifest/uap/windows10/6"
|
||||||
|
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
|
||||||
|
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
|
||||||
|
xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2"
|
||||||
|
IgnorableNamespaces="uap mp uap3 uap6 iot uap4 uap2">
|
||||||
|
|
||||||
<Identity
|
<Identity
|
||||||
Name="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1"
|
Name="ee2ef4f2-e61b-497a-8f0e-9fa7c90234b1"
|
||||||
@@ -45,7 +49,42 @@
|
|||||||
</Applications>
|
</Applications>
|
||||||
|
|
||||||
<Capabilities>
|
<Capabilities>
|
||||||
|
<Capability Name="internetClient" />
|
||||||
<Capability Name="internetClientServer"/>
|
<Capability Name="internetClientServer"/>
|
||||||
|
<Capability Name="allJoyn"/>
|
||||||
|
<uap:Capability Name="appointments"/>
|
||||||
|
<uap3:Capability Name="backgroundMediaPlayback"/>
|
||||||
|
<uap:Capability Name="blockedChatMessages"/>
|
||||||
|
<uap:Capability Name="chat"/>
|
||||||
|
<Capability Name="codeGeneration"/>
|
||||||
|
<uap:Capability Name="contacts"/>
|
||||||
|
<uap:Capability Name="enterpriseAuthentication"/>
|
||||||
|
<uap6:Capability Name="graphicsCapture"/>
|
||||||
|
<iot:Capability Name="lowLevelDevices"/>
|
||||||
|
<uap:Capability Name="musicLibrary"/>
|
||||||
|
<uap:Capability Name="objects3D"/>
|
||||||
|
<uap4:Capability Name="offlineMapsManagement"/>
|
||||||
|
<uap:Capability Name="phoneCall"/>
|
||||||
|
<uap2:Capability Name="phoneCallHistoryPublic"/>
|
||||||
|
<uap:Capability Name="picturesLibrary"/>
|
||||||
<Capability Name="privateNetworkClientServer"/>
|
<Capability Name="privateNetworkClientServer"/>
|
||||||
|
<uap3:Capability Name="remoteSystem"/>
|
||||||
|
<uap:Capability Name="removableStorage"/>
|
||||||
|
<uap:Capability Name="sharedUserCertificates"/>
|
||||||
|
<uap2:Capability Name="spatialPerception"/>
|
||||||
|
<iot:Capability Name="systemManagement"/>
|
||||||
|
<uap:Capability Name="userAccountInformation"/>
|
||||||
|
<uap3:Capability Name="userNotificationListener"/>
|
||||||
|
<uap:Capability Name="videosLibrary"/>
|
||||||
|
<uap:Capability Name="voipCall"/>
|
||||||
|
<uap4:Capability Name="userDataTasks"/>
|
||||||
|
<DeviceCapability Name="bluetooth"/>
|
||||||
|
<DeviceCapability Name="gazeInput"/>
|
||||||
|
<DeviceCapability Name="lowLevel"/>
|
||||||
|
<DeviceCapability Name="microphone"/>
|
||||||
|
<DeviceCapability Name="location"/>
|
||||||
|
<DeviceCapability Name="pointOfService"/>
|
||||||
|
<DeviceCapability Name="proximity"/>
|
||||||
|
<DeviceCapability Name="webcam"/>
|
||||||
</Capabilities>
|
</Capabilities>
|
||||||
</Package>
|
</Package>
|
||||||
@@ -34,6 +34,7 @@ namespace PolyChat.Views
|
|||||||
// TODO: use event handlers and asign actions here
|
// TODO: use event handlers and asign actions here
|
||||||
Primary = primary.Action;
|
Primary = primary.Action;
|
||||||
Secondary = secondary.Action;
|
Secondary = secondary.Action;
|
||||||
|
RequestedTheme = MainPage.GetTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setType(string type, string message)
|
private void setType(string type, string message)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace PolyChat.Views
|
|||||||
if (initialValue == null || initialValue.Length == 0) IsSecondaryButtonEnabled = false;
|
if (initialValue == null || initialValue.Length == 0) IsSecondaryButtonEnabled = false;
|
||||||
else input.Text = initialValue;
|
else input.Text = initialValue;
|
||||||
validate();
|
validate();
|
||||||
|
RequestedTheme = MainPage.GetTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getValue()
|
public string getValue()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace PolyChat.Views
|
|||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
IsPrimaryButtonEnabled = false;
|
IsPrimaryButtonEnabled = false;
|
||||||
|
RequestedTheme = MainPage.GetTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getValue()
|
public string getValue()
|
||||||
|
|||||||
20
README.md
Normal file
20
README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Polychat
|
||||||
|

|
||||||
|
serverless chat app written in c# using [`SocketIOSharp`](https://github.com/uhm0311/SocketIOSharp) & `UWP`
|
||||||
|
|
||||||
|
### Features:
|
||||||
|
- chat is not dependent on server, every client can be a server
|
||||||
|
- chatpartner discovery over ip address
|
||||||
|
- set username to be shown to chatpartners
|
||||||
|
- save chat history to local disk (encrypted)
|
||||||
|
- dark mode ;)
|
||||||
|
|
||||||
|
### Implentation:
|
||||||
|
- network connection via the library [`SocketIOSharp`](https://github.com/uhm0311/SocketIOSharp)
|
||||||
|
- graphical user interface uses `UWP` (Universal Windows App)
|
||||||
|
- messages are sent via json
|
||||||
|
- chat history gets saved as json after encryption
|
||||||
|
|
||||||
|
### Screenshots:
|
||||||
|

|
||||||
|

|
||||||
BIN
screenshots/polychat_dark.PNG
Normal file
BIN
screenshots/polychat_dark.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
BIN
screenshots/polychat_light.PNG
Normal file
BIN
screenshots/polychat_light.PNG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user