Unreal Engine Dedicated Server Manager: From Start to Finish

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so welcome or welcome back to be tight and in this video we are going to make a server manager now I have not seen a single video on this topic on YouTube so I thought I should create a video on this and I have been creating server managers for the last six months I think so what we need to do is for Server manager we just need a node.js server which will manage how many players are coming in and how many Port like how many servers do we need to start now we will not be covering the system on how to pack dedicated servers this is just maybe like based on making the dedicator like meeting making this server Manager work and now this server manager can do a couple of things firstly it can keep track of the number of players in the current session and it will even keep like it will start this dedicated servers if itself on a random Port uh if the number of player exceeds the minimum maximum number of players that can be in there like can that can be in a session now this can be made a lot of more like a lot more advanced but different virtual machines can be used together so that would be covered in advanced dedicated server manager which is available on our patreon you can go and get that and even the project files for this video is also available on patreon uh support here like thanks for supporting if you are going there and let's have a look at what we are going to do so if you play so we get this thing as we will make a connection successful note and we get the port status now like this returns as the port status let me just show you this gives us the post Port status and on a player count status and the IP of the server now this thing can then be used to open the level now if we go up we can see that we are trying to open that level and that's why we have a small error uh that Network failure and that's why because like on that that dedicated server is not the dedicated server of this game it's just for testing out purposes so that's why but you can pack dedicated servers and just run it in the way we did and this is not that much Advanced because you don't expect that in a 50 minutes video but I hope this video is useful and you can easily build up on this and yeah now you can start moving one more thing before moving ahead is the relation with play5 and EOS now if you're using playfab then it provides the virtual machines itself but basically they cost a lot so you can use your own homemade virtual machine that like is being hosted on your computer and then just run this server manager and from the game connect to this server manager and request a session and you can make this a session map like session managed sorry server manager region based or add rules for it forever like whatever rules you want to make and if you are using EOS you can do the same thing you can deploy your servers locally on your local network and connect it to your websocket connection of node.js that we will be covering in the video ahead and then any game from any part of the world user can connect and if one dedicated server is failed then you will connect to a new created dedicated server one last question uh that we will cover before starting on is uh what was it yeah how many dedicated servers a machine can handle now this really depends upon how uh Pro like what processing power your machine like your dedicated server is taking but if even for a pubg type game we have seen 20 20 servers on a single machine doesn't give a load so in this video we will be covering only one machine that means uh it is assumed the server manager is running on just a single machine and it will start multiple instances of the dedicated servers as required as in when required and yeah yeah now you know and uh one more thing nothing you can now start and do hit the Subscribe button if you wish and thank you okay so welcome back to the screen now presuming that you have oops my input was very high sorry for that but presuming you have uh node.js already installed which you can just go to the node.js website press download and then just go through the process remember to add it to the path and just press install and it will do that so after you do that we will just we have just created a basic server manager uh what we call a folder for that and now in this folder itself like this place where the path is put just press here on it and write CMD you can do that with normal file manager or even this enhanced file manager any of it will work just write CMD and this will open up the command panel in the location of uh this thing what we call sorry for messing up the name but command panel uh in this place in this folder path so now what you need to do is we need to initialize node.js so we will just make uh npm initialize and this will ask us for a few package names and things like that and we will leave everything to be default and remember we have set the entry point to index.js so we will keep our main server.js uh sorry the server file as index.js don't worry if it confuses if you're just here to make the server manager and don't know much about node.js following the video you will be knowing everything so just press enter enter and you will get this is this okay yes just press enter and you will get this line and done now you will see a new file package.json now the next thing you need to do is you need to write npm install WS now this will install the websocket for you in your project you will see a new folder named node modules which will have the Ws not node module this is the only thing we require for now so let's continue now again write CMD and this time write code dot now this will open up the visual studio code now I usually use Visual Studio code to edit this folder uh sorry edit Json code uh sorry edit node.js code you can use any uh I even use Fleet by jet brains of a very really nice tool for uh Edition but it's still in uh preview versions so that's why not very stable and I that's why I'm not using it here anyways the first line let's start writing the code for This node.js Server don't ask me many questions regarding This node.js Server because I'm not a backend developer although I have a good knowledge with node.js but not that good you can understand like okay okay now we will initialize the websocket connection and we will just make it and require ws and we already have the Ws oops WS installed so this now the websocket is initialized next we need to initialize spawn so if you don't know what the spawn is so what this Pawn will do is we'll start our dedicated servers uh it's like starting a terminal window from node.js code and child process and I believe I made a spelling mistake here c-h-i-l-d child oh sorry this should be this brackets and not the curly ones yep now this the error is gone then we will initialize uh our websocket like we will start our websocket connection so we're starting a websocket server is very easy we will just write a new websocket dot server and then we will pass in the port which we want the uh this websocket connection to run on I usually use 4000 for the ports so we will be using 4000. and then we need to initialize the latest dedicated server and the number of player it has so we will be holding the information of the last dedicated servers and which uh Port it is running on and we will keep on adding the number of players that join now just remember if you want a very Advanced dedicated server you can already as I already told in the start of the video you can check our patreon we have a very really Advanced dedicated server manager and it will be getting frequent updates uh and also we are planning a tool like that for our uh Unreal Engine in your program but anyways we will make a lit dirty dedicated so we are initializing a variable named dedicated server and we will make it equal to and this will hold the host info that is the IP address or you can make this IP address if you want or let's keep it host uh this will hold the IP IP of this machine that is uh the virtual machine which is running this script so that would be our let me open up Google Cloud okay so this is my public IP of my virtual machine and I will just put this here and after the this is done we will just pass in the port info now this port info will be managed by our server so we can just pass any random Port uh we can just make it 3000 Maybe and done so because it's a number so that's why we did not put it uh in that bracket type something because we will be taking a random Port info and then we will have a status so that we can check if the port is full or not and I would suggest if you don't want to use status you can leave this out but I would be using status because this will also be used in uh Advanced server manager and in this player count foreign so this player count is the number of players that this server currently has so the default would be zero of course and the when we have this dedicated server ready then we can just make WSS on so this is a listener for events so basically this will wait for a user to send a message or just like this will wait for a connections and currently only the key players would be connecting to this WSS connection so that that's why we just have WSS dot on connection uh just let me check if my OBS is even running yep it is so if we receive a connection request what we need to do then is we need to pass NWS and we need to make this event so that this fires up and the first thing that we need to check if the dedicated server player ground dedicated server dot player count is greater than equal to the max number of players you want so for instance I just want uh one player in my server uh maybe two then maybe I will just want two players in my server if it is greater than the that then what I will do is then I will just make dedicated server dot status and change it to full and this will do the trick for me now if this is not the case that means the server still can take pairs then I will make dedicated server uh Dot player count plus plus now this is uh basically we increase the player count so that like it's an async work more players can join and continue the process and the process is the fixed for every player now if this is done then what we need to do is we will check if the dedicated server status is equal to full so in this case we need to fire up a new server and we can just get a random Port first and this can be taken by math floor and then math dot random and you can pass in a random number now this random number can be a very big number as you can wish so now this thing will this random thing will return us a random number between 0 and 1. so what we need to do next is multiply it with a number which can be the possible maximum Port value so we will just multiply it with uh six five five three five I think yeah or three five yes and then we will just flow like make it uh flow sorry uh integer number as you can just hover away and it is the greatest integer less than or equal to this number so this will return us the port value so now we have a random Port then we will just set the dedicated server dot status and then we will make this equal to running and now we need to reset the player number oh sorry this should be the player count to zero and then we will just start the dedicated servers now we do not have a function for starting the dedicated server so we need to create one we can just end this thing here and we can create a function uh maybe start Teddy created server something like this and we here we will just start the dedicated server along with this now this dedicated server can also be just a second sorry for the break but yeah now we will just start that regarded server and after the dedicated server is started then we will just send the information over to the user now if this is not full then we just need to set send this thing itself so we will send this as a Json so we will make w s dot send so this will send this to the connected users and we will send this as Json we will trainify this and the data should be the dedicated server and we will end this here so now the user has the updated info so he will have the dedicated servers and everything like that and here so now we will work on the function that like the command that will start the server so we can just make a server start command and we can make it equal to the command that we are going to use now we can get the file path so we have uh our virtual machine and sorry I was testing this out and that's why you can see some error and you know why Theory it is and we can go to download so this is the dedicated server path that we are going to use then map one server and this is the server file so we will just copy this although we are going to make one more server dedicated server copy but I'm just I just want to show how this thing is done now after this is done we need to pass this file path so rename this and make hash and pass now you must see that we require two hashes everywhere so that I don't know why just add hashes everywhere where there is already in hash no word should be blue uh in my case it should be not be blue but I believe in your case it can be something different but now you need to add a log so this log basically uh prints the log and if you do not have this log option enabled if you are using a shipping build for a dedicated servers then you can just enable logging in shipping builds also now we need to pass in the port info so we will make it Port is equal to dollar sign now dollar sign is a wrapper my favorite one but anyways let's leave that behind and we will pass in the dedicated server.port here like this and this will have the port info now and we have the command panel ready now this command will start the servers as it is now we need to execute this command so we will get the spawn thing and we can just make so what start command and we can store the errors and everything like that so we will make an error command STD out so something like the process printing thing okay it brought the steady steady STD out itself and we will also put STD err or not much info that I know about this I believe these are just for printing the errors and informations of how the server is starting and then we will make console.log foreign we can directly print it right okay so we will check if there is an error and if there is an error we will make console dot error and we will print the error itself so we will exit error and that is it and we will make a return statement after this is done we will make console.log and put the STD out dollar sign STD out and end it out there and just copy this line again uh s t e r r paste this out here and paste this out here and then we are done with this thing so as you can see this is showing an error here it expected an end line but I do not know why it expected that from me do not have any expectations like this from me please but oh okay this should have been a normal uh brackets and not the calibration yeah the error is one and this is the updated code so we will copy this up the whole code open your virtual machine and go to your server.exe we will open up the server file and I usually use code.i for this so code.i and this must be having some code already in it but I will remove that it is not the correct code so I will copy everything and delete so that you do not know anything that I did and let's close this up paste please paste up yeah so we have the code here now let's save everything and one more thing that we need to do is okay let's just start this we will do things later we can just close these command panels we will write node Dot and start you can even write note index.js or index file name.js whatever file name you have I have put written index so I can write dot dot can only be used for index if you have the package dot Json like that ignore all version I said so now when we have the server started we can just go to a websocket checker I will uh reset yeah so we have this websocket Checker uh Pi socket websocket tester this is one of the best tools to use websocket like test for uh websocket and you can install this I will share the link in the description and then just go to this extension panel and make it open full size now this has a location for this websocket so we can use this to easily check out uh if the web sockets are working or not so we will copy the IP from here now this is the dedicated server IP because dedicated server will be running on this machine but the websocket IP will also be the same as you already know why because it is running on the same machine so we will remove this connect thing the whole thing that is this link and we will just leave ws and WS not double s just single s and write the IP here and then pass the port info that your server is running on so our node.js server is running on 4000 Port so we will make it 4000 and we will press connect so it says connection established received so as you can see it uh can we I do not want to share what is what else is being displayed on my screen yeah so so as you can see uh it gave us the host details the port status running and player count so Play account was here zero but we have an updated pay account because we connected to that that means the player connected to this server and the player count increased we will close the connection and reconnect now the player count is two the port is still 3000 that means the default port and it is still running and the dedicated server has not started because we first start the dedicated server at the point when we check if the current server is if the first server is full which is like a shortcoming but we will fix that and now if we connect this time it says established and close this time it did not give us an any thing like uh nothing came up now let's check the error this must have printed some error here yeah and this is or throw new invalid argument type object type and this has some error error error the RS must be so this line has an error uh let's do one thing uh in this child process let's add execution as the main file and change this spawn by execution and change this spawn by execute and now rerun the server now we reconnect established connection established we reconnect connection re-established connect and now it says exec is not a function although this should have been as you can see e x e c hmm let's check the server error for this okay I got it we are using brackets here which we should not have used and now let's try to run close and connect and as you can see it says uh it gives us a new Port 32769 status running and things like and you can see the server is started in behind Conga Congo Congo Congo the server is now running now let's just check the port again uh which Port it was it is three two seven six nine that is a very complex four by a uh but let's see if we get some Port info here also and can verify if the correct Port is used by Unreal Engine uh the port info cannot be seen again okay okay we will make a system to make this a randomization better but that can be laid done later because this is running on our webs uh saw server so this is just a line code so we will make sure to print out the port that the server is running on but yeah that works for us right that works that works bro that works that works so after uh we have two players we create a new server and things like that work now what we need to do next is we need to make a system which like the the Unreal Engine game can connect to the server and get that get the data and join the server then we will add a few more properties to this to make this a more advanced server and you know where to check for the most advanced server manager tick tick tick yeah it's important to promote patreon or else how will I Will Survive please save my life anyways let's get back to Unreal Engine so welcome back to the screen now we are going to use Unreal Engine 5.1 to create the small C plus plus code that we need to like that we want to use with this you can even get uh the project directly that doesn't require you to use the C plus as you already know the reason so now we are going to create a c plus project for third person and we are going to name the project maybe uh basic so manager and then we are going to make it maximum and disrupt let's leave that and just create the project so this will create the C plus project that we require and we are going to edit this in Rider you can use Visual Studio 2022 if you want but I don't think that uh concerns anyone but yeah so now yeah the rider is open so let's go to build dot CS folder and in the build.cs folder we will add a new sorry in the build.cs file we will add a new public dependency module name and that would be for the web sockets so Unreal Engine has that inbuilt so we do not need to do much here and yeah but it would be tougher than the node.js part so yeah node.js developers we do a lot of work anyways huh so so after this is added uh I mean this public dependency then we are going to our build servermanager Dot character.h and CBP now you can do this in game instance and in the character blueprint class also so okay let's do this in game instance because then we can call that function from anywhere and we do not require this so let's open the engine just compile this this will take a single second but yeah compile successful let's go to tools new C plus class let's even check plugins if we have to okay I don't think that we require this yeah let's just add a new C plus plus class for game instance and we can name this base game instance and we can just create class so we have this so let's close this up and open our game instance okay okay uh where is this let's just reload all from disk base game instance yeah base case game instance CPP and H so now when we have this up we will go and disable this sorry I'm a bit I am a bit uh confused because okay let's sleep okay now we will add and include and that is from for the I websocket and after the websocket include is added we will make a public selection and one more thing we need to write the code so that we only connect to the websocket server when we want that means when the user like clicks on that button so we will create a new property for this so sorry U function and this should be blueprint call label and this should have a category of uh match making functions and then name this you can just name this void or maybe you name this add a Boolean no let's add oil sorry sorry for that confusion void uh get Daddy created server so this will get us the dedicated server so we are going to now generate definition for this server and then uh when this hour like when we initialize this now we need to like connect to the server that means we need to first check if the websocket is loaded or not like the module itself is loaded or not and if it is not loaded you we will have to load that so we will get the F module manager and we will get dot is module loaded and we will pass the module in that is uh web sockets now after the module is checked if it is not loaded that means we need to load that so we will get the F mod you will manager and we will just load that up and we will pass with sockets so a lot of guys while copying the code see if like this something like it's written is in modulime so don't copy this this is just the Riders method of showing what this is so just write the web sockets in bracket I came up with a lot of questions in the Eos series that why this thing is written here and if you write it it gives us an error in visual studio so this is written by Rider and we have not written anything it's just this thing remove this in module name so after this we will initialize the websocket connection so for that we need to create a variable firstly for our websocket so that we can initialize the websocket so uh we can make a t-shirt pointer and this would be for ie websocket and we can name this websocket connection and let's go back here web socket connection so now after this websocket connection we will try to connect to this websocket connection so for that we need to get the if websocket module get dot create websocket and then we will pass in the websocket connection URL now if you remember I must have that tab open no please don't say that I have closed it sorry I'm really sorry I will have to open the code yeah if you remember we had this as the node.js and the dedicated server IP so we will just copy this and we will paste this here so if you remember we opened that websocket connection checker and we use this thing as the websocket location so same way we have to use the URL uh the websocket URL so we can just safely replace this by here now a better method would be to just go and declare a U property and make it blueprint uh read write edit anywhere category match making variables and make it a f is string let me just check if it takes the F string right yeah F string so if it it takes F string and you can name this web socket URL and here you can just pass in the web socket URL so that we can now modify this thing uh from the blueprints itself and we do not need to like come in the blueprints array sorry come in the C plus plus code and change that again and again then we will open the websocket connection and after we have connected we can now print and message that yeah the connection was successful so you can add a u object or add Lambda because the code that we have used from description has used Lambda so uh because he will even explain using Lambda so I believe it's better that we also use Lambda yeah and in this Lambda statement we will just print an string so UE log log temp warning text and what text we do we need to print oh we need to print the message that we have successfully connected so success fully connected and we will end this here now after the connection is done we receive a message that means as I already told in the start of the video we will receive a message message from websocket so we will have to change the on connected to uh on message on message and this will give us the message that we written now we also need to add in parameter that this message will be returned so we will have to add a const F string and we will make it message string and here we will just print the message string why is it not printing please print okay re-looking at the code we finally get it uh it's uh on a screen message debug but anyways we have to convert it to a Json later so let's use this we have this receive message and let's check if this works let's play and try this out build succeeded and yeah I'm just checking the code anyways let's go and create a new game instance oh this should not have been an actor class uh blueprint and we will search for base game instance and we will name this BP game instance and then in this BP game instance we will go to class default and we will have this websocket URL that we can copy from this website oh sorry you must have made this why would you copy it from website but yeah pass this here compile and Save and on initialization itself event initialization we will add a delay of just five seconds and we will search for get dedicated server let's check what it prints and we will also go to our virtual machine and start the dedicated server so it's already running and as you can see it says as a exec error uh that should not be a problem so don't worry for that but we can just connect from the website once and check everything is working yeah the player count is one and this will start the server I think or it must have already started something like that why is it opening mine bro what has happened to this okay let me just reconnect to my RDP I don't know what has happened okay so I have a different monitor size and that's why I think yeah so this works and we will just send this message again oh sorry close reconnect we have the pay account too and now whichever PC connects will start the server for sure so we can now successfully connect from our game let's check that we will go to this third person and we will just play in the selected level and then go to Output log in after five seconds let's see what it prints oh sorry I forgot to do one thing let's go to Project settings maps and modes and set this to BP games since I'm really sorry I forgot that but yeah now this should print in five seconds one two three four five oh done bro please print something bro please print I believe something is not correct the timer is for five seconds and in Project settings we have BP game instance everything is working then why is it not printing uh let's play in a standalone but before that let's go to edit play and let's add command line options DOT log nope we do not want that to be done and let's play an additional standalone tick tick tick nothing happens okay let's go to the website and check what number of players it already has anyways my something is happening to my graphics card any error okay it's combining here just anyways let's go back to a website and recheck connect again nothing connected that means and this has us over all single server started so that means the connection failed or maybe something happened that it did not start the server let's check the code for this we have this module oh we forgot to connect that's why we forgot to even connect ah nice that's the biggest thing connect oops we would forgot to do this and then we can just recompile compilation successful let's now play successfully connected and we have this received message host Port running player count one that means we are now connected to our server manager and we can get the host and the port details that is really great so we can now close this up and work on basically uh better like changing this to Json data so that we can use Json for this and then let's just close this like we can convert this message string to a Json data and then get all the values out of it so you can even use v a r e s t but okay let's do that so next what you need to do is you need to enable v-a-r-e-s-t plugin the most famous plugin for working with Json so we can just install this to the engine and we already have that so we can just safely close this and go to the project again you want you can eat a biscuit but anyways let's go to plugins and search for v a r e s t and cancel and restart now now here we will create a new F string and we can just copy this thing up and we can make this return of so this is something like a quicker method to solve this issue uh dedicated server and this will store the string for the dedicated servers so after sorry for that but now we can just go to the base game instance dot Edge and here we will make dedicated uh return of dedicated servers is equal to message string okay so now we have the return of dedicated server equal to the message a string function we can safely close the engine and this message string will hold the info and we can now just start and go to our game instance and in this game instance we will get we will make a branch although we should have made a more optimized solution to check whether we get the response or not something like a delegate but this thing will work for now we will get the return is empty if this is true then we will add a delay of maybe two seconds and we will just make a print string uh uh variable empty and then we will pin here then what we need to do is we will get uh the v a rst subsystem and then we will go to vrsd subsystem and sorry I have not worked with this thing from a long time but I believe something oh okay construct Json object yeah that is it right click this promote your variable and name this uh response and then in this list we will get this response get to V A rst Json and decode Json pass the string that is the return of dedicated servers using incremental password and then make branch foreign go to varst Json get field names for each Loop and just print all this print all the strings uh all the field names this way we can know that yeah we are getting the right values or not so save this up why is it taking so long it's giving me attention oh okay I already have it playing no worries I will close this closed now let's play save okay this should work now just give it five seconds to load that is the initial time it takes and successfully connected and yeah so as you already saw that works so now we can just add we can just remove this Branch because that is working perfectly but do we even have to do that and and we can remove this even and even this and we will just get the field and in the field name we will pass the first field that is let's go back to our Visual Studio code and we have host Port status and player count so we can use the host and the port info so we need post and we can copy this up and write port and I think we can just convert it as a string and we can then get uh open level or maybe execute console command and then in the command we will make append and here we will pass open then the IP information that is the host so host in for like stores the IP information and then we will make this thing uh so that we can connect the port and here we will copy this up and pass the port info to the D statement and this will open up the port so for now because no uh we have not built any dedicated server here we will just set this up here and paste and play let's check if that works although no dedicated server is running and the server on that level is uh variable empty open one this and open port so okay so that will not connect of course because no server is running on that Port uh in reality and you even have an error that broadcast network connection timed out and no server was found so it opened up the third person level but here is the thing now you can just and you can see the servers are running but that is of a different project so that is something else so this is how you create a dedicated server manager now I know you must have a lot of questions on how to expand this and create it much more better like in a much more better form so for that what you can do is you can either get the example project from patreon uh which has a lot of more functionalities for matchmaking and things like that and even region based uh matchmaking or uh what else you can do is basically you can just put to or basically you can just add all the logic that you want here like you can add the number of players what region they are you can add checks here now I know that can be difficult so if you want you can even hire us for freelance yeah like we are open to do jobs so you can even hire us to create custom dedicated server managers and if you have a large scale servers we can even create managers for them all the links will be in the description of course so that is it for this video meet you in the next one hope this video is helpful to for you guys and as I already told in the starting you can use this with EOS and play5 and I have already shown all the examples So yeah thank you meet you in the next one
Info
Channel: Betide Studio
Views: 8,102
Rating: undefined out of 5
Keywords: Unreal Engine, Dedicated Server, Server Manager, Game Development, Multiplayer, Video Tutorial, Unreal Engine Tutorial, Server Hosting, Game Server, Server Configuration, Server Deployment, Game Programming, Unreal Engine Programming, Unreal Engine Dedicated Server Tutorial, Server Management, Multiplayer Game Development
Id: QHPP48Y6Gu0
Channel Id: undefined
Length: 56min 3sec (3363 seconds)
Published: Wed Feb 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.