1. Hey guys,

    Is there a way to read the native Rust banlist and safe it to an array? I've tried looking everywhere but I can't find how people have read it, just a lot of custom solutions.

    Thanks for your help.
     
  2. Code:
    ServerUsers.GetAll(ServerUsers.UserGroup.Banned);
    ^ Will give you a List<ServerUsers.User> of all banned users.
     
  3. Ahhh thanks heaps Shady, really appreciate it! Sorry I'm a bit of a beginner when it comes to C# still but this line is all that is left for this plugin. Do you know of a way to convert that list to an array of SteamIDs? I'm not sure what that class looks like internally to extract that information.
     
  4. I don't use arrays much, but this seems to work:
    Code:
    var bannedUsers = ServerUsers.GetAll(ServerUsers.UserGroup.Banned);
                if (bannedUsers.Count < 1) return;
                var bannedArray = new ulong[bannedUsers.Count];
                for (int i = 0; i < bannedUsers.Count; i++)
                {
                    var user = bannedUsers[i];
                    bannedArray[i] = user.steamid;
                }
    
    Also, I'm guessing you're not using Visual Studio. I'd highly recommend you do!
     
  5. It would be better to do this:

    Code:
            List<ulong> GetBannedUsers()
            {
                List<ulong> ret = new List<ulong>();            foreach (var _user in ServerUsers.GetAll(ServerUsers.UserGroup.Banned).ToArray())
                    ret.Add(_user.steamid);            return ret;
            }
    
    No need to check if the count is >0 because it won't loop through the list if it is empty and return an empty list object.

    You should use foreach loops instead of for loops when iterating through arrays, that way you don't need to keep track of a key and use extra lines of code.

    Also, the usage of .ToArray() in my function will copy the current values for use in the loop to avoid enumeration errors.

    If you still wanted to set the capacity of the list/array when constructing it (no major requirement in an Oxide script,) you can construct it like this instead:

    Code:
    List<ulong> ret = new List<ulong>(ServerUsers.GetAll(ServerUsers.UserGroup.Banned).Count);
    
     
  6. Not sure why you're replying to me, the stuff you're saying is either subjective or obvious.

    No? There's an unnecessary .ToArray() in that snippet, you're not modifying the original at all.

    Not really. There's no reason I should use foreach over for, since there are numerous cases where for is faster (and when it's not, the difference is generally small, which makes saying either one is objectively better quite a difficult thing to do), and it's also just personal preference. I'm not worried about typing a few more characters.

    No idea why you're explaining very basic C# things in reply to my post.

    Lastly, he specifically asked for an array (more than once), and your snippets are lists. ;)
     
  7. Yes, you're right.

    Actually the array is copied into an array (which is what I said - List(T).ToArray Method (System.Collections.Generic) - you don't want to loop through a live collection of something that could be modified during enumeration in a different thread)

    Sure it's not a big deal to type a few more characters and it's better to use your personal coding preferences. I deal with large non-rust game servers on a daily basis (code projects of up to 5,000+ cs files and 100k+ lines total) and less code = better maintainability.

    Mainly because I try to be useful where I can, and I spotted your code and knew it could be done in a much cleaner way.

    And that there, is where you got me. It was a long day. I guess he could also just use this

    Code:
    return ServerUsers.GetAll(ServerUsers.UserGroup.Banned).ToArray();
    
     
  8. Except that still isn't what he asked for. He asked for the IDs in an array, not the ServerUsers.User(s) in an array. Again, I know exactly what ToArray is for, but you have no need to use it in your snippet since you're not modifying anything, and if you're trying to say the list you get from ServerUsers is somehow going to be modified before your loop finishes, I'm pretty sure it's not going to. Less code when possible = better, right?

    Regardless, I'll stop here because it's quickly going off topic.
     
  9. This seems so pointless that I would love to weigh in. One line :D

    Code:
    ServerUsers.GetAll(ServerUsers.UserGroup.Banned).Select(x=>x.steamid).ToArray();
    There isn't really a single correct way, however there are certain ways that most people will agree are wrong.