GetWriteLock() public method

Acquires and returns an exclusive (write) lock for this BlockDB. Disposing the object returned by this method releases the lock.
public GetWriteLock ( ) : IDisposable
return IDisposable
Exemplo n.º 1
0
 public World ChangeMap([NotNull] Map newMap)
 {
     if (newMap == null)
     {
         throw new ArgumentNullException("newMap");
     }
     lock ( SyncRoot ) {
         World newWorld = new World(Name)
         {
             AccessSecurity = (SecurityController)AccessSecurity.Clone(),
             BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
             IsHidden       = IsHidden,
             BlockDB        = BlockDB,
             lastBackup     = lastBackup,
             BackupInterval = BackupInterval,
             IsLocked       = IsLocked,
             LockedBy       = LockedBy,
             UnlockedBy     = UnlockedBy,
             LockedOn       = LockedOn,
             UnlockedOn     = UnlockedOn,
             LoadedBy       = LoadedBy,
             LoadedOn       = LoadedOn,
             MapChangedBy   = MapChangedBy,
             MapChangedOn   = DateTime.UtcNow,
             FogColor       = FogColor,
             CloudColor     = CloudColor,
             SkyColor       = SkyColor,
             EdgeLevel      = EdgeLevel,
             EdgeBlock      = EdgeBlock
         };
         newMap.World     = newWorld;
         newWorld.Map     = newMap;
         newWorld.Preload = preload;
         WorldManager.ReplaceWorld(this, newWorld);
         using (BlockDB.GetWriteLock()) {
             BlockDB.Clear();
             BlockDB.World = newWorld;
         }
         foreach (Player player in Players)
         {
             player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
         }
         return(newWorld);
     }
 }
Exemplo n.º 2
0
        public World ChangeMap([NotNull] Map newMap)
        {
            if (newMap == null)
            {
                throw new ArgumentNullException("newMap");
            }
            lock ( SyncRoot ) {
                World newWorld = new World(Name)
                {
                    AccessSecurity = (SecurityController)AccessSecurity.Clone(),
                    BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
                    IsHidden       = IsHidden,
                    BlockDB        = BlockDB,
                    lastBackup     = lastBackup,
                    BackupInterval = BackupInterval,
                    IsLocked       = IsLocked,
                    LockedBy       = LockedBy,
                    UnlockedBy     = UnlockedBy,
                    LockedOn       = LockedOn,
                    UnlockedOn     = UnlockedOn,
                    LoadedBy       = LoadedBy,
                    LoadedOn       = LoadedOn,
                    MapChangedBy   = MapChangedBy,
                    MapChangedOn   = DateTime.UtcNow,
                    Buildable      = Buildable,
                    Deletable      = Deletable,
                };
                newWorld.CopyENV(this);
                WorldManager.ParseCPEMetaData(ref newWorld, newMap, Name);
                newMap.World     = newWorld;
                newWorld.Map     = newMap;
                newWorld.Preload = preload;
                WorldManager.ReplaceWorld(this, newWorld);
                using (BlockDB.GetWriteLock()) {
                    BlockDB.Clear();
                    BlockDB.World = newWorld;
                }

                foreach (Player player in Players)
                {
                    player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
                }
                return(newWorld);
            }
        }
Exemplo n.º 3
0
        public World ChangeMap([NotNull] Map newMap)
        {
            if (newMap == null)
            {
                throw new ArgumentNullException("newMap");
            }
            lock ( SyncRoot ) {
                World newWorld = new World(Name)
                {
                    AccessSecurity = (SecurityController)AccessSecurity.Clone(),
                    BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
                    IsHidden       = IsHidden,
                    BlockDB        = BlockDB,
                    lastBackup     = lastBackup,
                    BackupInterval = BackupInterval,
                    IsLocked       = IsLocked,
                    LockedBy       = LockedBy,
                    UnlockedBy     = UnlockedBy,
                    LockedOn       = LockedOn,
                    UnlockedOn     = UnlockedOn,
                    LoadedBy       = LoadedBy,
                    LoadedOn       = LoadedOn,
                    MapChangedBy   = MapChangedBy,
                    MapChangedOn   = DateTime.UtcNow,
                    FogColor       = FogColor,
                    CloudColor     = CloudColor,
                    SkyColor       = SkyColor,
                    EdgeLevel      = EdgeLevel,
                    SidesOffset    = SidesOffset,
                    CloudsHeight   = CloudsHeight,
                    MaxFogDistance = MaxFogDistance,
                    EdgeBlock      = EdgeBlock,
                    HorizonBlock   = HorizonBlock,
                    LightColor     = LightColor,
                    ShadowColor    = ShadowColor,
                    Weather        = Weather,
                    Texture        = Texture,
                    CloudsSpeed    = CloudsSpeed,
                    WeatherSpeed   = WeatherSpeed,
                    WeatherFade    = WeatherFade,
                    SkyboxHorSpeed = SkyboxHorSpeed,
                    SkyboxVerSpeed = SkyboxVerSpeed,
                    Buildable      = Buildable,
                    Deletable      = Deletable,
                    BlockDefs      = BlockDefs,
                };
                newMap.World     = newWorld;
                newWorld.Map     = newMap;
                newWorld.Preload = preload;
                WorldManager.ReplaceWorld(this, newWorld);
                using (BlockDB.GetWriteLock()) {
                    BlockDB.Clear();
                    BlockDB.World = newWorld;
                }

                foreach (Player player in Players)
                {
                    player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
                }
                return(newWorld);
            }
        }
Exemplo n.º 4
0
        public World ChangeMap([NotNull] Map newMap, [NotNull] string newMapChangedBy)
        {
            if (newMap == null)
            {
                throw new ArgumentNullException("newMap");
            }
            if (newMapChangedBy == null)
            {
                throw new ArgumentNullException("newMapChangedBy");
            }
            lock (SyncRoot) {
                if (mapWasChanged)
                {
                    throw new InvalidOperationException("A map change is already pending!");
                }

                World newWorld = new World(Name)
                {
                    AccessSecurity = (SecurityController)AccessSecurity.Clone(),
                    BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
                    IsHidden       = IsHidden,
                    BlockDB        = BlockDB,
                    lastBackup     = lastBackup,
                    BackupInterval = BackupInterval,
                    IsLocked       = IsLocked,
                    LockedBy       = LockedBy,
                    UnlockedBy     = UnlockedBy,
                    LockedOn       = LockedOn,
                    UnlockedOn     = UnlockedOn,
                    LoadedBy       = LoadedBy,
                    LoadedOn       = LoadedOn,
                    MapChangedBy   = newMapChangedBy,
                    MapChangedOn   = DateTime.UtcNow,
                    FogColor       = FogColor,
                    CloudColor     = CloudColor,
                    SkyColor       = SkyColor,
                    EdgeLevel      = EdgeLevel,
                    EdgeBlock      = EdgeBlock
                };
                newMap.World     = newWorld;
                newWorld.Map     = newMap;
                newWorld.Preload = preload;

                // save a backup, just in case
                if (ConfigKey.BackupOnMapChange.Enabled())
                {
                    if (Map != null && Map.HasChangedSinceSave)
                    {
                        SaveMap();
                    }
                    string backupFileName = String.Format(MapChangeBackupFormat, Name, DateTime.Now); // localized
                    SaveBackup(Path.Combine(Paths.BackupPath, backupFileName));
                }

                // register the new world, and unregister this one
                WorldManager.ReplaceWorld(this, newWorld);
                mapWasChanged = true;

                // clear BlockDB for the old map
                using (BlockDB.GetWriteLock()) {
                    BlockDB.Clear();
                    BlockDB.World = newWorld;
                }

                // tell players to go ahead
                foreach (Player player in Players)
                {
                    player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
                }
                return(newWorld);
            }
        }