Exemple #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);
         }
     }
 }
Exemple #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);
     }
 }
Exemple #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);
            }
        }
Exemple #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);
         }
     }
 }
Exemple #5
0
        public XElement Serialize([NotNull] string elementName)
        {
            if (elementName == null)
            {
                throw new ArgumentNullException("elementName");
            }

            XElement root = new XElement(elementName);

            root.Add(new XAttribute("name", Name));

            if (AccessSecurity.HasRestrictions)
            {
                root.Add(AccessSecurity.Serialize(AccessSecurityXmlTagName));
            }
            if (BuildSecurity.HasRestrictions)
            {
                root.Add(BuildSecurity.Serialize(BuildSecurityXmlTagName));
            }

            if (BackupInterval != BackupIntervalDefault)
            {
                root.Add(new XAttribute("backup", BackupInterval.ToSecondsString()));
            }

            if (Preload)
            {
                root.Add(new XAttribute("noUnload", true));
            }
            if (IsHidden)
            {
                root.Add(new XAttribute("hidden", true));
            }
            root.Add(BlockDB.SaveSettings());

            if (!String.IsNullOrEmpty(LoadedBy))
            {
                root.Add(new XElement("LoadedBy", LoadedBy));
            }
            if (LoadedOn != DateTime.MinValue)
            {
                root.Add(new XElement("LoadedOn", LoadedOn.ToUnixTime()));
            }
            if (!String.IsNullOrEmpty(MapChangedBy))
            {
                root.Add(new XElement("MapChangedBy", MapChangedBy));
            }
            if (MapChangedOn != DateTime.MinValue)
            {
                root.Add(new XElement("MapChangedOn", MapChangedOn.ToUnixTime()));
            }

            XElement elEnv = new XElement(EnvironmentXmlTagName);

            if (CloudColor > -1)
            {
                elEnv.Add(new XAttribute("cloud", CloudColor));
            }
            if (FogColor > -1)
            {
                elEnv.Add(new XAttribute("fog", FogColor));
            }
            if (SkyColor > -1)
            {
                elEnv.Add(new XAttribute("sky", SkyColor));
            }
            if (EdgeLevel > -1)
            {
                elEnv.Add(new XAttribute("level", EdgeLevel));
            }
            if (EdgeBlock != Block.Water)
            {
                elEnv.Add(new XAttribute("edge", EdgeBlock));
            }
            if (elEnv.HasAttributes)
            {
                root.Add(elEnv);
            }
            return(root);
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }