Ejemplo n.º 1
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.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;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Clear all locks
 /// </summary>
 public void ClearAllLocks()
 {
     new Task(() =>
     {
         lock (_asteroidSyncLock)
         {
             AsteroidLock = null;
         }
         UpdateLocks.Clear();
         ControlLocks.Clear();
         SpectatorLocks.Clear();
         UnloadedUpdateLocks.Clear();
     }).Start(TaskScheduler.Current);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Clear all locks
 /// </summary>
 public void ClearAllLocks()
 {
     lock (_asteroidSyncLock)
     {
         AsteroidLock = null;
     }
     lock (_contractSyncLock)
     {
         ContractLock = null;
     }
     UpdateLocks.Clear();
     KerbalLocks.Clear();
     ControlLocks.Clear();
     SpectatorLocks.Clear();
     UnloadedUpdateLocks.Clear();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes given lock from storage
        /// </summary>
        public void RemoveLock(LockType lockType, string playerName, Guid vesselId, string kerbalName)
        {
            switch (lockType)
            {
            case LockType.Asteroid:
                lock (_asteroidSyncLock)
                {
                    AsteroidLock = null;
                }
                break;

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

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

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

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 6
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();
            }
        }