Beispiel #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                TCPJsonData data = new TCPJsonData()
                {
                    Auth   = GlobalData.Auth,
                    Header = "Get_Servers",
                    Body   = new Dictionary <string, string>()
                };

                try { MasterServer.SendandRecieveTCPData(data); }
                catch (Exception ex) { GlobalData.ErrorLogInput(ex, "ERROR"); }
                byte[] buffer     = new byte[1024];
                int    Recievebuf = 0;// MasterServer.MasterServerSocket.Receive(buffer);
                byte[] databuff   = new byte[Recievebuf];
                Array.Copy(buffer, databuff, Recievebuf);
                string text = Encoding.ASCII.GetString(databuff);
                //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
                    {
                        TCPJsonData recdata = JsonConvert.DeserializeObject <TCPJsonData>(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.LRMServerClientListTCP serverListData = JsonConvert.DeserializeObject <MasterServer.LRMServerClientListTCP>(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");
            }
        }
Beispiel #2
0
        private 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 (Visible)
                {
                    label2.Hide();
                    TCPJsonData data = new TCPJsonData();
                    data.Header = "Get_Servers";
                    data.Auth   = GlobalData.Auth;
                    byte[] sendBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(data));
                    //MasterServer.MasterServerSocket.ReceiveTimeout = 5000;
                    try { MasterServer.SendandRecieveTCPData(data); }
                    catch (Exception ex) { MessageBox.Show("Could not Refresh sevrers. The Master Didnt Respond!", "Uh Oh!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                    byte[] buffer     = new byte[1024];
                    int    Recievebuf = 0; //MasterServer.MasterServerSocket.Receive(buffer);
                    byte[] databuff   = new byte[Recievebuf];
                    Array.Copy(buffer, databuff, Recievebuf);
                    string text = Encoding.ASCII.GetString(databuff);

                    if (text.Contains("Header\":\"Server_Error"))
                    {
                        if (GlobalData.Auth == "")
                        {
                            label2.Show();
                        }
                        else
                        {
                            TCPJsonData recdata = JsonConvert.DeserializeObject <TCPJsonData>(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.LRMServerClientListTCP serverListData = JsonConvert.DeserializeObject <MasterServer.LRMServerClientListTCP>(text);
                        if (serverListData.Auth == GlobalData.Auth)
                        {
                            serverList = serverListData.Body;
                            updataFormItems();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Unknown Server Responce!", "Uh Oh!");
                    }
                }
            }
        }