Hi there,
So as I'm sure everyone knows, BasePlayer.Find is used by quite a few mods. Currently I have a specific individual who is apparently not a BasePlayer but logged into my server.
I had him restart Rust and restart his Steam Client to no effect.
I have verified the SteamID being reported by RCON is in-fact his real SteamID.
He has played on my server for a while and this issue only occurred after a wipe.
I should also mention that he had non-AlphaNumeric characters in his name but changed his Steam name to normal characters at my request (before the wipe).
Thanks
BasePlayer.Find returning null for specific individual
Discussion in 'Rust Development' started by Your Old Best Friend, May 6, 2015.
-
I also had such problems with some plugins (including my own), so i decided to not use BasePlayer.Find function and store my data by "string steamid" in array, and then read it in same way when needed. In some commands i'm using direct steamid access, without call BasePlayer.Find function at all. This solved all my problems, but plugin developers actually use this function so not sure what to say...
-
BasePlayer.Find is actually a pretty basic function to find a player, it will only match against exact SteamId or IP matches or partial name matches. However those partial matches need to start with what was enter so using BasePlayer.Find("Mug") would return my baseplayer while BasePlayer.Find("ughisi") won't.
I'm also pretty sure that the method doesn't properly handle multiple names matching the input and returning null when that happens as well. In all the plugins I've posted here that required a way to find a player I always have added my own method to find a player that allows for actual partial matches and multiple results. -
Mughisi I should have clarified I have tested it using only the SteamID and it still returns null.
-
That's odd, would it be possible to run another test and just loop all the values from BasePlayer.activePlayerList to see if he's in fact in that list because that's where the method looks for matches.
-
Does RCON use BasePlayer.activePlayerList? This particular player can log in and play the game, and he appears on Rusty player list.
I looked at the code for Find and it is safe to assume that this player is not being added to activePlayerList when he connects. -
The playerlist that is used for Rusty or any other RCon client uses the reply from the console command 'status'. Not sure where status gets the players from, can't check that right now. It seems odd that the player isn't being added to the activePlayerList though.
-
check every plugin that hooks onplayerconnect, see if any of them save the names to the config file. chances are, one of the characters in his original name is illegal, and some piece of code errors and doesn't finish executing somewhere.
if that's the case it would be good to know the name of the faulty plugin, this is a potential security issue.
try opening your config file and searching for his steamID, it might be faster that way -
Calytic Community Admin Community Mod
I have done some more research and found that this is an issue when an incomplete or empty BasePlayer instance is remaining in the activePlayerList after disconnect failure. This will cause problems for many mods with any calls to rust.UserIDFromPlayer and BasePlayer.Find fail, spamming the console with errors. A server restart fixes the issue.
-
Wulf Community Admin
Do you happen to use any plugins that kick users OnPlayerConnected? -
Calytic Community Admin Community Mod
Nope. None of that kinda stuff (Country block/VAC block). I do have a custom mod that uploads player data via EnqueueGet/EnqueuePost but that seems innocuous enough. -
how do you handle the names in this custom mod? are your handlers and parsers prepared to work with non-alpha chars?
-
Calytic Community Admin Community Mod
Thanks for the suggestion. No, this does not appear to be a problem as players are accepted routinely with special characters. The mod only passes off the data to a web api without any obstruction.Code:are your handlers and parsers prepared to work with non-alpha chars
-
Can you tell me what exactly you mean by "disconnect failure"? Any way I can reproduce this?
What language do you use for your custom plugin? Do you use it to get stats and such? Does it modify BasePlayer objects at any point?
activePlayerList is a List<BasePlayer> from what I see, Find is its standard method. In C# all non-set values of a class instance get the default values assign to them according to the current language specification. In that case 'empty' BasePlayer objects would still be iterable by Find(). For Find() to fail the object would have to get corrupted. There is slight chance this would be caused by Rust or Oxide code, since the players have really weird names sometimes, the problem would be much more common. Your best bet is one of the plugins malfunctions badly. Personally I always start to look through my code first in such cases
. Anything that handles
players names, with special attention to loops, arrays and functions like .Split(). If any part of your code depends on the successful result from the web API you are calling,
I hope there is a way you could investigate it too.
This is all I can say without knowing the details. I know you think the name might not be the problem since other player with weird names are fine, but believe me, sometimes it takes a really weird accident for non foolproof code to start throwing up. Handling user data was, is and always be a bitch, even long after we travel beyond the stars. -
Calytic Community Admin Community Mod
I have not been able to reproduce this. It only occurred for a period of about 6 hours until I finally gave up and just restarted the server. This missing BasePlayer error was causing CONSIDERABLE outages across my entire set of mods. Basically anything that relied on rust.UserIDByPlayer or BasePlayer.Find was causing an exception (for the players who "did not exist").
The only thing my mod does is generate a POST request with EnqueuePost when OnPlayerDisconnect. This is a read-only operation and should not affect the server in this way. I am prepared to believe that heavy deving and routine reloading of untested code may have created this problem. As of right now all I can do is shrug and move on. Thanks for your help everyone. -
call me thick or having been AF/Coding for a while but where do I find all the functions/features for BasePlayer.*? I looked at Oxide API for Rust and well there are not all there. for example BasePlayer.find (player).
also is BasePlayer global? in other words is it defined so I can do BasePlayer.* without doing something like: var targetPlayer = target as BasePlayer; -
Wulf Community Admin
They are from Rust, you'd need to use a tool such as JustDecompile to view the Assembly-CSharp.dll.
