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



 Hi Jo,


I don't see a problem with that approach. Just ensure that players receive messages when they've been connected. You need to keep your players updated on the status of the match.


Cheers,

Omar

Hi Omar,


I see, 30-day is enough to us.


Right now, it's easier to set the same ID from our other mechanism.

Who knows the ID can enter the game, so I add players when they ask for match detail (MatchDetailRequest script).


Any potential issue could occur for this approach?


Thanks,

Jo

The problem with creating a match is that it doesn't allow drop in drop out, players will have to be added via cloud code. The match session expires after 30 days too. You cannot configure them either, apart from enabling and disabling realtime. Again, since you cant configure it, you cant set min players to 1.


The token will stay valid as long as the match. I dont think it'll expire before. It will not cause you problems.


Cheers,

Omar



Hi Omar,


thanks for your solution. Good to know the new way.

I might try the original one first, because it can assign custom match ID.

its only drawback is min. 2 players.


If I could assign match ID via the new way, it would be perfect.


Looking forward to your answers to token, match instance, session life cycle.


Thanks,

Jo

Hey Jo,


I found a better approach for you that will fix all previous problem such as not having the ability to create a match based off a config and not being able to start a match for one player.


Here is the new Cloud Code:



 

 

//Example player list
var playerIds = ["58e5051c9650b504ccff2b40","58e505209650b504ccff2cb1"];
var players = []

playerIds.forEach(function(id) {
    players.push(Spark.loadPlayer(id));
});

//Create match, with a list of player IDs, this will return the match's ID
var matchID = Spark.getConfig().getMatchConfig(shortCode).createPendingMatch(matchGroup, skill, players);

 

 

By creating a pending match, you will receive a matchfound message the moment the minimum player limit is met. So you are still working within the system and not having to configure script messages.


I hope this approach suits you,

Omar

I'll find answers for your questions as I am not too sure.


Cheers,

Omar

 Hi Jo,


I dont think you should worry about that, I think it will remain valid until the session dies. If not, we can definitely pursue a solution.


Cheers,

Omar

Hi Omar,


How about the token expiration? Will the token expire? 

If so, when and how to detect it?


Thanks,

Jo

Hi Omar,


Thanks, I'll try it.


1. Is it possible that only passing one player into  createMatchById ? I always get null if I passed 1 player.

2. If I used MatchMakingRequest, the match instance will be deleted after the game is finished. (I don't know exactly when)

    Will the match created by cloud code be deleted in some conditions? or it will exist forever?


Thanks,

Jo

 

 

 You can then use this Cloud Code to create matches and add players to them:

 

 

//Example player list
var playerIds = ["58e5051c9650b504ccff2b40","58e505209650b504ccff2cb1"];

//Create match, with a list of player IDs, this will return the match's ID
var matchID = Spark.getMultiplayer().createMatchById(playerIds);

//If the game has been successfully created
if(matchID !== null){
    //Get the match object
    var match = Spark.getMultiplayer().loadMatch(matchID);
    //Enable Real-Time with the RT Script you want
    match.enableRealtime("shortcode");
    
    //This script message will be sent to the players notifying them a match has been found (Equivlent to match found message)
    var message = Spark.message();
    
    //Populate the message with the data you want
    message.setMessageData({"matchID":matchID,"message":"Game found!"});
    //Determine which players should get this message 
    message.setPlayerIds(playerIds)
    
    //Send
    message.send();
}

 

 

Once players receive this script message, they can use matchDetailsRequest to get the info they need to connect to sessions in the client, as if they're getting match found message.


Hope this helps,

Omar


 Hey Jo, I found a way for you players to retrieve their access token.


Use the MatchDetailsRequest with the matchId, here's an example response:



 

{
  "@class": ".MatchDetailsResponse",
  "accessToken": "WpFzNI0unBP/JcYzH1tbWreKQyTc1eJvdWg9n4GPARWRm4S44SGbYDgUL64FRi6qQ1BfutcEye+7OrgvcOu1e7gYFoy7R9IuK1nTjv2lpg/AS1OnvMhzbLsRIuVcproCWbkz7AvBxJYgXlupA1u4tK6X5+fEWQJqlkwOvM/7tUxCLErY0omO3YpFLUWofWSuJWfsP8mvRbteKdBFqQe8QeTuFdOXEEZQNpQRTkVl7mSKLwRigoH7qPzPRnVi2a4AaMA8Sm8kjmQrYPhg3tnr/GSALaFvvxKdveMFs0Dt0U7QcpC9zQivN3shh+JkX+64yqAFpNiIw2TXytfacVbwKehIwqW80m7sOqePdOxpDEidkgPGd1WnFq2JWCZVrfTNQdIpnUmZNr2l8k+/HJ835RKpiVjqDgxusnsNnxa0IlA=",
  "host": "gsp-aeu-rt01.gamesparks.net",
  "matchData": {},
  "matchId": "597efeb6ff5b8304fd22735f",
  "peerId": 1,
  "playerId": "58e5051c9650b504ccff2b40",
  "port": 5150
}

 


Cheers,

Omar

 Hi Jo,


The encryption is TLS 1.2


Hope that helps,

Omar

Hi Omar,


If it's possible, I would like to know the detail of encryption info, like what level encryption you use.


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

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

Login to post a comment