Beispiel #1
0
 /// <summary> Replaces this instance's access permissions
 /// with a copy of the source's access permissions </summary>
 public void CloneAccess(AccessController source)
 {
     Min = source.Min;
     Max = source.Max;
     // TODO this sould be atomic
     Whitelisted.Clear(); Whitelisted.AddRange(source.Whitelisted);
     Blacklisted.Clear(); Blacklisted.AddRange(source.Blacklisted);
 }
        private int onWhitelist(long handle, GoString goUrl, IntPtr categoriesPtr, int categoryLen)
        {
            int[] categories = new int[categoryLen];

            Marshal.Copy(categoriesPtr, categories, 0, categoryLen);
            Session session = new Session(handle, new Request(handle), new Response(handle));
            string  url     = goUrl.AsString;

            return(Whitelisted?.Invoke(session, url, categories) ?? 0);
        }
Beispiel #3
0
        public bool CheckDetailed(Player p, bool ignoreRankPerm = false)
        {
            AccessResult result = Check(p);

            if (result == AccessResult.Allowed)
            {
                return(true);
            }
            if (result == AccessResult.Whitelisted)
            {
                return(true);
            }
            if (result == AccessResult.AboveMaxRank && ignoreRankPerm)
            {
                return(true);
            }
            if (result == AccessResult.BelowMinRank && ignoreRankPerm)
            {
                return(true);
            }

            if (result == AccessResult.Blacklisted)
            {
                Player.Message(p, "You are blacklisted from {0} {1}", ActionIng, ColoredName);
                return(false);
            }

            string whitelist = "";

            if (Whitelisted.Count > 0)
            {
                whitelist = "(and " + Whitelisted.Join(pl => PlayerInfo.GetColoredName(p, pl)) + "%S) ";
            }

            if (result == AccessResult.BelowMinRank)
            {
                Player.Message(p, "Only {2}%S+ {3}may {0} {1}",
                               Action, ColoredName, Group.GetColoredName(Min), whitelist);
            }
            else if (result == AccessResult.AboveMaxRank)
            {
                Player.Message(p, "Only {2} %Sand below {3}may{0} {1}",
                               Action, ColoredName, Group.GetColoredName(Max), whitelist);
            }
            return(false);
        }
        public AccessResult Check(string name, LevelPermission rank)
        {
            if (Blacklisted.CaselessContains(name))
            {
                return(AccessResult.Blacklisted);
            }
            if (Whitelisted.CaselessContains(name))
            {
                return(AccessResult.Whitelisted);
            }

            if (rank < Min)
            {
                return(AccessResult.BelowMinRank);
            }
            if (rank > Max && MaxCmd != null && !CommandExtraPerms.Find(MaxCmd, 1).UsableBy(rank))
            {
                return(AccessResult.AboveMaxRank);
            }
            return(AccessResult.Allowed);
        }
Beispiel #5
0
        /// <summary> Prevents a player from acessing these permissions. </summary>
        /// <returns> true if the target is blacklisted, false if the given player
        /// had insufficient permission to blacklist the target. </returns>
        public bool Blacklist(Player p, string target)
        {
            if (!CheckList(p, target, false))
            {
                return(false);
            }
            if (Blacklisted.CaselessContains(target))
            {
                Player.Message(p, "\"{0}\" is already blacklisted.", target); return(true);
            }

            bool removed = true;

            if (!Whitelisted.CaselessRemove(target))
            {
                Blacklisted.Add(target);
                removed = false;
            }
            OnListChanged(p, target, false, removed);
            return(true);
        }
Beispiel #6
0
        /// <summary> Returns the allowed state for the given player. </summary>
        public AccessResult Check(string name, Group rank)
        {
            if (Blacklisted.CaselessContains(name))
            {
                return(AccessResult.Blacklisted);
            }
            if (Whitelisted.CaselessContains(name))
            {
                return(AccessResult.Whitelisted);
            }

            if (rank.Permission < Min)
            {
                return(AccessResult.BelowMinRank);
            }
            if (rank.Permission > Max && MaxCmd != null && rank.Permission < CommandExtraPerms.MinPerm(MaxCmd))
            {
                return(AccessResult.AboveMaxRank);
            }
            return(AccessResult.Allowed);
        }
        public bool Blacklist(Player p, LevelPermission plRank, Level lvl, string target)
        {
            if (!CheckList(p, plRank, target, false))
            {
                return(false);
            }
            if (Blacklisted.CaselessContains(target))
            {
                p.Message("{0} %Sis already blacklisted.", p.FormatNick(target));
                return(true);
            }

            bool removed = true;

            if (!Whitelisted.CaselessRemove(target))
            {
                Blacklisted.Add(target);
                removed = false;
            }
            OnListChanged(p, lvl, target, false, removed);
            return(true);
        }
        public bool Whitelist(Player p, LevelPermission plRank, Level lvl, string target)
        {
            if (!CheckList(p, plRank, target, true))
            {
                return(false);
            }
            if (Whitelisted.CaselessContains(target))
            {
                p.Message("{0} %Sis already whitelisted.", PlayerInfo.GetColoredName(p, target));
                return(true);
            }

            bool removed = true;

            if (!Blacklisted.CaselessRemove(target))
            {
                Whitelisted.Add(target);
                removed = false;
            }
            OnListChanged(p, lvl, target, true, removed);
            return(true);
        }
        public bool CheckDetailed(Player p, LevelPermission plRank)
        {
            AccessResult access = Check(p.name, plRank);

            if (access == AccessResult.Allowed)
            {
                return(true);
            }
            if (access == AccessResult.Whitelisted)
            {
                return(true);
            }

            if (access == AccessResult.Blacklisted)
            {
                p.Message("You are blacklisted from {0} {1}", ActionIng, ColoredName);
                return(false);
            }

            string whitelist = "";

            if (Whitelisted.Count > 0)
            {
                whitelist = "(and " + Whitelisted.Join(pl => p.FormatNick(pl)) + "%S) ";
            }

            if (access == AccessResult.BelowMinRank)
            {
                p.Message("Only {2}%S+ {3}may {0} {1}",
                          Action, ColoredName, Group.GetColoredName(Min), whitelist);
            }
            else if (access == AccessResult.AboveMaxRank)
            {
                p.Message("Only {2} %Sand below {3}may {0} {1}",
                          Action, ColoredName, Group.GetColoredName(Max), whitelist);
            }
            return(false);
        }
Beispiel #10
0
        /// <summary> Returns the allowed state for the given player. </summary>
        public LevelAccess Check(Player p)
        {
            if (Blacklisted.CaselessContains(p.name))
            {
                return(LevelAccess.Blacklisted);
            }
            if (Whitelisted.CaselessContains(p.name))
            {
                return(LevelAccess.Whitelisted);
            }

            if (p.Rank < Min)
            {
                return(LevelAccess.BelowMinRank);
            }
            string maxCmd = IsVisit ? "pervisitmax" : "perbuildmax";

            if (p.Rank > Max && !p.group.CanExecute(maxCmd))
            {
                return(LevelAccess.AboveMaxRank);
            }
            return(LevelAccess.Allowed);
        }
 public int OnWhitelisted(Session session, string url, int[] categories)
 {
     return(Whitelisted?.Invoke(session, url, categories) ?? 0);
 }