Пример #1
0
 private static bool Process_Type_10_JoinRequestDenied(IConnection thisConnection, IPacket_10_JoinRequestDenied packet)
 {
     throw new NotImplementedException();
 }
            public static async Task <bool> Process(IConnection thisConnection, IPacket thisPacket)
            {
                switch (thisPacket.Type)
                {
                case 1:
                {
                    IPacket_01_Login packet = ObjectFactory.CreatePacket01Login();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_01_Login(thisConnection, packet));
                }

                case 3:
                {
                    IPacket_03_Error packet = ObjectFactory.CreatePacket03Error();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_03_Error(thisConnection, packet));
                }

                case 4:
                {
                    IPacket_04_Field packet = ObjectFactory.CreatePacket04Field();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_04_Field(thisConnection, packet));
                }

                case 5:
                {
                    IPacket_05_AddVehicle packet = ObjectFactory.CreatePacket05AddVehicle();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_05_AddVehicle(thisConnection, packet));
                }

                case 6:
                {
                    IPacket_06_Acknowledgement packet = ObjectFactory.CreatePacket06Acknowledgement();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_06_Acknowledgement(thisConnection, packet));
                }

                case 7:
                {
                    IPacket_07_SmokeColor packet = ObjectFactory.CreatePacket07SmokeColor();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_07_SmokeColor(thisConnection, packet));
                }

                case 8:
                {
                    IPacket_08_JoinRequest packet = ObjectFactory.CreatePacket08JoinRequest();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_08_JoinRequest(thisConnection, packet));
                }

                case 9:
                {
                    IPacket_09_JoinRequestApproved packet = ObjectFactory.CreatePacket09JoinRequestApproved();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_09_JoinRequestApproved(thisConnection, packet));
                }

                case 10:
                {
                    IPacket_10_JoinRequestDenied packet = ObjectFactory.CreatePacket10JoinRequestDenied();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_10_JoinRequestDenied(thisConnection, packet));
                }

                case 11:
                {
                    IPacket_11_FlightData packet = ObjectFactory.CreatePacket11FlightData();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_11_FlightData(thisConnection, packet));
                }

                case 12:
                {
                    IPacket_12_LeaveFlight packet = ObjectFactory.CreatePacket12LeaveFlight();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_12_LeaveFlight(thisConnection, packet));
                }

                case 13:
                {
                    IPacket_13_RemoveAircraft packet = ObjectFactory.CreatePacket13RemoveAircraft();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_13_RemoveAircraft(thisConnection, packet));
                }

                case 16:
                {
                    IPacket_16_PrepareSimulation packet = ObjectFactory.CreatePacket16PrepareSimulation();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_16_PrepareSimulation(thisConnection, packet));
                }

                case 17:
                {
                    IPacket_17_HeartBeat packet = ObjectFactory.CreatePacket17HeartBeat();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_17_HeartBeat(thisConnection, packet));
                }

                case 18:
                {
                    IPacket_18_LockOn packet = ObjectFactory.CreatePacket18LockOn();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_18_LockOn(thisConnection, packet));
                }

                case 19:
                {
                    IPacket_19_RemoveGround packet = ObjectFactory.CreatePacket19RemoveGround();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_19_RemoveGround(thisConnection, packet));
                }

                case 20:
                {
                    IPacket_20_OrdinanceSpawn packet = ObjectFactory.CreatePacket20OrdinanceSpawn();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_20_OrdinanceSpawn(thisConnection, packet));
                }

                case 21:
                {
                    IPacket_21_GroundData packet = ObjectFactory.CreatePacket21GroundData();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_21_GroundData(thisConnection, packet));
                }

                case 22:
                {
                    IPacket_22_Damage packet = ObjectFactory.CreatePacket22Damage();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_22_Damage(thisConnection, packet));
                }

                case 29:
                {
                    IPacket_29_NetcodeVersion packet = ObjectFactory.CreatePacket29NetcodeVersion();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_29_NetcodeVersion(thisConnection, packet));
                }

                case 30:
                {
                    IPacket_30_AircraftCommand packet = ObjectFactory.CreatePacket30AircraftCommand();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_30_AircraftCommand(thisConnection, packet));
                }

                case 31:
                {
                    IPacket_31_MissilesOption packet = ObjectFactory.CreatePacket31MissilesOption();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_31_MissilesOption(thisConnection, packet));
                }

                case 32:
                {
                    IPacket_32_ChatMessage packet = ObjectFactory.CreatePacket32ChatMessage(thisConnection.User, "");
                    packet.Data = thisPacket.Data;
                    return(Process_Type_32_ChatMessage(thisConnection, packet));
                }

                case 33:
                {
                    IPacket_33_Weather packet = ObjectFactory.CreatePacket33Weather();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_33_Weather(thisConnection, packet));
                }

                case 35:
                {
                    IPacket_35_ReviveAllGrounds packet = ObjectFactory.CreatePacket35ReviveAllGrounds();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_35_ReviveAllGrounds(thisConnection, packet));
                }

                case 36:
                {
                    IPacket_36_WeaponsLoadout packet = ObjectFactory.CreatePacket36WeaponsLoadout();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_36_WeaponsLoadout(thisConnection, packet));
                }

                case 37:
                {
                    IPacket_37_ListUser packet = ObjectFactory.CreatePacket37ListUser();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_37_ListUser(thisConnection, packet));
                }

                case 38:
                {
                    IPacket_38_QueryAirstate packet = ObjectFactory.CreatePacket38QueryAirstate();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_38_QueryAirstate(thisConnection, packet));
                }

                case 39:
                {
                    IPacket_39_WeaponsOption packet = ObjectFactory.CreatePacket39WeaponsOption();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_39_WeaponsOption(thisConnection, packet));
                }

                case 41:
                {
                    IPacket_41_UsernameDistance packet = ObjectFactory.CreatePacket41UsernameDistance();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_41_UsernameDistance(thisConnection, packet));
                }

                case 43:
                {
                    IPacket_43_ServerCommand packet = ObjectFactory.CreatePacket43ServerCommand();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_43_ServerCommand(thisConnection, packet));
                }

                case 44:
                {
                    IPacket_44_AircraftList packet = ObjectFactory.CreatePacket44AircraftList();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_44_AircraftList(thisConnection, packet));
                }

                case 45:
                {
                    IPacket_45_GroundCommand packet = ObjectFactory.CreatePacket45GroundCommand();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_45_GroundCommand(thisConnection, packet));
                }

                case 47:
                {
                    IPacket_47_ForceJoin packet = ObjectFactory.CreatePacket47ForceJoin();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_47_ForceJoin(thisConnection, packet));
                }

                case 48:
                {
                    IPacket_48_FogColor packet = ObjectFactory.CreatePacket48FogColor();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_48_FogColor(thisConnection, packet));
                }

                case 49:
                {
                    IPacket_49_SkyColor packet = ObjectFactory.CreatePacket49SkyColor();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_49_SkyColor(thisConnection, packet));
                }

                case 50:
                {
                    IPacket_50_GroundColor packet = ObjectFactory.CreatePacket50GroundColor();
                    packet.Data = thisPacket.Data;
                    return(Process_Type_50_GroundColor(thisConnection, packet));
                }

                default:
                {
                    break;
                }
                }
                return(true);
            }
Пример #3
0
            private static bool Process_Type_08_JoinRequest(IConnection thisConnection, IPacket_08_JoinRequest packet)
            {
                #region Join Request Pending
                if (thisConnection.JoinRequestPending)
                {
                    Logger.Debug.AddWarningMessage("Join Request already pending for " + thisConnection.User.UserName.ToInternallyFormattedSystemString() + ".");
                    thisConnection.SendMessage("Issue with last join request. Cancelling last join request...");
                    IPacket_10_JoinRequestDenied JoinDenied = ObjectFactory.CreatePacket10JoinRequestDenied();
                    thisConnection.Send(JoinDenied);
                    thisConnection.JoinRequestPending = false;
                    return(true);
                }
                thisConnection.JoinRequestPending = true;
                #endregion

                #region Convert To JoinRequest
                IPacket_08_JoinRequest JoinRequest = ObjectFactory.CreatePacket08JoinRequest();
                JoinRequest.Data = packet.Data;
                #endregion

                #region Deny Requests if server is join locked!
                if (Settings.Flight.Join.Lock)
                {
                    //Reject the join request - don't have the start position requested!
                    IPacket_10_JoinRequestDenied JoinDenied = ObjectFactory.CreatePacket10JoinRequestDenied();
                    thisConnection.Send(JoinDenied);
                    thisConnection.SendMessage("Join request denied - Server is join locked!");
                    thisConnection.JoinRequestPending = false;
                    return(false);
                }
                #endregion

                #region Acknowledge Join Request
                //Acknowledge Join Request.
                IPacket_06_Acknowledgement AcknowledgeRequest = ObjectFactory.CreatePacket06Acknowledgement();
                AcknowledgeRequest.Arguments = new uint[] { 5, 0 };
                thisConnection.Send(AcknowledgeRequest);
                #endregion

                #region Check For Requested STP
                //Check if Server has STP - deny if it doesn't!
                if (!World.AllStartPositions.Select(x => x.Identify).Contains(JoinRequest.StartPositionIdentify))
                {
                    //Reject the join request - don't have the start position requested!
                    IPacket_10_JoinRequestDenied JoinDenied = ObjectFactory.CreatePacket10JoinRequestDenied();
                    thisConnection.Send(JoinDenied);
                    thisConnection.SendMessage("Join request denied - Server does not have that start position installed!");
                    thisConnection.JoinRequestPending = false;
                    return(false);
                }
                IWorldStartPosition StartPosition = World.AllStartPositions.First(x => x.Identify == JoinRequest.StartPositionIdentify);
                #endregion

                #region Check For Requested Aircraft
                IMetaDataAircraft MetaAircraft = MetaData.Aircraft.FindByName(JoinRequest.AircraftIdentify);
                if (MetaAircraft == MetaData.Aircraft.None)
                {
                    //Reject the join request - don't have the aircraft requested!
                    IPacket_10_JoinRequestDenied JoinDenied = ObjectFactory.CreatePacket10JoinRequestDenied();
                    thisConnection.Send(JoinDenied);
                    thisConnection.SendMessage("Join request denied - Server does not have that aircraft installed!");
                    thisConnection.JoinRequestPending = false;
                    return(false);
                }

                //TODO : Cache Aircraft!
                //CachedData.Aircraft CachedAircraft = MetaAircraft.Cache();
                #endregion

                #region Build EntityJoined(05)
                IPacket_05_AddVehicle EntityJoined = ObjectFactory.CreatePacket05AddVehicle();
                EntityJoined.VehicleType = Packet_05VehicleType.Aircraft;
                EntityJoined.Version     = 0;
                EntityJoined.ID          = World.GetNextID() | 256 * 256;
                EntityJoined.IFF         = JoinRequest.IFF;
                EntityJoined.PosX        = StartPosition.Position.X;
                EntityJoined.PosY        = StartPosition.Position.Y;
                EntityJoined.PosZ        = StartPosition.Position.Z;
                EntityJoined.HdgH        = StartPosition.Attitude.H;
                EntityJoined.HdgP        = StartPosition.Attitude.P;
                EntityJoined.HdgB        = StartPosition.Attitude.B;
                EntityJoined.Identify    = JoinRequest.AircraftIdentify;
                EntityJoined.OwnerName   = thisConnection.User.UserName.ToUnformattedSystemString();
                EntityJoined.OwnerType   = Packet_05OwnerType.Self;
                #endregion

                #region Build Flight Data Packet
                IPacket_11_FlightData FlightData = ObjectFactory.CreatePacket11FlightData(3);
                FlightData.ID = EntityJoined.ID;

                IDATFile CachedAircraft = ObjectFactory.CreateDATFileReference(Settings.YSFlight.Directory + MetaAircraft.Path_0_PropertiesFile);
                CachedAircraft.Load();

                FlightData.WeightFuel     = (CachedAircraft.CachedData.WeightOfFuel.ToKiloGrams().RawValue *(JoinRequest.FuelPercent)).KiloGrams();
                FlightData.WeightSmokeOil = 100.KiloGrams();
                FlightData.AmmoGUN        = CachedAircraft.CachedData.AmmoGun;
                if (!Settings.Options.AllowUnguidedWeapons)
                {
                    FlightData.AmmoGUN = 0;
                }
                FlightData.Strength     = CachedAircraft.CachedData.Strength;
                FlightData.AnimThrottle = StartPosition.Throttle;
                if (StartPosition.GearDown)
                {
                    FlightData.AnimGear = 1.0f;
                }
                FlightData.Timestamp = 0.Seconds().ToTime();
                FlightData.PosX      = EntityJoined.PosX;
                FlightData.PosY      = EntityJoined.PosY;
                FlightData.PosZ      = EntityJoined.PosZ;
                if (FlightData.PosY.ToMeters().RawValue < 1)
                {
                    FlightData.PosY = 1.Meters();
                }
                FlightData.HdgH   = EntityJoined.HdgH;
                FlightData.HdgP   = EntityJoined.HdgP;
                FlightData.HdgB   = EntityJoined.HdgB;
                FlightData.V_PosX = ((Math.Sin(-StartPosition.Attitude.H.ToRadians().RawValue) * (StartPosition.Speed.ToMetersPerSecond().RawValue))).MetersPerSecond();
                FlightData.V_PosZ = ((Math.Cos(-StartPosition.Attitude.H.ToRadians().RawValue) * (StartPosition.Speed.ToMetersPerSecond().RawValue))).MetersPerSecond();

                #region Turn on the brakes if Velocity == 0
                if (FlightData.V_PosX.ToMetersPerSecond().RawValue == 0 && FlightData.V_PosZ.ToMetersPerSecond().RawValue == 0 && Settings.Flight.Join.UseWheelChocks)
                {
                    FlightData.AnimBrake = 100;
                }
                #endregion
                #endregion

                #region Prepare Acknolwedgement Reponse.
                IPacketWaiter PacketWaiter_AcknowledgeJoinPacket = thisConnection.CreatePacketWaiter(6);
                if (EntityJoined.VehicleType == Packet_05VehicleType.Aircraft)
                {
                    PacketWaiter_AcknowledgeJoinPacket.Require(4, EntityJoined.ID);
                }
                else
                {
                    PacketWaiter_AcknowledgeJoinPacket.Require(0, 1);
                }
                PacketWaiter_AcknowledgeJoinPacket.StartListening();
                #endregion

                #region Assign Vehicle
                thisConnection.Vehicle          = ObjectFactory.CreateVehicle();
                thisConnection.Vehicle.Owner    = thisConnection.User;
                thisConnection.Vehicle.MetaData = MetaAircraft;
                #endregion

                #region Send Owner Join Data
                thisConnection.Vehicle.Update(EntityJoined);
                thisConnection.Vehicle.CreateVehicle();
                thisConnection.Send(EntityJoined);
                if (!thisConnection.GetResponseOrResend(PacketWaiter_AcknowledgeJoinPacket, EntityJoined))
                {
                    thisConnection.SendMessage("Expected an acknowledge Join Data Reply and didn't get an answer. Disconnecting...");
                    foreach (var thisConnectionLast5Packet in thisConnection.Last5Packets)
                    {
                        Logger.Debug.AddDetailMessage("&aIn Packet (" + thisConnectionLast5Packet.Type + ")\n" +
                                                      thisConnectionLast5Packet.Serialise().ToHexString() + "\n" +
                                                      thisConnectionLast5Packet.Serialise().ToSystemString());
                    }
                    //thisConnection.Disconnect();
                    //return false;
                }
                thisConnection.Vehicle.Update(FlightData);
                thisConnection.Send(FlightData);
                #endregion

                #region Send Owner Join Approved
                IPacket_09_JoinRequestApproved JoinApproved = ObjectFactory.CreatePacket09JoinRequestApproved();
                #region Prepare Acknowledgement Reponse.
                IPacketWaiter PacketWaiter_AcknowledgeJoinApproved = thisConnection.CreatePacketWaiter(6);
                PacketWaiter_AcknowledgeJoinApproved.Require(0, 6);
                PacketWaiter_AcknowledgeJoinApproved.StartListening();
                #endregion
                //thisConnection.SendGetPacket(JoinApproved, AcknowledgeJoinApproved);
                thisConnection.Send(JoinApproved);
                if (!thisConnection.GetResponseOrResend(PacketWaiter_AcknowledgeJoinApproved, JoinApproved))
                {
                    thisConnection.SendMessage("Expected an acknowledge Join Approval and didn't get an answer. Disconnecting...");
                    //thisConnection.Disconnect();
                    //return false;
                }
                thisConnection.JoinRequestPending = false;
                #endregion

                #region Send Others Join Data
                if (Settings.Flight.Join.Notification)
                {
                    Logger.Console.AddInformationMessage("&b" + thisConnection.User.UserName.ToInternallyFormattedSystemString() + "&b took off (" + EntityJoined.Identify + ")");
                }
                foreach (IConnection OtherClient in Connections.AllConnections.Exclude(thisConnection).ToArray())
                {
                    if (Settings.Flight.Join.Notification)
                    {
                        OtherClient.SendMessage(thisConnection.User.UserName.ToUnformattedSystemString() + " took off (" + EntityJoined.Identify + ")");
                    }

                    IPacket_05_AddVehicle OtherJoinPacket = ObjectFactory.CreatePacket05AddVehicle();
                    OtherJoinPacket.Data      = EntityJoined.Data;
                    OtherJoinPacket.OwnerType = Packet_05OwnerType.Other;

                    IPacketWaiter PacketWaiter_AcknowledgeOtherJoinPacket = thisConnection.CreatePacketWaiter(6);
                    if (EntityJoined.VehicleType == Packet_05VehicleType.Aircraft)
                    {
                        PacketWaiter_AcknowledgeOtherJoinPacket.Require(4, EntityJoined.ID);
                    }
                    else
                    {
                        PacketWaiter_AcknowledgeOtherJoinPacket.Require(0, 1);
                    }
                    PacketWaiter_AcknowledgeOtherJoinPacket.StartListening();
                    Logger.Console.AddInformationMessage("Sending Join Notification.");
                    OtherClient.Send(OtherJoinPacket);

                    if (!OtherClient.GetResponseOrResend(PacketWaiter_AcknowledgeOtherJoinPacket, OtherJoinPacket))
                    {
                        thisConnection.SendMessage("Expected a Other Entity Join Acknowldge for ID " + OtherJoinPacket.ID + " and didn't get an answer.");
                        //thisConnection.Disconnect();
                        //return false;
                    }
                    Logger.Console.AddInformationMessage("Sent Join Notification.");
                }
                #endregion
                return(true);
            }