예제 #1
0
 public void ChangeMap([NotNull] Map newMap)
 {
     if (newMap == null)
     {
         throw new ArgumentNullException("newMap");
     }
     MapChangedOn = DateTime.UtcNow;
     lock (SyncRoot)
     {
         World newWorld = new World(Name)
         {
             AccessSecurity = (SecurityController)AccessSecurity.Clone(),
             BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
             IsHidden       = IsHidden,
             IsRealm        = IsRealm,
             BlockDB        = BlockDB,
             lastBackup     = lastBackup,
             BackupInterval = BackupInterval,
             IsLocked       = IsLocked,
             LockedBy       = LockedBy,
             UnlockedBy     = UnlockedBy,
             LockedDate     = LockedDate,
             UnlockedDate   = UnlockedDate,
             LoadedBy       = LoadedBy,
             LoadedOn       = LoadedOn,
             MapChangedBy   = MapChangedBy,
             MapChangedOn   = MapChangedOn,
             FogColor       = FogColor,
             CloudColor     = CloudColor,
             SkyColor       = SkyColor,
             EdgeLevel      = EdgeLevel,
             SideBlock      = SideBlock,
             EdgeBlock      = EdgeBlock,
             CloudColorCC   = CloudColorCC,
             SkyColorCC     = SkyColorCC,
             FogColorCC     = FogColorCC,
             sideLevel      = sideLevel,
             sideBlock      = sideBlock,
             edgeBlock      = edgeBlock,
             textureURL     = textureURL
         };
         newWorld.Map         = newMap;
         newWorld.NeverUnload = neverUnload;
         WorldManager.ReplaceWorld(this, newWorld);
         lock (BlockDB.SyncRoot) {
             BlockDB.Clear();
             BlockDB.World = newWorld;
         }
         foreach (Player player in Players)
         {
             player.JoinWorld(newWorld, WorldChangeReason.Rejoin);
         }
     }
 }
예제 #2
0
 /// <summary> Creates a new World for the given Map, with same properties as this world. </summary>
 /// <returns> Newly-created World object, with the new map. </returns>
 public World ChangeMap([NotNull] Map newMap)
 {
     if (newMap == null)
     {
         throw new ArgumentNullException("newMap");
     }
     MapChangedOn = DateTime.UtcNow;
     lock ( SyncRoot ) {
         World newWorld = new World(Name)
         {
             AccessSecurity = (SecurityController)AccessSecurity.Clone(),
             BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
             IsHidden       = IsHidden,
             BlockDB        = BlockDB,
             BackupInterval = BackupInterval,
             lastBackup     = lastBackup,
             LoadedBy       = LoadedBy,
             LoadedOn       = LoadedOn,
             MapChangedBy   = MapChangedBy,
             MapChangedOn   = MapChangedOn,
             FogColor       = FogColor,
             CloudColor     = CloudColor,
             SkyColor       = SkyColor,
             EdgeLevel      = EdgeLevel,
             EdgeBlock      = EdgeBlock,
             IsLocked       = IsLocked,
             LockedBy       = LockedBy,
             UnlockedBy     = UnlockedBy,
             LockDate       = LockDate,
             UnlockDate     = UnlockDate
         };
         newMap.World     = newWorld;
         newWorld.Map     = newMap;
         newWorld.Preload = preload;
         WorldManager.ReplaceWorld(this, newWorld);
         lock (BlockDB.SyncRoot) {
             BlockDB.Clear();
             BlockDB.World = newWorld;
         }
         foreach (Player player in Players)
         {
             player.JoinWorld(newWorld, WorldChangeContext.Rejoin);
         }
         return(newWorld);
     }
 }
예제 #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,
                    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);
            }
        }
예제 #4
0
 public void ChangeMap(Map newMap)
 {
     if (newMap == null)
     {
         throw new ArgumentNullException("newMap");
     }
     lock ( WorldLock ) {
         World newWorld = new World(Name, NeverUnload)
         {
             Map            = newMap,
             AccessSecurity = (SecurityController)AccessSecurity.Clone(),
             BuildSecurity  = (SecurityController)BuildSecurity.Clone(),
             IsHidden       = IsHidden
         };
         newMap.World = newWorld;
         WorldManager.ReplaceWorld(this, newWorld);
         Map = null;
         foreach (Player player in PlayerList)
         {
             player.Session.JoinWorld(newWorld);
         }
     }
 }
예제 #5
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);
            }
        }
예제 #6
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);
            }
        }