Ejemplo n.º 1
0
        /// <summary>
        /// Called when a vessel is initiated.
        /// </summary>
        public void VesselCreate(Vessel data)
        {
            //No need to check the unloaded update locks as vessels when unloaded don't have parts!

            if (!VesselCommon.IsSpectating && data.id != VesselProtoSystem.CurrentlyUpdatingVesselId && !SystemsContainer.Get <VesselRemoveSystem>().VesselWillBeKilled(data.id))
            {
                //We are modifying a vessel that LMP is not handling
                if (VesselsProtoStore.AllPlayerVessels.ContainsKey(data.id))
                {
                    //The vessel even exists on the store so probably it's a vessel that has lost a part or smth like that...
                    if (LockSystem.LockQuery.UpdateLockBelongsToPlayer(data.id, SettingsSystem.CurrentSettings.PlayerName))
                    {
                        //We own the update lock of that vessel that suffered a modification so just leave it here
                        //The main system has a routine that will check changes and send the new definition
                        LunaLog.Log($"SKIPPING detected change in vesselId {data.id} name {data.vesselName} (we own update lock)");
                    }
                    else
                    {
                        LunaLog.Log($"REVERTING change in NEW vesselId {data.id} name {data.vesselName} (DON'T own UnloadedUpdate lock)");
                        VesselsProtoStore.AllPlayerVessels[data.id].VesselHasUpdate = true;
                    }
                }
                else
                {
                    //The vessel is NEW as it's not in the store. It might be a debris...
                    var rootPartOrFirstPart = data.rootPart ?? data.parts.FirstOrDefault();
                    if (rootPartOrFirstPart != null)
                    {
                        var originalVessel = VesselsProtoStore.GetVesselByPartId(rootPartOrFirstPart.flightID);
                        if (originalVessel == null)
                        {
                            //We didn't find an original vessel so it's probably a totally new vessel that was spawned...
                            return;
                        }

                        //The vessel even exists on the store so probably it's a vessel that has lost a part or smth like that...
                        if (LockSystem.LockQuery.UpdateLockBelongsToPlayer(originalVessel.id, SettingsSystem.CurrentSettings.PlayerName))
                        {
                            LunaLog.Log($"SENDING NEW vesselId {data.id} name {data.vesselName} (Original vessel UPD lock is ours)");

                            //We own the update lock of that vessel that originated that part so let's get that updat lock and send the definition
                            SystemsContainer.Get <LockSystem>().AcquireUpdateLock(data.id, true);
                            //Now send this debris and force it!
                            System.MessageSender.SendVesselMessage(data, true);
                            //Add it also to our store
                            VesselsProtoStore.AddVesselToDictionary(FlightGlobals.ActiveVessel);
                        }
                        else
                        {
                            LunaLog.Log($"REVERTING NEW vesselId {data.id} name {data.vesselName} (UPD lock is NOT ours)");
                            SystemsContainer.Get <VesselRemoveSystem>().AddToKillList(data.id);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SendVesselMessage(Vessel vessel, bool force)
        {
            if (vessel == null || VesselCommon.IsSpectating || vessel.state == Vessel.State.DEAD || VesselRemoveSystem.Singleton.VesselWillBeKilled(vessel.id))
            {
                return;
            }

            var vesselHasChanges = VesselToProtoRefresh.RefreshVesselProto(vessel);

            if (force || vesselHasChanges || !VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                SendVesselMessage(vessel.BackupVessel());
            }

            if (!VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                VesselsProtoStore.AddVesselToDictionary(vessel);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends our vessel just when we start the flight
        /// </summary>
        public void FlightReady()
        {
            if (!VesselCommon.IsSpectating && FlightGlobals.ActiveVessel != null)
            {
                CoroutineUtil.StartDelayedRoutine(nameof(FlightReady), () =>
                {
                    if (VesselCommon.IsSpectating || FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.id == Guid.Empty)
                    {
                        return;
                    }

                    System.MessageSender.SendVesselMessage(FlightGlobals.ActiveVessel, true);
                    //Add our own vessel to the dictionary aswell
                    VesselsProtoStore.AddVesselToDictionary(FlightGlobals.ActiveVessel);
                }, 5f);

                ScreenMessages.PostScreenMessage("Remember!! While you're inside the safety bubble you won't see other players!!", 10f, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Ejemplo n.º 4
0
        public void SendVesselMessage(Vessel vessel, bool force)
        {
            if (vessel == null || VesselCommon.IsSpectating || vessel.state == Vessel.State.DEAD)
            {
                return;
            }

            VesselProtoSystem.CurrentlyUpdatingVesselId = vessel.id;
            var vesselHasChanges = VesselToProtoRefresh.RefreshVesselProto(vessel);

            VesselProtoSystem.CurrentlyUpdatingVesselId = Guid.Empty;

            if (force || vesselHasChanges || !VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                SendVesselMessage(vessel.protoVessel);
            }

            if (!VesselsProtoStore.AllPlayerVessels.ContainsKey(vessel.id))
            {
                VesselsProtoStore.AddVesselToDictionary(vessel);
            }
        }
Ejemplo n.º 5
0
 public void OnAsteroidSpawned(Vessel asteroid)
 {
     if (LockSystem.LockQuery.AsteroidLockBelongsToPlayer(SettingsSystem.CurrentSettings.PlayerName))
     {
         if (System.GetAsteroidCount() <= SettingsSystem.ServerSettings.MaxNumberOfAsteroids)
         {
             System.ServerAsteroids.Add(asteroid.id.ToString());
             SystemsContainer.Get <VesselProtoSystem>().MessageSender.SendVesselMessage(asteroid, true);
             VesselsProtoStore.AddVesselToDictionary(asteroid);
         }
         else
         {
             LunaLog.Log($"[LMP]: Killing non-server asteroid {asteroid.id}");
             TryKillAsteroid(asteroid);
         }
     }
     else
     {
         LunaLog.Log($"[LMP]: Killing non-server asteroid {asteroid.id}, we don't own the asteroid lock");
         TryKillAsteroid(asteroid);
     }
 }