Ejemplo n.º 1
0
        public Packets.Packet_11_FlightData GetFlightData()
        {
            Packets.Packet_11_FlightData Output = new Packets.Packet_11_FlightData(3);
            Output.TimeStamp       = TimeStamp;
            Output.ID              = ID;
            Output.PosX            = PosX;
            Output.PosY            = PosY;
            Output.PosZ            = PosZ;
            Output.HdgX            = (short)HdgX;
            Output.HdgY            = (short)HdgY;
            Output.HdgZ            = (short)HdgZ;
            Output.V_PosX          = V_PosX;
            Output.V_PosY          = V_PosY;
            Output.V_PosZ          = V_PosZ;
            Output.Weight_Fuel     = Weight_Fuel;
            Output.Weight_SmokeOil = (short)Weight_SmokeOil;
            Output.Anim_Gear       = Anim_Gear;
            Output.Anim_Throttle   = Anim_Throttle;
            Output.Anim_Boards     = Anim_Boards;
            Output.Anim_VGW        = Anim_VGW;
            Output.Anim_BombBay    = Anim_BombBay;
            Output.Anim_Nozzle     = Anim_Nozzle;
            Output._Anim_Flags     = _Anim_Flags;

            return(Output);
        }
 private static bool YSFHandle_11_FlightData(Client ThisClient, Packets.GenericPacket InPacket)
 {
     #region Prepare Flight Data
     //Prepare FlightData Packet
     //Check if the server has the vehicle specified.
     //Deny old flightdatapackets.
     Packets.Packet_11_FlightData FlightData = new Packets.Packet_11_FlightData(InPacket);
     Vehicle SenderVehicle;
     lock (Vehicles.List)
     {
         if (Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).Count() <= 0)
         {
             //Console.WriteLine("Missing Aircraft ID: " + FlightData.ID + " for client " + ThisConnection.ThisClient.Info.Username);
             return(false);
         }
         SenderVehicle = Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).ToArray()[0];
     }
     #endregion
     #region ValidateFlightData
     if (SenderVehicle.TimeStamp > FlightData.TimeStamp)
     {
         return(false);
     }
     SenderVehicle.Update(FlightData);
     #endregion
     ThisClient.SendPacket(InPacket);
     return(true);
 }
Ejemplo n.º 3
0
        public bool Update(Packets.Packet_11_FlightData FlightData)
        {
            //Debug.WriteLine(TimeStamp + ", " + FlightData.TimeStamp);
            if (TimeStamp <= FlightData.TimeStamp && ID == FlightData.ID)
            {
                Prev_TimeStamp  = TimeStamp;
                TimeStamp       = FlightData.TimeStamp;
                Prev_PosX       = PosX;
                Prev_PosY       = PosY;
                Prev_PosZ       = PosZ;
                PosX            = FlightData.PosX;
                PosY            = FlightData.PosY;
                PosZ            = FlightData.PosZ;
                HdgX            = FlightData.HdgX;
                HdgY            = FlightData.HdgY;
                HdgZ            = FlightData.HdgZ;
                V_PosX          = FlightData.V_PosX;
                V_PosY          = FlightData.V_PosY;
                V_PosZ          = FlightData.V_PosZ;
                V_HdgX          = FlightData.V_HdgX;
                V_HdgY          = FlightData.V_HdgY;
                V_HdgZ          = FlightData.V_HdgZ;
                Weight_Fuel     = FlightData.Weight_Fuel;
                Weight_SmokeOil = FlightData.Weight_SmokeOil;
                Anim_Gear       = (byte)FlightData.Anim_Gear;
                Anim_Throttle   = (byte)FlightData.Anim_Throttle;
                Anim_Boards     = (byte)FlightData.Anim_Boards;
                Anim_VGW        = (byte)FlightData.Anim_VGW;
                Anim_BombBay    = (byte)FlightData.Anim_BombBay;
                Anim_Nozzle     = (byte)FlightData.Anim_Nozzle;
                _Anim_Flags     = (byte)FlightData._Anim_Flags;
                Strength        = FlightData.Strength;

                LastUpdated = DateTime.Now;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
            public bool SendUpdate()
            {
                if (!Loaded)
                {
                    return(false);
                }
                if (Playing)
                {
                    CurrentTime += 0.1;
                }
                #region GetCurrentPackets
                List <Packets.GenericPacket> PacketsToSend =
                    (
                        from ThisPacketEvent in Records
                        where ThisPacketEvent.TimeStamp >= PreviousTime
                        where ThisPacketEvent.TimeStamp < CurrentTime
                        select ThisPacketEvent.Packet
                    ).ToList();
                if (PacketsToSend.Count == 0)
                {
                    return(false);
                }
                List <Packets.Packet_11_FlightData> FlightDataPacketsToSend =
                    (
                        from ThisFlightDataPacket in PacketsToSend
                        where ThisFlightDataPacket.Type == 11
                        select new Packets.Packet_11_FlightData(ThisFlightDataPacket)
                    ).OrderByDescending(x => x.TimeStamp).ToList();
                #endregion

                List <Client> CurrentClients = Clients.LoggedIn;
                foreach (uint ThisACID in AircraftIDs)
                {
                    #region GetFlightDataFromThisAircraft
                    List <Packets.Packet_11_FlightData> ThisAircraftFlightData =
                        (
                            from ThisFlightDataPacket in FlightDataPacketsToSend
                            where ThisFlightDataPacket.ID == ThisACID
                            select ThisFlightDataPacket
                        ).ToList();
                    #endregion
                    if (ThisAircraftFlightData.Count < 1)
                    {
                        continue;
                    }

                    #region GetLatestFlightData
                    Packets.Packet_11_FlightData NewesetFlightData =
                        (from ThisFlightDataPacket in FlightDataPacketsToSend
                         where ThisFlightDataPacket.ID == ThisACID
                         select ThisFlightDataPacket).ToArray().Last();

                    #endregion

                    #region UpdateFlightData
                    foreach (Vehicle ThisVehicle in Vehicles.List.Where(x => x.ID == ThisACID))
                    {
                        ThisVehicle.Update(NewesetFlightData);
                    }
                    #endregion

                    float difference = (float)(NewesetFlightData.TimeStamp - PreviousTime);
                    foreach (Client ThisClient in CurrentClients)
                    {
                        #region SetTimeToNow
                        NewesetFlightData.TimeStamp = (float)((DateTime.Now - OpenYS.TimeStarted).TotalSeconds - (CurrentTime - PreviousTime) + difference);
                        #endregion

                        //Debug.WriteLine(NewesetFlightData.TimeStamp + " Ready to send to " + ThisClient.Username);
                        ThisClient.SendPacket(NewesetFlightData);
                        //Debug.WriteLine(NewesetFlightData.TimeStamp + " Send Flight Data.");
                    }
                    continue;
                }

                foreach (Packets.GenericPacket ThisPacket in PacketsToSend)
                {
                    if (ThisPacket.Type == 11)
                    {
                        continue;
                    }

                    #region Join Data
                    if (ThisPacket.Type == 05)
                    {
                        Packets.Packet_05_EntityJoined ThisJoinData = new Packets.Packet_05_EntityJoined(ThisPacket);

                        #region Create Vehicle
                        Vehicle ThisVehicle = new Vehicle();
                        ThisVehicle.Update(ThisJoinData);
                        //ThisJoinData = ThisVehicle.GetJoinPacket(false);
                        #endregion

                        #region Add Vehicle to Vehicles List
                        Vehicles.List.Add(ThisVehicle);
                        VehiclesHistory.List.Add(ThisVehicle);
                        #endregion

                        foreach (Client ThisClient in CurrentClients)
                        {
                            Packets.Packet_06_Acknowledgement Acknowledgement;
                            if (ThisJoinData.IsAircraft)
                            {
                                Acknowledgement = new Packets.Packet_06_Acknowledgement(0, ThisJoinData.ID);
                            }
                            else
                            {
                                Acknowledgement = new Packets.Packet_06_Acknowledgement(1, 0);
                            }
                            //ThisClient.SendPacketGetPacket(ThisJoinData, Acknowledgement);
                            ThisClient.SendPacket(ThisJoinData);
                        }
                        continue;
                    }
                    #endregion

                    #region Leave Data
                    if (ThisPacket.Type == 13)
                    {
                        Packets.Packet_13_RemoveAirplane ThisRemoveAirplane = new Packets.Packet_13_RemoveAirplane(ThisPacket);

                        lock (Vehicles.List) Vehicles.List.RemoveAll(x => x.ID == ThisRemoveAirplane.ID);

                        foreach (Client ThisClient in CurrentClients)
                        {
                            Packets.Packet_06_Acknowledgement AcknowledgeLeave = new Packets.Packet_06_Acknowledgement(2, ThisRemoveAirplane.ID);
                            //ThisClient.SendPacketGetPacket(ThisRemoveAirplane, AcknowledgeLeave);
                            ThisClient.SendPacket(ThisRemoveAirplane);
                        }
                        continue;
                    }
                    #endregion

                    CurrentClients.SendPacket(ThisPacket);
                }
                if (Playing)
                {
                    PreviousTime = CurrentTime;
                }
                return(true);
            }
Ejemplo n.º 5
0
            private PacketEvent ProcessYSFlightAircraftRecord(string[] Input, uint ID)
            {
                Packets.Packet_11_FlightData Output = new Packets.Packet_11_FlightData(3);
                if (Input.Length != 4)
                {
                    Debug.WriteLine("Failed to load a YSFlight Replay Record!");
                    foreach (string ThisString in Input)
                    {
                        Debug.WriteLine("    " + ThisString);
                    }
                    return(null);
                }
                string[] RecordArray = new string[27];
                try
                {
                    RecordArray = (Input[0] + " " + Input[1] + " " + Input[2] + " " + Input[3]).Split(' ');
                    //^^ This is MUCH faster!

                    //RecordArray[0] = Input[0].Split(' ')[0];    //TimeStamp

                    //RecordArray[1] = Input[1].Split(' ')[0];    //PosX - Float
                    //RecordArray[2] = Input[1].Split(' ')[1];    //PosY - Float
                    //RecordArray[3] = Input[1].Split(' ')[2];    //PosZ - Float
                    //RecordArray[4] = Input[1].Split(' ')[3];    //HdgX - Float
                    //RecordArray[5] = Input[1].Split(' ')[4];    //HdgY - Float
                    //RecordArray[6] = Input[1].Split(' ')[5];    //HdgZ - Float
                    //RecordArray[7] = Input[1].Split(' ')[6];    //LoadFactor - Float

                    //RecordArray[8]  = Input[2].Split(' ')[0];   //AirState Direct
                    //RecordArray[9]  = Input[2].Split(' ')[1];   //VGW 0-255
                    //RecordArray[10] = Input[2].Split(' ')[2];   //Boards 0-255
                    //RecordArray[11] = Input[2].Split(' ')[3];   //Gear 0-255
                    //RecordArray[12] = Input[2].Split(' ')[4];   //Flap 0-255
                    //RecordArray[13] = Input[2].Split(' ')[5];   //Brake 0-255
                    //RecordArray[14] = Input[2].Split(' ')[6];   //Smoke 0-255
                    //RecordArray[15] = Input[2].Split(' ')[7];   //??? - Leave 0
                    //RecordArray[16] = Input[2].Split(' ')[8];   //Anim Flags Direct
                    //RecordArray[17] = Input[2].Split(' ')[9];   //Strength 0-255
                    //RecordArray[18] = Input[2].Split(' ')[10];  //Throttle 0-100
                    //RecordArray[19] = Input[2].Split(' ')[11];  //Elevator - Signed Byte
                    //RecordArray[20] = Input[2].Split(' ')[12];  //Aileron - Signed Byte
                    //RecordArray[21] = Input[2].Split(' ')[13];  //Rudder - Signed Byte
                    //RecordArray[22] = Input[2].Split(' ')[14];  //Trim - Signed Byte
                    //RecordArray[23] = Input[2].Split(' ')[15];  //Thrust Vector 0-100
                    //RecordArray[24] = Input[2].Split(' ')[16];  //Thrust Reverse 0-100
                    //RecordArray[25] = Input[2].Split(' ')[17];  //Bomb Bay 0-100

                    //RecordArray[26] = Input[3].Split(' ')[0];   //Terminator
                }
                catch
                {
                    Debug.WriteLine("Failed to format a YSFlight Replay Record!");
                    foreach (string ThisString in Input)
                    {
                        Debug.WriteLine("    " + ThisString);
                    }
                    return(null);
                }
                try
                {
                    Output.TimeStamp = Single.Parse(RecordArray[0]);
                    if (Output.TimeStamp < 0)
                    {
                        Output.TimeStamp = 0;
                    }
                    Output.ID = ID;

                    Output.PosX       = Single.Parse(RecordArray[1]);
                    Output.PosY       = Single.Parse(RecordArray[2]);
                    Output.PosZ       = Single.Parse(RecordArray[3]);
                    Output.HdgX       = (short)(Single.Parse(RecordArray[4]) / Math.PI * 32767);
                    Output.HdgY       = (short)(Single.Parse(RecordArray[5]) / Math.PI * 32767);
                    Output.HdgZ       = (short)(Single.Parse(RecordArray[6]) / Math.PI * 32767);
                    Output.LoadFactor = (short)(Single.Parse(RecordArray[7]) * 10);

                    Output.FlightState = Byte.Parse(RecordArray[8]);
                    Output.Anim_VGW    = (byte)(Byte.Parse(RecordArray[9]) / 255d * 100d);
                    Output.Anim_Boards = (byte)(Byte.Parse(RecordArray[10]) / 255d * 100d);
                    Output.Anim_Gear   = (byte)(Byte.Parse(RecordArray[11]) / 255d * 100d);
                    Output.Anim_Flaps  = (byte)(Byte.Parse(RecordArray[12]) / 255d * 100d);
                    Output.Anim_Brake  = (byte)(Byte.Parse(RecordArray[13]) / 255d * 100d);
                    Output.Anim_Smoke  = (Byte.Parse(RecordArray[14]) > 0);
                    //15 == ???;
                    Output._Anim_Flags  |= Byte.Parse(RecordArray[16]);
                    Output.Strength      = Byte.Parse(RecordArray[17]);
                    Output.Anim_Throttle = Byte.Parse(RecordArray[18]);
                    Output.Anim_Elevator = SByte.Parse(RecordArray[19]);
                    Output.Anim_Aileron  = SByte.Parse(RecordArray[20]);
                    Output.Anim_Rudder   = SByte.Parse(RecordArray[21]);
                    Output.Anim_Trim     = SByte.Parse(RecordArray[22]);
                    Output.Anim_Nozzle   = (byte)(Byte.Parse(RecordArray[23]) / 255d * 100d);
                    Output.Anim_Reverse  = (byte)(Byte.Parse(RecordArray[24]) / 255d * 100d);
                    Output.Anim_BombBay  = (byte)(Byte.Parse(RecordArray[25]) / 255d * 100d);

                    //26 == Terminator;
                }
                catch
                {
                    Debug.WriteLine("Failed to allocate a YSFlight Replay Record!");
                    foreach (string ThisString in Input)
                    {
                        Debug.WriteLine("    " + ThisString);
                    }
                    return(null);
                }
                return(new PacketEvent(Output.TimeStamp, Output));
            }
Ejemplo n.º 6
0
            public bool LoadReplay(string FileName)
            {
                #region Deny if already loading!
                if (Loading)
                {
                    Debug.WriteLine("Failure to load YSFlight Replay (Already Loading! Can't Dual Process!)");
                    return(false);
                }
                #endregion
                #region Deny if already loaded!
                if (Loaded)
                {
                    Debug.WriteLine("Failure to load YSFlight Replay (Already Loaded! Can't OverWrite!)");
                    return(false);
                }
                #endregion
                #region Deny if file not found!
                if (!Files.FileExists(FileName))
                {
                    Debug.WriteLine("Failure to load YSFlight Replay (File Not Found):\n    " + FileName);
                    return(false);
                }
                #endregion
                #region load records to buffer
                string[] Contents = Files.FileReadAllLines(FileName);
                #endregion
                #region clear the records, ready to write to.
                CurrentTime = 0;
                Records.Clear();
                #endregion

                Console.WriteLine("&eLoading Replay...");
                Loading = true;

                Threads.Add(() =>

                {
                    string Mode = "NONE";

                    #region Aircraft Data
                    string CurrentAC_Identify = "NULL";
                    uint CurrentAC_ID         = 0;
                    uint CurrentAC_IFF        = 0;
                    float CurrentAC_Fuel      = 100;
                    string CurrentAC_Tag      = "Replay";
                    #endregion

                    for (int CurrentLineNumber = 0; CurrentLineNumber < Contents.Length; CurrentLineNumber++)
                    {
                        #region prepare variables
                        string ThisLine  = Contents[CurrentLineNumber];
                        string Keyword   = ThisLine;
                        string Arguments = "";
                        if (Keyword.Contains(' '))
                        {
                            Arguments = Keyword.Split(new char[] { ' ' }, 2)[1];
                            Keyword   = Keyword.Split(' ')[0].ToUpperInvariant();
                        }

                        #endregion

                        #region No Aircraft at the moment.
                        if (Mode == "NONE")
                        {
                            if (Keyword == "AIRPLANE")
                            {
                                Mode         = "AIRPLANE";
                                CurrentAC_ID = World.Objects.GetNextID() | 256 * 256;
                                AircraftIDs.Add(CurrentAC_ID);
                                if (ThisLine.Contains(' '))
                                {
                                    CurrentAC_Identify = ThisLine.Split(' ')[1];
                                }
                                continue;
                            }
                        }
                        #endregion
                        #region Working on an aircraft.
                        if (Mode == "AIRPLANE")
                        {
                            #region get IFF
                            if (Keyword == "IDENTIFY")
                            {
                                UInt32.TryParse(Arguments, out CurrentAC_IFF);
                                continue;
                            }
                            #endregion
                            #region get Tag
                            if (Keyword == "IDANDTAG")
                            {
                                if (Arguments.Contains(' '))
                                {
                                    CurrentAC_Tag = Arguments.Split(new char[] { ' ' }, 2)[1];
                                    if (CurrentAC_Tag == "\"\"")
                                    {
                                        CurrentAC_Tag = "Replay";
                                    }
                                    continue;
                                }
                            }
                            #endregion
                            #region get airpcmnd
                            if (Keyword == "AIRPCMND")
                            {
                                if (Arguments.Contains(' '))
                                {
                                    string[] SubArguments = Arguments.Split(' ');
                                    #region get fuel
                                    if (SubArguments.Length > 1)
                                    {
                                        try
                                        {
                                            if (SubArguments[0].ToUpperInvariant() == "INITFUEL")
                                            {
                                                try
                                                {
                                                    CurrentAC_Fuel = (float)MetaData._Aircraft.FindByName(CurrentAC_Identify).Cache().WEIGFUEL;
                                                }
                                                catch
                                                {
                                                    Debug.WriteLine("Failed to set default fuel!");
                                                }
                                                try
                                                {
                                                    CurrentAC_Fuel = CurrentAC_Fuel / 100 * UInt32.Parse(SubArguments[1].Split('%')[0]);
                                                }
                                                catch
                                                {
                                                    Debug.WriteLine("Failed to load fuel: " + ThisLine);
                                                }
                                            }
                                        }
                                        catch
                                        {
                                            Debug.WriteLine("Failed to process AIRPCMND: " + ThisLine);
                                        }
                                    }
                                    #endregion
                                    continue;
                                }
                            }
                            #endregion
                            #region process flight records.
                            if (Keyword == "NUMRECOR")
                            {
                                int RecordsCount = 0;
                                if (Arguments.Contains(' '))
                                {
                                    Int32.TryParse(Arguments.Split(' ')[0], out RecordsCount);
                                }
                                CurrentLineNumber++;
                                List <Packets.Packet_11_FlightData> ThisAircraftFlightDataRecords = new List <Packets.Packet_11_FlightData>();
                                for (int i = 0; i < RecordsCount; i++)
                                {
                                    string[] RecordContents = new string[4];
                                    try
                                    {
                                        RecordContents[0] = Contents[CurrentLineNumber];
                                        RecordContents[1] = Contents[CurrentLineNumber + 1];
                                        RecordContents[2] = Contents[CurrentLineNumber + 2];
                                        RecordContents[3] = Contents[CurrentLineNumber + 3];
                                    }
                                    catch
                                    {
                                        Debug.WriteLine("Error reading lines for YSF Record!");
                                        continue;
                                    }
                                    CurrentLineNumber                      += 4;
                                    PacketEvent ThisPacketEvent             = ProcessYSFlightAircraftRecord(RecordContents, CurrentAC_ID);
                                    Packets.Packet_11_FlightData FlightData = new Packets.Packet_11_FlightData(ThisPacketEvent.Packet);
                                    FlightData.Weight_Fuel                  = CurrentAC_Fuel;
                                    FlightData.Weight_SmokeOil              = 100;
                                    FlightData.Weight_Payload               = 0;
                                    #region spawn the aircraft
                                    if (i == 0)
                                    {
                                        //first event, need to add a creation packet!
                                        Packets.Packet_05_EntityJoined EntityJoined = new Packets.Packet_05_EntityJoined();
                                        EntityJoined.ID                   = CurrentAC_ID;
                                        EntityJoined.IFF                  = CurrentAC_IFF;
                                        EntityJoined.PosX                 = FlightData.PosX;
                                        EntityJoined.PosY                 = FlightData.PosY;
                                        EntityJoined.PosZ                 = FlightData.PosZ;
                                        EntityJoined.RotX                 = (float)(FlightData.HdgX / 32767 * Math.PI);
                                        EntityJoined.RotY                 = (float)(FlightData.HdgY / 32767 * Math.PI);
                                        EntityJoined.RotZ                 = (float)(FlightData.HdgZ / 32767 * Math.PI);
                                        EntityJoined.Identify             = CurrentAC_Identify;
                                        EntityJoined.OwnerName            = CurrentAC_Tag;
                                        EntityJoined.IsOwnedByThisPlayer  = false;
                                        EntityJoined.IsOwnedByOtherPlayer = true;
                                        EntityJoined.IsAircraft           = true;

                                        Records.Add(new PacketEvent(FlightData.TimeStamp, EntityJoined));
                                    }
                                    #endregion
                                    if (i > 0)
                                    {
                                        Packets.Packet_11_FlightData PrevFlightData = ThisAircraftFlightDataRecords.ToArray()[i - 1];
                                        float TimeDifference = FlightData.TimeStamp - PrevFlightData.TimeStamp;
                                        float ScalingFactor  = 1f / TimeDifference;

                                        //short _X_Left = (ushort)FlightData.HdgX - (ushort)ThisAircraftFlightDataRecords.ToArray()[i - 1].HdgX; //350-010 = 340; //010-350 = -340
                                        //short _X_Right = (ushort)ThisAircraftFlightDataRecords.ToArray()[i - 1].HdgX - (ushort)FlightData.HdgX; //

                                        float ChangeYDeg = Numbers.AngleAcuteDifference(FlightData.HdgX.ToDegrees(), PrevFlightData.HdgX.ToDegrees());
                                        float ChangeXDeg = Numbers.AngleAcuteDifference(FlightData.HdgY.ToDegrees(), PrevFlightData.HdgY.ToDegrees());
                                        float ChangeZDeg = Numbers.AngleAcuteDifference(FlightData.HdgZ.ToDegrees(), PrevFlightData.HdgZ.ToDegrees());

                                        //FlightData.V_HdgX = (float)(ChangeXDeg * ScalingFactor / 180 * Math.PI);
                                        //FlightData.V_HdgY = (float)(ChangeYDeg * ScalingFactor / 180 * Math.PI);
                                        //FlightData.V_HdgZ = (float)(ChangeZDeg * ScalingFactor / 180 * Math.PI);
                                        //FlightData.V_HdgX = 0;
                                        //FlightData.V_HdgY = 2;
                                        //FlightData.V_HdgZ = 0;
                                        FlightData.V_PosX = (short)((FlightData.PosX - PrevFlightData.PosX) * ScalingFactor * 10);
                                        FlightData.V_PosY = (short)((FlightData.PosY - PrevFlightData.PosY) * ScalingFactor * 10);
                                        FlightData.V_PosZ = (short)((FlightData.PosZ - PrevFlightData.PosZ) * ScalingFactor * 10);
                                    }
                                    ThisPacketEvent.Packet = FlightData;
                                    Records.Add(ThisPacketEvent);
                                    ThisAircraftFlightDataRecords.Add(FlightData);
                                    #region despawn the aircraft
                                    if (i == RecordsCount - 1)
                                    {
                                        //Last record, need to destory the aircraft now!
                                        Packets.Packet_13_RemoveAirplane RemoveACPacket = new Packets.Packet_13_RemoveAirplane(CurrentAC_ID);
                                        Records.Add(new PacketEvent(FlightData.TimeStamp, RemoveACPacket));
                                    }
                                    continue;
                                    #endregion
                                }
                                Mode = "NONE";
                                CurrentLineNumber--;
                            }
                            #endregion
                        }
                        #endregion
                    }
                    Loaded  = true;
                    Loading = false;
                    Console.WriteLine("&aLoaded Replay.");
                }, "Replay Loader: " + FileName);

                return(true);
            }
                private static bool YSFHandle_11_FlightData(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region Prepare Flight Data
                    //Prepare FlightData Packet
                    //Check if the server has the vehicle specified.
                    //Deny old flightdatapackets.
                    Packets.Packet_11_FlightData FlightData = new Packets.Packet_11_FlightData(InPacket);
                    Vehicle SenderVehicle;
                    lock (Vehicles.List)
                    {
                        if (Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).Count() <= 0)
                        {
                            Debug.WriteLine("Missing Aircraft ID: " + FlightData.ID + " for client " + ThisClient.Username);
                            return(false);
                        }
                        SenderVehicle = Vehicles.List.ToArray().Where(x => x.ID == FlightData.ID).ToArray()[0];
                    }
                    #endregion
                    #region Update...
                    #region ValidateFlightData
                    if (SenderVehicle.TimeStamp > FlightData.TimeStamp)
                    {
                        Debug.WriteLine("OLD DATA:" + SenderVehicle.TimeStamp + " > " + FlightData.TimeStamp);
                        return(false);
                    }
                    Debug.WriteLine("NEW DATA:" + SenderVehicle.TimeStamp + " <= " + FlightData.TimeStamp);
                    float Difference = FlightData.TimeStamp - SenderVehicle.TimeStamp;
                    OpenYS_Link.Stats.total_flight_seconds += Difference;
                    SenderVehicle.Update(FlightData);
                    #endregion
                    #endregion
                    #region FormationData
                    #region Validate
                    Vehicle TargetVehicle;
                    lock (Vehicles.List)
                    {
                        FlightData = new Packets.Packet_11_FlightData(InPacket);
                        if (!ThisClient.YSFServer.OpenYSSupport)
                        {
                            goto HandleFlightData;
                        }
                        if (ThisClient.FormationTarget == 0)
                        {
                            goto HandleFlightData;
                        }
                        if (Vehicles.List.ToArray().Where(x => x.ID == ThisClient.FormationTarget).Count() <= 0)
                        {
                            goto HandleFlightData;
                        }
                        if (!FlightData.Anim_Light_Land)
                        {
                            goto HandleFlightData;
                        }
                        TargetVehicle = Vehicles.List.ToArray().Where(x => x.ID == ThisClient.FormationTarget).ToArray()[0];
                        double Distance = Math.Sqrt(Math.Pow(FlightData.PosX - TargetVehicle.PosX, 2) + Math.Pow(FlightData.PosY - TargetVehicle.PosY, 2) + Math.Pow(FlightData.PosZ - TargetVehicle.PosZ, 2));
                        double Velocity = Math.Sqrt(Math.Pow(FlightData.V_PosX, 2) + Math.Pow(FlightData.V_PosY, 2) + Math.Pow(FlightData.V_PosZ, 2));
                        //if (Distance > Velocity / 25) goto HandleFlightData; //V / 10 / 2.5 eg: 1000cm/s -> 100m/s -> 40m. (at roughly 200 knots) or 80m at 400knots, 160m at 800 knots...
                    }
                    #endregion
                    #region BuildFormationData
                    Packets.Packet_64_11_FormationData FormationData = new Packets.Packet_64_11_FormationData(5);
                    FormationData.TimeStamp   = FlightData.TimeStamp;
                    FormationData.SenderID    = FlightData.ID;
                    FormationData.TargetID    = TargetVehicle.ID;
                    FormationData.Version     = 5;
                    FormationData._Anim_Flags = FlightData._Anim_Flags;

                    FormationData.PosX   = FlightData.PosX - TargetVehicle.PosX;
                    FormationData.PosY   = FlightData.PosY - TargetVehicle.PosY;
                    FormationData.PosZ   = FlightData.PosZ - TargetVehicle.PosZ;
                    FormationData.HdgX   = FlightData.HdgX;
                    FormationData.HdgY   = FlightData.HdgY;
                    FormationData.HdgZ   = FlightData.HdgZ;
                    FormationData.V_HdgX = (short)FlightData.V_HdgX;
                    FormationData.V_HdgY = (short)FlightData.V_HdgY;
                    FormationData.V_HdgZ = (short)FlightData.V_HdgZ;

                    //Need to add the below to the formation data packet...
                    FormationData.Anim_Aileron  = FlightData.Anim_Aileron;
                    FormationData.Anim_Boards   = FlightData.Anim_Boards;
                    FormationData.Anim_BombBay  = FlightData.Anim_BombBay;
                    FormationData.Anim_Brake    = FlightData.Anim_Brake;
                    FormationData.Anim_Elevator = FlightData.Anim_Elevator;
                    FormationData.Anim_Flaps    = FlightData.Anim_Flaps;
                    FormationData.Anim_Gear     = FlightData.Anim_Gear;
                    FormationData.Anim_Nozzle   = FlightData.Anim_Nozzle;
                    FormationData.Anim_Reverse  = FlightData.Anim_Reverse;
                    FormationData.Anim_Rudder   = FlightData.Anim_Rudder;
                    FormationData.Anim_Throttle = FlightData.Anim_Throttle;
                    FormationData.Anim_Trim     = FlightData.Anim_Trim;
                    FormationData.Anim_VGW      = FlightData.Anim_VGW;
                    #endregion

                    FormationData.PosX = 0;
                    FormationData.PosY = 0;
                    FormationData.PosZ = 0;
                    //ThisClient.YSFServer.SendPacket(FormationData.ToCustomPacket());
                    //ThisClient.LastFlightDataPacket = FlightData;
                    //Send FormationData to the server.
                    return(true);

                    #endregion
                    #region NormalFlightData
HandleFlightData:
                    //ThisClient.YSFServer.SendPacket(FlightData);
                    return(true);

                    #endregion
                }
Ejemplo n.º 8
0
                public static bool OYSHandle_11_FlightData(Client ThisClient, Packets.GenericPacket InPacket)
                {
                    #region PrepareFormationData
                    Packets.Packet_64_11_FormationData FormationData = new Packets.Packet_64_11_FormationData(InPacket);
                    if (Vehicles.List.ToArray().Where(x => x.ID == FormationData.TargetID).Count() <= 0)
                    {
                        return(false);
                    }
                    if (Vehicles.List.ToArray().Where(x => x.ID == FormationData.SenderID).Count() <= 0)
                    {
                        return(false);
                    }
                    Vehicle SenderVehicle = Vehicles.List.ToArray().Where(x => x.ID == FormationData.SenderID).ToArray()[0];
                    Vehicle TargetVehicle = Vehicles.List.ToArray().Where(x => x.ID == FormationData.TargetID).ToArray()[0];
                    #endregion
                    #region ValidateFlightData
                    if (SenderVehicle.TimeStamp > FormationData.TimeStamp)
                    {
                        return(false);
                    }
                    SenderVehicle.Update(FormationData);
                    #endregion
                    #region UpdateSendersVehicle
                    SenderVehicle.V_PosX = TargetVehicle.V_PosX;
                    SenderVehicle.V_PosY = TargetVehicle.V_PosY;
                    SenderVehicle.V_PosZ = TargetVehicle.V_PosZ;
                    #endregion
                    #region BasicFlightData
                    Packets.Packet_11_FlightData FlightDataOut = new Packets.Packet_11_FlightData(5);
                    float TDelta = (float)(DateTime.Now - TargetVehicle.LastUpdated).TotalSeconds;
                    FlightDataOut.ID              = FormationData.SenderID;
                    FlightDataOut.TimeStamp       = FormationData.TimeStamp;
                    FlightDataOut.PosX            = TargetVehicle.PosX + FormationData.PosX + (TDelta * (TargetVehicle.V_PosX / 10));
                    FlightDataOut.PosY            = TargetVehicle.PosY + FormationData.PosY + (TDelta * (TargetVehicle.V_PosY / 10));
                    FlightDataOut.PosZ            = TargetVehicle.PosZ + FormationData.PosZ + (TDelta * (TargetVehicle.V_PosZ / 10));
                    FlightDataOut.V_PosX          = TargetVehicle.V_PosX;
                    FlightDataOut.V_PosY          = TargetVehicle.V_PosY;
                    FlightDataOut.V_PosZ          = TargetVehicle.V_PosZ;
                    FlightDataOut.HdgX            = FormationData.HdgX;
                    FlightDataOut.HdgY            = FormationData.HdgY;
                    FlightDataOut.HdgZ            = FormationData.HdgZ;
                    FlightDataOut.V_HdgX          = (short)FormationData.V_HdgX;
                    FlightDataOut.V_HdgY          = (short)FormationData.V_HdgY;
                    FlightDataOut.V_HdgZ          = (short)FormationData.V_HdgZ;
                    FlightDataOut.Weight_Fuel     = 100;
                    FlightDataOut.Weight_Payload  = 100;
                    FlightDataOut.Weight_SmokeOil = 100;
                    #endregion
                    #region Animation
                    FlightDataOut.Anim_Aileron  = FormationData.Anim_Aileron;
                    FlightDataOut.Anim_Boards   = FormationData.Anim_Boards;
                    FlightDataOut.Anim_BombBay  = FormationData.Anim_BombBay;
                    FlightDataOut.Anim_Brake    = FormationData.Anim_Brake;
                    FlightDataOut.Anim_Elevator = FormationData.Anim_Elevator;
                    FlightDataOut.Anim_Flaps    = FormationData.Anim_Flaps;
                    FlightDataOut.Anim_Gear     = FormationData.Anim_Gear;
                    FlightDataOut.Anim_Nozzle   = FormationData.Anim_Nozzle;
                    FlightDataOut.Anim_Reverse  = FormationData.Anim_Reverse;
                    FlightDataOut.Anim_Rudder   = FormationData.Anim_Rudder;
                    FlightDataOut.Anim_Throttle = FormationData.Anim_Throttle;
                    FlightDataOut.Anim_Trim     = FormationData.Anim_Trim;
                    FlightDataOut.Anim_VGW      = FormationData.Anim_VGW;
                    FlightDataOut._Anim_Flags   = FormationData._Anim_Flags;
                    #endregion

                    #region SendFlightData
                    ThisClient.SendPacket(FlightDataOut);
                    #endregion
                    return(true);
                }
 public static bool OYSHandle_11_FlightData(Client ThisClient, Packets.GenericPacket InPacket)
 {
     Console.WriteLine("Got Formation Data.");
     #region PrepareFormationData
     Packets.Packet_64_11_FormationData FormationData = new Packets.Packet_64_11_FormationData(InPacket);
     if (Vehicles.List.ToArray().Where(x => x.ID == FormationData.TargetID).Count() <= 0)
     {
         Console.WriteLine("Target N/A");
         return(false);
     }
     if (Vehicles.List.ToArray().Where(x => x.ID == FormationData.SenderID).Count() <= 0)
     {
         Console.WriteLine("Sender N/A");
         return(false);
     }
     Vehicle SenderVehicle = Vehicles.List.ToArray().Where(x => x.ID == FormationData.SenderID).ToArray()[0];
     Vehicle TargetVehicle = Vehicles.List.ToArray().Where(x => x.ID == FormationData.TargetID).ToArray()[0];
     #endregion
     #region ValidateFlightData
     if (SenderVehicle.TimeStamp > FormationData.TimeStamp)
     {
         Console.WriteLine("OLD FORM");
         return(false);
     }
     SenderVehicle.Update(FormationData);
     #endregion
     #region UpdateSendersVehicle
     SenderVehicle.V_PosX = TargetVehicle.V_PosX;
     SenderVehicle.V_PosY = TargetVehicle.V_PosY;
     SenderVehicle.V_PosZ = TargetVehicle.V_PosZ;
     #endregion
     #region BasicFlightData
     Packets.Packet_11_FlightData FlightDataOut = new Packets.Packet_11_FlightData(3);
     float TDelta = (float)(DateTime.Now - TargetVehicle.LastUpdated).TotalSeconds;
     FlightDataOut.ID              = FormationData.SenderID;
     FlightDataOut.PosX            = TargetVehicle.PosX + FormationData.PosX + (TDelta * (TargetVehicle.V_PosX / 10));
     FlightDataOut.PosY            = TargetVehicle.PosY + FormationData.PosY + (TDelta * (TargetVehicle.V_PosY / 10));
     FlightDataOut.PosZ            = TargetVehicle.PosZ + FormationData.PosZ + (TDelta * (TargetVehicle.V_PosZ / 10));
     FlightDataOut.V_PosX          = TargetVehicle.V_PosX;
     FlightDataOut.V_PosY          = TargetVehicle.V_PosY;
     FlightDataOut.V_PosZ          = TargetVehicle.V_PosZ;
     FlightDataOut.HdgX            = FormationData.HdgX;
     FlightDataOut.HdgY            = FormationData.HdgY;
     FlightDataOut.HdgZ            = FormationData.HdgZ;
     FlightDataOut.V_HdgX          = FormationData.V_HdgX;
     FlightDataOut.V_HdgY          = FormationData.V_HdgY;
     FlightDataOut.V_HdgZ          = FormationData.V_HdgZ;
     FlightDataOut.Weight_Fuel     = 100;
     FlightDataOut.Weight_Payload  = 100;
     FlightDataOut.Weight_SmokeOil = 100;
     #endregion
     #region Animation
     FlightDataOut.Anim_Aileron  = FormationData.Anim_Aileron;
     FlightDataOut.Anim_Boards   = FormationData.Anim_Boards;
     FlightDataOut.Anim_BombBay  = FormationData.Anim_BombBay;
     FlightDataOut.Anim_Brake    = FormationData.Anim_Brake;
     FlightDataOut.Anim_Elevator = FormationData.Anim_Elevator;
     FlightDataOut.Anim_Flaps    = FormationData.Anim_Flaps;
     FlightDataOut.Anim_Gear     = FormationData.Anim_Gear;
     FlightDataOut.Anim_Nozzle   = FormationData.Anim_Nozzle;
     FlightDataOut.Anim_Reverse  = FormationData.Anim_Reverse;
     FlightDataOut.Anim_Rudder   = FormationData.Anim_Rudder;
     FlightDataOut.Anim_Throttle = FormationData.Anim_Throttle;
     FlightDataOut.Anim_Trim     = FormationData.Anim_Trim;
     FlightDataOut.Anim_VGW      = FormationData.Anim_VGW;
     FlightDataOut._Anim_Flags   = FormationData._Anim_Flags;
     #endregion
     #region Send FlightData
     FlightDataOut.TimeStamp = (float)(DateTime.Now - OpenYS.TimeStarted).TotalSeconds;
     FormationData.TimeStamp = (float)(DateTime.Now - OpenYS.TimeStarted).TotalSeconds;
     foreach (Client OtherClient in Clients.AllClients.ToArray())
     {
         if (OtherClient.Vehicle != null)
         {
             if (FlightDataOut.ID == OtherClient.Vehicle.ID)
             {
                 continue;
             }
             //Console.WriteLine("-Did nothing.");
         }
         if (OtherClient.YSFClient.OpenYSSupport)
         {
             ThisClient.SendPacket(FormationData.ToCustomPacket());
             //OtherClient.SendPacket(FlightDataOut);
         }
         if (!OtherClient.YSFClient.OpenYSSupport)
         {
             ThisClient.SendPacket(FlightDataOut);
         }
     }
     #endregion
     return(true);
 }