void SaveTask(SchedulerTask task) { if (!IsLoaded) { return; } lock ( SyncRoot ) { if (Map == null) { return; } lock ( BackupLock ) { if (BackupsEnabled && DateTime.UtcNow.Subtract(lastBackup) > BackupInterval && (HasChangedSinceBackup || !ConfigKey.BackupOnlyWhenChanged.Enabled())) { string backupFileName = String.Format(TimedBackupFormat, Name, DateTime.Now); // localized SaveBackup(Path.Combine(Paths.BackupPath, backupFileName)); lastBackup = DateTime.UtcNow; } } if (Map.HasChangedSinceSave) { SaveMap(); } if (BlockDB.IsEnabledGlobally && BlockDB.IsEnabled) { BlockDB.Flush(true); } } }
internal World( [NotNull] string name ) { if( name == null ) throw new ArgumentNullException( "name" ); if( !IsValidName( name ) ) { throw new ArgumentException( "Unacceptable world name." ); } BlockDB = new BlockDB( this ); AccessSecurity = new SecurityController(); BuildSecurity = new SecurityController(); Name = name; Players = new Player[0]; }
internal World( [NotNull] string name ) { if( name == null ) throw new ArgumentNullException( "name" ); if( !IsValidName( name ) ) { throw new ArgumentException( "Unacceptable world name." ); } BlockDB = new BlockDB( this ); AccessSecurity = new SecurityController(); BuildSecurity = new SecurityController(); Name = name; Players = new Player[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); } } }
internal World( [NotNull] string name ) { if( name == null ) throw new ArgumentNullException( "name" ); if( !IsValidName( name ) ) { throw new ArgumentException( "Unacceptable world name." ); } BlockDB = new BlockDB( this ); AccessSecurity = new SecurityController(); BuildSecurity = new SecurityController(); Name = name; UpdatePlayerList(); for (int i = 0; i < Enum.GetValues(typeof(TaskCategory)).Length; ++i) _physSchedulers.Add(new PhysScheduler(this)); }
/// <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); } }
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); } }
internal World([NotNull] string name) { if (name == null) { throw new ArgumentNullException("name"); } if (!IsValidName(name)) { throw new ArgumentException("Unacceptable world name."); } BlockDB = new BlockDB(this); AccessSecurity = new SecurityController(); BuildSecurity = new SecurityController(); Name = name; UpdatePlayerList(); Buildable = true; Deletable = true; BlockDefs = new BlockDefinition[256]; for (int i = 0; i < BlockDefs.Length; i++) { BlockDefs[i] = BlockDefinition.GlobalDefs[i]; } }
internal World( [NotNull] string name ) { if( name == null ) throw new ArgumentNullException( "name" ); if( !IsValidName( name ) ) { throw new ArgumentException( "Unacceptable world name." ); } BlockDB = new BlockDB( this ); AccessSecurity = new SecurityController(); BuildSecurity = new SecurityController(); Name = name; UpdatePlayerList(); for (int i = 0; i < Enum.GetValues(typeof(TaskCategory)).Length; ++i) _physSchedulers.Add(new PhysScheduler(this)); }
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); }
public World([NotNull] string name, [NotNull] XElement el) { if (name == null) { throw new ArgumentNullException("name"); } if (el == null) { throw new ArgumentNullException("el"); } if (!IsValidName(name)) { throw new ArgumentException("Unacceptable world name."); } Name = name; BlockDB = new BlockDB(this); UpdatePlayerList(); XAttribute tempAttr; // load hidden status if ((tempAttr = el.Attribute("hidden")) != null) { bool isHidden; if (Boolean.TryParse(tempAttr.Value, out isHidden)) { IsHidden = isHidden; } else { Logger.Log(LogType.Warning, "World: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.", Name); } } // load access and build security XElement tempEl; if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null) { AccessSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("accessSecurity")) != null) { AccessSecurity = new SecurityController(tempEl, true); } else { AccessSecurity = new SecurityController(); } if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null) { BuildSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("buildSecurity")) != null) { BuildSecurity = new SecurityController(tempEl, true); } else { BuildSecurity = new SecurityController(); } // load backup interval if ((tempAttr = el.Attribute("backup")) != null) { if (!tempAttr.Value.ToTimeSpan(out backupInterval)) { backupInterval = BackupIntervalDefault; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).", Name, BackupInterval.ToMiniString()); } } else { BackupInterval = BackupIntervalDefault; } // load BlockDB settings XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { BlockDB.LoadSettings(blockEl); } // load map (if needed) Preload = (el.Attribute("noUnload") != null); // load environment settings XElement envEl = el.Element(EnvironmentXmlTagName); if (envEl != null) { if ((tempAttr = envEl.Attribute("cloud")) != null) { if (!Int32.TryParse(tempAttr.Value, out CloudColor)) { CloudColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name); } } if ((tempAttr = envEl.Attribute("fog")) != null) { if (!Int32.TryParse(tempAttr.Value, out FogColor)) { FogColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name); } } if ((tempAttr = envEl.Attribute("sky")) != null) { if (!Int32.TryParse(tempAttr.Value, out SkyColor)) { SkyColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name); } } if ((tempAttr = envEl.Attribute("level")) != null) { if (!Int32.TryParse(tempAttr.Value, out EdgeLevel)) { EdgeLevel = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name); } } if ((tempAttr = envEl.Attribute("edge")) != null) { Block block; if (!Map.GetBlockByName(tempAttr.Value, false, out block)) { EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", Name); } else { if (Map.GetEdgeTexture(block) == null) { EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", Name); } else { EdgeBlock = block; } } } } }
public World( [NotNull] string name, [NotNull] XElement el ) { if( name == null ) throw new ArgumentNullException( "name" ); if( el == null ) throw new ArgumentNullException( "el" ); if( !IsValidName( name ) ) { throw new ArgumentException( "Unacceptable world name." ); } Name = name; BlockDB = new BlockDB( this ); UpdatePlayerList(); XAttribute tempAttr; // load hidden status if( ( tempAttr = el.Attribute( "hidden" ) ) != null ) { bool isHidden; if( Boolean.TryParse( tempAttr.Value, out isHidden ) ) { IsHidden = isHidden; } else { Logger.Log( LogType.Warning, "World: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.", Name ); } } // load access and build security XElement tempEl; if( ( tempEl = el.Element( AccessSecurityXmlTagName ) ) != null ) { AccessSecurity = new SecurityController( tempEl, true ); } else if( ( tempEl = el.Element( "accessSecurity" ) ) != null ) { AccessSecurity = new SecurityController( tempEl, true ); } else { AccessSecurity = new SecurityController(); } if( ( tempEl = el.Element( BuildSecurityXmlTagName ) ) != null ) { BuildSecurity = new SecurityController( tempEl, true ); } else if( ( tempEl = el.Element( "buildSecurity" ) ) != null ) { BuildSecurity = new SecurityController( tempEl, true ); } else { BuildSecurity = new SecurityController(); } // load backup interval if( ( tempAttr = el.Attribute( "backup" ) ) != null ) { if( !tempAttr.Value.ToTimeSpan( out backupInterval ) ) { backupInterval = BackupIntervalDefault; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).", Name, BackupInterval.ToMiniString() ); } } else { BackupInterval = BackupIntervalDefault; } // load BlockDB settings XElement blockEl = el.Element( BlockDB.XmlRootName ); if( blockEl != null ) { BlockDB.LoadSettings( blockEl ); } // load map (if needed) Preload = ( el.Attribute( "noUnload" ) != null ); // load environment settings XElement envEl = el.Element( EnvironmentXmlTagName ); if( envEl != null ) { if( ( tempAttr = envEl.Attribute( "cloud" ) ) != null ) { if( !Int32.TryParse( tempAttr.Value, out CloudColor ) ) { CloudColor = -1; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name ); } } if( ( tempAttr = envEl.Attribute( "fog" ) ) != null ) { if( !Int32.TryParse( tempAttr.Value, out FogColor ) ) { FogColor = -1; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name ); } } if( ( tempAttr = envEl.Attribute( "sky" ) ) != null ) { if( !Int32.TryParse( tempAttr.Value, out SkyColor ) ) { SkyColor = -1; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name ); } } if( ( tempAttr = envEl.Attribute( "level" ) ) != null ) { if( !Int32.TryParse( tempAttr.Value, out EdgeLevel ) ) { EdgeLevel = -1; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).", Name ); } } if( ( tempAttr = envEl.Attribute( "edge" ) ) != null ) { Block block; if( !Map.GetBlockByName( tempAttr.Value, false, out block ) ) { EdgeBlock = Block.Water; Logger.Log( LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", Name ); } else { if( Map.GetEdgeTexture( block ) == null ) { EdgeBlock = Block.Water; Logger.Log( LogType.Warning, "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", Name ); } else { EdgeBlock = block; } } } } }
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); } }
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); } }
internal static void Init() { CommandManager.RegisterCommand(CdMassRank); CommandManager.RegisterCommand(CdSetInfo); CommandManager.RegisterCommand(CdReload); CommandManager.RegisterCommand(CdShutdown); CommandManager.RegisterCommand(CdRestart); //CommandManager.RegisterCommand( CdPruneDB ); CommandManager.RegisterCommand(CdImport); CommandManager.RegisterCommand(CdInfoSwap); #if DEBUG CommandManager.RegisterCommand(new CommandDescriptor { Name = "BUM", IsHidden = true, Category = CommandCategory.Maintenance | CommandCategory.Debug, Help = "Bandwidth Use Mode statistics.", Handler = delegate(Player player, CommandReader cmd) { string newModeName = cmd.Next(); if (newModeName == null) { player.Message("{0}: S: {1} R: {2} S/s: {3:0.0} R/s: {4:0.0}", player.BandwidthUseMode, player.BytesSent, player.BytesReceived, player.BytesSentRate, player.BytesReceivedRate); } else { var newMode = (BandwidthUseMode)Enum.Parse(typeof(BandwidthUseMode), newModeName, true); player.BandwidthUseMode = newMode; player.Info.BandwidthUseMode = newMode; } } }); CommandManager.RegisterCommand(new CommandDescriptor { Name = "BDBDB", IsHidden = true, Category = CommandCategory.Maintenance | CommandCategory.Debug, Help = "BlockDB Debug", Handler = delegate(Player player, CommandReader cmd) { if (player.World == null) { PlayerOpException.ThrowNoWorld(player); } BlockDB db = player.World.BlockDB; lock (db.SyncRoot) { player.Message("BlockDB: CAP={0} SZ={1} FI={2}", db.CacheCapacity, db.CacheSize, db.LastFlushedIndex); } } }); #endif }