From 08143b7b84bc4dfd11a2e83e08af563d99c4a036 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sat, 16 Sep 2017 15:55:28 +0200 Subject: [PATCH] Fixed database corruption problems --- master.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/master.js b/master.js index 324e19cb..2bd5f3a5 100644 --- a/master.js +++ b/master.js @@ -76,10 +76,24 @@ db.flows.ensureIndex({ fieldName: "slaveID", expireAfterSeconds: 2592000}); // e })() db.items.addItem = function(object) { - db.items[object.name] += object.count; + if(object.name == "addItem") { + console.log("Fuck you, that would screw everything up if you named your item that."); + } + if(this[object.name] && typeof this[object.name] == "number"){ + this[object.name] += object.count; + } else { + this[object.name] = object.count; + } } db.items.removeItem = function(object) { - db.items[object.name] -= object.count; + if(object.name == "addItem") { + console.log("Fuck you, that would screw everything up if you named your item that."); + } + if(this[object.name] && typeof this[object.name] == "number"){ + this[object.name] -= object.count; + } else { + this[object.name] = 0; + } } // store slaves and inventory in a .json full of JSON data