private GetEdgeTexture ( Block block ) : string | ||
block | Block | |
Résultat | string |
public string GenerateWoMConfig(bool sendMotd) { StringBuilder sb = new StringBuilder(); sb.AppendLine("server.name = " + ConfigKey.ServerName.GetString()); if (sendMotd) { sb.AppendLine("server.detail = " + ConfigKey.MOTD.GetString()); } else { sb.AppendLine("server.detail = " + ClassyName); } sb.AppendLine("user.detail = World " + ClassyName); if (CloudColor > -1) { sb.AppendLine("environment.cloud = " + CloudColor); } if (FogColor > -1) { sb.AppendLine("environment.fog = " + FogColor); } if (SkyColor > -1) { sb.AppendLine("environment.sky = " + SkyColor); } if (EdgeLevel > -1) { sb.AppendLine("environment.level = " + EdgeLevel); } if (Terrain != null) { sb.AppendLine("environment.terrain = " + Terrain); } if (EdgeBlock != Block.Water) { string edgeTexture = Map.GetEdgeTexture(EdgeBlock); if (edgeTexture != null) { sb.AppendLine("environment.edge = " + edgeTexture); } } if (SideBlock != Block.Admincrete) { string sideTexture = Map.GetEdgeTexture(SideBlock); if (sideTexture != null) { sb.AppendLine("environment.side = " + sideTexture); } } sb.AppendLine("server.sendwomid = true"); return(sb.ToString()); }
private static void LoadWorldListEntry([NotNull] XElement el) { if (el == null) { throw new ArgumentNullException("el"); } XAttribute tempAttr; if ((tempAttr = el.Attribute("name")) == null) { Logger.Log(LogType.Error, "WorldManager: World tag with no name skipped."); return; } string worldName = tempAttr.Value; bool neverUnload = (el.Attribute("noUnload") != null); World world; try { world = AddWorld(null, worldName, null, neverUnload); } catch (WorldOpException ex) { Logger.Log(LogType.Error, "WorldManager: Error adding world \"{0}\": {1}", worldName, ex.Message); return; } if ((tempAttr = el.Attribute("hidden")) != null) { bool isHidden; if (Boolean.TryParse(tempAttr.Value, out isHidden)) { world.IsHidden = isHidden; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.", worldName); } } if ((tempAttr = el.Attribute("visitCount")) != null) { int vCount; if (Int32.TryParse(tempAttr.Value, out vCount)) { world.VisitCount = vCount; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"VisitCount\" attribute of world \"{0}\", assuming NO Visits.", worldName); } } if (firstWorld == null) { firstWorld = world; } XElement tempEl = el.Element("Greeting"); if (tempEl != null && !String.IsNullOrEmpty(tempEl.Value)) { world.Greeting = tempEl.Value; } if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("accessSecurity")) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("buildSecurity")) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } if ((tempAttr = el.Attribute("backup")) != null) { TimeSpan backupInterval; if (tempAttr.Value.ToTimeSpan(out backupInterval)) { world.BackupInterval = backupInterval; } else { world.BackupInterval = WorldManager.DefaultBackupInterval; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).", worldName, world.BackupInterval.ToMiniString()); } } else { world.BackupInterval = WorldManager.DefaultBackupInterval; } XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { world.BlockDB.LoadSettings(blockEl); } XElement PhyEl = el.Element(Physics.XmlRootName); if (PhyEl != null) { Physics.LoadSettings(PhyEl, world); } XElement PhyEl2 = el.Element(Physics.XmlRootName2); if (PhyEl2 != null) { Physics.LoadOtherSettings(PhyEl2, world); } XElement RealmEl = el.Element(world.RealmXMLRootName); if (RealmEl != null) { world.LoadRealmState(RealmEl); } XElement envEl = el.Element(EnvironmentXmlTagName); if (envEl != null) { if ((tempAttr = envEl.Attribute("cloud")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.CloudColor)) { world.CloudColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("terrain")) != null) { world.Terrain = envEl.Attribute("terrain").Value; } if ((tempAttr = envEl.Attribute("fog")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.FogColor)) { world.FogColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("sky")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.SkyColor)) { world.SkyColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("level")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.EdgeLevel)) { world.EdgeLevel = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("edge")) != null) { Block block = Map.GetBlockByName(tempAttr.Value); if (block == Block.Undefined) { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } else { if (Map.GetEdgeTexture(block) == null) { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } else { world.EdgeBlock = block; } } } } foreach (XElement mainedRankEl in el.Elements(RankMainXmlTagName)) { Rank rank = Rank.Parse(mainedRankEl.Value); if (rank != null) { if (rank < world.AccessSecurity.MinRank) { world.AccessSecurity.MinRank = rank; Logger.Log(LogType.Warning, "WorldManager: Lowered access MinRank of world {0} to allow it to be the main world for that rank.", rank.Name); } rank.MainWorld = world; } } CheckMapFile(world); }
static void LoadWorldListEntry([NotNull] XElement el) { if (el == null) { throw new ArgumentNullException("el"); } XAttribute tempAttr; if ((tempAttr = el.Attribute("name")) == null) { Logger.Log(LogType.Error, "WorldManager: World tag with no name skipped."); return; } string worldName = tempAttr.Value; bool neverUnload = (el.Attribute("noUnload") != null); World world; try { world = AddWorld(null, worldName, null, neverUnload); } catch (WorldOpException ex) { Logger.Log(LogType.Error, "WorldManager: Error adding world \"{0}\": {1}", worldName, ex.Message); return; } if ((tempAttr = el.Attribute("hidden")) != null) { bool isHidden; if (Boolean.TryParse(tempAttr.Value, out isHidden)) { world.IsHidden = isHidden; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.", worldName); } } if (firstWorld == null) { firstWorld = world; } XElement tempEl = el.Element("Greeting"); if (tempEl != null && !String.IsNullOrEmpty(tempEl.Value)) { world.Greeting = tempEl.Value; } if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("accessSecurity")) != null) { world.AccessSecurity = new SecurityController(tempEl, true); } if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } else if ((tempEl = el.Element("buildSecurity")) != null) { world.BuildSecurity = new SecurityController(tempEl, true); } // load backup settings if ((tempAttr = el.Attribute("backup")) != null) { TimeSpan backupInterval; if (DateTimeUtil.TryParseTimeSpan(tempAttr.Value, out backupInterval)) { if (backupInterval <= TimeSpan.Zero) { world.BackupEnabledState = YesNoAuto.No; } else { world.BackupInterval = backupInterval; } } else { world.BackupEnabledState = YesNoAuto.Auto; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).", worldName, world.BackupInterval.ToMiniString()); } } else { world.BackupEnabledState = YesNoAuto.Auto; } // load BlockDB settings XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { world.BlockDB.LoadSettings(blockEl); } // load environment settings XElement envEl = el.Element(EnvironmentXmlTagName); if (envEl != null) { if ((tempAttr = envEl.Attribute("cloud")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.CloudColor)) { world.CloudColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("fog")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.FogColor)) { world.FogColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("sky")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.SkyColor)) { world.SkyColor = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("level")) != null) { if (!Int32.TryParse(tempAttr.Value, out world.EdgeLevel)) { world.EdgeLevel = -1; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).", worldName); } } if ((tempAttr = envEl.Attribute("edge")) != null) { Block block; if (Map.GetBlockByName(tempAttr.Value, false, out block)) { if (Map.GetEdgeTexture(block) == null) { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } else { world.EdgeBlock = block; } } else { world.EdgeBlock = Block.Water; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).", worldName); } } } // load loaded/map-changed information long timestamp; tempEl = el.Element("LoadedBy"); if (tempEl != null) { world.LoadedBy = tempEl.Value; } tempEl = el.Element("LoadedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.LoadedOn = DateTimeUtil.TryParseDateTime(timestamp); } tempEl = el.Element("MapChangedBy"); if (tempEl != null) { world.MapChangedBy = tempEl.Value; } tempEl = el.Element("MapChangedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.MapChangedOn = DateTimeUtil.TryParseDateTime(timestamp); } // load lock information if ((tempAttr = el.Attribute("locked")) != null) { bool isLocked; if (Boolean.TryParse(tempAttr.Value, out isLocked)) { world.IsLocked = isLocked; } tempEl = el.Element("LockedBy"); if (tempEl != null) { world.LockedBy = tempEl.Value; } tempEl = el.Element("LockedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.LockedOn = DateTimeUtil.TryParseDateTime(timestamp); } } else { tempEl = el.Element("UnlockedBy"); if (tempEl != null) { world.UnlockedBy = tempEl.Value; } tempEl = el.Element("UnlockedOn"); if (tempEl != null && Int64.TryParse(tempEl.Value, out timestamp)) { world.UnlockedOn = DateTimeUtil.TryParseDateTime(timestamp); } } foreach (XElement mainedRankEl in el.Elements(RankMainXmlTagName)) { Rank rank = Rank.Parse(mainedRankEl.Value); if (rank != null) { if (rank < world.AccessSecurity.MinRank) { world.AccessSecurity.MinRank = rank; Logger.Log(LogType.Warning, "WorldManager: Lowered access MinRank of world {0} to allow it to be the main world for that rank.", rank.Name); } rank.MainWorld = world; } } CheckMapFile(world); }
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; } } } } }