Sign In Register

How can we help you today?

Start a new topic
Answered

Questions of RT service

Hi,


After reading tutorial of RT server, I still have questions about it.


1. what is the life cycle of session? when will it be terminated? can I control it?

2. what is the life cycle of a RT script? what happened to a running game if I changed the code?

    the variable in the script will be alive forever?

3. if I want to save some data to Mongodb, all I can do is sending LogEventRequest to save it in cloud code?

4. can users enter two RT session at the same time?

5. how many player can enter a RT session? any limit?


Thanks,

Jo


Best Answer

1- The session stays alive as long as players are connected to it. If the last player leaves, there's a grace period of 60 seconds. If no one connects to this session within the 60 seconds it will be terminated.

2- In the preview environment, the RT session will use the last saved RT Script. In the live environment, the RT session will use the RT Script in the published snapshot. Changing the code midway in the session won't affect it. The variables within the script will stay alive until the session is terminated.

3-Yes, because the RT server is an independent container, it has no connection to the normal API and Spark functions apart from calling requests on behalf of players.

4-Yes, but I'm not sure if the SDKs (Client) can handle multiple sessions.

5-I don't think there's an upper limit, but of course, performance will take a hit.


Hope this helps,

Omar



Answer

1- The session stays alive as long as players are connected to it. If the last player leaves, there's a grace period of 60 seconds. If no one connects to this session within the 60 seconds it will be terminated.

2- In the preview environment, the RT session will use the last saved RT Script. In the live environment, the RT session will use the RT Script in the published snapshot. Changing the code midway in the session won't affect it. The variables within the script will stay alive until the session is terminated.

3-Yes, because the RT server is an independent container, it has no connection to the normal API and Spark functions apart from calling requests on behalf of players.

4-Yes, but I'm not sure if the SDKs (Client) can handle multiple sessions.

5-I don't think there's an upper limit, but of course, performance will take a hit.


Hope this helps,

Omar


Hi Omar,


Thanks for quick reply.


About 1.

I have to keep the game even after 60 secs.

How can I save the game state to DB before it is terminated?

How can I rebuild the session if the players came back after 60 secs?

I want to make user feel transparent about resuming games.


more question:

6. The real-time session is generated by MatchFoundMessage. 

    If I set min. player to 1, the first player entered the RT session, can I just pass the RT-server info (port, ip, token) to other players to let them attend the RT session? Or every player must make MatchMakingRequest?


7. If player disconnected (network fails or app terminated), how do I handle the rejoin process?


Thanks,

Jo

You can keep track of your players leaving using the OnPlayerDisconnected event. If the last player leaves you can send a log event using any player ID, it doesnt have to be a player in the game. You can create an admin account and send requests through that ID or use a player in the game. This can trigger some Cloud code you configured that takes the data sent via the log event request input and save it to mongo.


Adding players to a session can be done via Cloud Code using the Spark.getMultiplayer function which exposes useful functions, for example:


Spark.getMultiplayer().createMatchById(playerId1,playerid2)
Spark.getMultiplayer().loadMatch(matchId).addPlayers([player1,player2])

 

I think this will allow you to answer all your questions. If you need more details on this API, please follow this link:


https://docs.gamesparks.com/api-documentation/cloud-code-api/multiplayer/sparkmultiplayer.html

Hope this helps,

Omar

Hi Omar,


Thanks, I'll look into that.


BTW, how to get realtime.log via cloud code?

I would like to build Real-time ScriptLog Screen in dynamic form, but the runtime collection of realtime log is kind of special , not like script.xxxx.

So I have no idea how.


Thanks,

Jo

 Hi Jo, you should be able to use:

 

Spark.systemCollection("realtime.log")

 

It is a system collection, even though its under runtime collections. I understand this is confusing. By nature, system collections are readOnly. This is an exception.


Cheers,

Omar

Hi Omar


it works! thanks.


Is there any way to trigger realtime script function from original GS platform?


Ex : 

An user A in realtime game may need owner B to confirm a game-related request, but B is not in the same realtime game.


the flow might be:

A send a packet in realtime server, realtime script send a Log event request to GS platform, save the request data in DB, send message to inform B.

B send a LogEventRequest to confirm/deny the game-related request, save the result in DB, but the game state in realtime server have no way to know it.


Any solution to achieve this?


Thanks,

Jo


 Hey Jo,


Yes, you can, however, you're gonna have to do it via the client.


Player B will send player A a script message when they've made their decision. Player A's client will handle this message and will invoke a packet to the real-time session and changing its value.


Unfortunately, there's no way for the backend to change a session's data.


Cheers,

Omar

Hi Omar,


I see. thanks.


You said I can use createMatchById to create match manually, but why is there a matchShortCode parameter in that function?

if no matchShortCode, how do the server create real-time instance for me?


Do players in the match receive the MatchFoundMessage after  createMatchById to get realtime server info?


a little bit confuse how to use.


Thanks,

Jo



 Hi Jo,


Sorry for the delayed reply. I was testing some stuff for you. It seems the approach I suggested will not work for RT because you cannot obtain the auth token to make the initial connection. I have made a feature request to include this. For now, I have found a work around for you.


 

//String array. Can be obtained through input or database collection
var exampleString = ["58e5051c9650b504ccff2b40","58e505209650b504ccff2cb1"]
//Create matchmaking request
var request = new SparkRequests.MatchmakingRequest();

//Set shortcode
request.matchShortCode = "shortCode"
//Set matchgroup ID by getting the long epoch time, this will mean only the players with the exact time will join each other
request.matchGroup = Date.now().toString()
//This is not important but has to be set, you can set the epoch time here instead if you'd like
request.skill = 0

//Loop through every ID and send the request on behalf of the player, all requests will be exactly the same
for (var i = 0; i < exampleString.length; i++) {
  request.SendAs(exampleString[i])
}

 

Your players will receive a match found message.


Hoping this helps you,

Omar

Hi Omar,


I'll try it.


1. Are the tokens all the same for each player? 

If some other players wanted to join, can I just send them the RT server info and the token to let them join directly without MatchmakingRequest?

(I know I can set the match dropin/dropout, what do suggest?)


2. If my client disconnected / app terminated, how to get the RT server info and the token again to reconnect?


sorry about so many questions, it's a little bit hard for me to get the whole picture only by tutorials.


Thanks,

Jo


 Hi Jo,


I think the token is time sensitive. I don't think it's limited to one player, any player can use it to join the session. Currently, there's only one way to obtain this token and it's through the match found message, which is not convenient if you want to add players to the same match through cloud code or other means. Drop in drop out will have to be a feature in your match if you want to allow players to join and leave. 


I think if you player disconnects, the only way to reconnect is by trying to use the same auth token as before, it might work, I dont know the time period the auth stays available for.


No, I am sorry, this should be clearer. Thank you for your feedback, I will ensure that we bolster our documentation to avoid similar confusion. I will look into allowing you to generate auth codes for players to join the RT game.


I will look into the token stuff into more detail for you.


Cheers,

Omar

Hi Omar,


Thanks for your patience.

The token expiration is quire important to our game, because our game may last for hours, even 1 day.

I have to ensure players can rejoin the game anytime as long as the game is not terminated.


Looking forward to your answers.

I believe it will be very helpful to all developers, too.


Jo


Hi Omar,


I have some questions:

1. is the RT service connection encrypted? is it possible to intercept the packet and see the raw data?

    If no, is there any encryption could easily be applied? I know the websocket connection of GS platform is encrypted, but am wondering the RT service.


2. if I used "reliable" packets, is the order of packets delivered guaranteed?


Thanks,

Jo

 Hi Jo,


I have to do a bit of digging to find out the exact expiry time of the token. I will find out for you.


RT packets are only encrypted if their intent is reliable. Also, reliable packets are queued up, so they are delivered in order.


Hope this helps,

Omar

Login to post a comment