private void RegisterButton_Click(object sender, EventArgs e) { Refresh(); List <string> registerErrors = new List <string>(); if (string.IsNullOrWhiteSpace(RegisterEmail.Text)) { registerErrors.Add("Please enter your e-mail."); RegisterEmailBorder.Image = Theming.BorderEmailError; } else if (!IsEmailValid.Validate(RegisterEmail.Text)) { registerErrors.Add("Please enter a valid e-mail address."); RegisterEmailBorder.Image = Theming.BorderEmailError; } if (string.IsNullOrWhiteSpace(RegisterTicket.Text) && _ticketRequired) { registerErrors.Add("Please enter your ticket."); RegisterTicketBorder.Image = Theming.BorderTicketError; } if (string.IsNullOrWhiteSpace(RegisterPassword.Text)) { registerErrors.Add("Please enter your password."); RegisterPasswordBorder.Image = Theming.BorderPasswordError; } if (string.IsNullOrWhiteSpace(RegisterConfirmPassword.Text)) { registerErrors.Add("Please confirm your password."); RegisterConfirmPasswordBorder.Image = Theming.BorderPasswordError; } if (RegisterConfirmPassword.Text != RegisterPassword.Text) { registerErrors.Add("Passwords don't match."); RegisterConfirmPasswordBorder.Image = Theming.BorderPasswordError; } if (!RegisterAgree.Checked) { registerErrors.Add("You have not agreed to the Terms of Service."); RegisterAgree.ForeColor = Theming.Error; } if (registerErrors.Count == 0) { bool allowReg = false; String Email; String Password; switch (Authentication.HashType(InformationCache.SelectedServerJSON.authHash ?? string.Empty)) { case AuthHash.H10: Email = RegisterEmail.Text.ToString(); Password = RegisterPassword.Text.ToString(); break; case AuthHash.H11: Email = RegisterEmail.Text.ToString(); Password = MDFive.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; case AuthHash.H12: Email = RegisterEmail.Text.ToString(); Password = SHA.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; case AuthHash.H13: Email = RegisterEmail.Text.ToString(); Password = SHATwoFiveSix.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; case AuthHash.H20: Email = MDFive.Hashes(RegisterEmail.Text.ToString()).ToLower(); Password = MDFive.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; case AuthHash.H21: Email = SHA.Hashes(RegisterEmail.Text.ToString()).ToLower(); Password = SHA.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; case AuthHash.H22: Email = SHATwoFiveSix.Hashes(RegisterEmail.Text.ToString()).ToLower(); Password = SHATwoFiveSix.Hashes(RegisterPassword.Text.ToString()).ToLower(); break; default: Log.Error("HASH TYPE: Unknown Hash Standard was Provided"); return; } try { string[] regex = new Regex(@"([0-9A-Z]{5})([0-9A-Z]{35})").Split(Password.ToUpper()); Uri URLCall = new Uri("https://api.pwnedpasswords.com/range/" + regex[1]); ServicePointManager.FindServicePoint(URLCall).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds; var Client = new WebClient { Encoding = Encoding.UTF8 }; if (!WebCalls.Alternative()) { Client = new WebClientWithTimeout { Encoding = Encoding.UTF8 }; } else { Client.Headers.Add("user-agent", "SBRW Launcher " + Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)"); } String serverReply = null; try { serverReply = Client.DownloadString(URLCall); } catch (WebException Error) { APIChecker.StatusCodes(URLCall.GetComponents(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), Error, (HttpWebResponse)Error.Response); } catch (Exception Error) { LogToFileAddons.OpenLog("Register", null, Error, null, true); } finally { if (Client != null) { Client.Dispose(); } } if (!string.IsNullOrWhiteSpace(serverReply)) { String verify = regex[2]; string[] hashes = serverReply.Split('\n'); foreach (string hash in hashes) { var splitChecks = hash.Split(':'); if (splitChecks[0] == verify) { var passwordCheckReply = MessageBox.Show(null, "Password used for registration has been breached " + Convert.ToInt32(splitChecks[1]) + " times, you should consider using a different one.\n\nAlternatively you can use the unsafe password anyway." + "\nWould you like to continue to use it?", "GameLauncher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (passwordCheckReply == DialogResult.Yes) { allowReg = true; } else { allowReg = false; } } else { allowReg = true; } } } else { allowReg = true; } } catch { allowReg = true; } if (allowReg) { Tokens.Clear(); Tokens.IPAddress = InformationCache.SelectedServerData.IPAddress; Tokens.ServerName = ServerListUpdater.ServerName("Register"); Authentication.Client("Register", InformationCache.SelectedServerJSON.modernAuthSupport, Email, Password, _ticketRequired ? RegisterTicket.Text : null); if (!String.IsNullOrWhiteSpace(Tokens.Success)) { DialogResult Success = MessageBox.Show(null, Tokens.Success, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (Success == DialogResult.OK) { Close(); } } else { MessageBox.Show(null, Tokens.Error, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { var message = "There were some errors while registering. Please fix them:\n\n"; foreach (var error in registerErrors) { message += "• " + error + "\n"; } MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void DoModNetJob() { /* Disable Any Buttons */ ServerDropDownList.Enabled = false; ButtonLogin.Enabled = false; ButtonRegister.Enabled = false; ForgotPassLink.Enabled = false; if (Directory.Exists("modules")) { Directory.Delete("modules", true); } if (!Directory.Exists("scripts")) { Directory.CreateDirectory("scripts"); } String[] RemoveAllFiles = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module", "modules/xmppsubject.soapbox.module", "scripts/global.ini", "lightfx.dll", "PocoFoundation.dll", "PocoNet.dll", "ModManager.dat" }; foreach (string file in RemoveAllFiles) { if (File.Exists(file)) { try { File.Delete(file); } catch { MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } String jsonModNet = ModNetReloaded.ModNetSupported(ServerDropDownList.SelectedValue.ToString()); if (jsonModNet != String.Empty) { actionText.Text = "Detecting ModNetSupport for " + ServerDropDownList.SelectedItem.ToString(); try { try { if (File.Exists("lightfx.dll")) { File.Delete("lightfx.dll"); } } catch { } /* Get Remote ModNet list to process for checking required ModNet files are present and current */ String modules = new WebClient().DownloadString(URLs.modnetserver + "/launcher-modules/modules.json"); string[] modules_newlines = modules.Split(new string[] { "\n" }, StringSplitOptions.None); foreach (String modules_newline in modules_newlines) { if (modules_newline.Trim() == "{" || modules_newline.Trim() == "}") { continue; } String trim_modules_newline = modules_newline.Trim(); String[] modules_files = trim_modules_newline.Split(new char[] { ':' }); String ModNetList = modules_files[0].Replace("\"", "").Trim(); String ModNetSHA = modules_files[1].Replace("\"", "").Replace(",", "").Trim(); if (SHATwoFiveSix.HashFile(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList).ToLower() != ModNetSHA || !File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList)) { actionText.Text = ("ModNet: Downloading " + ModNetList).ToUpper(); if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList)) { File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\" + ModNetList); } WebClient newModNetFilesDownload = new WebClient(); newModNetFilesDownload.DownloadFile(URLs.modnetserver + "/launcher-modules/" + ModNetList, AppDomain.CurrentDomain.BaseDirectory + "/" + ModNetList); } else { actionText.Text = ("ModNet: Up to Date " + ModNetList).ToUpper(); } Application.DoEvents(); } JSONNode MainJson = JSON.Parse(jsonModNet); Uri newIndexFile = new Uri(MainJson["basePath"] + "/index.json"); String jsonindex = new WebClient().DownloadString(newIndexFile); JSONNode IndexJson = JSON.Parse(jsonindex); String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } /* new */ foreach (JSONNode modfile in IndexJson["entries"]) { if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"]) { modFilesDownloadUrls.Enqueue(new Uri(MainJson["basePath"] + "/" + modfile["Name"])); TotalModFileCount++; if (File.Exists(path + "/" + modfile["Name"])) { File.Delete(path + "/" + modfile["Name"]); } } } if (modFilesDownloadUrls.Count != 0) { this.DownloadModNetFilesRightNow(path); } else { actionText.Text = "Launching game..."; LaunchGame(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { //Yikes from me Coders - DavidCarbon actionText.Text = "Launching game..."; LaunchGame(); } }
public void DoModNetJob() { File.Delete("ModManager.dat"); if (!Directory.Exists("modules")) { Directory.CreateDirectory("modules"); } if (!Directory.Exists("scripts")) { Directory.CreateDirectory("scripts"); } String[] GlobalFiles = new string[] { "dinput8.dll", "global.ini" }; String[] ModNetReloadedFiles = new string[] { "7z.dll", "PocoFoundation.dll", "PocoNet.dll", "ModLoader.asi" }; String[] ModNetLegacyFiles = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module", "modules/xmppsubject.soapbox.module", "scripts/global.ini", "lightfx.dll", "ModManager.asi", "global.ini" }; String[] RemoveAllFiles = GlobalFiles.Concat(ModNetReloadedFiles).Concat(ModNetLegacyFiles).ToArray(); foreach (string file in RemoveAllFiles) { if (File.Exists(file)) { try { File.Delete(file); } catch { MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } actionText.Text = "Detecting ModNetSupport for " + serverText.SelectedItem.ToString(); String jsonModNet = ModNetReloaded.ModNetSupported(serverText.SelectedValue.ToString()); if (jsonModNet != String.Empty) { actionText.Text = "ModNetReloaded support detected, downloading required files..."; string[] newFiles = GlobalFiles.Concat(ModNetReloadedFiles).ToArray(); try { try { if (File.Exists("lightfx.dll")) { File.Delete("lightfx.dll"); } } catch { } WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout(); foreach (string file in newFiles) { actionText.Text = "Fetching ModNetReloaded Files: " + file; Application.DoEvents(); newModNetFilesDownload.DownloadFile("https://cdn.soapboxrace.world/modules/" + file, file); } try { newModNetFilesDownload.DownloadFile("https://launcher.worldunited.gg/legacy/global.ini", "global.ini"); } catch { } SimpleJSON.JSONNode MainJson = SimpleJSON.JSON.Parse(jsonModNet); Uri newIndexFile = new Uri(MainJson["basePath"] + "/index.json"); String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile); SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex); CountFilesTotal = IndexJson["entries"].Count; String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (JSONNode modfile in IndexJson["entries"]) { if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"]) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(MainJson["basePath"] + "/" + modfile["Name"]), path + "/" + modfile["Name"]); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() == modfile["Checksum"]) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + modfile["Name"]); Console.WriteLine(modfile["Name"] + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { string[] newFiles = GlobalFiles.Concat(ModNetLegacyFiles).ToArray(); WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout(); foreach (string file in newFiles) { actionText.Text = "Fetching LegacyModnet Files: " + file; Application.DoEvents(); newModNetFilesDownload.DownloadFile("http://launcher.worldunited.gg/legacy/" + file, file); } if (result["modsUrl"] != null) { actionText.Text = "Electron support detected, checking mods..."; Uri newIndexFile = new Uri(result["modsUrl"] + "/index.json"); String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile); SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex); CountFilesTotal = IndexJson.Count; String electronpath = (new Uri(serverText.SelectedValue.ToString()).Host).Replace(".", "-"); String path = Path.Combine("MODS", electronpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllText(path + ".json", jsonindex); using (var fs = new FileStream("ModManager.dat", FileMode.Create)) using (var bw = new BinaryWriter(fs)) { bw.Write(CountFilesTotal); foreach (JSONNode file in IndexJson) { var originalPath = Path.Combine(file["file"]).Replace("/", "\\").ToUpper(); var modPath = Path.Combine(path, file["file"]).Replace("/", "\\").ToUpper(); bw.Write(originalPath.Length); bw.Write(originalPath.ToCharArray()); bw.Write(modPath.Length); bw.Write(modPath.ToCharArray()); } } foreach (JSONNode modfile in IndexJson) { String directorycreate = Path.GetDirectoryName(path + "/" + modfile["file"]); Directory.CreateDirectory(directorycreate); if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) != modfile["hash"]) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(result["modsUrl"] + "/" + modfile["file"]), path + "/" + modfile["file"]); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) == modfile["hash"]) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + modfile["file"]); Console.WriteLine(modfile["file"] + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } else if ((bool)result["rwacallow"] == true) { actionText.Text = "RWAC support detected, checking mods..."; String rwacpath = MDFive.HashPassword(new Uri(serverText.SelectedValue.ToString()).Host); String path = Path.Combine("MODS", rwacpath); Uri rwac_wev2 = new Uri(result["homePageUrl"] + "/rwac/fileschecker_sbrw.xml"); String getcontent = new WebClient().DownloadString(rwac_wev2); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(getcontent); var nodes = xmlDoc.SelectNodes("rwac/files/file"); CountFilesTotal = nodes.Count; //ModManager.dat using (var fs = new FileStream("ModManager.dat", FileMode.Create)) using (var bw = new BinaryWriter(fs)) { bw.Write(nodes.Count); foreach (XmlNode files in nodes) { string realfilepath = Path.Combine(files.Attributes["path"].Value, files.Attributes["name"].Value); String directorycreate = Path.GetDirectoryName(path + "/" + realfilepath); var originalPath = Path.Combine(realfilepath).Replace("/", "\\").ToUpper(); var modPath = Path.Combine(path, realfilepath).Replace("/", "\\").ToUpper(); bw.Write(originalPath.Length); bw.Write(originalPath.ToCharArray()); bw.Write(modPath.Length); bw.Write(modPath.ToCharArray()); Directory.CreateDirectory(directorycreate); if (files.Attributes["download"].Value != String.Empty) { if (MDFive.HashFile(path + "/" + realfilepath).ToLower() != files.InnerText) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(files.Attributes["download"].Value), path + "/" + realfilepath); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (MDFive.HashFile(path + "/" + realfilepath).ToLower() == files.InnerText) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + realfilepath); Console.WriteLine(realfilepath + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } } else { actionText.Text = "Deprecated modnet detected. Aborting..."; launchGame(); } } }