Is there anyway to expire a session after not getting requests from client for more than 5 minutes, and get the time when the session expires??
Best Answer
R
Ryan Fuller
said
about 7 years ago
I can think of 2 ways, and I'm sure there are more, but the following would be the way I tackle this:
Every time a request is made (in cloud code) cancel the previous SparkScheduler task and reschedule it to call a module in 5 minutes. Then if the module ever gets called you know no request was made in 5 minutes. You could get the current time in the module and call Spark.getPlayer().disconnect(true).
So you could made an "ExpirationManagerModule":
var ExpirationManager = new function(){
this.scheduleExpiration = function(){
Spark.getScheduler().inSeconds("DisconnectionModule", 5*60, null, "disconnection_scheduler");
}
this.cancelExpiration = function(){
Spark.getScheduler().cancel("disconnection_scheduler");
}
}
Then you'd make a DisconnectionModule that simply called: Spark.getPlayer().disconnect(false);
Then in any cloud code requests/events you would add:
require("ExpirationManager");
ExpirationManager.cancelExpiration();
//Your custom code here
ExpirationManager.scheduleExpiration();
Anyway, just one of the ways to do this. Hopefully it helps.
I can think of 2 ways, and I'm sure there are more, but the following would be the way I tackle this:
Every time a request is made (in cloud code) cancel the previous SparkScheduler task and reschedule it to call a module in 5 minutes. Then if the module ever gets called you know no request was made in 5 minutes. You could get the current time in the module and call Spark.getPlayer().disconnect(true).
So you could made an "ExpirationManagerModule":
var ExpirationManager = new function(){
this.scheduleExpiration = function(){
Spark.getScheduler().inSeconds("DisconnectionModule", 5*60, null, "disconnection_scheduler");
}
this.cancelExpiration = function(){
Spark.getScheduler().cancel("disconnection_scheduler");
}
}
Then you'd make a DisconnectionModule that simply called: Spark.getPlayer().disconnect(false);
Then in any cloud code requests/events you would add:
require("ExpirationManager");
ExpirationManager.cancelExpiration();
//Your custom code here
ExpirationManager.scheduleExpiration();
Anyway, just one of the ways to do this. Hopefully it helps.
R
Ryan Fuller
said
about 7 years ago
Oh and as far as get the time when the session expires, you could just call Date.now() inside the DisconnectionModule, though I'm not sure where you want to store that (you could set it to the player's scriptData or a custom collection).
N
Nipitpon Wongsuparatkul
said
about 7 years ago
Hey Ryan.
Yes that helps a lot. It is exactly what I was looking for. You have my gratitude.
Nipitpon Wongsuparatkul
Is there anyway to expire a session after not getting requests from client for more than 5 minutes, and get the time when the session expires??
I can think of 2 ways, and I'm sure there are more, but the following would be the way I tackle this:
Every time a request is made (in cloud code) cancel the previous SparkScheduler task and reschedule it to call a module in 5 minutes. Then if the module ever gets called you know no request was made in 5 minutes. You could get the current time in the module and call Spark.getPlayer().disconnect(true).
So you could made an "ExpirationManagerModule":
Then you'd make a DisconnectionModule that simply called: Spark.getPlayer().disconnect(false);
Then in any cloud code requests/events you would add:
Anyway, just one of the ways to do this. Hopefully it helps.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstRyan Fuller
I can think of 2 ways, and I'm sure there are more, but the following would be the way I tackle this:
Every time a request is made (in cloud code) cancel the previous SparkScheduler task and reschedule it to call a module in 5 minutes. Then if the module ever gets called you know no request was made in 5 minutes. You could get the current time in the module and call Spark.getPlayer().disconnect(true).
So you could made an "ExpirationManagerModule":
Then you'd make a DisconnectionModule that simply called: Spark.getPlayer().disconnect(false);
Then in any cloud code requests/events you would add:
Anyway, just one of the ways to do this. Hopefully it helps.
Ryan Fuller
Oh and as far as get the time when the session expires, you could just call Date.now() inside the DisconnectionModule, though I'm not sure where you want to store that (you could set it to the player's scriptData or a custom collection).
Nipitpon Wongsuparatkul
Hey Ryan.
Yes that helps a lot. It is exactly what I was looking for. You have my gratitude.
Ryan Fuller
No problem. Glad I could help!
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics