Add a basic validity check to savefile.js constructor

This commit is contained in:
chylex committed 2016-10-24 18:39:49 +02:00
1 parent 497e196d52
commit 827553a00c
1 file changed
+5 -1
+5 -1
View File
@@ -66,7 +66,7 @@
*/ */
var SAVEFILE = function(parsedObj){ var SAVEFILE = function(parsedObj){
if (parsedObj){ if (SAVEFILE.isValid(parsedObj)){
this.meta = parsedObj.meta; this.meta = parsedObj.meta;
this.meta.users = this.meta.users || {}; this.meta.users = this.meta.users || {};
this.meta.userindex = this.meta.userindex || []; this.meta.userindex = this.meta.userindex || [];
@@ -89,6 +89,10 @@ var SAVEFILE = function(parsedObj){
this.tmp.userlookup = {}; this.tmp.userlookup = {};
}; };
SAVEFILE.isValid = function(parsedObj){
return parsedObj && typeof parsedObj.meta === "object" && typeof parsedObj.data === "object";
};
SAVEFILE.prototype.findOrRegisterUser = function(userId, userName){ SAVEFILE.prototype.findOrRegisterUser = function(userId, userName){
if (!(userId in this.meta.users)){ if (!(userId in this.meta.users)){
this.meta.users[userId] = { this.meta.users[userId] = {