Announcement

Collapse
No announcement yet.

Separating procedures on server or client

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Separating procedures on server or client

    Hi everyone,
    I started to learn a new chapter of Unreal Engine. I wanted to understand how actually the networking in this engine works. For now I am not looking for the option of multiple clients where one of them is the "hosting" client. I want to create a server-client model. My game should have a server because I have plans, that the server will save some variables. So basically, the server should be used also as a database. I tried to implement some SQL into my own C++ BP node, but since I've heard of that there is a possibility to create a server, I wanted to do it that way. I read this topic and I understood a little how to create the separated server. But I don't actually know, how I should create a blueprint code for that. Because what I learnt is that you are making both - server and client - in one project... So how can I separate blueprints for each of them? I know there is a node called "Switch has Authority", but what I thought is that if I package my project, I will get only one <MyGame>.exe game. How can I select then, if this game will run as a client or as a server? And how can I specify, which IP should the clients connect to? Because If I will rent a server hosting, then the server will run on some IP address - where should I "type" this address to make the client version connect to this IP? I wanted to create also some simple version of "accounts", so you can login or register via the client version (using GameSaves, where there will be an array for usernames, array for passwords,...). Keep on mind, that I'm very new in networking. So if I can ask you, how would you proceed, if you want to solve this problem:

    1) <Client> has loaded the server map
    2) <Client> player found a weapon in the map and picked it up
    3) <Client> now has the weapon, so the weapon will "disappear" on the <Server> for the rest of the players
    4) <Server> has to add this weapon to the player's inventory in the SaveGame database
    5) <Client> logged out
    6) <Client> logged in
    7) <Client> loaded his inventory from <Server> SaveGame database
    8) <Client> is able to use this weapon again (even though he picked it up in a different session)

    #2
    1) ServerTravel on the UWorld of the PlayerController (https://docs.unrealengine.com/latest...vel/index.html)
    2) Do a Serverside Check (Run on Server function) if the player really found something (maybe do another trace)
    3) Same thing as 2 when its picked up on the server Destroy the actor (if it is set to replicated it will be destroyed on the client as well)
    4) still serverside stuff (set the inventory array to be replicated, maybe even using a rep notify so that your ui can respond to that inventory array change)
    5) On the PlayerController Code use the EndPlay method do a quick check if its the serverside pc (if(Role == ROLE_Authority) or use the Switch HasAuthority BP node) and use a savegame object to save stuff
    7) same way use the begin play check if its the server version and load the savegame object
    8) rebuild the character from your serverside pc using all the data that lies within the savegame object
    Free Inventory System (BP AND C++ Version): Clicky Clicky
    Player Structure System (Houses!) (BP): Pew Pew Marketplace Version: Yoink!
    Howto: Create Dragable UMG Windows: Zoom Zoom

    Comment


      #3
      Woah mate , you should not write things in a long paragraph like these, maintain the spacing. Big blocks of text would ward off people and many will not even bother to read.

      as for your question try this https://wiki.unrealengine.com/Standa...dicated_Server

      Also there are some command line parameters you can pass to yourgame.exe to make it run in a listen server mode

      Comment


        #4
        ruohki, thanks for your answer.. Unfortunally I didn't understand it. I don't know how to use ServerTravel via blueprints. I'm not working with C++ (the part with SQL was just a try). I don't know what is a Serverside Check (because I couldn't find a function called "Run on Server" in Blueprints). I need to know, where should I type IP address if I'm using only blueprints? And my another question is, how can I launch the server? I expected just some console without any graphics, not the whole game running.

        Comment


          #5
          ServerTravel in Blueprints can be run by using "Execute Console Command" and typing "ServerTravel MAPNAME" into it.
          ServerTravel will move the Server and all connected Clients to the new Map specified as "MAPNAME".

          A ServerSide Check can be made by creating a "Custom Event". In the CustomEvents settings you can make it "RunOnServer".

          There are 2 kinds of Servers in UE4. ListenHost (where the Server is a Client) and a DedicatedServer, which you start and other
          people can connect to it. You want the DedicatedServer. You can test him by hitting the "DedicatedServer" check box in the Editor
          right beneath the Settings for the Amount of Players in the PlayButton Settings (there is a small arrow to expand options).

          To create a separated Server.exe, you need to follow the step that are mentioned Commander Shepard's Wiki Link.

          I think to completely customize your Server with different parameters etc, you will need some C++, but i could be wrong here.

          Connecting to the IP of this Server will be done with the "Open Level" node (at least i think you can use this) and instead of the
          level name, you take the IP. Or you put the IP into the "ExecuteConsoleCommand" node with "open IPADDRESS".

          If you create yourself a UMG Widget with a textbox, the Player can enter it and connect.

          Servers can also be retrieved via the Sessions Nodes. If you have a session up and running, it can be found via "Search Sessions".

          NOTE: Without a MasterServer (or an OnlineSubsystem like Steam) you are limited to retrieving Servers only in LAN mode. So as long
          as you don't have such a Server that manages your Sessions or an OnlineSubsystem like Steam, you will want to join directly per IP
          if you want to join an OnlineGame.
          Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

          My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
          (Including 100+ Pages Multiplayer Network Compendium to get you started.)

          Comment


            #6
            eXi, pefect! I could understand it really easily :-) Really thanks a lot! :-) Once I think, the server is ready, I will read the Commander Shepard's Wiki and build the server.exe.
            However about the MasterServer... If I got it right, without the system I won't be able to "look for servers" in the client game. But will I be able to manually type in an IP address (through UMG) and connect to it? Because I want to provide servers to another people. I won't be probably able to run servers forever, so someone will be able to take it instead of me :-)
            By the way: Is it possible to run multiple servers on different ports and then just type in something like 127.0.0.1:7777 for World 1 and 127.0.0.1:7778 for World 2?

            Comment


              #7
              Think about it that way:

              When 10.000 Servers in the World are started for your Game and 10.000 Servers for some second Game. How would you know which Servers are for your Game when Searching for them?
              That's why you would need a MasterServer. When a Server starts, it tells the MasterServer "Hey i'm a new Server, add me to the ServerList". When a client wants the List, it asks
              for it. That's the most basic "MasterServer". Surely there is more about it.

              If you have Steam activated, you use their MasterServer. You may know about the "AppID" each Game has on Steam. This is the ID Steam uses to determine which Server belongs to which
              Game. Steam just lays beneath the Session System. UE4 uses wrapper functions. It will use the Functions that are needed to create and join Sessions for the active, supported Subsystem.
              Means once your Sessions System works for "OnlineSubsystem NULL" (which is the UE4 basic one with only LAN Session Support), you only need to get Steam activated + greenlit and you
              should be ready to use it.

              Back to the MasterServer question. If you don't use any MasterServer/OnlineSubsystem, you can still join OnlineServers by typing in their IP.
              And, as far as my knowledge goes, yes. You can host multiple Servers on one by using different Ports. But i don't know how to change the Port
              UE4 is using for its Dedicated Servers (: That is up to you to find out.
              Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

              My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
              (Including 100+ Pages Multiplayer Network Compendium to get you started.)

              Comment


                #8
                That's true, I didn't think about it that way, but what if I would just add a blueprint function, that will just call the server and ask for some answer. For example I will create function called "Check server" on client and the answer from the server would be "Hey, I am for Game XYZ"... And then everything will just continue. Any different answer would just cause that you won't be able to login and load the game :-) Something like free servers for World of Warcraft. You just had to type IP in some file to connect.

                Comment


                  #9
                  You can't access the Server without joining it and you can't join it if it is the wrong game. So it's not possible to ask the Server.
                  You would also need to ask 10.000 and more Servers before maybe finding one that is from your Game. (: Not really an option, or?

                  As i already said: Joining a server directly via IP is always possible (as long as Ports are forwarded correctly of course).
                  Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

                  My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
                  (Including 100+ Pages Multiplayer Network Compendium to get you started.)

                  Comment


                    #10
                    I won't give the player an option, to "search" the server through some kind of a server-list. He would just be supposed to type in the IP address. He would have to look for some server on the internet. Every server would have a web page, where the administrator would write "Our IP is ***.***.***.***, join us". If the player would type in an IP address, that doesn't have the correct server or doesn't have any server at all, it would just fail the login part. But if there would be a running server to this game, it will connect, load a map and play :-)

                    Comment


                      #11
                      Yop. You can do that. (: If it's the wrong IP, it won't join. So there won't even be a login fail.
                      Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

                      My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
                      (Including 100+ Pages Multiplayer Network Compendium to get you started.)

                      Comment


                        #12
                        Perfect :-) But even though it would be at least a decency to tell the player, that the server doesn't answer (either it doesn't exist or it is not currently running). Am I able to somehow decide through blueprints that the client game couldn't connect?

                        Comment


                          #13
                          There are "Network Travel Error" Events in the GameInstance if i'm not mistaken.
                          They fire when something went wrong while trying to travel and give you and enum
                          with the result/cause.
                          Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

                          My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
                          (Including 100+ Pages Multiplayer Network Compendium to get you started.)

                          Comment


                            #14
                            Okay, I will look for them :-)

                            Comment

                            Working...
                            X