Godot Multiplayer - Create New Account Function | Godot Dedicated Server #8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

In this Godot Multiplayer Tutorial, I will teach you how to program a create account function for your multiplayer game.

When your players have downloaded your Godot Multiplayer game for the very first time, they will need a player account. Otherwise, they wouldn't be able to login to your multiplayer game with their own unique credentials.

Check out the entire playlist over here:
https://www.youtube.com/playlist?list=PLZ-54sd-DMAKU8Neo5KsVmq8KtoDkfi4s

πŸ‘οΈŽ︎ 4 πŸ‘€οΈŽ︎ u/Stefan_GameDev πŸ“…οΈŽ︎ Nov 01 2020 πŸ—«︎ replies

Awesome! I don't need these right now, but multiplayer is something I'd like to fiddle with in the future.

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/freakmeaning πŸ“…οΈŽ︎ Nov 02 2020 πŸ—«︎ replies
Captions
in this godot tutorial i'll teach you how you can create a create account mechanic so that your players when downloading your game for the very first time can create their own user accounts let's get started so the first thing we're going to need is a user interface to put all that new account data into right here we got the login screen that we've made in a previous tutorial and we'll use exactly the same building blocks to create ourselves a you know runementary easy create account process so i've already made that and i trust you can do the same using the building blocks in the tutorial from last time when we have a look at it i'll hide the login screen i'll show the create account screen and as you can see i'm not creating a new scene for the create account panel i'm just creating a second option inside the same scene that we already have and that will basically give this user interface panel two different states that it can be in so this basically is an email address for a username and a password and uh please repeat your password because typing your passport wrong when you create a new account seems to be a thing these days so we got that back button that's of course going to bring us back to that login screen and on the login screen we got that create account button that's going to take us to that create account screen that's what we have to code that manual switching what i do here that needs to be done in code so talking about code let's go over to the code on the bottom here you can see the five different nodes they're going to be imported in the code and i've put those all in a variable so they're easily accessible we got the three user inputs that's the username password repeat password and the two buttons also on the top i have a note reference to both this login screen and the create account screens here or the v box containers what they actually are so i can easily call those two on those um screens the switching between the two i've hooked up the signals of the buttons back and create account and on create account press we want to hide the login screen and show the create account screen and on back press we do of course exactly the opposite we hide to create account screen and we show the login screen now the magic of course happens when we press on confirm because that's actually when we start requesting to make a new account what we do is we first do a couple of checks with the usernames and passwords usernames one i i would assume and the passwords that were provided to make sure that you know if the player typed something wrong character or the password didn't meet the requirements or type the wrong password we can we can filter that out right here we don't have to send that to the server however there's always that one or two or five or ten funky players that are trying to break your server they'll recompile the executable they'll rip out these checks and suddenly they can send all kinds of data to your server so we also need to be doing some checks on the server that's basically going to be double checks but we do want to make sure that on the incoming traffic the code that cannot be changed by a player we make sure that the input that we get is actually going to be up to par and with our standards so what we do we first check if the player actually put in a proper user um username so if it's not empty if the password field is not empty if the repeated password field is not empty if the password field and the repeated password field are the same and lastly we check if the password is at least seven characters long so that's one demand i'm putting here on the password i could go into you know need to have a special character needs to have at least an uppercase or a username needs to have at least an ending that's a valid email address like gmail.com or hotmail.com or at live.com but that would all just drag out this tutorial it's not really necessary to get the multiplayer functions working so i'll leave that up to you and you know maybe i'll make one time a special tutorial on how you can implement those kind of things in godot but not going to go into that right here all we do right now is just make sure that the player has at least a password of seven characters or longer so if the player survives all these checks then basically the else will hit right here we're going to disable the confirm and the back button very similar to what we did with the login screen where we lock the login button just to make sure that the player cannot click create account three times in a row because you know that would probably create some weird stuff at the server then we are going to save the username and password by getting the text out of those input fields and then we call the gateway we connect to the server we push the username the password and then uh boolean true now that last one bowling there is one thing i do want to mention quickly opening the code for the on login press you can see that the connection here is exactly the same we're calling exactly the same function even though we want two different things to happen one is a login the other is a create account here you can see that this boolean is false and that has to do this so this is new from the last tutorial tutorial on creating a login screen or doing the player authentication so add that one when we go to the gateway you can now see that this boolean true or false is actually whether a new account is requested so that's a new variable on the top here and we set that on the gateway right there so the player is going to connect in both cases logging in and create an account it's going to connect through this connect to server method and the moment his connection is succeeded the on connection succeeded function will fire and here is where we previously only had request login now we're checking for that if new account is true then it's a request for a new account or a create account request and otherwise it's a request for login so that's how we're splitting that up but we make use of the same connect to server function to ensure that we don't have to do you know extra complicated things with the code so once we are requesting that create account that's what we got right down here that's really easy it's basically just taking the username and the password sends it to the server with that one there it's gonna request a function create account request with that username and password that's all that's to it that's all that we need at that point in time and then of course we clear the username and the password as we don't need them anymore so with all that done we now basically fire a signal to the gateway server so let's check out the gateway server the the server side verifications that we do there and how we push it forward to the authentication server and how it eventually gets back so i'm on the gateway right now and here we have the remote function create account request on the gateway script we'll receive that username and password and first we have to do a couple of verifications we're going to assume that the valid uh that the request is actually valid but if the username is empty the password is empty or if the password length is not at least seven characters we're going to set that to false um we don't need to check any like repeated password checks anymore because at this point in time what the player send us is what the players send us a player which intentionally tries to do something funky probably intentionally has some specific kind of password that he sent over and a player that didn't do anything funky and was just logging in his signals will be catched by the client side so we don't really have to worry about that repeat password once we're on the server with that said if the valid request is falsified by one of these three statements then we're immediately going to return the create account request so we're going to immediately call this function this function can be called by both the authentication server and straight here when the valid request is actually false so we are separating i'm not putting these lines of code straight underneath here because these this function has multiple functions so with that said we of course push the request false or true in this case always false because that's the if statement we need the player id so we can communicate back with to the player id and the rpc id call and we send this one here and this one means one is a field to create this basically the signal is already captured by the gateway and it's not going to happen two is this is an existing username that's of course a check we're going to be have to be doing on the authentication server it can be the case that a username is already in use maybe you forgot you had an account maybe you were checking if your account created successfully or for some reason somebody was using somebody else's email uh and three is just you know welcome i'm not really doing anything with that welcome yet um but that's basically a successful uh input so let's first see how this is going to be returned to the player so we first we're going to take the short loop like we couldn't process your request go straight back to the player and after that we'll take the long loop go all the way to the authentication server and see how that one identifies whether or not the account username was already existing or whether it has actually created that username that account and how it does that and how that looks in the data so first back to the player going to the player we have the remote function return create account request and when you look at that that's going to receive the results that's a boolean true or false and that message one two or three so if the results were true well we don't have to look at that yet because that's always the case with the authentication server otherwise if the message is one that's why we need that one two three because then we can show different error messages then we couldn't create account please try again or if it's an error message too username already exist please use a different username or login because it could also be the case that this player simply already has an account maybe you didn't play for a couple of months where the discount maybe was gone or whatever um of course if the logging goes wrong we have to then enable the confirm and back buttons again otherwise the player will be stuck in the user interface panel then we're disconnecting the signals just like we did with logging in that's exactly the same now when you look at the return login request we're also disconnecting those signals so with that said now let's go back to the gateway and then to the authentication server to see how a positive valid request is being processed so when the request is not false but therefore is true we go to the authentication singleton we call the create account function we're going to be pushing the username the password and the player id however as you can see we are changing the username here with a function to lower that means that all the capital letters will be changed into lowercase letter letters so uppercase goes to lowercase what we do that because sometimes people type their email addresses especially if they use their own name in the email address they have a very big tendency to write the first letter with a capital letter or to write their name with capital letters but that can actually be quite annoying when you try to log in again because then suddenly your your email address is case letter sensitive and i know if you ever tried to log in with case uppercase letters within your in your username if your username is your email address if that's the case usually you can log in with both uppercase and lowercase doesn't really matter so because it doesn't really matter we are just changing or converting everything to lowercase so before we send it to the authentication server everything is going to be lowercase it's going to be saved in the data database almost lowercase and whenever you try to log in we'll make sure that it's lowercase as well so with that said we're going to go over to the authentication script or authenticate script i should say here we got the create account which receives that data and this does nothing else but just send it off to the authentication server when we switch that authentication server this is where we're actually going to be creating that account so let's go over this now the create account function basically has two outcomes one is congratulations with your new account and two is sorry this username already exists so what we need is we need a result and we need an output a message know that two or that three that we talked about just a moment ago so first if the player data player id so this comes out of the player id data that we have on the on the server if that data has the username that was provided then we know that the result is going to be false and the message is going to be 2. else that means that the username does not exist we know that the result is going to be true and the message is going to be three on that player data player ids with that username we're going to input a new dictionary that's going to be password and then we input the password of the player and then of course we need to save those player ids so when we have a quick look at the player data right here i've changed by the way location from rest to user so that we can actually save this without having too much authentication or writes on the local os so i've changed that to user this for the rest is exactly the same but now we also have the safe player ids which basically takes a save file as a new file we open that file and instead of read we write and then we store the line to json player ids and we save close so every time we get a new account we're saving that file just to make sure that whenever the server crashes we still have that file on the os system and then of course you know good practice would also be to have a regular backup of that probably several times a day but yeah just make sure that you're saving that data because otherwise if you just keep collecting those usernames as long as you're not saving that file those usernames are only known on the server they're not automatically synced to the actual file on the file system and of course the last thing you want is your server running for two weeks with maybe 100 or 200 new accounts being created and players playing and suddenly you cut the line off and there you are you you miss all your player accounts players cannot log in anymore because it's a player the account is not recognized so do make sure you save those files regularly and back them up regularly that's very important data okay so with all that said there is one thing i do want to mention here now we're saving the password just as a piece of string that is a very bad practice because of that we're going to be doing a next episode on hashing and salting this password but i do want to let you know that that's like i want to put that in a separate tutorial this tutorial is going to be too long but watch that tutorial don't do this this is very bad practice if you're if you're a server for some reason gets compromised and somebody gets their hands on that foul then everybody or every single account on your game is then suddenly compromised unsafe and hackers will be able to log into every single player account with that file without any obstruction so we're going to be hashing and salting these passwords in their storage so that players can actually not use that storage they'll have to use um very hard decryption methods uh forced entries which takes uh just a gazillions of hours more than a lifetime of years so we do want to make sure that we add that extra layer of security so don't forget to watch the next tutorial and subscribe to the channel so once we have the player data and we have saved it all we're going to rpc call the gateway we're going to push that results that's going again we're going to be true or false the player id and the message so then of course we're going to go back to the gateway that's going to take this remote function that's going to straight call the gateway uh singleton with return create account request so that is basically where we're gonna come into the same function as we had earlier so that's why i said i didn't put these lines of code um in the ifvel request is false because we're going to be reusing this function several times and now we are using it so this is basically also received the boolean again the player id and the message one two or three and then we basically come back to the player script but now we don't have a false moment we have a true moment and if the results are true then we the account is created please proceed with logging in then we're gonna get that login screen and we're actually gonna go on back to log and press so we're gonna emulate as if the player has pressed that back button on the create account screen so it immediately switches to the login screen and you know we would have a pop-up saying hey congratulations welcome to the game and please proceed with logging in and then login screen presents itself player can log in start playing that's pretty much all there is to it that that i added of course there's always a couple of small caveats right so let me go over a small minor changes that i had to make to make all of this work so first of all on the login screen player client side this login screen used to be called vbox container um i didn't rename that the login screen ever but that means that on these node references you probably if you copied over that piece of the tutorial you have instead of login screen right there you have vbox container so you do have to change those references also first in the previous tutorial in the in the player authentication tutorials we had no function behind the create account button behind this button right there a couple of you actually asked in the comments and well now it's functional however we never disabled that button we only disabled the login button because while the create account button didn't do anything anyway so i've added an extra note reference here under the login notes and when i am disabling the login button i'm also disabling the create account button and i have to repeat that every time in the code so when i go to the gateway script and when i look at the remote function return login request here not only the login button is again enabled but also the create account button is enabled and when i go to the game server if the token verification came back unsuccessful uh we also have the login button disabled here is false so enabled and also the create account so you have to bring that in a couple of times but that's important so you have to change these these references here and you have to make sure that those that create account button disabled is also reverted that is also true for the gateway and now i have to find it if the connection fails so if we fail to connect to the gateway for whatever reason lost packets timed out pings whatever here we previously only had that the login button disabled was full so we enabled login button again and because we use the same connection for both logging in and creating the account we don't know which buttons we have disabled and which are still enabled so in this case we are just going to be enabling all of these buttons again i mean a connection with the gateway field so the player will have to make another tent so yeah this is pretty much what we have to do for all of this so with all that out of the way now you know all the small changes you need to make final thing we have to do is a small demonstration i think so i have all my servers running i'm here in the client or ready to log in but we're going to create a new account instead so uh you know what let's let's just first try um i don't need to add an actual email address we don't make that test let's say we didn't we forgot to put a password in there press confirm and immediately says please provide a valid password so okay uh right without a password and i please repeat your password and let's repeat something different and it all says the passwords don't match so that all seems to work pretty well now let's do actually something more serious so let's go with uh test at uh test.nl because we know what i'm in the knowledge so why not uh let's go for a password just does not make it very complicated as i can't remember it you know there's always a problem with me so let's just go one two three four five six seven that's it so we go for uh confer and here we go successfully connected to the gateway requesting your account result received account created please proceed with logging in and we switch to the logging in screen um now of course the question is uh did it actually work so i got the file actually here um so this should have now been saved so first we of course had the test in the test1234 or test123 so that was this user and now we have a comma we have a new user that's test test.nl um password13567 so that seems to work perfectly and if you think that i've put that data here because you always have people that doubt you know that that's okay that's okay let's just put in a um one two three here that means it's a new user and users can't have the same password um of course the confirm button is not working so it's a little bit of a shame but let's quickly rerun this small effort small effort stay with me create account go test one two three at um uh test.now we go one two three four five six seven eight you know what let's make the password different as well do have to make that the same you confirm i can't create it now when i look at this file when i open it and it was still open it will recognize like hey it has been modified by another program in the meantime do you want to check that yes and now you can see we also have test123 with password one two three five seven eight so that all seems to work perfectly now of course the question is can we log in with that and of course we can so we're gonna do test um let's do that last one one two three at test.nl and for the password one two three four five six seven eight and we log in there we go successful token verification and we can kill ware bears again everybody happy so that's it that was it for today guys hope you liked it if you did smash that like button hit subscribe don't forget that little bell icon to make sure you don't miss out on that next episode where we'll be hashing and salting the passwords of our users now i want to give a big thank you and a big shout out to everybody that has been supporting me through the youtube memberships right here it's been absolutely heartwarming to see all that support come in and it definitely drives me to make more of these high quality tutorials if you don't know what the memberships are don't know what i'm talking about there's this little join button down below where normally the subscribe button is i will show you a little bit of a pop-up with the various levels you can support me at works pretty much exactly the same on like patreon but then right here on youtube yeah helps me out and you get some benefits too so go check it out i hope to see you on the next tutorial and until then keep on gaming keep on coding see you later guys
Info
Channel: Game Development Center
Views: 3,800
Rating: undefined out of 5
Keywords: Godot Multiplayer, Godot Multiplayer Account, Godot Multiplayer Tutorial, Godot Create Account, Godot New Account, Godot Account, Godot Create New Account, Godot Network, Godot Networking, Godot Dedicated Server, Godot Multiplayer Server, How to make a multiplayer game, Godot MMO, Godot Beginner Tutorial, Godot 2d Tutorial, Godot Tutorial, Godot
Id: KN0GbiposqU
Channel Id: undefined
Length: 21min 52sec (1312 seconds)
Published: Sun Nov 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.