private void button3_Click(object sender, EventArgs e) { try { HTTPData data = new HTTPData() { Auth = GlobalData.Auth, Header = "Get_Servers", Body = new Dictionary <string, string>() }; string text = ""; try { text = MasterServer.SendandRecieveTCPData(data).Result; } catch (Exception ex) { GlobalData.ErrorLogInput(ex, "ERROR"); MessageBox.Show("Error Recieving The servers list!", "Uh Oh!", MessageBoxButtons.OK); } //var header = JsonConvert.DeserializeObject<Dictionary<string, string>>(text).FirstOrDefault(x => x.Key == "Header").Value; if (text.Contains("Header\":\"Server_Error")) { if (GlobalData.Auth == "") { label2.Show(); } else { HTTPData recdata = JsonConvert.DeserializeObject <HTTPData>(text); MessageBox.Show($"Invalad Request! Server Responce:\n{recdata.Body.FirstOrDefault(x => x.Key == "Reason").Value}", "Uh Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); GlobalData.ErrorLogInput(new Exception("Invalad Authentication Token!"), "ERROR"); } } if (text.Contains("Header\":\"LRMServers_List")) { label2.Hide(); MasterServer.LRMServerClientListHTTP serverListData = JsonConvert.DeserializeObject <MasterServer.LRMServerClientListHTTP>(text); if (serverListData.Auth == GlobalData.Auth) { serverList = serverListData.Body; updataFormItems(); } } else { MessageBox.Show("Unknown Server Responce!", "Uh Oh!"); } } catch (Exception ex) { GlobalData.ErrorLogInput(ex, "WARNING"); } }
private async void GetServers(object sender, EventArgs e) { if (GlobalData.Offlinemode) { label1.Hide(); label5.Show(); dataGridView1.Hide(); button1.Hide(); button2.Hide(); button3.Hide(); comboBox1.Hide(); label2.Hide(); } else { if (GlobalData.LoggedIn) { if (Visible) { label2.Hide(); HTTPData data = new HTTPData(); data.Header = "Get_Servers"; data.Auth = GlobalData.Auth; //byte[] sendBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(data)); MasterServer.ReceiveTimeout = 5000; string retString = ""; try { retString = await MasterServer.SendandRecieveTCPData(data); } catch (Exception ex) { MessageBox.Show("Could not Refresh sevrers. The Master Didnt Respond!", "Uh Oh!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string text = retString; if (text.Contains("Header\":\"Server_Error")) { if (GlobalData.Auth == "") { label2.Show(); } else { HTTPData recdata = JsonConvert.DeserializeObject <HTTPData>(text); MessageBox.Show($"Invalad Request! Server Responce:\n{recdata.Body.FirstOrDefault(x => x.Key == "Reason").Value}", "Uh Oh!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); GlobalData.ErrorLogInput(new Exception("Invalad Authentication Token!"), "ERROR"); } } if (text.Contains("Header\":\"LRMServers_List")) { label2.Hide(); MasterServer.LRMServerClientListHTTP serverListData = JsonConvert.DeserializeObject <MasterServer.LRMServerClientListHTTP>(text); if (serverListData.Auth == GlobalData.Auth) { serverList = serverListData.Body; updataFormItems(); } } else { MessageBox.Show("Unknown Server Responce!", "Uh Oh!"); } } } else { label1.Hide(); label5.Hide(); dataGridView1.Hide(); button1.Hide(); button2.Hide(); button3.Hide(); comboBox1.Hide(); label2.Show(); } } }