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

            LunaLog.Log("Docking message received!");

            if (msgData.WeakVesselId == CurrentDockEvent.WeakVesselId && msgData.DominantVesselId == CurrentDockEvent.DominantVesselId &&
                (LunaNetworkTime.UtcNow - CurrentDockEvent.DockingTime) < TimeSpan.FromSeconds(5))
            {
                LunaLog.Log("Docking message received was detected so ignore it");
                return;
            }

            var dominantProto = VesselSerializer.DeserializeVessel(msgData.FinalVesselData, msgData.NumBytes);

            VesselLoader.LoadVessel(dominantProto);

            WarpSystem.WarpIfSubspaceIsMoreAdvanced(msgData.SubspaceId);

            if (FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.id == msgData.WeakVesselId)
            {
                LunaLog.Log($"Docking NOT detected. We DON'T OWN the dominant vessel. Switching to {msgData.DominantVesselId}");
                if (dominantProto.vesselRef != null)
                {
                    dominantProto.vesselRef.Load();
                    dominantProto.vesselRef.GoOffRails();
                    FlightGlobals.ForceSetActiveVessel(dominantProto.vesselRef);
                }
            }
            else if (FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.id == msgData.DominantVesselId)
            {
                LunaLog.Log("Docking NOT detected. We OWN the dominant vessel");
            }

            VesselRemoveSystem.Singleton.KillVessel(msgData.WeakVesselId, "Killing weak (active) vessel during a docking that was not detected");
            CurrentDockEvent.Reset();
        }
Esempio n. 2
0
        /// <summary>
        /// Event called after the undocking is completed and we have the 2 final vessels
        /// </summary>
        public void UndockingComplete(Vessel vessel1, Vessel vessel2)
        {
            if (VesselCommon.IsSpectating)
            {
                return;
            }

            LunaLog.Log("Undock detected!");

            VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(vessel1);
            VesselProtoSystem.Singleton.MessageSender.SendVesselMessage(vessel2);

            //Release the locks of the vessel we are not in
            var crewToReleaseLocks = FlightGlobals.ActiveVessel == vessel1
                ? vessel2.GetVesselCrew().Select(c => c.name)
                : vessel1.GetVesselCrew().Select(c => c.name);

            var vesselToRelease = FlightGlobals.ActiveVessel == vessel1 ? vessel2 : vessel1;

            LockSystem.Singleton.ReleaseAllVesselLocks(crewToReleaseLocks, vesselToRelease.id);

            LunaLog.Log($"Undocking finished. Vessels: {vessel1.id} and {vessel2.id}");
            CurrentDockEvent.Reset();
        }