public bool NextBlock([NotNull] Player player, bool allowNoneBlock, out Block block) { if (player == null) { throw new ArgumentNullException("player"); } string blockName = Next(); block = Block.None; if (blockName != null) { if (Map.GetBlockByName(blockName, true, out block)) { if (block == Block.None && !allowNoneBlock) { player.Message("The \"none\" block is not allowed here"); return(false); } else { return(true); } } else { player.Message("Unrecognized blocktype \"{0}\"", blockName); return(false); } } else { return(false); } }
public bool NextBlock([CanBeNull] Player player, bool allowNoneBlock, out Block block) { string blockName = Next(); block = Block.None; if (blockName != null) { if (Map.GetBlockByName(blockName, true, out block)) { if (block != Block.None || allowNoneBlock) { return(true); } else if (player != null) { player.Message("The \"none\" block is not allowed here"); } } else if (player != null) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } } return(false); }
public static void LoadupEnvPreset(World world, string name) { EnvPresets preset = Find(name); world.SkyColor = preset.SkyColor; world.CloudColor = preset.CloudColor; world.FogColor = preset.FogColor; world.ShadowColor = preset.ShadowColor; world.LightColor = preset.LightColor; world.Texture = preset.TextureURL; Block Border, Horizon; Map.GetBlockByName(world, preset.BorderBlock.ToString(), false, out Border); if (Border == Block.None) { Border = Block.Admincrete; } Map.GetBlockByName(world, preset.HorizonBlock.ToString(), false, out Horizon); if (Horizon == Block.None) { Horizon = Block.Water; } world.EdgeBlock = (byte)Border; world.HorizonBlock = (byte)Horizon; world.EdgeLevel = preset.HorizonLevel; world.SidesOffset = preset.SidesOffset; world.CloudsHeight = preset.CloudLevel; world.MaxFogDistance = preset.MaxViewDistance; world.Weather = preset.WeatherType; foreach (Player p in world.Players) { p.SendEnvSettings(); } WorldManager.SaveWorldList(); }
public void Start() { #if !(DEBUG) if (_world.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { _world.Players.Message("&WPropHunt&s requires at least 2 people to play."); return; } #endif if (PropHuntWorlds.Count <= 3) { Logger.Log(LogType.Error, "You must have at least 3 PropHunt maps. Please add some with /PropHunt add [mapname]."); return; } _world = PropHuntWorlds[RandWorld.Next(0, PropHuntWorlds.Count)]; _world.gameMode = GameMode.PropHunt; _startTime = DateTime.Now; Logger.Log(LogType.SystemActivity, "&WPropHunt &S is starting in {0} seconds on world {1}.", TimeDelay, _world.ClassyName); if (StartMode != Game.StartMode.PropHunt) { _task = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromMilliseconds(500)); _world.Players.Message("&WPropHunt &S is starting in {0} seconds on world {1}.", TimeDelay, _world.ClassyName); //Time delay if it is the on-demand instance of the game if ((DateTime.Now - _startTime).TotalSeconds > TimeDelay) { foreach (Player p in PropHuntPlayers) { BeginGame(p); ChooseSeeker(); if (p.IsPropHuntSeeker) { continue; } p.Model = blockId[randBlock.Next(0, blockId.Length)]; string blockName = Map.GetBlockByName(p.Model).ToString(); p.Message("&WYou are disgused as {0}.", blockName); p.iName = null; } } Player.Moving += PlayerMovingHandler; LastChecked = DateTime.Now; //used for intervals _checkIdlesTask = Scheduler.NewTask(CheckIdles).RunForever(TimeSpan.FromMilliseconds(100)); IsOn = true; #if DEBUG Logger.Log(LogType.Warning, "It is on and stuff..."); #endif } Player.Clicking += PlayerClickingHandler; Player.Connected += PlayerConnectedHandler; Player.Disconnected += PlayerDisconnectedHandler; }
private static void SetNewborn(Player p, Life2DZone life, string val) { Block b = Map.GetBlockByName(val); if (b == Block.Undefined) { p.Message("&WUnrecognized block name " + val); return; } life.Newborn = b; p.Message("&yNewborn block set to " + val); }
//Used if the server starts prophunt on launch. This brings the player to the world that the game is in. public void PlayerConnectedHandler(object sender, Events.PlayerConnectedEventArgs e) { PropHuntPlayers.Add(e.Player); e.StartingWorld = _world; if (StartMode != Game.StartMode.PropHunt) { return; } if (PropHuntPlayers.Count() < 2) { e.Player.Message("&WThere are not enough players online to being PropHunt. Please try again later."); Logger.Log(LogType.Warning, "There are not enough players online to being PropHunt. Please try again later."); } else { BeginGame(e.Player); if (PropHuntPlayers.Count(player => player.IsPropHuntSeeker) == 0) { ChooseSeeker(); } if (RoundStarted && TimeDelay == 0) { e.Player.Message("&cYou connected while a round was in progress. You have been made a seeker."); Logger.Log(LogType.SystemActivity, "{0} connected while a round was in progress. They have been made a seeker.", e.Player); e.Player.IsPropHuntSeeker = true; } foreach (Player p in PropHuntPlayers) { if (!p.IsPropHuntSeeker) { p.Model = blockId[randBlock.Next(0, blockId.Length)]; string blockName = Map.GetBlockByName(p.Model).ToString(); p.Message("&HYou are disgused as {0}.", blockName); p.iName = null; } } //Handlers for various things Player.Moving += PlayerMovingHandler; _checkIdlesTask = Scheduler.NewTask(CheckIdles).RunForever(TimeSpan.FromMilliseconds(100)); _task = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromMilliseconds(500)); #if DEBUG Logger.Log(LogType.Warning, "It is on and stuff..."); #endif } }
public Block NextBlockWithParam([NotNull] Player player, ref int param) { if (player == null) { throw new ArgumentNullException("player"); } string jointString = Next(); if (jointString == null) { return(Block.Undefined); } Block targetBlock; int slashIndex = jointString.IndexOf('/'); if (slashIndex != -1) { string blockName = jointString.Substring(0, slashIndex); string paramString = jointString.Substring(slashIndex + 1); targetBlock = Map.GetBlockByName(blockName); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } int tempParam; if (Int32.TryParse(paramString, out tempParam)) { param = tempParam; } else { player.Message("Could not parse \"{0}\" as an integer.", paramString); } } else { targetBlock = Map.GetBlockByName(jointString); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", jointString); } } return(targetBlock); }
// checks for idle players public static void CheckIdles(SchedulerTask task) { foreach (Player p in PropHuntPlayers) { if (p.IdleTime.TotalSeconds < 7) { continue; } if (!(p.IdleTime.TotalSeconds >= 7)) { continue; } if (p.IsSolidBlock || p.IsPropHuntSeeker) { continue; } p.Info.IsHidden = true; p.IsSolidBlock = true; //Gets the coords of the player short x = (short)(p.Position.X / 32 * 32 + 16); short y = (short)(p.Position.Y / 32 * 32 + 16); short z = (short)(p.Position.Z / 32 * 32); Vector3I Pos = new Vector3I(p.Position.X / 32, p.Position.Y / 32, (p.Position.Z - 32) / 32); //Saves the player pos when they were solid for later removing the block p.prophuntSolidPos = Pos; //Converts player's model block into Block.*blockname* Block playerBlock = Map.GetBlockByName(p.Model); //Places the block at the players current location var blockUpdate = new BlockUpdate(null, Pos, playerBlock); if (p.World != null) { if (p.World.Map != null) { p.World.Map.QueueUpdate(blockUpdate); } } p.WorldMap.SetBlock(Pos, playerBlock); p.Message("&cYou are now a solid block. Don't move!"); } }
public Block NextBlock([NotNull] Player player) { if (player == null) { throw new ArgumentNullException("player"); } string blockName = Next(); Block targetBlock = Block.Undefined; if (blockName != null) { targetBlock = Map.GetBlockByName(blockName); if (targetBlock == Block.Undefined) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } } return(targetBlock); }
static bool ParseBlock(string blockName, [CanBeNull] Player player, bool allowNoneBlock, ref Block block) { World world = player == null ? null : player.World; if (Map.GetBlockByName(world, blockName, true, out block)) { if (block != Block.None || allowNoneBlock) { return(true); } else if (player != null) { player.Message("The \"none\" block is not allowed here"); } } else if (player != null) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } return(false); }
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("worldOnlyChat")) != null) { bool worldOnlyChat; if (Boolean.TryParse(tempAttr.Value, out worldOnlyChat)) { world.WorldOnlyChat = worldOnlyChat; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"worldOnlyChat\" attribute of world \"{0}\", assuming NO world only chat.", worldName); } } if ((tempAttr = el.Attribute("realm")) != null) { if (tempAttr.Value == "yes") { world.IsRealm = true; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"realm\" attribute of world \"{0}\", assuming NOT a realm.", worldName); } } 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; 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 = World.DefaultBackupInterval; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default({1}).", worldName, world.BackupInterval.ToMiniString()); } } else { world.BackupInterval = World.DefaultBackupInterval; } if ((tempEl = el.Element("Locked")) != null) { bool locked; if (Boolean.TryParse(tempEl.Value, out locked)) { world.IsLocked = locked; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"Locked\" attribute of world \"{0}\", assuming NOT locked.", worldName); } } if ((tempEl = el.Element("LockedBy")) != null) { world.LockedBy = tempEl.Value; } if ((tempEl = el.Element("LockedOn")) != null) { DateTime lockedOn = DateTime.UtcNow; if (DateTimeUtil.ToDateTime(tempEl.Value, ref lockedOn)) { world.LockedDate = lockedOn; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"LockedOn\" attribute of world \"{0}\", assuming NO lock time.", worldName); } } if ((tempEl = el.Element("UnlockedBy")) != null) { world.UnlockedBy = tempEl.Value; } if ((tempEl = el.Element("UnlockedOn")) != null) { DateTime unlockedOn = DateTime.UtcNow; if (DateTimeUtil.ToDateTime(tempEl.Value, ref unlockedOn)) { world.UnlockedDate = unlockedOn; } else { Logger.Log(LogType.Warning, "WorldManager: Could not parse \"UnlockedOn\" attribute of world \"{0}\", assuming NO unlock time.", worldName); } } XElement blockEl = el.Element(BlockDB.XmlRootName); if (blockEl != null) { world.BlockDB.LoadSettings(blockEl); } 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 { world.EdgeBlock = block; } } if ((tempAttr = envEl.Attribute("side")) != null) { Block block = Map.GetBlockByName(tempAttr.Value); if (block == Block.Undefined) { world.EdgeBlock = Block.Admincrete; Logger.Log(LogType.Warning, "WorldManager: Could not parse \"side\" attribute of Environment settings for world \"{0}\", assuming default(Admincrete).", worldName); } else { world.SideBlock = block; } } if ((tempAttr = envEl.Attribute("cloudCC")) != null) { world.CloudColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("fogCC")) != null) { world.FogColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("skyCC")) != null) { world.SkyColor = System.Drawing.ColorTranslator.FromHtml(tempAttr.Value).ToArgb(); } if ((tempAttr = envEl.Attribute("levelCC")) != null) { world.EdgeLevel = Convert.ToInt16(tempAttr.Value); } if ((tempAttr = envEl.Attribute("edgeCC")) != null) { world.EdgeBlock = (Block)Byte.Parse(tempAttr.Value); } if ((tempAttr = envEl.Attribute("sideCC")) != null) { world.SideBlock = (Block)Byte.Parse(tempAttr.Value); } if ((tempAttr = envEl.Attribute("textureCC")) != null) { world.textureURL = tempAttr.Value; } if ((tempAttr = envEl.Attribute("hacks")) != null) { world.Hax = Convert.ToBoolean(tempAttr.Value); } } 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); }
/// <summary> Parses next parameter as a Minecraft block name. /// Allows an optional integer parameter to follow the block name after a slash, e.g. "BlockName/#" /// Messages warnings directly to the player in case of problems. </summary> /// <param name="player"> Player to send warnings to (if any come up). </param> /// <param name="allowNoneBlock"> Whether "none"/"skip" blocktype is allowed. </param> /// <param name="block"> On success, this is set to the given block type. /// On failure, this is set to Block.None </param> /// <param name="param"> Optional integer parameter. Set to 1 if not given. </param> /// <returns> True on success. /// False if no more parameters were given; /// if next parameter could not be parsed as a block name; /// if optional parameter was given but was not an integer; /// or if "none" blocktype was given and allowNoneBlock is false. </returns> public bool NextBlockWithParam([CanBeNull] Player player, bool allowNoneBlock, out Block block, out int param) { block = Block.None; param = 1; string jointString = Next(); if (jointString == null) { return(false); } int slashIndex = jointString.IndexOf('/'); if (slashIndex != -1) { string blockName = jointString.Substring(0, slashIndex); string paramString = jointString.Substring(slashIndex + 1); if (Map.GetBlockByName(blockName, true, out block)) { if (block == Block.None && !allowNoneBlock) { if (player != null) { player.Message("The \"none\" block is not allowed here"); } } else if (Int32.TryParse(paramString, out param)) { return(true); } else if (player != null) { player.Message("Could not parse \"{0}\" as an integer.", paramString); } } else if (player != null) { player.Message("Unrecognized blocktype \"{0}\"", blockName); } } else { if (Map.GetBlockByName(jointString, true, out block)) { if (block != Block.None || allowNoneBlock) { return(true); } else if (player != null) { player.Message("The \"none\" block is not allowed here"); } } else if (player != null) { player.Message("Unrecognized blocktype \"{0}\"", jointString); } } return(false); }
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; } } } } }
void Draw(Player player, Command command, DrawMode mode) { if (!player.Can(Permissions.Draw)) { world.NoAccessMessage(player); return; } if (player.drawingInProgress) { player.Message("Another draw command is already in progress. Please wait."); return; } string blockName = command.Next(); Block block; if (blockName == null || blockName == "") { if (mode == DrawMode.Cuboid) { player.Message("Usage: " + Color.Help + "/cuboid blockName" + Color.Sys + " or " + Color.Help + "/cub blockName"); } else { player.Message("Usage: " + Color.Help + "/ellipsoid blockName" + Color.Sys + " or " + Color.Help + "/ell blockName"); } return; } try { block = Map.GetBlockByName(blockName); } catch (Exception) { player.Message("Unknown block name: " + blockName); return; } player.tag = block; Permissions permission = Permissions.Build; switch (block) { case Block.Admincrete: permission = Permissions.PlaceAdmincrete; break; case Block.Air: permission = Permissions.Delete; break; case Block.Water: case Block.StillWater: permission = Permissions.PlaceWater; break; case Block.Lava: case Block.StillLava: permission = Permissions.PlaceLava; break; } if (!player.Can(permission)) { player.Message("You are not allowed to draw with this block."); return; } player.marksExpected = 2; player.markCount = 0; player.marks.Clear(); player.Message(mode.ToString() + ": Place a block or type /mark to use your location."); if (mode == DrawMode.Cuboid) { player.selectionCallback = DrawCuboid; } else { player.selectionCallback = DrawEllipsoid; } }