Solved Getting users in group?

Discussion in 'Rust Development' started by DylanSMR, Jul 18, 2016.

  1. The link you posted has a method GetUsersInGroup.
     
  2. Oh does it? Thanks :p
     
  3. 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. :p
     
  4. 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);
                        }
     
  5. 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
     
  6. 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 :p
    Nowadays I am using the Oxide API for MySQL. That was hard to code for me. :p
     
  7. So I have:
    Code:
                foreach(var entry in permission.GetUsersInGroup(groupName))
                {            
                    if(entry == player.displayName)
                    {
                        SendReply(arg, player.displayName+" is already in the oxide group.");
                        return;
                    }
                }
    While I am in the group it does not give me the SendReply warning.
     
  8. Arg is BasePlayer?
     
  9. 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
     
  10. arg.ReplyWith() maybe?
     
  11. 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}.");
            }   
     
  12. User names may change, be aware of that.
     
  13. Yeah just realized that. I changed:
    Code:
    if(entry.Contains(player.displayName))
    to
    Code:
    if(entry.Contains(player.UserIDString))