Beispiel #1
0
        public bool Load()
        {
            string configPath = SDTM.API.configDataPath;

            if (FileUtils.ensureDirectoryExists(configPath))
            {
                configPath = configPath + "/experm.xml";

                if (!File.Exists(configPath))
                {
                    return(false);
                }

                XmlDocument xmlDoc = new XmlDocument();
                try{
                    xmlDoc.Load(configPath);
                }
                catch (XmlException e) {
                    Log.Error(string.Format("[ExPerm] Could not Load Config: {0}", e.Message));
                    return(false);
                }

                XmlNode rootNode         = xmlDoc.DocumentElement;
                XmlNode defaultGroupAttr = rootNode.Attributes.GetNamedItem("defaultgroup");
                if (defaultGroupAttr != null)
                {
                    this.DefaultGroupName = defaultGroupAttr.Value;
                }
                foreach (XmlNode configNode in rootNode.ChildNodes)
                {
                    switch (configNode.Name.ToLower())
                    {
                    case "groups":
                        foreach (XmlNode groupNode in configNode.ChildNodes)
                        {
                            PermissionGroup g = new PermissionGroup(groupNode);
                            Log.Out("Added Group: " + g.Name);
                            this.Groups.Add(g.Name, g);
                        }
                        break;

                    case "users":
                        foreach (XmlNode userNode in configNode.ChildNodes)
                        {
                            PermissionUser u = new PermissionUser(userNode);
                            this.Users.Add(u.SteamId, u);
                        }
                        break;
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public bool AddGroup(string groupName)
        {
            if (!Groups.ContainsKey(groupName))
            {
                PermissionGroup grp = new PermissionGroup(groupName);
                Groups.Add(groupName, grp);
            }

            return(this.Save());
        }
Beispiel #3
0
        public bool SetGroupPermission(string groupName, string permission, bool allowed)
        {
            if (!this.Groups.ContainsKey(groupName))
            {
                return(false);
            }

            PermissionGroup grp = this.Groups[groupName];

            if (grp.SetPermission(permission, allowed))
            {
                return(this.Save());
            }

            return(false);
        }
Beispiel #4
0
        public void ProcessGroupCommand(List <string> _params, CommandSenderInfo _senderInfo)
        {
            string userCommand = "";

            if (_params.Count == 1)
            {
                userCommand = "list";
            }
            else
            {
                userCommand = _params [1].ToLower();
            }

            SDTM.API thisMod = SDTM.API.Instance;

            string groupName;

            switch (userCommand)
            {
            case "list":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.list") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (SDTM.API.Permissions.Groups.Count > 0)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Groups List");
                    foreach (KeyValuePair <string, PermissionGroup> kvp in SDTM.API.Permissions.Groups)
                    {
                        PermissionGroup grp  = kvp.Value;
                        string          sOut = grp.Name;
                        if (grp.Name == SDTM.API.Permissions.DefaultGroupName)
                        {
                            sOut += "(Default Group)";
                        }
                        SdtdConsole.Instance.Output(sOut);
                    }
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] No ExPerm Groups found.");
                }

                break;

            case "info":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.info") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 3)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count.");
                    return;
                }

                groupName = _params [2].ToLower();

                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group not Found.");
                    return;
                }

                PermissionGroup pGrp = SDTM.API.Permissions.Groups [groupName];
                SdtdConsole.Instance.Output("[ExPerm] Group Information");
                SdtdConsole.Instance.Output("Name: " + pGrp.Name);
                SdtdConsole.Instance.Output("Default: " + (pGrp.Name == SDTM.API.Permissions.DefaultGroupName ? "Yes" : "No"));
                SdtdConsole.Instance.Output("Permissions: ");
                Dictionary <string, bool> perms = pGrp.Permissions.GetAll();
                foreach (KeyValuePair <string, bool> kvp in perms)
                {
                    SdtdConsole.Instance.Output(kvp.Key + " - " + (kvp.Value == true?"Allowed":"Denied"));
                }
                break;

            case "create":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.create") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 3)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count.");
                    return;
                }

                groupName = _params [2].ToLower();

                if (SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group Already Exists");
                    return;
                }

                if (SDTM.API.Permissions.AddGroup(groupName))
                {
                    SDTM.API.Permissions.Save();
                    SdtdConsole.Instance.Output("[ExPerm] Group created Successfully.");
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] Could not create Group.");
                }

                break;

            case "rename":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.modify") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 4)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count.");
                    return;
                }


                groupName = _params [2].ToLower();

                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group not Found.");
                    return;
                }

                string newGroupName = _params [3].ToLower();

                if (SDTM.API.Permissions.Groups.ContainsKey(newGroupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group already Exists: " + newGroupName);
                    return;
                }

                PermissionGroup grp1 = SDTM.API.Permissions.Groups [groupName];

                if (grp1 == null)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group Object not Found: " + groupName);
                    return;
                }

                grp1.Name = newGroupName;
                SDTM.API.Permissions.Groups.Remove(groupName);
                SDTM.API.Permissions.Groups.Add(newGroupName, grp1);
                foreach (KeyValuePair <string, PermissionUser> grp1User in SDTM.API.Permissions.Users)
                {
                    PermissionUser grpRenUser = grp1User.Value;
                    if (grpRenUser.Group == groupName)
                    {
                        grpRenUser.Group = newGroupName;
                        SDTM.API.Permissions.Users [grp1User.Key] = grpRenUser;
                    }
                }

                if (groupName == SDTM.API.Permissions.DefaultGroupName)
                {
                    SDTM.API.Permissions.DefaultGroupName = newGroupName;
                }
                SDTM.API.Permissions.Save();
                SdtdConsole.Instance.Output("[ExPerm] Group renamed successfully.");
                break;

            case "remove":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.remove") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 3)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count.");
                    return;
                }


                groupName = _params [2].ToLower();

                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group not Found.");
                    return;
                }

                if (groupName == SDTM.API.Permissions.DefaultGroupName)
                {
                    SdtdConsole.Instance.Output("[ExPerm] You can not remove the default group.");
                    return;
                }

                if (SDTM.API.Permissions.Groups.Remove(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group removed.");
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] Could not remove Group.");
                }
                break;

            case "default":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.default") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 3)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count.");
                    return;
                }

                groupName = _params [2].ToLower();

                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group not Found.");
                    return;
                }

                SDTM.API.Permissions.DefaultGroupName = groupName;
                SDTM.API.Permissions.Save();

                SdtdConsole.Instance.Output("[ExPerm] Default Group Updated");
                break;

            case "setperm":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.setperm") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 5)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Paramater Count.");
                    return;
                }

                groupName = _params [2].ToLower();
                string permName   = _params [3];
                bool   bIsAllowed = _params [4].ToLower() == "true" ? true : false;
                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group could not be Found.");
                    return;
                }

                if (SDTM.API.Permissions.Groups [groupName].SetPermission(permName, bIsAllowed))
                {
                    SDTM.API.Permissions.Save();
                    SdtdConsole.Instance.Output("[ExPerm] Group permission set Successfully.");
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] Could not set Group Permission.");
                }

                break;

            case "removeperm":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.group.removeperm") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 4)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Paramater Count.");
                    return;
                }

                groupName = _params [2].ToLower();
                string sPermName = _params [3];

                if (!SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group could not be Found.");
                    return;
                }

                if (SDTM.API.Permissions.Groups [groupName].RemovePermission(sPermName))
                {
                    SDTM.API.Permissions.Save();
                    SdtdConsole.Instance.Output("[ExPerm] Group permission removed Successfully.");
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] Could not remove Group Permission.");
                }
                break;

            case "clearperms":
                if (SDTM.API.Permissions.isAllowed(_senderInfo.RemoteClientInfo, "permissions.user.removeperm") == false)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Permission Denied");
                    return;
                }

                if (_params.Count != 3)
                {
                    SdtdConsole.Instance.Output("[ExPerm] Invalid Parameter Count");
                    return;
                }

                groupName = _params [2].ToLower();

                if (SDTM.API.Permissions.Groups.ContainsKey(groupName))
                {
                    PermissionGroup setPermGroup = SDTM.API.Permissions.Groups [groupName];

                    if (setPermGroup.Permissions.RemoveAll())
                    {
                        SDTM.API.Permissions.Save();
                        SdtdConsole.Instance.Output("[ExPerm] Permissions Cleared Successfully.");
                    }
                    else
                    {
                        SdtdConsole.Instance.Output("[ExPerm] Could not clear Group Permissions.");
                    }
                }
                else
                {
                    SdtdConsole.Instance.Output("[ExPerm] Group not found: " + groupName);
                }
                break;
            }
        }