Ejemplo n.º 1
0
        public void HandleMessage(IServerMessageBase msg)
        {
            if (!(msg.Data is VesselFlightStateMsgData msgData))
            {
                return;
            }

            var vesselId = msgData.VesselId;

            if (!VesselCommon.DoVesselChecks(vesselId))
            {
                return;
            }

            //Vessel might exist in the store but not in game (while in KSC for example)
            VesselsProtoStore.UpdateVesselProtoFlightState(msgData);

            //System is not ready nor in use so just skip the message
            if (!System.FlightStateSystemReady)
            {
                return;
            }

            //We are not close (unpacked range) to this vessel so ignore the message
            if (!System.FlyByWireDictionary.ContainsKey(vesselId))
            {
                return;
            }

            if (VesselFlightStateSystem.CurrentFlightState.TryGetValue(vesselId, out var currentFlightState) && currentFlightState.GameTimeStamp > msgData.GameTime)
            {
                //A user reverted, so clear his message queue and start from scratch
                System.RemoveVessel(vesselId);
            }

            if (!VesselFlightStateSystem.CurrentFlightState.ContainsKey(vesselId))
            {
                VesselFlightStateSystem.CurrentFlightState.TryAdd(vesselId, new VesselFlightStateUpdate(msgData));
                VesselFlightStateSystem.TargetFlightStateQueue.TryAdd(vesselId, new FlightStateQueue());
            }
            else
            {
                VesselFlightStateSystem.TargetFlightStateQueue.TryGetValue(vesselId, out var queue);
                queue?.Enqueue(msgData);
            }
        }
        public void SendCurrentFlightState()
        {
            var flightState = new FlightCtrlState();

            flightState.CopyFrom(FlightGlobals.ActiveVessel.ctrlState);

            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselFlightStateMsgData>();

            msgData.GameTime   = TimeSyncerSystem.UniversalTime;
            msgData.SubspaceId = WarpSystem.Singleton.CurrentSubspace;

            msgData.VesselId          = FlightGlobals.ActiveVessel.id;
            msgData.GearDown          = flightState.gearDown;
            msgData.GearUp            = flightState.gearUp;
            msgData.Headlight         = flightState.headlight;
            msgData.KillRot           = flightState.killRot;
            msgData.MainThrottle      = flightState.mainThrottle;
            msgData.Pitch             = flightState.pitch;
            msgData.PitchTrim         = flightState.pitchTrim;
            msgData.Roll              = flightState.roll;
            msgData.RollTrim          = flightState.rollTrim;
            msgData.WheelSteer        = flightState.wheelSteer;
            msgData.WheelSteerTrim    = flightState.wheelSteerTrim;
            msgData.WheelThrottle     = flightState.wheelThrottle;
            msgData.WheelThrottleTrim = flightState.wheelThrottleTrim;
            msgData.X       = flightState.X;
            msgData.Y       = flightState.Y;
            msgData.Yaw     = flightState.yaw;
            msgData.YawTrim = flightState.yawTrim;
            msgData.Z       = flightState.Z;

            SendMessage(msgData);

            VesselsProtoStore.UpdateVesselProtoFlightState(msgData);
            System.UpdateFlightStateInProtoVessel(FlightGlobals.ActiveVessel.protoVessel, msgData);
        }