/// <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(); } }
/// <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(); } }
/// <summary> /// Checks if the given lock exists /// </summary> public bool LockExists(LockDefinition lockDefinition) { switch (lockDefinition.Type) { case LockType.Asteroid: return(LockStore.AsteroidLock != null); case LockType.Update: return(LockStore.UpdateLocks.ContainsKey(lockDefinition.VesselId)); case LockType.Control: return(LockStore.ControlLocks.ContainsKey(lockDefinition.VesselId)); case LockType.Spectator: return(LockStore.SpectatorLocks.ContainsKey(lockDefinition.PlayerName)); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Adds or replace the given lock to the storage /// </summary> public void AddOrUpdateLock(LockDefinition lockDefinition) { switch (lockDefinition.Type) { case LockType.Asteroid: AsteroidLock = lockDefinition; break; case LockType.Update: UpdateLocks.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; default: throw new ArgumentOutOfRangeException(); } }
public void CopyFrom(LockDefinition lockDefinition) { PlayerName = lockDefinition.PlayerName.Clone() as string; Type = lockDefinition.Type; VesselId = lockDefinition.VesselId; }