Пример #1
0
        /// <summary>
        /// Adds or replace the given lock to the storage
        /// </summary>
        public void AddOrUpdateLock(LockDefinition lockDefinition)
        {
            switch (lockDefinition.Type)
            {
            case LockType.Asteroid:
                lock (_asteroidSyncLock)
                {
                    if (AsteroidLock == null)
                    {
                        AsteroidLock = new LockDefinition(LockType.Asteroid, lockDefinition.PlayerName);
                    }
                    else
                    {
                        AsteroidLock.PlayerName = lockDefinition.PlayerName;
                    }
                }
                break;

            case LockType.Kerbal:
                KerbalLocks.AddOrUpdate(lockDefinition.KerbalName, lockDefinition, (key, existingVal) => lockDefinition);
                break;

            case LockType.Update:
                UpdateLocks.AddOrUpdate(lockDefinition.VesselId, lockDefinition, (key, existingVal) => lockDefinition);
                break;

            case LockType.UnloadedUpdate:
                UnloadedUpdateLocks.AddOrUpdate(lockDefinition.VesselId, lockDefinition, (key, existingVal) => lockDefinition);
                break;

            case LockType.Control:
                ControlLocks.AddOrUpdate(lockDefinition.VesselId, lockDefinition, (key, existingVal) => lockDefinition);
                break;

            case LockType.Spectator:
                SpectatorLocks.AddOrUpdate(lockDefinition.PlayerName, lockDefinition, (key, existingVal) => lockDefinition);
                break;

            case LockType.Contract:
                lock (_contractSyncLock)
                {
                    if (ContractLock == null)
                    {
                        ContractLock = new LockDefinition(LockType.Contract, lockDefinition.PlayerName);
                    }
                    else
                    {
                        ContractLock.PlayerName = lockDefinition.PlayerName;
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        /// <summary>
        /// Removes given lock from storage
        /// </summary>
        public void RemoveLock(LockDefinition lockDefinition)
        {
            switch (lockDefinition.Type)
            {
            case LockType.Asteroid:
                lock (_asteroidSyncLock)
                {
                    AsteroidLock = null;
                }
                break;

            case LockType.Kerbal:
                KerbalLocks.TryRemove(lockDefinition.KerbalName, out _);
                break;

            case LockType.UnloadedUpdate:
                UnloadedUpdateLocks.TryRemove(lockDefinition.VesselId, out _);
                break;

            case LockType.Update:
                UpdateLocks.TryRemove(lockDefinition.VesselId, out _);
                break;

            case LockType.Control:
                ControlLocks.TryRemove(lockDefinition.VesselId, out _);
                break;

            case LockType.Spectator:
                SpectatorLocks.TryRemove(lockDefinition.PlayerName, out _);
                break;

            case LockType.Contract:
                lock (_contractSyncLock)
                {
                    ContractLock = null;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #3
0
        /// <summary>
        /// Adds or replace the given lock to the storage
        /// </summary>
        public void AddOrUpdateLock(LockDefinition lockDefinition)
        {
            //Be sure to clone the lock before storing to avoid any reference issue
            var safeLockDefinition = (LockDefinition)lockDefinition.Clone();

            switch (safeLockDefinition.Type)
            {
            case LockType.Asteroid:
                lock (_asteroidSyncLock)
                {
                    if (AsteroidLock == null)
                    {
                        AsteroidLock = new LockDefinition(LockType.Asteroid, safeLockDefinition.PlayerName);
                    }
                    else
                    {
                        AsteroidLock.PlayerName = safeLockDefinition.PlayerName;
                    }
                }
                break;

            case LockType.Kerbal:
                KerbalLocks.AddOrUpdate(safeLockDefinition.KerbalName, safeLockDefinition, (key, existingVal) =>
                {
                    existingVal.PlayerName = safeLockDefinition.PlayerName;
                    return(existingVal);
                });
                break;

            case LockType.Update:
                UpdateLocks.AddOrUpdate(safeLockDefinition.VesselId, safeLockDefinition, (key, existingVal) =>
                {
                    existingVal.PlayerName = safeLockDefinition.PlayerName;
                    return(existingVal);
                });
                break;

            case LockType.UnloadedUpdate:
                UnloadedUpdateLocks.AddOrUpdate(safeLockDefinition.VesselId, safeLockDefinition, (key, existingVal) =>
                {
                    existingVal.PlayerName = safeLockDefinition.PlayerName;
                    return(existingVal);
                });
                break;

            case LockType.Control:
                ControlLocks.AddOrUpdate(safeLockDefinition.VesselId, safeLockDefinition, (key, existingVal) =>
                {
                    existingVal.PlayerName = safeLockDefinition.PlayerName;
                    return(existingVal);
                });
                break;

            case LockType.Spectator:
                SpectatorLocks.AddOrUpdate(safeLockDefinition.PlayerName, safeLockDefinition, (key, existingVal) => safeLockDefinition);
                break;

            case LockType.Contract:
                lock (_contractSyncLock)
                {
                    if (ContractLock == null)
                    {
                        ContractLock = new LockDefinition(LockType.Contract, safeLockDefinition.PlayerName);
                    }
                    else
                    {
                        ContractLock.PlayerName = safeLockDefinition.PlayerName;
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }