Beispiel #1
0
 /// <summary>
 /// Try to get contract lock
 /// </summary>
 public void LockReleased(LockDefinition lockDefinition)
 {
     if (lockDefinition.Type == LockType.Contract)
     {
         System.TryGetContractLock();
     }
 }
 /// <summary>
 /// Try to get asteroid lock
 /// </summary>
 public void LockReleased(LockDefinition lockDefinition)
 {
     if (lockDefinition.Type == LockType.Asteroid)
     {
         System.TryGetAsteroidLock();
     }
 }
Beispiel #3
0
 public void OnLockRelease(LockDefinition lockdefinition)
 {
     if (KSCVesselMarkers.fetch)
     {
         KSCVesselMarkers.fetch.RefreshMarkers();
     }
 }
        public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire)
        {
            repeatedAcquire = false;

            //Player tried to acquire a lock that he already owns
            if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.PlayerName))
            {
                repeatedAcquire = true;
                return(true);
            }

            if (force || !LockQuery.LockExists(lockDef))
            {
                if (GeneralSettings.SettingsStore.DropControlOnVesselSwitching && lockDef.Type == LockType.Control)
                {
                    //If he acquired a control lock he probably switched vessels or smth like that and he can only have 1 control lock.
                    //So remove the other control locks just for safety...
                    var controlLocks = LockQuery.GetAllPlayerLocks(lockDef.PlayerName).Where(l => l.Type == LockType.Control);
                    foreach (var control in controlLocks)
                    {
                        ReleaseLock(control);
                    }
                }

                LockStore.AddOrUpdateLock(lockDef);
                return(true);
            }
            return(false);
        }
Beispiel #5
0
 /// <summary>
 /// If we acquire the control of a ship set it's orbit color
 /// </summary>
 public void OnLockAcquire(LockDefinition lockDefinition)
 {
     if (System.Enabled && lockDefinition.Type == LockType.Control)
     {
         UpdateVesselColorsFromLockVesselId(lockDefinition.VesselId);
     }
 }
 public void LockAcquire(LockDefinition lockDef)
 {
     if (lockDef.Type == LockType.Control && lockDef.PlayerName == SettingsSystem.CurrentSettings.PlayerName)
     {
         SubscribeToFieldChanges(FlightGlobals.ActiveVessel);
     }
 }
 /// <summary>
 /// If we release the control of a ship et it's orbit color back to normal
 /// </summary>
 public void OnLockRelease(LockDefinition lockDefinition)
 {
     if (lockDefinition.Type == LockType.Control)
     {
         UpdateVesselColorsFromLockVesselId(lockDefinition.VesselId);
     }
 }
Beispiel #8
0
 /// <summary>
 /// If we get the contract lock then generate contracts
 /// </summary>
 public void LockAcquire(LockDefinition lockDefinition)
 {
     if (lockDefinition.Type == LockType.Contract && lockDefinition.PlayerName == SettingsSystem.CurrentSettings.PlayerName)
     {
         ContractSystem.generateContractIterations = ShareContractsSystem.Singleton.DefaultContractGenerateIterations;
     }
 }
        public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire)
        {
            repeatedAcquire = false;

            //Player tried to acquire a lock that they already own
            if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.KerbalName, lockDef.PlayerName))
            {
                repeatedAcquire = true;
                return(true);
            }

            if (force || !LockQuery.LockExists(lockDef))
            {
                if (lockDef.Type == LockType.Control)
                {
                    //If they acquired a control lock they probably switched vessels or something like that and they can only have one control lock.
                    //So remove the other control locks just for safety...
                    var controlLocks = LockQuery.GetAllPlayerLocks(lockDef.PlayerName).Where(l => l.Type == LockType.Control);
                    foreach (var control in controlLocks)
                    {
                        ReleaseLock(control);
                    }
                }

                LockStore.AddOrUpdateLock(lockDef);
                return(true);
            }
            return(false);
        }
Beispiel #10
0
 /// <summary>
 /// Aquire the specified lock by sending a message to the server.
 /// </summary>
 /// <param name="lockDefinition">The definition of the lock to acquire</param>
 /// <param name="force">Force the aquire. Usually false unless in dockings.</param>
 public void AcquireLock(LockDefinition lockDefinition, bool force = false)
 {
     MessageSender.SendMessage(new LockAcquireMsgData
     {
         Lock  = lockDefinition,
         Force = force
     });
 }
Beispiel #11
0
        private static LockDefinition GetLockDefinitionFromBytes(Stream messageData)
        {
            var lockDefinition = new LockDefinition();

            PrivDeserialize(messageData, lockDefinition);

            return(lockDefinition);
        }
Beispiel #12
0
        /// <summary>
        /// Aquire the specified lock by sending a message to the server.
        /// </summary>
        /// <param name="lockDefinition">The definition of the lock to acquire</param>
        /// <param name="force">Force the aquire. Usually false unless in dockings.</param>
        private void AcquireLock(LockDefinition lockDefinition, bool force = false)
        {
            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <LockAcquireMsgData>();

            msgData.Lock  = lockDefinition;
            msgData.Force = force;

            MessageSender.SendMessage(msgData);
        }
Beispiel #13
0
        //Lock types
        //control-vessel-(vesselid) - Replaces the old "inUse" messages, the active pilot will have the control-vessel lock.
        //update-vessel-(vesselid) - Replaces the "only the closest player can update a vessel" code,
        //Now you acquire locks to update crafts around you.
        //asteroid - Held by the player that can spawn asteroids into the game.

        public static bool AcquireLock(LockDefinition lockDef, bool force)
        {
            if (force || !LockQuery.LockExists(lockDef))
            {
                LockStore.AddOrUpdateLock(lockDef);
                return(true);
            }
            return(false);
        }
Beispiel #14
0
 public static bool ReleaseLock(LockDefinition lockDef)
 {
     if (LockQuery.LockExists(lockDef) && LockQuery.GetLock(lockDef.Type, lockDef.PlayerName, lockDef.VesselId)
         .PlayerName == lockDef.PlayerName)
     {
         LockStore.RemoveLock(lockDef);
         return(true);
     }
     return(false);
 }
        public static bool ReleaseLock(LockDefinition lockDef)
        {
            if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.KerbalName, lockDef.PlayerName))
            {
                LockStore.RemoveLock(lockDef);
                return(true);
            }

            return(false);
        }
Beispiel #16
0
        /// <summary>
        /// Release the specified lock by sending a message to the server.
        /// </summary>
        /// <param name="lockDefinition">The definition of the lock to release</param>
        private void ReleaseLock(LockDefinition lockDefinition)
        {
            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <LockReleaseMsgData>();

            msgData.Lock.CopyFrom(lockDefinition);

            LockStore.RemoveLock(lockDefinition);
            LockEvent.onLockRelease.Fire(lockDefinition);

            MessageSender.SendMessage(msgData);
        }
Beispiel #17
0
        private static LockDefinition[] GetLockDefinitionArrayFromBytes(Stream messageData)
        {
            var numberOfElements = GetIntFromBytes(messageData);
            var outputData       = new LockDefinition[numberOfElements];

            for (var element = 0; element < numberOfElements; element++)
            {
                outputData[element] = GetLockDefinitionFromBytes(messageData);
            }
            return(outputData);
        }
        /// <summary>
        /// Handles the vessel immortal state when someone gets an update or control lock
        /// </summary>
        public void OnLockAcquire(LockDefinition lockDefinition)
        {
            if (lockDefinition.Type < LockType.Update)
            {
                return;
            }

            var vessel = FlightGlobals.fetch.LmpFindVessel(lockDefinition.VesselId);

            System.SetImmortalStateBasedOnLock(vessel);
        }
        /// <summary>
        /// Whenever a release/acquire lock fails, call this method to relay the correct lock definition to the player
        /// </summary>
        private static void SendStoredLockData(ClientStructure client, LockDefinition lockDefinition)
        {
            var storedLockDef = LockSystem.LockQuery.GetLock(lockDefinition.Type, lockDefinition.PlayerName, lockDefinition.VesselId, lockDefinition.KerbalName);

            if (storedLockDef != null)
            {
                var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <LockAcquireMsgData>();
                msgData.Lock = storedLockDef;
                MessageQueuer.SendToClient <LockSrvMsg>(client, msgData);
            }
        }
        /// <summary>
        /// Handles the vessel immortal state when someone gets a lock
        /// </summary>
        public void OnLockAcquire(LockDefinition lockDefinition)
        {
            if (lockDefinition.Type < LockType.Update)
            {
                return;
            }

            var vessel = FlightGlobals.FindVessel(lockDefinition.VesselId);

            System.SetVesselImmortalState(vessel, lockDefinition.PlayerName != SettingsSystem.CurrentSettings.PlayerName);
        }
        /// <summary>
        /// Handles the vessel immortal state when YOU release an update or control lock
        /// </summary>
        public void OnLockRelease(LockDefinition lockDefinition)
        {
            if (lockDefinition.Type != LockType.Control && lockDefinition.Type != LockType.Update && lockDefinition.Type != LockType.UnloadedUpdate)
            {
                return;
            }

            var vessel = FlightGlobals.FindVessel(lockDefinition.VesselId);

            System.SetImmortalStateBasedOnLock(vessel);
        }
        /// <summary>
        /// Acquire the specified lock by sending a message to the server.
        /// </summary>
        /// <param name="lockDefinition">The definition of the lock to acquire</param>
        /// <param name="force">Force the acquire. Usually false unless in dockings.</param>
        /// <param name="immediate">Acquire the lock immediately without waiting confirmation from the server</param>
        private void AcquireLock(LockDefinition lockDefinition, bool force = false, bool immediate = false)
        {
            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <LockAcquireMsgData>();

            msgData.Lock  = lockDefinition;
            msgData.Force = force;

            MessageSender.SendMessage(msgData);

            if (force && immediate)
            {
                LockStore.AddOrUpdateLock(lockDefinition);
            }
        }
Beispiel #23
0
 /// <summary>
 /// This event is triggered when some player acquired a lock
 /// It then calls all the methods specified in the delegate
 /// </summary>
 public void FireAcquireEvent(LockDefinition lockDefinition, bool lockResult)
 {
     foreach (var methodObject in LockAcquireEvents)
     {
         try
         {
             methodObject(lockDefinition, lockResult);
         }
         catch (Exception e)
         {
             LunaLog.LogError($"[LMP]: Error thrown in acquire lock event, exception {e}");
         }
     }
 }
Beispiel #24
0
 /// <summary>
 /// This event is triggered when some player released a lock
 /// It then calls all the methods specified in the delegate
 /// </summary>
 public void FireReleaseEvent(LockDefinition lockDefinition)
 {
     foreach (var methodObject in LockReleaseEvents)
     {
         try
         {
             methodObject(lockDefinition);
         }
         catch (Exception e)
         {
             LunaLog.LogError($"[LMP]: Error thrown in release lock event, exception {e}");
         }
     }
 }
        /// <summary>
        /// Handles the vessel immortal state when YOU release an update or control lock
        /// </summary>
        public void OnLockRelease(LockDefinition lockDefinition)
        {
            if (lockDefinition.Type < LockType.Update)
            {
                return;
            }
            if (lockDefinition.PlayerName != SettingsSystem.CurrentSettings.PlayerName)
            {
                return;
            }

            var vessel = FlightGlobals.fetch.LmpFindVessel(lockDefinition.VesselId);

            System.SetImmortalStateBasedOnLock(vessel);
        }
Beispiel #26
0
        /// <summary>
        /// If we get the Update lock, force the getting of the unloaded update lock.
        /// If we get a control lock, force getting the update and unloaded update
        /// </summary>
        public void LockAcquire(LockDefinition lockDefinition)
        {
            switch (lockDefinition.Type)
            {
            case LockType.Control:
                KscSceneSystem.Singleton.RefreshTrackingStationVessels();
                if (lockDefinition.PlayerName == SettingsSystem.CurrentSettings.PlayerName)
                {
                    VesselLockSystem.Singleton.StopSpectating();
                    LockSystem.Singleton.AcquireUpdateLock(lockDefinition.VesselId, true);
                    LockSystem.Singleton.AcquireUnloadedUpdateLock(lockDefinition.VesselId, true);
                    LockSystem.Singleton.AcquireKerbalLock(lockDefinition.VesselId, true);

                    //As we got the lock of that vessel, remove its FS and position updates
                    VesselCommon.RemoveVesselFromSystems(lockDefinition.VesselId);
                }
                else if (FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.id == lockDefinition.VesselId)
                {
                    System.StartSpectating(lockDefinition.VesselId);
                }
                break;

            case LockType.Update:
                if (lockDefinition.PlayerName != SettingsSystem.CurrentSettings.PlayerName)
                {
                    return;
                }

                LockSystem.Singleton.AcquireUnloadedUpdateLock(lockDefinition.VesselId, true);
                LockSystem.Singleton.AcquireKerbalLock(lockDefinition.VesselId, true);

                //As we got the lock of that vessel, remove its FS and position updates
                VesselCommon.RemoveVesselFromSystems(lockDefinition.VesselId);

                break;

            case LockType.UnloadedUpdate:
                if (lockDefinition.PlayerName != SettingsSystem.CurrentSettings.PlayerName)
                {
                    return;
                }

                //As we got the lock of that vessel, remove its FS and position updates
                VesselCommon.RemoveVesselFromSystems(lockDefinition.VesselId);

                break;
            }
        }
        /// <summary>
        /// Whenever we acquire a UnloadedUpdate/Update/Control lock of a vessel, remove it from the dictionaries
        /// </summary>
        public void OnLockAcquire(LockDefinition data)
        {
            if (data.PlayerName != SettingsSystem.CurrentSettings.PlayerName)
            {
                return;
            }

            switch (data.Type)
            {
            case LockType.UnloadedUpdate:
            case LockType.Update:
            case LockType.Control:
                System.RemoveVessel(data.VesselId);
                break;
            }
        }
        public static void SendLockAquireMessage(LockDefinition lockDefinition, bool force)
        {
            var lockResult = LockSystem.AcquireLock(lockDefinition, force);

            var newMessageData = new LockAcquireMsgData
            {
                Lock       = lockDefinition,
                LockResult = lockResult,
                Force      = force
            };

            MessageQueuer.SendToAllClients <LockSrvMsg>(newMessageData);

            LunaLog.Debug(lockResult
                ? $"{lockDefinition.PlayerName} acquired lock {lockDefinition}"
                : $"{lockDefinition.PlayerName} failed to acquire lock {lockDefinition}");
        }
Beispiel #29
0
        public static bool AcquireLock(LockDefinition lockDef, bool force, out bool repeatedAcquire)
        {
            repeatedAcquire = false;

            //Player tried to acquire a lock that he already owns
            if (LockQuery.LockBelongsToPlayer(lockDef.Type, lockDef.VesselId, lockDef.PlayerName))
            {
                repeatedAcquire = true;
                return(true);
            }

            if (force || !LockQuery.LockExists(lockDef))
            {
                LockStore.AddOrUpdateLock(lockDef);
                return(true);
            }
            return(false);
        }
        public static void ReleaseAndSendLockReleaseMessage(ClientStructure client, LockDefinition lockDefinition)
        {
            var lockReleaseResult = LockSystem.ReleaseLock(lockDefinition);

            if (lockReleaseResult)
            {
                var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <LockReleaseMsgData>();
                msgData.Lock       = lockDefinition;
                msgData.LockResult = true;

                MessageQueuer.RelayMessage <LockSrvMsg>(client, msgData);
                LunaLog.Debug($"{lockDefinition.PlayerName} released lock {lockDefinition}");
            }
            else
            {
                SendStoredLockData(client, lockDefinition);
                LunaLog.Debug($"{lockDefinition.PlayerName} failed to release lock {lockDefinition}");
            }
        }