Sign In Register

How can we help you today?

Start a new topic
Answered

GameSparks with a dedicated server

Good evening,


We are developing a multiplayer game using Unreal Engine 4. The game requires dedicated game server and clients, which comminicate with each other during match using UE4's own network system. We want to build our match-making backend using GameSparks, and we are struggling planning how's the best approach.


Currently, we launch the UE4's GameServer using a GS's custom script attached to the MatchFoundMessage, which makes a request to our own HTTP Server which is listening in the same physical server in which the UE4's GameServer will be deployed. This launch server sends back to GS the IP and port of the UE4's GameServer, which in turn sends it to bout UE4's clients, so they can connect to the running UE4's GameServer to start the match properly. Is this a correct approach?


Moreover, there are two options in this exchange of messages:


  1. GameSparks takes the IP and PORT as response to the HTTP requests in the MatchFoundMessage and sends the message to the players.
  2. The HTTP server, once it is 100% sure that the UE4's GameServer is launched, sends a LogEventRequest to the Requests API of GameSparks and in this event, the Cloud Code sends the message. <- How to manage the authentification? Can we employ one of the player's ID?


Those're our doubts about the initial launch. The real problem comes now that the UE4's GameServer needs to retrieve some information from the GameSparks' NoSQL. We couldn't come with the best solution to this problem since we have several options:


  1. The UE4's GameServer, using the Requests API and one of the player's ID, makes a LogEventRequest to GA. The event in the Cloud Code retrieves the info from NoSQL and sends a Message back to the UE4's GameServer, with the info cantined in JSONs.
  2. The UE4's GameServer employs directly the NoSQL HTTP API, doing the authentification with one on the collaborators' GA credentials.
  3. The NoSQL JSONS are sent to the HTTP's launch server in the very first request and then, it sends them to the UE4's GameServer locally in some way (writing in local files, via parameters,... )
  4. Any other suggestion?


The cleanest solution, we guess, would be to use the UE4 SDK to retrieve the information from the NoSQL without using the player's authorization because it's a server-server request, maybe using API KEY and Secret. Is that possible and/or advisable?


Could you help us to decide which way is the best in terms of performance and security?


Thank you very much,

Anas Belli dev team


Best Answer

Hi Anas,


The callbacks will allow you to run extra logic through cloud code that the NoSQL API does not give you. Also it means you can change the way data is sent back or what comes back without having to update your game. The servers will always be calling the same Callback no matter what sequence is in it which is extra flexibility for you. 


You can use Log Event requests to return NoSQL data to an Unreal Client. This is an example Cloud code for a log event request accessing a document in a mongoDB collection, adding a calculation to the values we pull and returning it:


//Get Collection

var collection = Spark.runtimeCollection("exampleCollection");

//Get document relevant to the level we're requesting the average for

var testDocument = collection.findOne({"level": Spark.getData().LEVEL});

//Calculate average, Total and Entries are variables within the document

var average = testDocument.total / testDocument.entries;

 

 //Return average performance for level

Spark.setScriptData("average", average);


I've put this example in to show you the advantage of Callback or requesting the data through a Log event request. It's having the ability to perform extra logic on top of acquiring the information from a collection.


Hope this helps,

Omar


Hi Anas,


I'm glad you chose GameSparks to aid your development. You'll find that it works wonders with Unreal.


For the initial setup:


When your dedicated server becomes available it can either use a callback (https://docs.gamesparks.com/tutorials/cloud-code-and-the-test-harness/using-custom-callback-urls.html) or use Device authentication to be able to send data back and forth using the SDK (Easier). 

Callbacks means you wont need to authenticate the server, but it also means you'll need to use the Unreal HTTP helpers to make those calls and turn the response JSON to useful gameplay information. 


Authenticating and using the SDK will be easier so you'd treat the server as one of the clients but with more permissions. 


For in-game interaction:


Similarly with in-game interactions you'll pick between Callbacks or SDK. Callbacks would use the API Key and Credentials set up by you in our credentials section. 


It falls back to you deciding if you want to implement callbacks. They are very useful and mean you can skip authenticating the server. However information needs a pipeline starting from sending the Callback through Unreal HTTP helpers to receiving the data to using the data.


Hope this helps, please update us on your progress,

Omar


1 person likes this

Hello Omar,


Many thanks for your fast response and ideas.


We were not aware of the existence of the Device Authentication and it's really cool. We're still confused on how to make use of the APIs, are we wrong saying that Unreal SDK can only use the Requests API and thus, do not have access to NoSQL? Forgive us if we are wrong, we are still learning the system. We are storing info such as decks in the NoSQL and we need the server to access to it.


If going through Callbacks (you're right, really useful stuff here), we assume that we would have to create a single callback for all the operations and return a different information based on a parameter's value. Apart from treating the info that's going back to the GameServer, what's the difference between using this or the specialised NoSQL API? The main problem of this is that UE4 HTTP helper is not really usable.


Thank you again,

Anas Belli dev team

Answer

Hi Anas,


The callbacks will allow you to run extra logic through cloud code that the NoSQL API does not give you. Also it means you can change the way data is sent back or what comes back without having to update your game. The servers will always be calling the same Callback no matter what sequence is in it which is extra flexibility for you. 


You can use Log Event requests to return NoSQL data to an Unreal Client. This is an example Cloud code for a log event request accessing a document in a mongoDB collection, adding a calculation to the values we pull and returning it:


//Get Collection

var collection = Spark.runtimeCollection("exampleCollection");

//Get document relevant to the level we're requesting the average for

var testDocument = collection.findOne({"level": Spark.getData().LEVEL});

//Calculate average, Total and Entries are variables within the document

var average = testDocument.total / testDocument.entries;

 

 //Return average performance for level

Spark.setScriptData("average", average);


I've put this example in to show you the advantage of Callback or requesting the data through a Log event request. It's having the ability to perform extra logic on top of acquiring the information from a collection.


Hope this helps,

Omar


1 person likes this

Dear Omar,


Thank you so much for your comments. They are really useful. We have decided that the GameServer is going to use DeviceAuthentication + LogEventRequests to do the communication with GameSparks using the UE4 SDK.


We'll use the Callbacks for our MasterServer since the communication via HTTP there will be easier.


Thank you very much again for your quick and very useful support,

Anas Belli dev team

You are very welcome Anas!


We'll be very happy knowing how you get on and as always are here to help.


Cheers,

Omar


2 people like this
Login to post a comment