Controller for setting and checking per-rank permissions and per-player exceptions. Used by World.AccessSecurity, World.BuildSecurity, and Zone.
Inheritance: ICloneable, INotifiesOnChange
示例#1
0
 public WorldListEntry( WorldListEntry original ) {
     name = original.Name;
     Hidden = original.Hidden;
     Backup = original.Backup;
     accessSecurity = new SecurityController( original.accessSecurity );
     buildSecurity = new SecurityController( original.buildSecurity );
 }
示例#2
0
 public SecurityController( SecurityController other ) {
     if( other == null ) throw new ArgumentNullException( "other" );
     if( other.NoRankRestriction ) {
         MinRank = null;
     } else {
         MinRank = other.MinRank;
     }
     includedPlayers = new Dictionary<string, PlayerInfo>( other.includedPlayers );
     excludedPlayers = new Dictionary<string, PlayerInfo>( other.excludedPlayers );
     UpdatePlayerListCache();
 }
示例#3
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];
 }
示例#4
0
文件: World.cs 项目: fragmer/fCraft
 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];
 }
示例#5
0
 /// <summary> Creates a copy of an existing controller. </summary>
 public SecurityController([NotNull] SecurityController other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     minRank = other.minRank;
     lock (other.locker) {
         includedPlayers = new Dictionary <string, PlayerInfo>(other.includedPlayers);
         excludedPlayers = new Dictionary <string, PlayerInfo>(other.excludedPlayers);
     }
     UpdatePlayerListCache();
 }
示例#6
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;
            UpdatePlayerList();
			for (int i = 0; i < Enum.GetValues(typeof(TaskCategory)).Length; ++i)
				_physSchedulers.Add(new PhysScheduler(this));
        }
示例#7
0
 public SecurityController(SecurityController other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     if (other.NoRankRestriction)
     {
         MinRank = null;
     }
     else
     {
         MinRank = other.MinRank;
     }
     includedPlayers = new Dictionary <string, PlayerInfo>(other.includedPlayers);
     excludedPlayers = new Dictionary <string, PlayerInfo>(other.excludedPlayers);
     UpdatePlayerListCache();
 }
示例#8
0
        public WorldListEntry( XElement el ) {
            XAttribute temp;

            if( (temp = el.Attribute( "name" )) == null ) {
                throw new FormatException( "WorldListEntity: Cannot parse XML: Unnamed worlds are not allowed." );
            }
            if( !World.IsValidName( temp.Value ) ) {
                throw new FormatException( "WorldListEntity: Cannot parse XML: Invalid world name skipped \"" + temp.Value + "\"." );
            }
            name = temp.Value;

            if( (temp = el.Attribute( "hidden" )) != null && !String.IsNullOrEmpty( temp.Value ) ) {
                bool hidden;
                if( Boolean.TryParse( temp.Value, out hidden ) ) {
                    Hidden = hidden;
                } else {
                    throw new FormatException( "WorldListEntity: Cannot parse XML: Invalid value for \"hidden\" attribute." );
                }
            } else {
                Hidden = false;
            }

            if( (temp = el.Attribute( "backup" )) != null && !String.IsNullOrEmpty( temp.Value ) ) { // TODO: Make per-world backup settings actually work
                if( Array.IndexOf( World.BackupEnum, temp.Value ) != -1 ) {
                    Backup = temp.Value;
                } else {
                    throw new FormatException( "WorldListEntity: Cannot parse XML: Invalid value for \"backup\" attribute." );
                }
            } else {
                Backup = World.BackupEnum[5];
            }

            if( el.Element( "accessSecurity" ) != null ) {
                accessSecurity = new SecurityController( el.Element( "accessSecurity" ) );
            }else if( (temp = el.Attribute( "access" )) != null && !String.IsNullOrEmpty( temp.Value ) ) {
                accessSecurity.MinRank = RankManager.ParseRank( temp.Value );
            }

            if( el.Element( "buildSecurity" ) != null ) {
                buildSecurity = new SecurityController( el.Element( "buildSecurity" ) );
            }else if( (temp = el.Attribute( "build" )) != null && !String.IsNullOrEmpty( temp.Value ) ) {
                buildSecurity.MinRank = RankManager.ParseRank( temp.Value );
            }
        }
示例#9
0
        public Zone([NotNull] XContainer root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            Name = root.Element("name").Value;

            if (root.Element("created") != null)
            {
                XElement created = root.Element("created");
                CreatedBy = created.Attribute("by").Value;
                DateTime createdDate;
                created.Attribute("on").Value.ToDateTime(out createdDate);
                CreatedDate = createdDate;
            }

            if (root.Element("edited") != null)
            {
                XElement edited = root.Element("edited");
                EditedBy = edited.Attribute("by").Value;
                DateTime editedDate;
                edited.Attribute("on").Value.ToDateTime(out editedDate);
                EditedDate = editedDate;
            }

            XElement temp = root.Element(BoundingBox.XmlRootName);

            if (temp == null)
            {
                throw new SerializationException("No BoundingBox specified for zone.");
            }
            Bounds = new BoundingBox(temp);

            temp = root.Element(SecurityController.XmlRootName);
            if (temp == null)
            {
                throw new SerializationException("No SecurityController specified for zone.");
            }
            Controller = new SecurityController(temp, PlayerDB.IsLoaded);
        }
示例#10
0
        public Zone([NotNull] XContainer root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            // ReSharper disable PossibleNullReferenceException
            Name = root.Element("name").Value;

            if (root.Element("created") != null)
            {
                XElement created = root.Element("created");
                CreatedBy   = PlayerDB.FindPlayerInfoExact(created.Attribute("by").Value);
                CreatedDate = DateTime.Parse(created.Attribute("on").Value);
            }

            if (root.Element("edited") != null)
            {
                XElement edited = root.Element("edited");
                EditedBy   = PlayerDB.FindPlayerInfoExact(edited.Attribute("by").Value);
                EditedDate = DateTime.Parse(edited.Attribute("on").Value);
            }

            XElement temp = root.Element(BoundingBox.XmlRootElementName);

            if (temp == null)
            {
                throw new FormatException("No BoundingBox specified for zone.");
            }
            Bounds = new BoundingBox(temp);

            temp = root.Element(SecurityController.XmlRootElementName);
            if (temp == null)
            {
                throw new FormatException("No SecurityController specified for zone.");
            }
            Controller = new SecurityController(temp, true);
            // ReSharper restore PossibleNullReferenceException
        }
示例#11
0
        public Zone([NotNull] XContainer root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            Name = root.Element("name").Value;

            if (root.Element("created") != null)
            {
                XElement created = root.Element("created");
                CreatedBy   = created.Attribute("by").Value;
                CreatedDate = DateTime.Parse(created.Attribute("on").Value);
            }

            if (root.Element("edited") != null)
            {
                XElement edited = root.Element("edited");
                EditedBy   = edited.Attribute("by").Value;
                EditedDate = DateTime.Parse(edited.Attribute("on").Value);
            }

            XElement temp = root.Element(BoundingBox.XmlRootElementName);

            if (temp == null)
            {
                throw new FormatException("No BoundingBox specified for zone.");
            }
            Bounds = new BoundingBox(temp);

            temp = root.Element(SecurityController.XmlRootElementName);
            if (temp == null)
            {
                throw new FormatException("No SecurityController specified for zone.");
            }
            Controller = new SecurityController(temp, true);
        }
示例#12
0
        public Zone(NbtCompound tag)
        {
            NbtCompound boundsTag = tag.Get <NbtCompound>("Bounds");

            if (boundsTag == null)
            {
                throw new SerializationException("Bounds missing from zone definition tag.");
            }
            Bounds = new BoundingBox(boundsTag);

            NbtCompound controllerTag = tag.Get <NbtCompound>("Controller");

            if (controllerTag == null)
            {
                throw new SerializationException("Controller missing from zone definition tag.");
            }
            Controller = new SecurityController(controllerTag);

            var createdByTag   = tag.Get <NbtString>("CreatedBy");
            var createdDateTag = tag.Get <NbtLong>("CreatedDate");

            if (createdByTag != null && createdDateTag != null)
            {
                CreatedBy   = createdByTag.Value;
                CreatedDate = DateTimeUtil.TryParseDateTime(createdDateTag.Value);
            }

            var editedByTag   = tag.Get <NbtString>("EditedBy");
            var editedDateTag = tag.Get <NbtLong>("EditedDate");

            if (editedByTag != null && editedDateTag != null)
            {
                EditedBy   = editedByTag.Value;
                EditedDate = DateTimeUtil.TryParseDateTime(editedDateTag.Value);
            }
        }
示例#13
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;
            UpdatePlayerList();

            Buildable = true;
            Deletable = true;
            BlockDefs = new BlockDefinition[256];
            for (int i = 0; i < BlockDefs.Length; i++)
            {
                BlockDefs[i] = BlockDefinition.GlobalDefs[i];
            }
        }
示例#14
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;
     UpdatePlayerList();
     for (int i = 0; i < Enum.GetValues(typeof(TaskCategory)).Length; ++i)
         _physSchedulers.Add(new PhysScheduler(this));
 }
示例#15
0
        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;
                        }
                    }
                }
            }
        }
示例#16
0
文件: Zone.cs 项目: GlennMR/800craft
        public Zone( [NotNull] XContainer root )
        {
            if ( root == null )
                throw new ArgumentNullException( "root" );
            // ReSharper disable PossibleNullReferenceException
            Name = root.Element( "name" ).Value;

            if ( root.Element( "created" ) != null ) {
                XElement created = root.Element( "created" );
                CreatedBy = created.Attribute( "by" ).Value;
                CreatedDate = DateTime.Parse( created.Attribute( "on" ).Value );
            }

            if ( root.Element( "edited" ) != null ) {
                XElement edited = root.Element( "edited" );
                EditedBy = edited.Attribute( "by" ).Value;
                EditedDate = DateTime.Parse( edited.Attribute( "on" ).Value );
            }

            XElement temp = root.Element( BoundingBox.XmlRootElementName );
            if ( temp == null )
                throw new FormatException( "No BoundingBox specified for zone." );
            Bounds = new BoundingBox( temp );

            temp = root.Element( SecurityController.XmlRootElementName );
            if ( temp == null )
                throw new FormatException( "No SecurityController specified for zone." );
            Controller = new SecurityController( temp, true );
            // ReSharper restore PossibleNullReferenceException
        }
示例#17
0
文件: World.cs 项目: fragmer/fCraft
        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;
                        }
                    }
                }
            }
        }
示例#18
0
文件: Zone.cs 项目: fragmer/fCraft
        public Zone( NbtCompound tag ) {
            NbtCompound boundsTag = tag.Get<NbtCompound>( "Bounds" );
            if( boundsTag == null ) {
                throw new SerializationException( "Bounds missing from zone definition tag." );
            }
            Bounds = new BoundingBox( boundsTag );

            NbtCompound controllerTag = tag.Get<NbtCompound>( "Controller" );
            if( controllerTag == null ) {
                throw new SerializationException( "Controller missing from zone definition tag." );
            }
            Controller = new SecurityController( controllerTag );

            var createdByTag = tag.Get<NbtString>( "CreatedBy" );
            var createdDateTag = tag.Get<NbtLong>( "CreatedDate" );
            if( createdByTag != null && createdDateTag != null ) {
                CreatedBy = createdByTag.Value;
                CreatedDate = DateTimeUtil.TryParseDateTime( createdDateTag.Value );
            }

            var editedByTag = tag.Get<NbtString>( "EditedBy" );
            var editedDateTag = tag.Get<NbtLong>( "EditedDate" );
            if( editedByTag != null && editedDateTag != null ) {
                EditedBy = editedByTag.Value;
                EditedDate = DateTimeUtil.TryParseDateTime( editedDateTag.Value );
            }
        }
示例#19
0
文件: Zone.cs 项目: fragmer/fCraft
        public Zone( [NotNull] XContainer root ) {
            if( root == null ) throw new ArgumentNullException( "root" );
            Name = root.Element( "name" ).Value;

            if( root.Element( "created" ) != null ) {
                XElement created = root.Element( "created" );
                CreatedBy = created.Attribute( "by" ).Value;
                DateTime createdDate;
                created.Attribute( "on" ).Value.ToDateTime( out createdDate );
                CreatedDate = createdDate;
            }

            if( root.Element( "edited" ) != null ) {
                XElement edited = root.Element( "edited" );
                EditedBy = edited.Attribute( "by" ).Value;
                DateTime editedDate;
                edited.Attribute( "on" ).Value.ToDateTime( out editedDate );
                EditedDate = editedDate;
            }

            XElement temp = root.Element( BoundingBox.XmlRootName );
            if( temp == null ) throw new SerializationException( "No BoundingBox specified for zone." );
            Bounds = new BoundingBox( temp );

            temp = root.Element( SecurityController.XmlRootName );
            if( temp == null ) throw new SerializationException( "No SecurityController specified for zone." );
            Controller = new SecurityController( temp, PlayerDB.IsLoaded );
        }