private void Form1_Load(object sender, EventArgs e)
        {
            if (!File.Exists(GlobalData.landinglistsJsonPath))
            {
                File.Create(GlobalData.landinglistsJsonPath).Close();
            }
            if (!File.Exists(GlobalData.ErrorLog))
            {
                File.Create(GlobalData.ErrorLog).Close();
            }

            //handles memory login
            if (!File.Exists(GlobalData._5DatFile))
            {
                File.Create(GlobalData._5DatFile).Close();
            }
            string dat = File.ReadAllText(GlobalData._5DatFile);

            if (dat != "")
            {
                string dB64 = "";
                try { dB64 = Encoding.ASCII.GetString(Convert.FromBase64String(dat)); }
                catch (Exception ex) { GlobalData.ErrorLogInput(ex, "ERROR"); return; }
                try
                {
                    LoginDetail detail = JsonConvert.DeserializeObject <LoginDetail>(dB64);
                    memloging     = true;
                    memloginName  = detail.UserName;
                    memloginToken = detail.UserToken;
                }
                catch (Exception ex) { GlobalData.ErrorLogInput(ex, "ERROR"); return; }
            }
        }
 private void SendData(string fpm, string airspd, string plnPitch, string pnlBank, string windSpeed, string windHeading, string aircrftType, string aircraftID)
 {
     try
     {
         if (GlobalData.LoggedIn && GlobalData.CurrentConnectedLRMServer.Type == "LRMComp")
         {
             TCPJsonData data = new TCPJsonData()
             {
                 Auth   = GlobalData.Auth,
                 Header = "Landing_Data",
                 Body   = new Dictionary <string, string>()
                 {
                     { "Fpm", fpm },
                     { "Air_Speed", airspd },
                     { "Plane_Pitch", plnPitch },
                     { "Plane_Bank", pnlBank },
                     { "Wind_Speed", windSpeed },
                     { "Wind_Heading", windHeading },
                     { "Aircraft_Type", aircrftType },
                     { "Aircraft_ID", aircraftID }
                 }
             };
             //Send to master server
         }
     }
     catch (Exception ex)
     {
         GlobalData.ErrorLogInput(ex, "WARNING");
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (SignIn.memloging)
         {
             var msgb = MessageBox.Show("Are you sure you want to Forget your Account?", "Are you Sure?", MessageBoxButtons.YesNo);
             if (msgb == DialogResult.Yes)
             {
                 var    memloginName  = SignIn.memloginName;
                 var    memloginToken = SignIn.memloginToken;
                 string filecont      = File.ReadAllText(Environment.CurrentDirectory + @"\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);
                 }
                 MessageBox.Show("Removed account!");
             }
         }
     }
     catch (Exception ex)
     {
         GlobalData.ErrorLogInput(ex, "Error");
     }
 }
Example #4
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");
            }
        }
        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");
            }
        }
 static void Main()
 {
     try
     {
         if (!File.Exists(ErrorLog))
         {
             File.Create(ErrorLog);
         }
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new Form1());
     }
     catch (Exception ex)
     {
         GlobalData.ErrorLogInput(ex, "FATAL");
         MessageBox.Show("Fatal Error: " + ex.Message + " Please send the file: " + ErrorLog + " to quin#3017 on discord, Press \"OK\" to close the program", "Uh Oh!", MessageBoxButtons.OK);
         Environment.Exit(-1);
     }
 }
Example #7
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (ModifierKeys.HasFlag(Keys.Control))
     {
         ConnectionStatus(true);
     }
     else
     {
         try
         {
             FSUIPCConnection.Open(FlightSim.Any);
             ConnectionStatus();
         }
         catch (FSUIPCException ex)
         {
             GlobalData.ErrorLogInput(ex, "WARNING");
             MessageBox.Show("Error: " + ex.Message, "Uh oh!", MessageBoxButtons.OK);
         }
     }
 }
        private void updataFormItems()
        {
            try
            {
                if (comboBox1.InvokeRequired || dataGridView1.InvokeRequired)
                {
                    var d = new SafeCallDelegate(updataFormItems);
                    Invoke(d, new object[] { });
                }
                else
                {
                    I = 0;
                    dataGridView1.Rows.Clear();
                    comboBox1.Items.Clear();
                    foreach (var server in serverList)
                    {
                        var dat = new KeyValuePair <string, string>(server.Name, server.IP);
                        comboBox1.Items.Add(dat);
                        serverNameIP.Add(dat);
                        comboBox1.DisplayMember = "key";
                        comboBox1.ValueMember   = "value";
                        string stat = "Online!";

                        dataGridView1.Rows[I].Cells[2].Style.ForeColor = Color.Green;

                        dataGridView1.Rows[I].Cells[0].Value = server.Name;
                        dataGridView1.Rows[I].Cells[1].Value = server.CurrentUsers;
                        dataGridView1.Rows[I].Cells[2].Value = stat;
                        dataGridView1.Rows[I].Cells[3].Value = server.Type;
                        dataGridView1.Rows[I].Visible        = true;
                        dataGridView1.Rows.Add();

                        I++;
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalData.ErrorLogInput(ex, "WARNING");
            }
        }
Example #9
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 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 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 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++;
            }
        }