Hello!
My game has endless arcade style rounds where at the end there is an API call to my server to submit started_at and ended_at times to calculate how long users lasted. im getting insane scores on my server every once in a while. Usually round times are lik 1-6 min, but occasionally i see 500 min+. This is really impossible in my game and my presumption is that the device went to sleep or something.
My current solution i thought should work but has proven not to. Does anyone see issues with my solution or have other solutions that would work better than mine?
Any advice would be helpful!
Solution Summary:
Reset a new date()
timestamp every time the user clicks, touches, or does a keyboard key on this browser tab. If the last input was over a min old, refresh the browser immediately, also before we submit the data on gameover, we check if the input was over a min old, if so we don’t submit the game
GameDataController.js:
GameDataController.prototype.initialize = function() {
// Setup listeners for any user interaction
pc.BSM.Input.lastInputDateTime = new Date();
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.resetLastInput, this);
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.resetLastInput, this);
try {
this.app.touch.on(pc.EVENT_TOUCHSTART, this.resetLastInput, this);
} catch (e){
console.log("No touch listener - must not be mobile");
}
};
//Reset our pc.BSM.Input.lastInputDateTime whenever user input is detected
//If it has been over 60 secodns since last input, just restart the browser
GameDataController.prototype.resetLastInput = function(){
var currentDate = new Date();
var seconds = Math.abs(pc.BSM.Input.lastInputDateTime - currentDate) / 1000;
if (seconds > 60 && pc.SceneController.currentSceneIsGame()){
//Reload if its been over a min during a game since the last input
location.reload();
} else {
pc.BSM.Input.lastInputDateTime = new Date();
}
};
//This is called when the player dies and the game ends
GameDataController.prototype.submitGameScore = function() {
//If its been more than 60 seconds since user input, dont submit game score
var currentDate = new Date();
var seconds = Math.abs(pc.BSM.Input.lastInputDateTime - currentDate) / 1000;
console.log("Seconds since last input = "+seconds.toString());
if (seconds > 60){
//Send error to raygun so we can track if this happens a lot
location.reload();
return;
}
///API Call Submit Game Code Down Here
};