private async void loginButton_Click(object sender, EventArgs e) { stat = 0; Thread thread = new Thread(() => { this.BeginInvoke((MethodInvoker) delegate { try { if (internet == false) { notifView(translateDic["errorInternet"]); return; } if (server == false) { notifView(translateDic["error404"]); return; } var client = new RestClient(apiUrl); var request = new RestRequest("api/login", Method.POST); request.AddParameter("login", loginUsername.Text); request.AddParameter("password", loginPassword.Text); request.AddParameter("launcher", 1); IRestResponse response = client.Execute(request); var content = response.Content; dynamic res = JObject.Parse(content.ToString()); if (res.status == "42") { sessionToken = res.token; if (loginRemember.Checked == true) { string token = res.token; File.WriteAllText(appdata + communityName + "/token.bin2hex", token); } // Reset form startLauncher = true; stat = 1; } else { string message = res.message; notifView(message); } } catch { notifView(translateDic["error404"]); } }); }); thread.Start(); while (stat == 0) { await Task.Delay(1000); } if (startLauncher == true) { startLauncher = false; loginUsername.Text = ""; loginPassword.Text = ""; loginRemember.Checked = false; this.Visible = false; if (!File.Exists(appdata + communityName + "/autoConnect")) { using (var chooseServer = new serverChoose(apiUrl, communityName, translateDic, appdata)) { var result = chooseServer.ShowDialog(); if (result == DialogResult.OK) { serverID = chooseServer.currentServerid; serverIP = chooseServer.currentServerIP; serverGame = chooseServer.currentServerGame; serverName = chooseServer.currentServerName; getServerInfo(serverID); } else { this.Close(); } } } else { string id = File.ReadAllText(appdata + communityName + "/autoConnect"); //GET SERVER INFO getServerInfo(id); } switch (serverGame) { case "arma3": using (var launcher = new launcherMain(communityName, apiUrl, webSite, teamSpeak, sessionToken, ftp_url, ftp_user, ftp_pass, vLast, taskforce, vtaskforce, modDev, serverIP, translateDic, showIGinfo, serverName, serverID, modPackName, downloadPath, serverLocked, serverMaintenance, serverPass)) { var result = launcher.ShowDialog(); if (result == DialogResult.Yes) { if (File.Exists(appdata + communityName + "/autoConnect")) { File.Delete(appdata + communityName + "/autoConnect"); } loginWithToken(); } } break; default: MessageBox.Show("This game is not created on this launcher"); break; } materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; this.Visible = true; } }
void loginWithToken() { stat = 0; try { var client = new RestClient(apiUrl); var request = new RestRequest("api/users/client/get", Method.POST); request.AddParameter("token", sessionToken); IRestResponse response = client.Execute(request); var content = response.Content; dynamic res = JObject.Parse(content.ToString()); if (res.status == "42") { startLauncher = false; loginUsername.Text = ""; loginPassword.Text = ""; loginRemember.Checked = false; this.Visible = false; if (!File.Exists(appdata + communityName + "/autoConnect")) { using (var chooseServer = new serverChoose(apiUrl, communityName, translateDic, appdata)) { var result = chooseServer.ShowDialog(); if (result == DialogResult.OK) { serverID = chooseServer.currentServerid; serverIP = chooseServer.currentServerIP; serverGame = chooseServer.currentServerGame; serverName = chooseServer.currentServerName; getServerInfo(serverID); } else { this.Close(); } } } else { string id = File.ReadAllText(appdata + communityName + "/autoConnect"); //GET SERVER INFO getServerInfo(id); } switch (serverGame) { case "arma3": using (var launcher = new launcherMain(communityName, apiUrl, webSite, teamSpeak, sessionToken, ftp_url, ftp_user, ftp_pass, vLast, taskforce, vtaskforce, modDev, serverIP, translateDic, showIGinfo, serverName, serverID, modPackName, downloadPath, serverLocked, serverMaintenance, serverPass)) { var result = launcher.ShowDialog(); if (result == DialogResult.Yes) { if (File.Exists(appdata + communityName + "/autoConnect")) { File.Delete(appdata + communityName + "/autoConnect"); } loginWithToken(); } } break; default: MessageBox.Show("This game is not created on this launcher"); break; } materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; this.Visible = true; } else { string msg = res.message; notifView(msg); if (File.Exists(appdata + communityName + "/token.bin2hex")) { File.Delete(appdata + communityName + "/token.bin2hex"); } } } catch { notifView(translateDic["error404"]); } }
private void checkOptions(object sender, EventArgs e) { if (loaded == true) { materialSkinManager.ColorScheme = new ColorScheme(Primary.Cyan400, Primary.Indigo700, Primary.Indigo100, Accent.LightGreen200, TextShade.WHITE); materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; return; } loaded = true; try { Ping myPing = new Ping(); String host = "google.com"; byte[] buffer = new byte[32]; int timeout = 1000; PingOptions pingOptions = new PingOptions(); PingReply reply = myPing.Send(host, timeout, buffer, pingOptions); internet = true; } catch { this.Style = MetroColorStyle.Red; materialSkinManager.ColorScheme = new ColorScheme(Primary.Red600, Primary.Indigo700, Primary.Indigo100, Accent.LightGreen200, TextShade.WHITE); internet = false; newsTitle.Text = translateDic["errorInternet"]; notifView(translateDic["errorInternet"]); errorImage.BringToFront(); return; } try { var client = new RestClient(apiUrl); var request = new RestRequest("api/settings", Method.GET); IRestResponse response = client.Execute(request); var content = response.Content; dynamic res = JObject.Parse(content.ToString()); if (res.maintenance == "1") { maintenance = true; loginButton.Enabled = false; registerLink.Enabled = false; materialSkinManager.ColorScheme = new ColorScheme(Primary.Orange400, Primary.Indigo700, Primary.Indigo100, Accent.LightGreen200, TextShade.WHITE); this.Style = MetroColorStyle.Orange; if (res.maintenance_title == "{picture}") { newsImage.Visible = true; newsImage.ImageLocation = res.maintenance_content; newsImage.BringToFront(); } else { newsTitle.Text = res.maintenance_title; newsContent.Text = res.maintenance_content; } maintenanceRefresh.RunWorkerAsync(); return; } if (res.msg_title == "{picture}") { newsImage.Visible = true; newsImage.ImageLocation = res.msg_content; newsImage.BringToFront(); } newsTitle.Text = res.msg_title; newsContent.Text = res.msg_content; if (modDev == false && res.vlauncher != getLauncherMd5().ToLower()) { launcherUpdate(); return; } if (res.login == "0") { sessionToken = null; startLauncher = false; loginUsername.Text = ""; loginPassword.Text = ""; loginRemember.Checked = false; this.Visible = false; if (!File.Exists(appdata + communityName + "/autoConnect")) { using (var chooseServer = new serverChoose(apiUrl, communityName, translateDic, appdata)) { var result = chooseServer.ShowDialog(); if (result == DialogResult.OK) { serverID = chooseServer.currentServerid; serverIP = chooseServer.currentServerIP; serverGame = chooseServer.currentServerGame; serverName = chooseServer.currentServerName; getServerInfo(serverID); } } } else { string id = File.ReadAllText(appdata + communityName + "/autoConnect"); //GET SERVER INFO getServerInfo(id); } switch (serverGame) { case "arma3": using (var launcher = new launcherMain(communityName, apiUrl, webSite, teamSpeak, sessionToken, ftp_url, ftp_user, ftp_pass, vLast, taskforce, vtaskforce, modDev, serverIP, translateDic, showIGinfo, serverName, serverID, modPackName, downloadPath, serverLocked, serverMaintenance, serverPass)) { var result = launcher.ShowDialog(); if (result == DialogResult.Yes) { if (File.Exists(appdata + communityName + "/autoConnect")) { File.Delete(appdata + communityName + "/autoConnect"); } loginWithToken(); } } break; default: MessageBox.Show("This game is not created on this launcher"); break; } materialSkinManager.Theme = MaterialSkinManager.Themes.DARK; this.Visible = true; } if (res.register == "0") { registerLink.Enabled = false; registerMessage.Text = translateDic["registerDisabled"]; } if (sessionToken != null) { loginWithToken(); } server = true; } catch { this.Style = MetroColorStyle.Red; materialSkinManager.ColorScheme = new ColorScheme(Primary.Red600, Primary.Indigo700, Primary.Indigo100, Accent.LightGreen200, TextShade.WHITE); server = false; newsTitle.Text = translateDic["error404"]; notifView(translateDic["error404"]); newsContent.Visible = false; newsImage.Visible = false; errorImage.BringToFront(); } }