Solved Remove users from permission

Discussion in 'Rust Development' started by Maik8, Jun 30, 2017.

  1. Hey guys, i am kinda new to Oxide plugins.
    So all i want to do is to write a methode that removes every user from a single permission.
    Here is what i came up with:

    Code:
    void Loaded()
                {
                    ClearPermission("kits.revolver");            if (permission.UserHasPermission("76561198037281736", "kits.revolver")) // this is for debugging
                {
                    Puts("failed");
                }
                else
                {
                    Puts("Success!");
                }
                }void ClearPermission(string perm)
            {
                foreach (var item in permission.GetPermissionUsers(perm))
                {
                    permission.RevokeUserPermission(item, perm);
                    Puts("Removed permission: {0} from player {1}", perm, item); // just for debuging
                }
            }
    If i just use this methode, i get this as output:
    Code:
    [DMRights] DMRights loading...
    [DMRights] Removed permission: kits.revolver from player 76561198037281736(Maik8)
    [DMRights] failed
    
    but i still have the permission, so it does not remove me the permission, am i missing something or so?
     
  2. An example for how to remove all users from a group. When you get all the users it does not just return a user id, it will return: 76561198167856311 (Unnamed) for example. Thats why in my example I used regex to get the user name from the string. And I get the first 17 characters as a steam ID is always 17 chars long.
    Code:
            void WipeGroup(string name)
            {
                string[] players = permission.GetUsersInGroup(name);
                for (var i = 0; i < players.Count(); i++)
                {
                    string raw, id, user; raw = players[i];
                    id = raw.Substring(0, 17);
                    user = Regex.Replace(raw, "[^a-zA-Z -]", string.Empty);
                    permission.RemoveUserGroup(id, name);
                    if (!permission.UserHasGroup(id, name)) PrintWarning(""+user+" has been removed from group "+name+"");
                    else PrintWarning("" + user + " was not removed from group " + name + "");
                }
            }
    [DOUBLEPOST=1498793553][/DOUBLEPOST]You should be able to adjust this code for permissions pretty easily.
     
  3. Wulf

    Wulf Community Admin

    Code:
    if (!permission.UserHasGroup(id, name)) PrintWarning(user + " has been removed from group " + name);
    No need for the extra quotation marks. ;)

    Could even use string interpolation if you'd like:
    Code:
    if (!permission.UserHasGroup(id, name)) PrintWarning($"{user} has been removed from group {name}");
     
  4. Funny thing is I tried that. But forgot I have to use {variable name} instead of {0}, {1} lol. :p
     
  5. Wulf

    Wulf Community Admin

    Using the way you tried would work, but you'd wrap it in string.Format instead of using the $.
     
  6. Thanks for the help guys, i solved it now as follow, since i don't use groups for the permissions that are used in this case (permissions for kits buyable throught a shop, with money you earn by killing ppl):
    Code:
    void ClearPermission(string perm)
            {
                foreach (string item in permission.GetPermissionUsers(perm))
                {
                    permission.RevokeUserPermission(item.Substring(0, item.LastIndexOf('(')), perm);
                    Puts("Removed permission: {0} from player {1}", perm, item);
                }
            }
    The item looks like 76561198167856311 (Unnamed) as DylanSMR already said, wich i did forget about.
    now i just remove the (Unnamed) part (in this case) and it works.