Godot Multiplayer Server-Client Tutorial | Godot Dedicated Server #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I just finished following along with this series for fun (yes, network architecture... for fun). These are absolutely brilliant tutorials. I'd recommend these videos for anyone, even if you just want to know the basics about how all this server stuff works.

I feel like a networking expert (ha, not really) compared to what I knew going in, and I've got my own practical and lightly-secured server system up and running in just a couple of days.

Quality, high-density knowledge tutorials, which are easy to follow for someone who doesn't already know the source material, are an absolute rarity. Stefan here did a better job even explaining the concepts behind networking and password encryption than most, let alone along side an easy to follow practical example exclusively in Godot.

I rarely follow anything on youtube, preferring written tutorials, but I'll be following the rest of this series for sure.

👍︎︎ 23 👤︎︎ u/pxlgamedev 📅︎︎ Nov 13 2020 🗫︎ replies

This is solid stuff, produced at an epic rate. Keep it going Stefan!!

👍︎︎ 5 👤︎︎ u/Zulfiqaar 📅︎︎ Nov 13 2020 🗫︎ replies

Loving this series! Its been super helpful, keep up the hard work. Keenly awaiting the next videos in the series. :)

👍︎︎ 3 👤︎︎ u/aebece123 📅︎︎ Nov 13 2020 🗫︎ replies

Thanks for creating this content!

👍︎︎ 3 👤︎︎ u/SawdustSparky 📅︎︎ Nov 13 2020 🗫︎ replies

Direct link to playlist
https://www.youtube.com/playlist?list=PLZ-54sd-DMAKU8Neo5KsVmq8KtoDkfi4s
Subscribe to get notified in your feed on new episodes https://youtube.com/c/GameDevelopmentCenter?sub_confirmation=1

In the next couple of weeks, I will get into the topic of player & world synchronization, interpolation and extrapolation, lag compensation etc.

👍︎︎ 7 👤︎︎ u/Stefan_GameDev 📅︎︎ Nov 13 2020 🗫︎ replies

FUCK YES.

👍︎︎ 3 👤︎︎ u/wh33t 📅︎︎ Nov 14 2020 🗫︎ replies

Do you have any recommendations for debugging a Godot server that is running on some aws instance? All i can see is the shell and often times the errors are just like "mbed tls error" or something else that cannot be decoded. Im at a point where i cannot determine their causes if they dont happen often because when it does happen i cant tell what went wrong and testing locally doesnt recreate the problem.

👍︎︎ 2 👤︎︎ u/carshalljd 📅︎︎ Nov 13 2020 🗫︎ replies

really nice!

👍︎︎ 2 👤︎︎ u/cenuh 📅︎︎ Nov 13 2020 🗫︎ replies

Stefan, these videos are amazing! I'd love to see a similar series that tackles same instance client/host with central lobby/STUN server. Is that something you might consider doing in the future?

👍︎︎ 2 👤︎︎ u/Bloodyaugust 📅︎︎ Nov 13 2020 🗫︎ replies
Captions
in this first episode of a brand new godot tutorial series we'll be programming a server client interface we'll be making sure that we actually have the server starting the client connecting to the server and them communicating with each other let's get started so you read the documentation you watch some tutorials and now you got this map and this player you can walk around shoot some bullets and if you shoot enough of them you can kill some weirdest but that's not enough for you you want multiplayer you may even want massive multiplayer well i can tell you that i cannot teach you how to make an mmo in just 30 minutes or so i don't know how long this tutorial will take what i can tell you is that if you watch this entire tutorial series of which this is the first episode i will teach you all the concepts that you need to know to do just that to make an mmo however i gotta start somewhere and this is where i have chosen to start and no doubt there's gonna be some people telling me that i should have started somewhere else but hey we got to start somewhere so if you don't know how to make this follow my tile map player movement and combat series of godot tutorials that will teach you all the concepts you need to produce a sort of single player scene like this we're gonna take this single player scene and we're gonna bring that up to the multiplayer level experience now this in this entire series is gonna be a lot of stuff from security and account data and avoiding exploits and making sure that the server has full authority and all that good stuff and today we're just going to start with the first concepts we're going to slowly build it up episode by episode so that you can grasp all the concepts that you need to know to make your own creative id a reality so let's stop talking and let's start coding so i'm back in the editor right here for that single player kind of scene that we made i'm going to give you a quick tour in just a moment first i want to get some code in because all you hear is me talk and that's not why they clicked this video so i first want to show you how i've set up my work environment because it's kind of important as you can see i got two gold editors open and that's because this is not a peer-to-peer connection so we cannot cram the server and client code into a single executable we want a separate executable to be playing on a vps or a home server that's going to be the server and we want another executable that we can send out to players through play store hio steam or whatever so we need two separate executables and therefore we got two separate godot clients you can easily run two clients at the same time go to this very light for now i'm not going to give you the tour yet we're first going to jump into the server project and we're going to start with making actual the server i'll try and remember to call out every time i switch from client to server and server to client project because that can go really fast and you might get lost otherwise but make sure you pay attention to that so right here i pretty much got a blank slate this is pretty much like an entirely new project the only thing i've done is add a little bit of folder structure one folder for scenes and then within that a folder for instances and the main scene under the main scene we're going to be creating a new scene and we call it server just call this server for now follow the tutorial because the naming of this note is going to be extremely important so just just stick with that for a moment you can rename it later this is going to be an other node and this is just going to be a normal node as normal as you can get it and we'll immediately rename this to server as well and we'll add a script that will be an empty script and that will be called server at gd as well now with that done let's immediately save this and we're going to be pasting in some code here not a lot of code we're going to go over it don't worry step by step like i said but this is all the code we need to get the server running that's it it's that easy we're going to be making use of the godot integrated high-level multiplayer networked multiplayer inept node that's a lot of words what this means is this is just a built-in multiplayer function of coda you could make a a server in node.js or any other language and you can create mysql database and all kinds of stuff well you'll need to follow some other tutorials for that this tutorial series is about godot high level multiplayer the integrated multiplayer system in the godot engine so what we do we first define three variables on the top we define network as the network multiply inet new so it's basically going to be a new node and then you have the port number through which the server will accept connections and for which the clients will make connections to the server excuse me and then we have the maximum number of players you have to indicate this because this is a required field when we actually create a server the maximum numbers of players through a high-level multiplayer e-net kind of note is i believe 4 900 something it's quite a lot if you can get 4 000 concurrent players on your server you did a great job you can hire a server architect probably so don't worry too much about the maximum number of players and 100 is more than enough for development now this is going to be the main node so on the project project settings we can immediately say under where is it that i on the run main scene you can immediately say on the scenes it's going to be the main you're going to be opening the server scene as your main scene as soon as we start is executable this server node will load ready will play and we'll start the server straight ahead on the start server we basically say network so that's going to be that thing we're going to create a server which is a standard function on this node and we have to give them two variables the port and the maximum number of players which we've defined here already so that pretty much creates the server right there right there then we get a tree and we set the network pair to the network nothing special there this is just setting up the peer and then we can pretty much say that the server has started now the server or the network multiplayer e-net comes with built-in signals building signals from the server side and building signals from the client side that we'll look at in a moment these are going to be firing off the moment a peer connects or when a peer makes a connection so we got two for the server and two for the client for the server these are peer connected and paired disconnected so whenever a client is going to be connecting to this server and that would be appear where this signal is automatically going to fire and whenever a client disconnects from the server appear disconnected automatically will fire so we'll connect both of those signals up to self to pair connected and be disconnected and we're just going to be printing for now that the user with the id disconnected that id is built in integrated in that signal that fires it's actually a pair id but since the pair is a player in this case we're just going to call this player id to make this a little bit more readable so right now this is running this should run if i click play this should just start off us off of the server you can see right here underneath the output server started congratulations for now we'll close it now we're going to go back to the client and we're going to be setting up the client that can actually connect with the server we'll make the connection happen and then we'll go and do the tour inside the um the single player which is then at that point a client scene we'll make a little bit of a tour around there so now i'm going to go back to the client project and in here we're going to be creating the server singleton that's going to be connecting to the server don't worry one step at a time we got a little bit of a folder structure going on already in this project we've got scenes main scenes singletons and support scenes and under singletons we already got game data game data is already gonna be loading the json data into the client that it needs right now it only loads skill data under these singletons we're going to create a new script and this is going to be called server and that's important call this server don't be that guy that's going to leave me a comment and i'm going to be figuring out you should name this differently and that things don't work because things won't work really on the server we're or actually with server we are going to be creating this piece of code but before we forget let's first make sure we set that up as an auto load singleton so under auto load i'm gonna be navigating to the server path i'm gonna be adding it now it was already added there because i tested this before so it will add in there and it will automatically load when you establish or when you when you execute the executable when you execute the project it will automatically load that auto load single turn and it will automatically run the ready file and it will automatically connect to the server now first things first let's first go over these couple of things before we actually get into how we make this connection establish our seller's disconnection as you can see the structure is very very similar to what we just made on the server again we have a network again we have a port instead of a maximum number of players we have an ip address more on that in a moment the moment we run the executable we're going to be connected to the server in a future tutorial we'll be replacing this and will only connect to server the moment you hit the login button after putting in your credentials your username and your password right now we are not going to program that in yet that's another tutorial that's going to come out maybe next week or the week after for now we'll just connect to the server straight away so we connect the server we now network create client so not network create server this is a network create client we push an ip and a port number we get the tree and we set a network pair that's basically going to push an id number to disappear more on that later as well again we got those two signals that i just talked about we had two for the server and two for the client well these are the ones for the clients a connection filled and a connection succeeded which will connect to self to two various functions two functions here again both for the print one is failed to connect another is successfully connected easy as that now this ip address super important because some of you might be thinking will i need a server do i need a home server do i need to get a vps how can i start developing without incurring too much cost now those of you that are experienced in developing will know this probably and those of you who are not are going to be super happy celebrate and go oh my god i can do so much stuff yes you can one two seven zero zero one the rp address is looping back to yourself it is like writing a letter putting your own address on the envelope putting it in the mailbox and you're gonna get it back in your own mailbox in a day or so of course on the internet goes faster luckily what this means is one two seven zero zero one does not require vps home servers any kinds of servers whatsoever it just loops back on itself in your own computer so you can develop with a single desktop or a single laptop you can just develop an entire multiplayer game not incur any cost of building a home server or renting a a vps and you can just get going now as you see i also have an ip address here and this ip address is actually my vps that's currently running in a data center in amsterdam and that's this is the remote connection to that desktop so right now we're watching the desktop of the server running on the data center and we're going to be using that remote connection today to demonstrate to you that this is actually working so i'm going to be using this ip in a moment now with this setup and with that server setup we can start testing this connection so let's do that right now so you may be thinking well that's easy just press play in both the editors and off we go well technically that is true but there's a very big downside there right here in the output this is where all our bugs and things and our print commands are coming out and that output is kind of important however godot only has one boss and the bosses cannot run parallel with each other for i know some reason so what happens if you press play on in two godot editors while one of them is running already so have two basically project running at the same time what happens is that one of these outputs is going to be entirely blank and the other output in the other client may run the project's output that is related to that project or it may even run the output of the the other one um so you're gonna have some some cross crazy magic going on and that is just super annoying and the only way to repair it is to completely restart all the godot projects that you got running at that moment so it's very annoying to develop that way so as an alternative i sort of figured out that the handiest way to work with this is to simply export the server the moment you made some changes so you're just going to go to project you're going to go to export and i'm i'm running a windows machine here so i'm exporting for windows desktop you can just add that through windows desktop and you've got other options if you're programming on something else under the resources all i've done is add.json the server doesn't have any json files yet but we will be adding some uh already in this tutorial so that's important that those are included in the export otherwise in the options i've not made any changes it's just the standard output it might be the case when you do this you get some big box here with a lot of red text in that case you have not downloaded the export templates yet you'll have a link there somewhere i believe it's called templates it will automatically suggest you the version templates of the current version you're working with you just hit download it's about 400 megabytes and then you should be facing exactly the same screen don't forget that resources part hit export project and save it somewhere where you can find it back so i'll just save it right there now as that has been exported this goes pretty fast i'm going to go to that location where that is located and i'm going to be running it executable it will give me this big nice gray box this is where normally your game would be but as we have not added any 2d or 3d elements it's entirely empty we can just minimize that and here you have this big black box you see server started that's the text of the actual server that's the print command you see right there now with this setup and this running we now basically run the server we can now go to the client and play this one through the editor that way we only play one game through the editor and not two and it's not working because i was already fiddling around with my vps and we'll have another attempt and here we go now we have established a successfully connected output there and if we have a look at the server we can now see the user 759282505 as connected this number is the the peer id and that is going to be completely random for every time a connection is established so if i were to close this and i would to rerun it now you see immediately has disconnected i would to play it again you can now see that the peer id has changed those are not the same so don't think you can use the peer id to save account data or something like that because this id is only the same for as long as the session lasts so pretty much now we have a server and a client and we managed to connect them together now you might be wondering is that one two seven is it not really like is it really working yes it's really working and to show you i'll just copy these files i'll go to my oh i'll turn that one off first i'll replace these files here so this is the vpn that's currently vpn pps pps that's currently running in a data center in amsterdam i'll play the project on here i'll get a couple of errors because there's no audio driver on the server obviously and then we'll close this one and we'll reconnect when we comment out this one and replace it for the ip address of my server again we get a successfully connected and if we now look on the server that's running in amsterdam we now get a server started and user has connected so i'm even able to make this and establish this connection outside of my desktop go over the internet through my modem land somewhere in the data center and i will be able to connect to this client right here or this server server executable i should say server server thing congratulations so now that we have established that connection between the client and the server we also want to make sure that they communicate between the two like the concept of communication between client and server of course making the connection is a form of communication as well but we really want some communication while the game is running so i set up a little bit of a test case for that is not 100 percent a natural sort of situation you would have when developing but it's good enough for us to grasp the concept of communication for you to start understanding that and get further in this tutorial and also this is a great way to keep this tutorial under 30 minutes because else you're going to lose your concentration so right here we got the client side and as i said i'll give you a quick tour that quick tour is kind of important so that you can reproduce the sort of test scenario um and well i promise you so i should so what we got is the scene handler is the main scene and all that does right now is it has a map start which pre-loads the map and it starts that makes an instance announced at a child the reason why i've added this scene handler thing is because we also need to have a login menu coming pretty soon in the tutorial like i said where you can put your credentials and then connect to the server where the server can actually authenticate you see if your password is correct and that kind of stuff and for that we're going to need a second scene a login scene so we're going to go from login scene to main scene in pretty much one the next or the next next tutorial so that's why we have a scene handler here now on the map itself it's a very easy very simple map we got two tile maps right here on the top one for the main tiles and one for the back fixes to make sure that there is no gap between the grass and the uh the road we got a y sword here to make sure that everything is wide sorted nicely that has a couple of trees nothing special static bodies sprite coalition uh polygon nothing there no code or anything then we have the player and then we have a y sword for enemies right now it's only one enemies one wherever but we could add more while having them all y sorted properly so they render in the right order now for the player um if i'm gonna go into the player scene we have four uh sprite sheets that is for the armor main hand off hand and the head that way we can give this guy a sword if we want to very easily without changing the actual sprite we have of course the coalition shape so i can bump into things we got the camera so the camera moves the player around we got the animation player with for every animation um four tracks to change uh the are my main and off hand and head sprites so this is a stacked sprite sheet and then we have the animation tree um for the animation player and animation tree i got two tutorials out in my i believe animation series so you can follow that and then we have a turn axis and position 2d that is to make sure to determine the cast point that's part of the combat tutorial series now going into the code of this player we are walking with our left mouse button in the unhandled function right here for that you can follow my player movement click to move tutorial and we have an event if attack press which is the right mouse button which is going to set all the animations and kind of stuff like i said the previous tutorials that i mentioned is going to help you with this then under the attack we're basically calling in a ice spear scene which is uh yet another scene that we'll go to in a moment this is pretty much a tutorial number one in the combat series so this will help you to create this ice spear here this ice spear is basically having a lot of standard stuff this is really a dumb down version of the actual combat series to make this as easy for you as possible to reproduce um it basically has a standard things like self-destruct and it detects when it actually hits something it verifies if whatever it hit was an enemy and then it's going to run the body on his function this body on it function and this actual hitting part this is part of the second tutorial in the combat series and that will also help you to put that on hit function here on the wear bear and the wear bear is really nothing more than a single sprite sheet not stacked simple animation player not even the animation tree and i've actually for the animations i've only got the idle southwest and the death southwest because this is where it's not doing anything else it's not even walking around yet so this is super super super basic now for the ice sphere and that is where we're gonna be starting the communication between the server and the client the challenge for this tutorial for me as a maker for you as a listener is right now the damage of this ice spear is the damage right here on the top and whenever the scene is instant so when the player costs and this ice spear comes into the game the damage is determined from the game data skill data isp damage now what that is is it accessed the game data singleton that we talked about just a moment ago on the game data we have the variable skill data which comes out of the json file this is tutorial number two of the inventory series if you don't know anything about json files but you shouldn't be watching server tutorials if you don't know how to interact with json so but otherwise watch that tutorial now what this is if i'm quickly going to where i actually have this project and that is going to be here under data we have the skill data sheet1 json so that would be that file this is a super easy json it's not even worth making a json for almost it just basically says i spear does 68 damage 68 86 very well read stefan that's english so with that done or that set the damage is determined by going into the singleton game data to look into that skill data variable to look up the dictionary key i sphere in basically that json file which is now a dictionary file format in godot and to look up that damage the goal of this tutorial is to basically delete this delete the game data make sure that this is not accessible anymore remove the json file from the client and put that data on the server and then instead of having the damage being determined here by the client itself to request the server what the damage on that ispear should be and then the server having communicating that damage back to the client that way the player will not be able to exploit through going into the files and then changing the json folder or the json file changing the damage values in the background and restarting the game and suddenly you can do 400 damage instead of 86 damage like all the other players would now like ask that this is not like a real world example in a real multiplayer game the whole structure of where things are saved and stored is going to be a little bit different but this is going to teach us how we can communicate between server and client and then in following tutorials we will really get to that true structure of a multiplayer game or even a massive multiplayer game so with that done let's get started so the first thing i'm going to do i'm going to rip out the data from the client and i'm going to give it to the server so i'm going to be taking this json file that we got on the client side gonna be cutting it away i'm gonna go to the server side i go into the data folder that i've added on here and in that data folder i'll add the json file now i'll take the code here on the client side and basically it's not necessary anymore but this can be exactly the same as it would otherwise be on the server so i'm going to cut it away from there i'm going to go to my server and under the main scenes and instances i can now make another node folder nodes folder scene folder i'm going to call this singletons like it's called on the client and under singletons i'll make a new script that script i'll call server data and server data is going to have exactly that code that i just took away from a client because again that json is going to be in the data folder is going to be available on exactly the same location from the client's perspective or the server's perspective and then we basically just load up that json into this variable so with this done all we have to do is make sure that this server data is actually loading as a single term because else we cannot access that data so we go to project project settings go to the auto load tab we'll navigate to scenes single turns server data we'll open that up and add that to the list and of course automatically singleton is enabled so with that this is going to be loading from the start of the executable and as this function ready is going to be firing immediately we then load that json file into a dictionary that is called skill data the variable right on the top there so with that done our client no longer has access to that data it no longer exists on the client so we're going to go to the ice spear script so this damage game data skill data ice spirit damage this is no longer possible in fact we can't even define the damage right now so we're gonna take that damage away from here and now we're going to be calling or programming in a server call so to make this server call full loop to communicate to the server from the server back and then make sure that the ice spear has the damage there's a quite a couple of smaller code snippets there's not a lot of code but there's just a couple of smaller snippets so i've already programmed everything in we're going to go over this step by step and i'll tell you all the little details you need to know along the way so instead of getting the skill data from the game data singleton on the client we now need to get it from the server to do that we start off by calling the server singleton so this is not the actual server the the thing that's running somewhere in the data center this is the server singleton still on the client now on there we're going to be creating a function called fetch skill damage and we're going to push the i spear the name of the skill because of course the server needs to know hey what skill do you want the damage off and we're going to get the get instance id what this does is going to return an id number of this specific scene or this specific node that way once the damage comes back from the server we know where to push this damage to because by then different enemies oh by then but there may be i know 17 ice spears five fireballs three shock waves and i don't know what more on the battlefield so we need to make sure that we push that damage to the original requester so this ice sphere is the skill name and it's get instance id is basically the requester of skill damage now we're going to go to that server singleton and on this server singleton you'll see that we have a function fetch skill damage with that skill name and that requester and here we rpc id called the server now this is where all the communication from client to server and server to client happened our pc what is that when i go into the documentation you'll see you have four flavors you have rpc rpc id rpc unreliable and rpc unreliable id now you'll see that you have the normal calls rpc and then you have rpc id you have the same with unreliable the difference is that rpc calls everything every pair that's connected to that network and the rpc id allows you to call one specific pair on a network zero being everybody one being the server and otherwise a specific peer id that you want to call for example when we connected to the server you saw player and then a number connected that number is the peer id so with that you can let the server connect back to the player you could also technically make a player connect to a player but that's not what you want that's what you would do in a in a peer-to-peer uh kind of multiplayer game but not in a server client with an authority server authoritative server so never go player to player always play it through the server so that's the difference between rpc and rpc id or rpc unreliable and rpc on reliable id now what's the difference between rpc and rpc unreliable you may ask it's basically the speed with which happens and the verification that happens in that connection moment so rpc unreliable is basically going to be shooting packets over the internet with all kinds of data for example i don't know position of where you are currently standing and while you're moving on the map with your wasd keys or you're clicking your mouse maybe 30 times a second or 60 times a second you're going to be sending that information to the server and then the server has to communicate some position back well if you were to reliably communicate that position to the server there's going to be more latency before the server can send that updated position back to your screen that way the motion of your player movement will not feel fluid there will be latency in there and that latency is very bad for the player experience so if rpc unreliable you're basically just shooting things to the server and you don't care if they arrive if they arrive properly or anything but you know that you're shooting so many for example with position 60 a second that even if two are not arriving at all and maybe one is corrupted the other remaining 57 in that single second are enough for the server to properly display your movement back to you or back to other players however if you are done with your raid and you got this magic chest and you got this legendary item and the player presses loot you want to be a hundred percent sure that that legendary item actually gets in the inventory of the player because if that does not happen that's a great way to get support tickets in your in your mailbox so in that case you want to rpc call instead of rpc unreliable what that does is that it's going to be sending a packet to the server but in that packet is also a request to send information back so the server is going to send back to the client this is all behind the scenes by the way it's going to send back to the client yes i received the packet and there will also be some code in there usually through the length of the packet then being in bit rates and i don't know what more to make sure that there can be a verification that the packet was not only received but also that the packet has received and is not corrupted that that is an identical packet to what was originally sent and if the client does not get a packet back it's just gonna keep on sending that same packet until it receives the signal that it arrives and if it's arrived but it arrives corrupted it will resend it again with the instruction to not take that original packet that was received earlier but take this packet instead because this one is good and then of course it will again check and check and check now that can create some latency for looting an item that's no problem but for positioning a position updating various players it would just be experiences lag so that's where you want to you sometimes use rpc unreliable and sometimes you just want to use rpc in this case with the damage we want to be 100 sure that that server sends back damage because otherwise our ice sphere might be hitting a target and maybe that's the target that that function is going to be expecting damage if there's no damage your skill won't do any damage that could run into an error in your code or you're gonna have a player asking himself the question why is my ice spinner doing any damage and that only has to happen a couple of times during a player session and you'll get a support ticket as well um so we want to be 100 sure that server sends back that information and then it arrives properly so we're going to be making use of rpc id in this case that was a lot of information read the go to documentation specifically the documentation on the website not inside the editor for the latest version and the best description of this if you ever want to reread that again also if you're more familiar with internet communication yes this is pretty much udp and t cp although they're a little bit different there's a little bit of udp inside rpc but it still has all the necessary checks that small difference um yeah let's not get into that here this is the first tutorial going on continue so we're going to rpc id called the server server being one remember zero everybody one server or a specific peer id for another player which you would never want to use from the client so we're gonna call the server and we're gonna tell the server run your uh function fetch skill damage we push the skill name and we push the requester to the server now we're going to go over to the server and on the server we have the function fetch skill damage now you'll see that this is not just a normal function this is a remote function and this is very important a function will not be allowed to be activated by an outside connection unless it has the remote keyword in front of the function call the reason for this is that otherwise a player a malevolent player could deconstruct your code and could compile it back up and for example call the function start server 100 times a second that's a great way to get your game server to crash so you will not want that and you can shield various functions that you would not allow want that you would not want a player to be able to activate you can shield those from outside connections and thereby you can create some safety into your code and otherwise it just wouldn't work in the first place it's just building so you remote function fetch skill damage fetch skill damage with the skill name with the requester the first thing we do is we are going to define the player id which made the request because we need a player id when we gonna rpc id call back to player because we need to know which pair we need to send this damage to and before we know where to send it to we need to know who requested it this requester is not the client that made the request this requester is the scene within the client the specific i spear so we can't use requester so we define player id by get tree get rpc center id this is a standard function that is inside or a part of this remote function call here then we're going to define the damage now we're going to go to the server damage skill data skill name damage very similar to how we went to game data skill data skill name damage when this was still on the client side so server data is now of course the server singleton where we have copied this code to that now comes from the from the json file then like i said we're gonna rpc id called the player now we're gonna run the return skill damage function like i said if i need something from the server i called fetch if i return something from the server i call return we're going to push that damage and the requester as you can see we don't do anything with the requester the requester is just piggybacking along for the ride so that we can use it again when it comes back to the client now i'm going to print just for demonstration purposes that this is actually working now going back to client you'll see here we have the function return skill damage is a remote function because again the server needs to be able to activate this therefore we use the remote keyword it's going to be receiving the damage and i've added s underscore here that s underscore indicates to me that that is original from the server that way i identify which variables come from the server and which are not it's easier to code like that and to make the code more maintainable we still have the original requester then we're going to instance from id so we're going to determine the instance from the id requester and then on that scene we're going to set the damage and we're going to push the s damage so here's where we use that requester again after it is piggybacked along for the ride all the way to the server takes no no no kilobytes or bytes on the internet whatsoever all very tiny so don't worry about that um then back to the ice sphere where probably you already seen that i had an extra function set damage that's going to be receiving the server damage and we're going to set the damage variable on the ice spear the damage here to equal to the server damage so that when we hit the wear bear when we hit the enemy we got that damage available from the server now with all that done we have to re-export the server to make sure that it has all those latest functions so i'm going to be re-exporting i'm just going to be overriding your original executable we made in the first place we can close that off i can now run the server we don't need a big gray box we need this black box now in the editor i'm going to run the client that should be successfully connecting yes it is let's also get this server here we see the user id connected can we get a little bit more yeah now we can walk around and as we here call the ice spear as you here see here sending 686 to the player and every fight is often enough this is where there is dying with damage from the skill that we retrieved from the server free communication between both client and server before you go please hear me out for like 20 seconds before i close out this tutorial because i got some important information for you now a last thing that i absolutely want to inform you on is that these rpc connections by default are not secure a valued member of the gdc community secret on discord has proven that if you are in a public network for example you're connected to the wi-fi at your local starbucks you're sipping away on your coffee and you're trying to log in through a bare rpc call a packet sniffer by another user on that network can sniff out your username and password your login credentials and that's of course a great way to get more support emails in your mailbox that you don't want to be working on because you want to be developing your next patch so please take seriously the security if you're making or working on a multiplayer title security is very important it's your responsibility as a developer to yourself as developer but also to the players that are actually playing your game so we will of course be covering security and how to implement dtls protocols using ssl certificates to make these rpc connections safe that's going to be a future episode along with other episodes regarding how to store account data on the server how to log in of course in the first place how to make sure players cannot exploit to all kinds of other good stuff including some great recommendations on youtube and twitter when i asked what do you want to know about multiplayer service if you get any other uh suggestions just please leave them down in the comments box below if you ever feel like you want to know what i'm working on myself my own personal titles i twitch stream every tuesday and thursday where i work on a title called souls whisper which is also multiplayer so it's great if you're working on this multiplayer project to maybe see me struggle with the multiplayer as well in my own game so without further ado i'll be closing this tutorial i hope to see you in the next episode and until then keep on gaming keep on coding see you later guys
Info
Channel: Game Development Center
Views: 55,880
Rating: undefined out of 5
Keywords: Godot Multiplayer, Godot Multiplayer Tutorial, Godot Server, Godot Dedicated Server, Godot Multiplayer Server, How to make a multiplayer game, Godot MMO, Godot Beginner Tutorial, Godot 2d Tutorial, Godot Tutorial, Godot
Id: lnFN6YabFKg
Channel Id: undefined
Length: 41min 19sec (2479 seconds)
Published: Sat Sep 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.