Is there a way to get every user in a group? I searched around and I cannot find a method. I also searched: Oxide/Permission.cs at master · OxideMod/Oxide · GitHub
Solved Getting users in group?
Discussion in 'Rust Development' started by DylanSMR, Jul 18, 2016.
-
The link you posted has a method GetUsersInGroup.
-
Oh does it? Thanks
-
Yes. I have a personal plugin for that that get players with granted permissions. I think if you decopile the assembly you will find what you need.
Code:[LibraryFunction("GetUserGroups")] [ConsoleCommand("recolectarpermisos")] void RecolectarPermisos(ConsoleSystem.Arg arg) { if (arg.Player() != null && arg.Player().IsAdmin()) { int a = 0; AbrirConexion(Conexion); foreach (var data in buscarusuarios.Players) { string permisos = string.Join(", ", this.permission.GetUserPermissions(data.Value.SteamID)); string usuario = data.Value.Name; usuario = usuario.Replace("'", ""); if (permisos != "") { string PonerInfoUserSTRING = "INSERT INTO usuarios(id,usuario,steamid,permisos) VALUES(null,'" + usuario + "','" + data.Value.SteamID + "','" + permisos + "')"; MySqlCommand BuscarDatosCOMANDO = new MySqlCommand(PonerInfoUserSTRING, Conexion); BuscarDatosCOMANDO.ExecuteNonQuery(); } } CerrarConexion(Conexion); } }
You probably will make a better code than mine.
-
It returns a string for each name so I did it like:
Code:foreach(var player in permission.GetUsersInGroup(name)) { object addPlayer = FindPlayerU(player); BasePlayer target = (BasePlayer)addPlayer; GrantPermission(newcount, target); } -
Since you're not using the Oxide API for MySQL, please consider the following: Using MySQL without callbacks | Oxide
The entire server will completly stop until your MySQL query is completed, which might be a long time if the database is a remote database (and might even be a long time if the database is local).
Also, the Oxide api allows for a way better way to prevent against SQL injections than replacing ' with nothing: Preventing SQL injections | Oxide -
Yes, I did read your post on that thread like a week ago and I have to say that I learned a lot.
Since I did not knew that and, because I have a personal donation system, after reading that I had to update everything
Nowadays I am using the Oxide API for MySQL. That was hard to code for me.
-
So I have:
While I am in the group it does not give me the SendReply warning.Code:foreach(var entry in permission.GetUsersInGroup(groupName)) { if(entry == player.displayName) { SendReply(arg, player.displayName+" is already in the oxide group."); return; } } -
Arg is BasePlayer?
-
Arg is console. I have a command searching for a player thats in a group. If a player is in that group it called that function. This is telling the arg(console) that the player is already in the group so he will not be added.
[DOUBLEPOST=1468907382][/DOUBLEPOST]Here is another portion of the code: Solved - Steam Group Error | Oxide -
arg.ReplyWith() maybe?
-
So after some investigating I found that it gives me: [Oxide] 00:53 [Info] [SteamGroupChecker] 76561198167856311 (DylanSMR) instead of just a username.
[DOUBLEPOST=1468907717][/DOUBLEPOST]Fixed:
Code:void AddToGroup(ConsoleSystem.Arg arg, BasePlayer player) { var est = 0; foreach(var entry in permission.GetUsersInGroup(groupName)) { if(entry.Contains(player.displayName)) { SendReply(arg, $"{player.displayName} is already in the oxide group."); return; } } rust.RunServerCommand($"oxide.usergroup add {player.displayName} {groupName}"); SendReply(arg, $"{player.displayName} was added to oxide group {groupName}."); } -
User names may change, be aware of that.
-
Yeah just realized that. I changed:
toCode:if(entry.Contains(player.displayName))
Code:if(entry.Contains(player.UserIDString))
