Store when a game was last updated
authorRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Sat, 4 Apr 2020 14:51:45 +0000 (16:51 +0200)
committerRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Sat, 4 Apr 2020 14:51:45 +0000 (16:51 +0200)
trivabble-server.js

index 21b3140889b15afd5d339f5a9b7f25a98e875863..04c333b8d1d2afa1cad782dc259ef0b56099e7e1 100644 (file)
@@ -168,6 +168,7 @@ Game.prototype.init = function () {
     this.remainingLetters = this.bag.length;
     this.racks = {};
     this.scores = {};
+    this.lastUpdated = new Date();
 };
 
 Game.prototype.toJSON = function () {
@@ -176,7 +177,8 @@ Game.prototype.toJSON = function () {
         board:            this.board,
         bag:              this.bag,
         racks:            this.racks,
-        scores:           this.scores
+        scores:           this.scores,
+        lastUpdated:      this.lastUpdated.toISOString()
     };
 };
 
@@ -187,6 +189,7 @@ Game.fromJSON = function (obj) {
     game.remainingLetters = obj.remainingLetters || game.bag.length;
     game.racks            = obj.racks  || {};
     game.scores           = obj.scores || {};
+    game.lastUpdated      = obj.lastUpdated ? new Date(obj.lastUpdated) : new Date();
     return game;
 };
 
@@ -407,6 +410,8 @@ function handleCommand(cmd, gameNumber, playerName, response) {
         return;
     }
 
+    game.lastUpdated = new Date();
+
     var rack = null;
 
     switch (cmd.cmd) {