Creating Admin Lists in VRChat

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so we just got VR chat's new string loading and image loading features for udon and there's a lot of stuff that we can do with that and I think a really good way to start with the string loading is to do a simple admin list just a list of usernames on a website that you can access and then determine whether or not the local player is on that admin list and give them the light toggle buttons or the video player buttons or whatever the features are still pretty new so there's occasional bugs here and there and I'll make sure to go over what I know so with that let's get started so first off we need an actual thing that we're going to be toggling on and off and we'll just be using this sign over here that says you're an admin over here I'll have the admin list behavior and the here is the sign that we can turn on and off now this is going to be a little bit easier to explain by doing udon sharp first and then moving to udon graph I will explain both of them but this will be a little bit backwards of how I normally do my videos which is where I explain it in graph first and then convert that into udon shark you'll see why a lot of the features are a lot easier to show off in udon sharp when I get to them to start off with let's actually just make our u-sharp script I'm going to call this admin list sharp since I'm going to distinguish between udon sharpener and my graph in this project you can just call it admin list or whatever because I'm assuming you're just doing the one after that all compiles you can open it up and I'm just going to be using visual studio for this as always I'm going to put my code into a namespace so that it doesn't obstruct anyone else's so I'm just going to type namespace valgin open and close curly brackets and put all of the code in there since this will be looking at a list of names on the internet and toggling a bunch of objects the first two things we're going to do are make our VRC URL variable and our game object array so we'll start with a public VRC URL admin list URL and then a public game object array admin objects these will just be things that get turned on if you're an admin and turned off if you're not for the moment let's actually go back into unity and set up those two things if we add our script onto our Behavior we'll see we got the slot for the URL and for the object just going to add the sign in here and for the URL I've gone and made a paste bin post which just has three names in it Falcon Mike and Kevin these are really easy to make and paste bin is one of the three URLs that are actually whitelisted by vrchat so you can use any URL but if you're using something that isn't GitHub paste bin or GitHub guest you will have to require your users to have untrusted URLs enabled and then reload the instance if they were not so I'm just using pasteman and if I want to get this raw data instead of loading the entire website name and all we will just hit the RAW button and then copy this URL which for some reason Google thinks is in Finnish and we will be just just getting this data here I'll paste this URL here and then we can go back to our code one of the main advantages of having this poll from the website is that we can change that data at any time so if there's an event going on we can add or remove someone from the admin list since we can do that at any time we'll want this event to be looping so every 60 seconds or so it will pull from the newest list because of that we'll be using send custom event delayed seconds we're going to have a custom event that we will be calling with that event so let's do a public void underscore download list open codes quarterly brackets and the underscore is just to make sure it's never called over the network so in order to actually download our URL we're going to have to call from VRC string downloader which as you see isn't coming up here at all and that's because we need to use the namespace VRC sdk3 string loading semicolon and the line and now this has gone green we can type here load URL and there's two things that we're going to have to pass it the first one is obviously our URL so admin list URL then normally we can end it like that but that's because there's a second value in here that tells it what udon Behavior to tell hey the downloader system has finished downloading do stuff with this information by default if you leave this empty it'll just refer to itself but there's currently an issue in udon sharp where it does not do this and we need to actually be able to tell it hey use this script specifically but since it isn't looking for an udon Behavior it's looking for a iudon event receiver we need to cast it as such or basically tell it hey this is our script but it's actually an iudon events receiver with u sharp and C sharp in general to refer to a script we can just type this but obviously this isn't an iudon event receiver and we get that by using the namespace PRC udon common interfaces and here we can just cast it so put in parentheses I udon event receiver and now it'll call this URL and tell this script that hey we have finished downloading this URL and of course since we want this to Loop every 60 seconds we'll just make a float up here so public float reload delay I'll have that be 60. then the next line we'll just do send custom event delayed seconds first we could put in just the raw name so in quotes underscore download but if we ever wanted to change the name it would be a lot easier to realize oh something has changed so we want to do name of and then pass that download list now we need to tell it how many seconds so we'll just pass our reload delay and end the line now every 60 seconds this will reload a download list and basically call this on a infinite Loop of course this actually needs to be called once for it to start the loop so we're just going to have our start event which happens right at the beginning call underscore download list now when the URL is loaded there are two things that can happen it can either succeed or it can fail maybe you just typed in the URL wrong and it didn't load or maybe the website is just down so we're going to need two different events to handle those two different scenarios and those would be the public override on string load success delete the Baseline and public override on string load error delete the Baseline now this passes a result which results have the full thing that it put out the error code the error message anything that can come with a string that has succeeded or failed to download we're just going to handle our error here quick and we'll just have it log the fact that there was an error so we'll do debug.log and in here we'll pass result dot error and that will give us the whole error of what failed to load but since we plan on actually succeeding our download we want to actually do stuff with it here now our results gives us the actual full string from the web page that we have downloaded so let's make sure we have that stored we'll do a public string and I'll just call this admin page since it's the whole page that you have downloaded and we'll just set admin page to equal result dot result and that's just just the whole output from the text if we control s to save and head back into Unity we can actually enter play mode here quick to see what actually happens now I'm going to change our reload Delay from 60 to 10 just so they can actually load faster in case any changes are made but now that's loaded you see hey admin Pages put valgan though this doesn't show the whole thing so if I copy it and paste it into the search bar here you'll see it says Falcon Mike and Kevin that's just because this doesn't show each individual line so it's all stuck in this line now that we've succeeded in downloading the web page we actually need to split it up into the different names that are coming with it and since I'm doing this by hitting return every time we need to clear out every new line character and carriage return character this can be done by a simple string split but we're going to go up here and make a public string array so we can separate out all the names admin names and right after our string load success we'll just do admin names equals admin page dot split we're going to have to tell it what characters to be splitting out there's two different characters that we're going to need to get rid of on Windows it is the carriage return and new line characters and on Linux and Android it's just a new line character so we need to make sure we get rid of both of them since we do need to get rid of both of them we're going to have to give an array of string characters that we're separating out so we can just do new string array and then curly brackets and inside of here will be everything that we are clearing out now a carriage return or the generic return symbol is represented by a backslash r and that's just the return character since we want the new line character as well we need a comma for a second one and then in quotes we do backslash n for new line now this will make it clear out any line breaks any separations that we have but it will still leave empty names in this array which we don't want so the second thing that we will be passing is a system string split options remove empty entries I'll just extend this out a bit like this and semicolon to end the line now we don't necessarily need system to be typed here we can actually in fact just use it up here so using system and that cuts down on the amount of things we need to type down here all right now that this separates out all the names we can go into unity and hit play and we'll see that once it loads up the web page it'll separate out the entire page into the separate names inside of this array you'll see it's loaded up and we have Falcon Mike and Kevin that separates everything out so that we can go through and actually use those names to compare against so next we're going to need two things we're going to need the local player's name to see if it's actually in this array and we're going to need to store whether or not the player is an admin because that can change if we remove someone from a list or add them to it so first we'll have a public Bool is admin and then we'll have a private reference to the player's local name since that never changes private string local name and then in start right before download list we'll store local name as the networking local player display name so now that we know their name we can go and check for it in the array first off though we want to make sure that we've cleared out whatever the last situation was so we're going to make sure that is admin is reset to false and only set it to be true if we actually find it inside of that array c-sharp has some pretty good ways of finding out if a specific thing exists inside of a list or array but since we're just an sharp for now we're going to be iterating through the entire array until we find it or if we don't we don't so we're going to use a forward each Loop for all of the names to compare against we'll type for each parentheses and we'll be getting a string for each one of the names so for each string admin name in admin names curly brackets now we have a reference to admin name for every single one of these we can check to see if admin name equals local name and if so is admin equals true now with the advantages of it on Sharp and the for each Loop is that now that we found it we don't need to keep going through all of the other names we can just hit break and that ends the entire for each Loop and lets us continue right down here very last thing for us to do is actually enable or disable the objects based on whether or not we are an admin so we'll do another for each Loop and this one will be for each game object just obj in admin objects and we'll just set obj dot set active is admin so it will be turned on if you're an admin and turned off if you are not control s is safe and we can head back right into Unity now again I've shortened this to 10 seconds so this is easier to test but again you will likely want it as 60 seconds or the likes when you're actually in deployment so now that we've launched in you'll see it has separated into Falcon Mike and Kevin again and as checked is admin so it found my name valgan in that list now I'm using client Sim so I've set my name as valgin here in the editor so that it knows the actual name to compare against now for the advantage of the system I can actually just go pull up the page where we have the paste bin with the name in it I can just go and edit it and misspell my name here quick so hit save quickly and when we go back here we'll watch as this gets updated to no longer be valgan but instead just have the end gone and now I'm no longer an admin I'm no longer on this list and is disabled the object and that's the whole thing that is the whole admin system set up here in udon sharp hi editor valgin here if your username looks something like this or someone on your list you'll want to make sure you copy their name from the vrchat website because they do some sanitation of certain symbols and usernames if you wanted to actually show up correctly and identify as their username you're going to have to copy the one that VR chat is most absolutely definitely using this is probably fine in 99.99 of situations but you you made this choice you person with this name next of course we'll want to go through and do this with udon graph now a lot of what you saw were these names and values changing in play mode and udon graph doesn't support updating the inspector like that so we'll pretty much have to make the entire thing and then test its end result so I'm going to make a new udon graph program asset and just call this admin list graph and quickly I'm going to copy this URL before removing the component adding a udon behavior and then putting our graph in there now that we have the graph let's open it up here quick and set up a few variables first of all we need our URL so we'll do a VRC URL call this admin list URL and set it to be public hit compile and I'll just paste the URL there so I don't lose it next we need all of the objects that we're turning on and off so we'll do a game object array admin objects and set that to be public as well drop that down and just add the admin sign in there and now we can get to setting up the actual code so similarly we're going to start with our custom event so we'll do event custom and I'm just going to call this like I did there underscore download list the first thing that we want to do is just start downloading our URL so I'll drag out from here and do load URL and connect that in since this feature Works in udon graph we don't have to connect anything to udon Behavior we can just leave that empty and of course that will be fixed in udon sharp eventually it just isn't at the moment next we of course want this to reset itself and call itself after a delay so let's make a float variable up here and just call this reload the light I'll set this to be public default value of 60 compile and I'll just set it to be 10 in the inspector for testing now in order to call this again we'll do send custom event delayed seconds we'll select the event download list from the drop down connecting the flow and give it to the reload delay into the delay seconds and of course we want to actually be able to start this event so it won't ever Loop if it's never called we're just going to go to our starts event so event start and we'll do send custom event and just select the download list option connect that in and when you hit start it'll do the whole thing same as withude on Sharp we'll be using our success and fail events so I'll just type success so on string load success then on string load error and we can just put these down here we'll just finish our string load error here quick so we'll just do a debug log of the error message so we can just select error connect that in here attach that to the debug log and then we can move this out of the way since we will no longer be using this as we did in udon sharp we want to actually store the result of downloading the web pages as we did there so we'll do a string variable and just call this admin page since we can't see this update in the inspector I don't really have a reason to set it to be public so we'll just leave it like that I'll control drag out to get a set value for the variable connecting the carrot and then let's get the result so just type get result and connect that into the value next as we did in udon sharp we want to split it up into the individual words instead of just having the entire big string that we get so we'll drag out from admin page do split and then we're going to want to put this into a new string array variable so string array and admin names and again since this can't be seen changing in the inspector I don't need to set it to be public control drag out for a set value and we can just connect that in here connect up the flow and there we go this is the part that starts to be a bit more difficult than it was in udon sharp if we just open up this we can see that I'm passing it a new array with these two characters the slash R and the slash n these are represented as characters and not the literal string values of Slash n what these are actually representing are those ASCII characters in the background that are the carriage return and the new line but since these are chars or characters we can't actually type those into a value in the graph so you'll see in here if I want to type backslash N I can't do that because this only accepts a single value you because it's only expecting a single normal character so we're gonna have to get some very specific values in order to put this in similar to udon sharp however let's swap this over to string array string split options and just for now select remove empty entries now we need to actually build this separator array in Newton sharp we just made it here quick in the same line but we'll have to initialize this up in the start event so we're going to want a new string array and I'll just call this line separators now we'll do control drag out to set the value of this array now when you're setting a value of an array you need to use a Constructor so string array Constructor and this allows us to tell it how long it's going to be since we have two values that we're going to be setting we're just going to set it to be 2. and then we'll put this in so that happens before this of course however we need to actually set what those two values are the backslash R and backslash n respectively this becomes a little bit less obvious than I would really like it to be but we're essentially going to be telling it the raw ASCII index of those two characters in order to set those specifically we'll drag out from line separators drag out from there and do set and we want string array dot set to not set to value and we will be setting the index 0 to be 13 and the index 1 to be 10 and I'll show you a quick why we are using these specific numbers if I open up the page that shows me the full ASCII table you'll see that we have carriage return and Line Feed on 13 and 10. and those are representative of the return and new line characters unfortunately this means you just kind of have to either Google or remember the index of these two things if you're using graph but for now that does work so this is properly set to those two values in this array so we'll go down to the separator and connect it in to that value so now split up the string based on that similarly in udon sharp we immediately set is admin to be false to clear anything out so let's make our Bool is admin is admin and since we can't see these changes in the inspector it doesn't need to be public so right afterwards we'll do a control drag out for a set to value and since we don't have a check mark for the specific value we'll need a Boolean constant so Bool const and we'll leave that unchecked so that the value will be false unfortunately we don't have four each Loops in udon graph like we do in udon sharp but we do have normal for Loops they have added a few tools to make this a bit easier though so we can drag out from admin names and just right click and do generates for each Loop and that creates a for Loop that essentially acts as a for each Loop we don't need this block here so we can connect that into is admin while we're setting it and then we can just line up everything so it's a bit more easy to read get our reference here our debug log here is what we are doing actively with the individual object similarly to what we would be doing here and checking our admin name but we won't be using a debug log we'll swap this out this block down here represents the escape from it so when we leave this Loop and we'll just connect things to this later now instead of debug logging we want to check this name against the player's local name so let's go up and store that local name we'll do a string value local name and then control drag out from that and we will be setting this uh here at the beginning of start we'll be setting it to networking local player and dragging out from there for display name and connecting that into value we'll just move everything out of the way so that it's connected in right at the beginning and then we'll just line everything back up again now that we have the local player name we can check against it with a equality check and since we're checking this specific name we'll drag out from local name check the equality and then we want to get a branch here a branch is just your true false check so instead of our debug log we'll connect into this Branch delete that and if it is true we want to set is admin to be true I'll just copy these nodes and put them over here and check this value here now if it's false we again don't want to do anything especially because in udon sharp we can break out of these Loops but in udon graph we cannot so we need to let it resolve and go through every single name so if it finds one that isn't your name we don't want it overriding the fact that it did just find the right name with the fact that it just looked at a bad name now that we've set this value we can take our block and swap it out for our for Loop for the objects for turning them on and off so similarly I'll drag out from admin objects right click it and then do generate for each Loop and I'll just line everything up here the same way I did with the other one we won't need our debug log but we can have it hold that position but we definitely won't need our block because we won't need any code after this seal our block here and line it up there and delete these two blocks so that everything just goes together and instead of debug logging from this game object we want to do set active and pass the value is admin so we'll stick that in here and this will subsequently enable the object if you're an admin and disable it if you are not line up these things here and there we go that is our entire graph we'll go back to our scene view one quick note there's currently attract candy so this will be resolved eventually but if you are currently using the editor settings reload domain disabled in this for fast play mode entering this will actually cause a issue currently and again it will be resolved with the queuing for these URLs URL loading for security reasons is delayed by 5 Seconds for everyone so if you try to load 8 URLs right at the beginning it'll cue them all up in a list and do one by one every five seconds however if the domain doesn't reload here in the editor it won't be able to clear out that queue so let's say I loaded three URLs at the beginning of my event the next time I open play mode if I have this disabled it will still think that oh it has those three queued up we need to delay it more so it'll delay its Buy 15 seconds which is the five times the three that it already tried to do again this issue should be gone eventually it's just one that you might have to worry about if you are currently using these play settings so for now I'll keep reload domain checked but I typically leave it unchecked just because of how fast it lets you get into play mode so here again we can hit play and once it loads up you'll see that this object should get disabled because my name is still spelled wrong on the website and there we go it goes away so if I grab the website again I can go and edit it put my name back to being spelled right save changes and then we should see it here reload and actually get my username right again and then enable the object all right it didn't because I screwed up one thing here we're actually trying to split by the numbers 13 and 10. we're not actually setting these ASCII characters that was my mistake so instead of setting it to be 13 and 10 here you need to be doing Char convert from UTF 32. and that is where we will type 13 and 10. and all this does is get the actual value from that ASCII index now that we're back in play mode you'll see that it hasn't disabled this object because my name is still fixed on the list so if we go back to it and once again hit edit and misspell my name save changes we can watch as it disappears and there we go that's the whole admin list working again in play mode so now we have the ability to do it in graph and the ability to do it in udon sharp and again this can be expanded Way Beyond just toggling objects on and off it can be set to call events on scripts you can realistically do anything but toggling objects on and off was the fastest and probably the most universal application for this kind of tool of course if you have objects that are admin specific you'll probably want to manually disable them at start in the event that someone's internet takes a little bit longer to load that URL and it doesn't immediately gets disabled so you'll want to actually have it set up so that it's ready for that as well if you have a lot of other things in your scene that try to download a string URL at the beginning it might accidentally get the admin list queued way later on if you have six different strings that you're trying to download right at the beginning and you might accidentally get your admin list set right at the end which will take 30 seconds so they won't have those admin permissions done until then if this is your only string downloader then it should almost absolutely guaranteed be done downloading by the time the player is fully loaded the scene so you should be good and there you have it I know this one was a lot longer and a bit more Technical and I even had to start with udon sharp first in order to explain a few things but hopefully this was helpful and I no I haven't done a few too many of these for a bit but here's to us getting back into it alright we'll see you again all right [Music]
Info
Channel: Vowgan VR
Views: 4,053
Rating: undefined out of 5
Keywords: VRChat, Tutorial, Udon, UdonSharp, U#, Unity, Unity3D, admin, whitelist, blacklist, permission
Id: IxWnYm8f7AA
Channel Id: undefined
Length: 28min 49sec (1729 seconds)
Published: Sat Mar 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.