using System; using System.IO; using System.Net; using System.Text; using System.Windows; using System.Diagnostics; using System.Windows.Controls; using System.Threading; namespace Launcher { public partial class LoginWindow : Window { private WebClient ServerClient = new WebClient(); public LoginWindow() { InitializeComponent(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } private void Window_Initialized(Object Sender, EventArgs Args) { if (File.Exists(String.Format("{0}Launcher\\01e57932-109d-4e99-884a-74561b6bb999.txt", AppDomain.CurrentDomain.BaseDirectory))) { String[] FileSplit = Encoding.UTF8.GetString(Convert.FromBase64String(File.ReadAllLines(String.Format("{0}Launcher\\01e57932-109d-4e99-884a-74561b6bb999.txt", AppDomain.CurrentDomain.BaseDirectory))[0])).Split('#'); L_Username.Text = FileSplit[0]; L_Password.Password = FileSplit[1]; SaveInfo.IsChecked = true; } App.LauncherTitle = ServerClient.DownloadString(String.Format("http://{0}:10002?Type=InformationRequest&ServerID={1}&InformationType=LauncherTitle", App.ServerIP, 0)); Title = String.Format("{0} - Login & Register", App.LauncherTitle); if (!File.Exists(String.Format("{0}Launcher\\NoBackground.txt", AppDomain.CurrentDomain.BaseDirectory))) { Video.Source = new Uri(String.Format("{0}Video.mp4", AppDomain.CurrentDomain.BaseDirectory)); Music.Source = new Uri(String.Format("{0}Music.mp3", AppDomain.CurrentDomain.BaseDirectory)); Video.Play(); Music.Play(); Music.Volume = 0; } } private void CurrentDomain_UnhandledException(Object Sender, UnhandledExceptionEventArgs Args) { MessageBox.Show(((Exception)Args.ExceptionObject).ToString()); File.WriteAllLines(String.Concat(AppDomain.CurrentDomain.BaseDirectory, "LauncherCrash.txt"), new String[] { ((Exception)Args.ExceptionObject).ToString() }); } private void Video_MediaEnded(Object Sender, RoutedEventArgs Args) { Video.Position = TimeSpan.Zero; Video.Play(); } private void Music_MediaEnded(Object Sender, RoutedEventArgs Args) { Music.Position = TimeSpan.Zero; Music.Play(); } private void Login_Click(Object Sender, RoutedEventArgs Args) { L_Username.IsEnabled = false; L_Password.IsEnabled = false; Login.IsEnabled = false; WebClient ServerClient = new WebClient(); App.Username = L_Username.Text; App.Password = L_Password.Password; String Response = ServerClient.DownloadString(String.Format("http://{0}:10002?Type=Login&Username={1}&Password={2}", App.ServerIP, App.Username, App.Password)); if (!Response.StartsWith("Success")) { MessageBox.Show(Response, String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); } else { String[] ResponseSplit = Response.Split('#'); App.Token = ResponseSplit[1]; App.ID = Convert.ToInt32(ResponseSplit[2]); App.MallPoints = Convert.ToInt64(ResponseSplit[3]); if (!File.Exists(String.Format("{0}\\Launcher\\{1}RecoveryKey.txt", AppDomain.CurrentDomain.BaseDirectory, App.Username))) { File.WriteAllLines(String.Format("{0}\\Launcher\\{1}RecoveryKey.txt", AppDomain.CurrentDomain.BaseDirectory, App.Username), new String[] { ResponseSplit[5] }); } if (Convert.ToBoolean(ResponseSplit[4])) { MessageBox.Show(String.Format("A recovery key has been saved to your computer for the account {0}, if you ever lose your account this can be used to quickly recover it :).", App.Username), String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); } if (SaveInfo.IsChecked == true) { Byte[] B64Bytes = Encoding.UTF8.GetBytes(String.Format("{0}#{1}", App.Username, App.Password)); String B64String = Convert.ToBase64String(B64Bytes); if (File.Exists(String.Format("{0}Launcher\\01e57932-109d-4e99-884a-74561b6bb999.txt", AppDomain.CurrentDomain.BaseDirectory))) { File.Delete(String.Format("{0}Launcher\\01e57932-109d-4e99-884a-74561b6bb999.txt", AppDomain.CurrentDomain.BaseDirectory)); } File.WriteAllLines(String.Format("{0}Launcher\\01e57932-109d-4e99-884a-74561b6bb999.txt", AppDomain.CurrentDomain.BaseDirectory), new String[] { B64String }); } UserWindow UW = new UserWindow(); UW.ShowDialog(); Dispatcher.BeginInvoke((Action)(() => { Close(); })); } L_Username.IsEnabled = true; L_Password.IsEnabled = true; Login.IsEnabled = true; } private void Register_Click(Object Sender, RoutedEventArgs Args) { R_Username.IsEnabled = false; R_Password.IsEnabled = false; R_RePassword.IsEnabled = false; Register.IsEnabled = false; WebClient ServerClient = new WebClient(); if (R_Password.Password != R_RePassword.Password) { MessageBox.Show("Your password & re-password do not match.", String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); } else { App.Username = R_Username.Text; App.Password = R_Password.Password; String Response = ServerClient.DownloadString(String.Format("http://{0}:10002?Type=Register&Username={1}&Password={2}", App.ServerIP, App.Username, App.Password)); if (!Response.StartsWith("Success")) { MessageBox.Show(Response, String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); } else { String[] ResponseSplit = Response.Split('#'); MessageBox.Show(ResponseSplit[1], String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); MessageBoxResult MBResult = MessageBox.Show("Would you like to login with your new account?", String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.YesNo); if (MBResult == MessageBoxResult.No) { Close(); } else { Response = ServerClient.DownloadString(String.Format("http://{0}:10002?Type=Login&Username={1}&Password={2}", App.ServerIP, App.Username, App.Password)); if (!Response.StartsWith("Success")) { MessageBox.Show(Response, String.Format("{0} Launcher", App.LauncherTitle), MessageBoxButton.OK); } else { ResponseSplit = Response.Split('#'); App.Token = ResponseSplit[1]; UserWindow UW = new UserWindow(); UW.ShowDialog(); Dispatcher.BeginInvoke((Action)(() => { Close(); })); } } } } R_Username.IsEnabled = true; R_Password.IsEnabled = true; R_RePassword.IsEnabled = true; Register.IsEnabled = true; } private void L_Username_TextChanged(Object Sender, TextChangedEventArgs Args) { if (L_Username.Text.Length >= 1) { L_UsernameB.Content = ""; } else { L_UsernameB.Content = "Username"; } } private void L_Password_PasswordChanged(Object Sender, RoutedEventArgs Args) { if (L_Password.Password.Length >= 1) { L_PasswordB.Content = ""; } else { L_PasswordB.Content = "Password"; } } private void R_Username_TextChanged(Object Sender, TextChangedEventArgs Args) { if (R_Username.Text.Length >= 1) { R_UsernameB.Content = ""; } else { R_UsernameB.Content = "Username"; } } private void R_Password_PasswordChanged(Object Sender, RoutedEventArgs Args) { if (R_Password.Password.Length >= 1) { R_PasswordB.Content = ""; } else { R_PasswordB.Content = "Password"; } } private void R_RePassword_PasswordChanged(Object Sender, RoutedEventArgs Args) { if (R_RePassword.Password.Length >= 1) { R_RePasswordB.Content = ""; } else { R_RePasswordB.Content = "Repeat Password"; } } private void Close_Click(Object Sender, RoutedEventArgs Args) { Process.GetCurrentProcess().Kill(); } private void Volume_ValueChanged(Object Sender, RoutedPropertyChangedEventArgs Args) { Music.Volume = Volume.Value; } } }