diff --git a/PolyChat.sln b/PolyChat.sln new file mode 100644 index 0000000..4a3e4d9 --- /dev/null +++ b/PolyChat.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PolyChat", "PolyChat\PolyChat.csproj", "{23ACF793-F4C9-48C2-893C-7BD4A601EF40}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM.ActiveCfg = Debug|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM.Build.0 = Debug|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM.Deploy.0 = Debug|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM64.Build.0 = Debug|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|ARM64.Deploy.0 = Debug|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x64.ActiveCfg = Debug|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x64.Build.0 = Debug|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x64.Deploy.0 = Debug|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x86.ActiveCfg = Debug|x86 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x86.Build.0 = Debug|x86 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Debug|x86.Deploy.0 = Debug|x86 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM.ActiveCfg = Release|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM.Build.0 = Release|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM.Deploy.0 = Release|ARM + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM64.ActiveCfg = Release|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM64.Build.0 = Release|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|ARM64.Deploy.0 = Release|ARM64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x64.ActiveCfg = Release|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x64.Build.0 = Release|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x64.Deploy.0 = Release|x64 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x86.ActiveCfg = Release|x86 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x86.Build.0 = Release|x86 + {23ACF793-F4C9-48C2-893C-7BD4A601EF40}.Release|x86.Deploy.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {58B9261A-B53D-4C9F-B1C5-D3855184F5B1} + EndGlobalSection +EndGlobal diff --git a/PolyChat/App.xaml b/PolyChat/App.xaml new file mode 100644 index 0000000..923cba6 --- /dev/null +++ b/PolyChat/App.xaml @@ -0,0 +1,6 @@ + + diff --git a/PolyChat/App.xaml.cs b/PolyChat/App.xaml.cs new file mode 100644 index 0000000..66a761b --- /dev/null +++ b/PolyChat/App.xaml.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.ApplicationModel; +using Windows.ApplicationModel.Activation; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace PolyChat +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + sealed partial class App : Application + { + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + public App() + { + this.InitializeComponent(); + this.Suspending += OnSuspending; + } + + /// + /// Invoked when the application is launched normally by the end user. Other entry points + /// will be used such as when the application is launched to open a specific file. + /// + /// Details about the launch request and process. + protected override void OnLaunched(LaunchActivatedEventArgs e) + { + Frame rootFrame = Window.Current.Content as Frame; + + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (rootFrame == null) + { + // Create a Frame to act as the navigation context and navigate to the first page + rootFrame = new Frame(); + + rootFrame.NavigationFailed += OnNavigationFailed; + + if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) + { + //TODO: Load state from previously suspended application + } + + // Place the frame in the current Window + Window.Current.Content = rootFrame; + } + + if (e.PrelaunchActivated == false) + { + if (rootFrame.Content == null) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame.Navigate(typeof(MainPage), e.Arguments); + } + // Ensure the current window is active + Window.Current.Activate(); + } + } + + /// + /// Invoked when Navigation to a certain page fails + /// + /// The Frame which failed navigation + /// Details about the navigation failure + void OnNavigationFailed(object sender, NavigationFailedEventArgs e) + { + throw new Exception("Failed to load Page " + e.SourcePageType.FullName); + } + + /// + /// Invoked when application execution is being suspended. Application state is saved + /// without knowing whether the application will be terminated or resumed with the contents + /// of memory still intact. + /// + /// The source of the suspend request. + /// Details about the suspend request. + private void OnSuspending(object sender, SuspendingEventArgs e) + { + var deferral = e.SuspendingOperation.GetDeferral(); + //TODO: Save application state and stop any background activity + deferral.Complete(); + } + } +} diff --git a/PolyChat/Assets/LockScreenLogo.scale-200.png b/PolyChat/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..735f57a Binary files /dev/null and b/PolyChat/Assets/LockScreenLogo.scale-200.png differ diff --git a/PolyChat/Assets/SplashScreen.scale-200.png b/PolyChat/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..023e7f1 Binary files /dev/null and b/PolyChat/Assets/SplashScreen.scale-200.png differ diff --git a/PolyChat/Assets/Square150x150Logo.scale-200.png b/PolyChat/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..af49fec Binary files /dev/null and b/PolyChat/Assets/Square150x150Logo.scale-200.png differ diff --git a/PolyChat/Assets/Square44x44Logo.scale-200.png b/PolyChat/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..ce342a2 Binary files /dev/null and b/PolyChat/Assets/Square44x44Logo.scale-200.png differ diff --git a/PolyChat/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/PolyChat/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..f6c02ce Binary files /dev/null and b/PolyChat/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/PolyChat/Assets/StoreLogo.png b/PolyChat/Assets/StoreLogo.png new file mode 100644 index 0000000..7385b56 Binary files /dev/null and b/PolyChat/Assets/StoreLogo.png differ diff --git a/PolyChat/Assets/Wide310x150Logo.scale-200.png b/PolyChat/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..288995b Binary files /dev/null and b/PolyChat/Assets/Wide310x150Logo.scale-200.png differ diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs new file mode 100644 index 0000000..850c213 --- /dev/null +++ b/PolyChat/Controller.cs @@ -0,0 +1,104 @@ +using System; +using System.Net; +using EngineIOSharp.Common.Enum; +using PolyChat.Models; +using PolyChat.Models.Exceptions; +using SocketIOSharp.Client; +using SocketIOSharp.Common; +using SocketIOSharp.Common.Packet; +using SocketIOSharp.Server.Client; + +namespace PolyChat +{ + public class Controller + { + public static IPAddress ip; + private MainPage UIController; + + private ClientHandler clientHandler; + public Controller(MainPage uiController) + { + UIController = uiController; + clientHandler = new ClientHandler(); + Socket s = new Socket(this); + } + + public void Connect(string ip) + { + clientHandler.connectNewClient(ip); + } + + public void sendMessage(String ip, String name, String msg) + { + clientHandler.getClient(ip).sendMessage(SendCode.Message, name, msg, DateTime.Now); + } + + /// + /// prints out ip. on server side automatticaly finds 10.... ip (which is the correct one) + /// + /// users ip + private String getIP() + { + while (true) + { + string input = Console.ReadLine(); + if (input.Equals("server")) + { + Console.WriteLine("starting as server..."); + for (short i = 0; i < GetIPs().Length; i++) + { + if (GetIPs()[i].ToString().Substring(0, 3).Equals("10.")) + { + Controller.ip = GetIPs()[i]; + Console.WriteLine(GetIPs()[i]); + //get ip as byte array + byte[] ba = System.Text.Encoding.ASCII.GetBytes(GetIPs()[i].ToString()); + foreach (var item in ba) + { + Console.Write(item.ToString() + ","); + } + break; + } + } + Socket s = new Socket(this); + } + else if (input.Equals("client")) + { + ClientHandler cl = new ClientHandler(); + Console.WriteLine("Enter IP:"); + cl.connectNewClient(Console.ReadLine()); + } + } + } + + static void InitEventHandlers(SocketIOClient client) + { + client.On(SocketIOEvent.CONNECTION, () => + { + Console.WriteLine("Connected!"); + client.Emit("Message", "This is a Message Body!"); + }); + + client.On(SocketIOEvent.DISCONNECT, () => + { + Console.WriteLine(); + Console.WriteLine("Disconnected!"); + }); + } + + + + public void OnMessageCallback(SocketIOSocket socket, SocketIOAckEvent message) + { + Console.WriteLine($"Message received from {socket.GetHashCode()}:{message.Data[0]}"); + } + + static IPAddress[] GetIPs() + { + IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName()); + IPAddress[] addr = ipEntry.AddressList; + return addr; + } + + } +} diff --git a/PolyChat/MainPage.xaml b/PolyChat/MainPage.xaml new file mode 100644 index 0000000..8439a3e --- /dev/null +++ b/PolyChat/MainPage.xaml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +