Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!GlobalData.LoggedIn)
            {
                if (!memloging)
                {
                    try
                    {
                        HttpListener l = new HttpListener();
                        l.Prefixes.Add("http://*****:*****@"\5Daddy Landing Monitor.exe.config");
                        if (Regex.IsMatch(filecont, "<!--" + memloginName + "|" + memloginToken + "-->"))
                        {
                            string newrplc = Regex.Replace(filecont, "<!--" + memloginName + "|" + memloginToken + "-->", string.Empty);
                            File.WriteAllText(Environment.CurrentDirectory + @"\5Daddy Landing Monitor.exe.config", newrplc);
                            button1.Text = "Login with Discord";
                        }
                    }
                }

                GlobalData.Username = "";
                GlobalData.LoggedIn = false;
                memloginToken       = "";
                memloginName        = "";
                memloging           = false;
                timer1.Enabled      = false;
                label4.Text         = "Not logged in..";
                label4.ForeColor    = Color.Red;
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     //if(GlobalData.socket is null)
     {
         try
         {
             if (comboBox1.SelectedItem != null)
             {
                 KeyValuePair <string, string> KVP = (KeyValuePair <string, string>)comboBox1.SelectedItem;
                 if (KVP.Value != null)
                 {
                     _clientSocket.Connect(KVP.Value, 7878);
                     HTTPData jdata = new HTTPData()
                     {
                         Auth   = GlobalData.Auth,
                         Header = "Connect",
                         Body   = new Dictionary <string, string>()
                     };
                     jdata.Body.Add("Discord_Username", GlobalData.Username);
                     GlobalData.sendJSONdata(jdata);
                     label1.Text                  = "Connected to: " + KVP.Key;
                     label1.ForeColor             = Color.Green;
                     _clientSocket.ReceiveTimeout = 5000;
                     byte[] ResponceBuff = new byte[1024];
                     int    lng          = 0;
                     try { lng = _clientSocket.Receive(ResponceBuff); }
                     catch (Exception ex) { MessageBox.Show("Server Timed out!, Disconnecting!", "Uh Oh!", MessageBoxButtons.OK); GlobalData.ErrorLogInput(ex, "Sever Time Out!"); _clientSocket.Disconnect(true); return; }
                     byte[] recBytes = new byte[lng];
                     Array.Copy(ResponceBuff, recBytes, lng);
                     string   responce     = Encoding.ASCII.GetString(recBytes);
                     HTTPData responceData = JsonConvert.DeserializeObject <HTTPData>(responce);
                     if (responceData.Auth == GlobalData.Auth)
                     {
                         if (responceData.Header == "Success_Connect")
                         {
                             LRMServerData serv = new LRMServerData()
                             {
                                 Name        = responceData.Body.FirstOrDefault(x => x.Key == "Name").Value,
                                 Type        = responceData.Body.FirstOrDefault(x => x.Key == "Type").Value,
                                 PlayerCount = responceData.Body.FirstOrDefault(x => x.Key == "Players").Value,
                                 //serverSocket = _clientSocket,
                             };
                         }
                         else
                         {
                             MessageBox.Show("Server Responded with an Invalad Responce!", "Uh Oh!", MessageBoxButtons.OK);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Server Responded with an Invalad Responce!", "Uh Oh!", MessageBoxButtons.OK);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             GlobalData.ErrorLogInput(ex, "ERROR");
             MessageBox.Show("Error: " + ex.Message, "Uh Oh!");
         }
     }
 }
 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();
         }
     }
 }
        private void timer1_Tick(object sender, EventArgs e)
        {
            UpdateScreenData();
            if (checkGroundTime >= 150)
            {
                if (FSUIPCConnection.IsOpen)
                {
                    try
                    {
                        FSUIPCConnection.Process();
                        if (GlobalData.COM1act != COM1act.Value)
                        {
                            GlobalData.COM1act = COM1act.Value;
                        }
                        if (GlobalData.COM1sby != COM1sby.Value)
                        {
                            GlobalData.COM1sby = COM1sby.Value;
                        }
                        ATCID = aircraftID.Value;

                        int fpm = 0;
                        if (ATCID != OldCraft)
                        {
                            imageList1.Images.Clear();
                            Console.WriteLine("Changing Image...");
                            ATCID        = aircraftID.Value;
                            ATCTYPE      = aircraftType.Value;
                            label10.Text = $"{ATCID} - {ATCTYPE}";
                            string urlAddress = "https://www.airplane-pictures.net/registration.php?p=" + ATCID;
                            Console.WriteLine(urlAddress);
                            WebClient client = new WebClient();
                            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                            int    lineis   = 0;
                            bool   Found    = false;
                            bool   count    = false;
                            string image    = "";
                            int    permline = 0;
                            client.DownloadFile(urlAddress, Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp");
                            string[] Page_AppGet = File.ReadAllLines(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp");
                            foreach (string line in Page_AppGet)
                            {
                                lineis = lineis + 1;
                                if (Found == false)
                                {
                                    if (line.Contains("<img src='"))
                                    {
                                        Found = true;
                                    }
                                }
                                else
                                {
                                    if (count == false)
                                    {
                                        permline = lineis - 1;
                                        count    = true;
                                    }
                                }
                            }
                            string Line = GetLine(File.ReadAllText(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp"), permline);
                            if (Line != "0x359")
                            {
                                string before = Regex.Split(Line, "<img src='")[1];
                                string Images = Regex.Split(before, "'")[0];
                                string Type   = Images.Split('.')[1];
                                client.DownloadFile(Images, Environment.CurrentDirectory + @"\Data\AircraftImage.lco");
                                imageList1.Images.Add(Image.FromFile(Environment.CurrentDirectory + @"\Data\AircraftImage.lco"));
                                imageList1.ImageSize = new Size(191, 125);
                                pictureBox1.Image    = imageList1.Images[0];
                                File.Delete(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp");
                            }
                            else
                            {
                                try
                                {
                                    imageList1.Images.Clear();
                                    Console.WriteLine("Failed..");
                                }
                                catch { }
                            }
                        }
                        OldCraft = ATCID;
                        if (!ongrnd)
                        {
                            double verticalSpeedMPS = verticalSpeed.Value / 256d;
                            double verticalSpeedFPM = verticalSpeedMPS * 60d * 3.28084d;
                            var    vsFPM            = Convert.ToInt32(verticalSpeedFPM);

                            ATCTYPE        = aircraftType.Value;
                            label10.Text   = $"{ATCID} - {ATCTYPE}";
                            fpm            = vsFPM;
                            VSRate.Text    = "Feet Per Minute: " + vsFPM.ToString();
                            timer1.Enabled = timerOn;
                            double airspeedKnots = (double)airspeed.Value / 128d;
                            airspd          = Convert.ToInt32(airspeedKnots).ToString();
                            SpeedLabel.Text = "Speed: " + airspd;
                            var plnPitch = (double)pitch.Value * 360 / 4294967296 * -1;

                            WeatherServices ws      = FSUIPCConnection.WeatherServices;
                            FsWeather       weather = ws.GetWeatherAtAircraft();

                            if (weather.WindLayers.Count > 0)
                            {
                                FsWindLayer windLayer = weather.WindLayers[0];
                                windHdg        = windLayer.Direction.ToString("000");
                                windSpd        = windLayer.SpeedKnots.ToString("F0");
                                WiSpLabel.Text = "Wind Speed: " + windLayer.SpeedKnots.ToString("F0");
                                WiDiLabel.Text = "Wind Direction: " + windLayer.Direction.ToString("000");
                            }

                            tmp = Convert.ToInt32(plnPitch);
                            if (tmp >= 0)
                            {
                                PitchLabel.Text = "Pitch: " + tmp.ToString() + "▲";
                            }
                            if (tmp < 0)
                            {
                                tmp             = tmp * -1;
                                PitchLabel.Text = "Pitch: " + tmp.ToString() + "▼";
                            }

                            var plnBank  = (double)roll.Value * 360 / 4294967296;
                            var planebnk = "";
                            if (plnBank >= 0)
                            {
                                planebnk = Convert.ToInt32(plnBank).ToString() + "L";
                            }
                            if (plnBank < 0)
                            {
                                planebnk = Convert.ToInt32(plnBank * -1).ToString() + "R";
                            }
                            plnbnk          = planebnk;
                            BankLabel.Text  = "Bank: " + planebnk;
                            timer1.Interval = RefreshRate;
                        }


                        string onGroundText = this.onGround.Value > 0 ? "Y" : "N";

                        if (onGroundText == "Y")
                        {
                            checkGroundTime = 0;
                            if (GlobalData.LoggedIn)
                            {
                                if (rptask)
                                {
                                    checkBox1.Show();
                                    rptask = false;
                                }
                            }
                            if (!GlobalData.LoggedIn)
                            {
                                if (rptask)
                                {
                                    checkBox1.Hide();
                                    rptask = true;
                                }
                            }

                            if (rptOnGround)
                            {
                                if (checkBox1.Checked)
                                {
                                    SendData(fpm.ToString(), airspd, tmp.ToString(), plnbnk, windSpd, windHdg, ATCID, ATCTYPE);
                                }

                                rptOnGround = false;

                                label8.Text = "Landed!";
                                ongrnd      = true;

                                fpmstringscore(fpm);
                                if (Rate.Text != "")
                                {
                                    LandingStats ls = new LandingStats();
                                    ls.FPM           = fpm.ToString();
                                    ls.Speed         = airspd;
                                    ls.Score         = Rate.Text;
                                    ls.Roll          = plnbnk;
                                    ls.Pitch         = PitchLabel.Text.Replace("Pitch: ", "");
                                    ls.WindSpeed     = windSpd;
                                    ls.WindDirection = windHdg;
                                    LRMDatabase.AddStat(ls);
                                }
                            }
                        }
                        if (onGroundText == "N")
                        {
                            label8.Text = "Airborn";
                            ongrnd      = false;
                            rptOnGround = true;
                        }
                    }
                    catch (FSUIPCException ex)
                    {
                        FSUIPCConnection.Close();
                        timer1.Enabled = false;
                        GlobalData.ErrorLogInput(ex, "ERROR");
                        MessageBox.Show("Error, Cannot read game data: " + ex.Message + ", please Disconnect");
                        return;
                    }
                }
            }
            else
            {
                checkGroundTime++;
            }
        }