From e2a795528f9b88e874408f1a1a3b3b642ee15b84 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Tue, 21 Nov 2017 21:39:41 +0100 Subject: [PATCH] Change name from slaveID to instanceID for consistency accross endpoints --- client.js | 2 +- master.js | 50 +++++++++---------- sharedPlugins/UPSdisplay/index.js | 2 +- .../inventoryImports/interfacingFunctions.js | 2 +- static/nodeDetails.js | 16 +++--- static/slaveDisplay.js | 8 +-- static/storage.js | 20 ++++---- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/client.js b/client.js index 2139d370..a3c5084b 100644 --- a/client.js +++ b/client.js @@ -619,7 +619,7 @@ function instanceManagement() { } } console.log("Recorded flows, copper plate since last time: " + payload["copper-plate"]); - needle.post(config.masterIP + ":" + config.masterPort + '/api/logStats', {timestamp: timestamp, slaveID: instanceconfig.unique,data: payload}, function (err, response, body) { + needle.post(config.masterIP + ":" + config.masterPort + '/api/logStats', {timestamp: timestamp, instanceID: instanceconfig.unique,data: payload}, function (err, response, body) { // we did it, keep going }); } diff --git a/master.js b/master.js index 84ef5d54..991681e1 100644 --- a/master.js +++ b/master.js @@ -164,18 +164,18 @@ app.post("/api/getID", function(req,res) { app.post("/api/editSlaveMeta", function(req,res) { // request.body should be an object - // {slaveID, pass, meta:{x,y,z}} + // {instanceID, pass, meta:{x,y,z}} - if(req.body && req.body.slaveID && req.body.password && req.body.meta){ + if(req.body && req.body.instanceID && req.body.password && req.body.meta){ // check for editing permissions - if(slaves[req.body.slaveID] && slaves[req.body.slaveID].rconPassword == req.body.password){ - if(!slaves[req.body.slaveID].meta){ - slaves[req.body.slaveID].meta = {}; + if(slaves[req.body.instanceID] && slaves[req.body.instanceID].rconPassword == req.body.password){ + if(!slaves[req.body.instanceID].meta){ + slaves[req.body.instanceID].meta = {}; } - slaves[req.body.slaveID].meta = deepmerge(slaves[req.body.slaveID].meta, req.body.meta, {clone:true}); - console.log("Updating slave: " + slaves[req.body.slaveID].mac + " : " + slaves[req.body.slaveID].serverPort+" at " + slaves[req.body.slaveID].publicIP); + slaves[req.body.instanceID].meta = deepmerge(slaves[req.body.instanceID].meta, req.body.meta, {clone:true}); + console.log("Updating slave: " + slaves[req.body.instanceID].mac + " : " + slaves[req.body.instanceID].serverPort+" at " + slaves[req.body.instanceID].publicIP); } else { - res.send("ERROR: Invalid slaveID or password") + res.send("ERROR: Invalid instanceID or password") } } }); @@ -435,28 +435,28 @@ app.get("/api/inventoryAsObject", function(req, res) { }); // post flowstats here for production graphs -// {timestamp: Date, slaveID: string, data: {"item":number}} +// {timestamp: Date, instanceID: string, data: {"item":number}} /** POST endpoint to log production graph statistics. Should contain a timestamp -gathered from Date.now(), a slaveID (also reffered to as "unique") and of +gathered from Date.now(), a instanceID (also reffered to as "unique") and of course the timeSeries data. @memberof clusterioMaster @instance @alias api/logStats -@param {object} JSON {timestamp: Date.now(), slaveID: "string", data: {"item": number}} +@param {object} JSON {timestamp: Date.now(), instanceID: "string", data: {"item": number}} @returns {string} failure */ app.post("/api/logStats", function(req,res) { - if(typeof req.body == "object" && req.body.slaveID && req.body.timestamp && req.body.data) { + if(typeof req.body == "object" && req.body.instanceID && req.body.timestamp && req.body.data) { if(Number(req.body.timestamp) != NaN){ req.body.timestamp = Number(req.body.timestamp); db.flows.insert({ - slaveID: req.body.slaveID, + instanceID: req.body.instanceID, timestamp: req.body.timestamp, data: req.body.data, }); - console.log("inserted: " + req.body.slaveID + " | " + req.body.timestamp); + console.log("inserted: " + req.body.instanceID + " | " + req.body.timestamp); } else { console.log("error invalid timestamp " + req.body.timestamp); res.send("failure"); @@ -465,7 +465,7 @@ app.post("/api/logStats", function(req,res) { res.send("failure"); } }); -// {slaveID: string, fromTime: Date, toTime, Date} +// {instanceID: string, fromTime: Date, toTime, Date} /** POST endpoint to get timeSeries statistics stored on the master. Can give production graphs and other IO statistics. @@ -481,7 +481,7 @@ app.post("/api/getStats", function(req,res) { req.body = JSON.parse(req.body); } // console.log(req.body); - if(typeof req.body == "object" && req.body.slaveID && req.body.statistic === undefined) { + if(typeof req.body == "object" && req.body.instanceID && req.body.statistic === undefined) { // if not specified, get stats for last 24 hours if(!req.body.fromTime) { req.body.fromTime = Date.now() - 86400000 // 24 hours in MS @@ -491,7 +491,7 @@ app.post("/api/getStats", function(req,res) { } console.log("Looking... " + JSON.stringify(req.body)); db.flows.find({ - slaveID: req.body.slaveID, + instanceID: req.body.instanceID, }, function(err, docs) { let entries = docs.filter(function (el) { return el.timestamp <= req.body.toTime && el.timestamp >= req.body.fromTime; @@ -499,12 +499,12 @@ app.post("/api/getStats", function(req,res) { // console.log(entries); res.send(entries); }); - } else if(typeof req.body == "object" && req.body.slaveID && typeof req.body.slaveID == "string" && req.body.itemName){ + } else if(typeof req.body == "object" && req.body.instanceID && typeof req.body.instanceID == "string" && req.body.itemName){ if(req.body.statistic == "place"){ - console.log(`sending place data for slaveID ${req.body.slaveID} ${req.body.itemName}`); + console.log(`sending place data for instanceID ${req.body.instanceID} ${req.body.itemName}`); // Gather data //console.log(recievedItemStatisticsBySlaveID) - let itemStats = recievedItemStatisticsBySlaveID[req.body.slaveID]; + let itemStats = recievedItemStatisticsBySlaveID[req.body.instanceID]; if(itemStats === undefined){ res.send({statusForDebugging:"no data available"}); return false; @@ -517,10 +517,10 @@ app.post("/api/getStats", function(req,res) { data: data, }); } else if(req.body.statistic == "remove"){ - console.log(`sending remove data for slaveID ${req.body.slaveID} ${req.body.itemName}`); + console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`); // Gather data console.log(sentItemStatisticsBySlaveID) - let itemStats = sentItemStatisticsBySlaveID[req.body.slaveID]; + let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID]; console.log(itemStats) if(typeof itemStats == "object"){ let data = itemStats.get(config.itemStats.maxEntries, req.body.itemName); @@ -546,12 +546,12 @@ making up about 92% of the response body weight.) @memberof clusterioMaster @instance @alias api/getTimelineStats -@param {object} JSON {slaveID:1941029, fromTime: ???, toTime: ???} +@param {object} JSON {instanceID:1941029, fromTime: ???, toTime: ???} @returns {object[]} timeseries where each entry is a set point in time. */ app.post("/api/getTimelineStats", function(req,res) { console.log(req.body); - if(typeof req.body == "object" && req.body.slaveID) { + if(typeof req.body == "object" && req.body.instanceID) { // if not specified, get stats for last 24 hours if(!req.body.fromTime) { req.body.fromTime = Date.now() - 86400000 // 24 hours in MS @@ -561,7 +561,7 @@ app.post("/api/getTimelineStats", function(req,res) { } console.log("Looking... " + JSON.stringify(req.body)); db.flows.find({ - slaveID: req.body.slaveID, + instanceID: req.body.instanceID, }, function(err, docs) { if(err) { console.error(err); diff --git a/sharedPlugins/UPSdisplay/index.js b/sharedPlugins/UPSdisplay/index.js index 269067ec..6a1bd2ac 100644 --- a/sharedPlugins/UPSdisplay/index.js +++ b/sharedPlugins/UPSdisplay/index.js @@ -32,7 +32,7 @@ setInterval(function(){ let UPS = Math.round(ticksInPeriod / (timePeriod/1000)); // console.log("UPS: " + UPS); try{ - needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) { + needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {instanceID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) { // success? }); } catch (err){ diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.js b/sharedPlugins/inventoryImports/interfacingFunctions.js index 5ba1c5f3..dd537786 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.js @@ -143,7 +143,7 @@ function pollInventories(outputFile){ //return "/silent-command "+'local a="{"for b,c in pairs(game.players)do if c.connected then local d=game.players[b].get_inventory(defines.inventory.player_main).get_contents()local e=game.players[b].get_quickbar().get_contents()local f={}for g=1,game.players[b].force.character_logistic_slot_count do f[g]=game.players[b].character.get_request_slot(g)end;a=a..b..":{inventory:{"for h,i in pairs(d)do a=a.."['+"'"+'"..h.."'+"'"+']:"..i..","end;for h,i in pairs(e)do a=a.."['+"'"+'"..h.."'+"'"+']:"..i..","end;a=a.."},requestSlots:{"for h,i in pairs(f)do a=a.."['+"'"+'"..i["name"].."'+"'"+']:"..i["count"]..", "end;a=a.."}},"end end;a=a.."}"game.write_file("'+outputFile+'",a)' return '/silent-command '+'local a='+"'"+'{"players":{'+"'"+'local b=false;for c,d in pairs(game.players)do if d.connected then if b then a=a..'+"'"+','+"'"+'else b=true end;local e=game.players[c].get_inventory(defines.inventory.player_main).get_contents()local f=game.players[c].get_quickbar().get_contents()local g={}for h=1,game.players[c].force.character_logistic_slot_count do g[h]=game.players[c].character.get_request_slot(h)end;a=a..'+"'"+'"'+"'"+'..c..'+"'"+'":{"inventory":{'+"'"+'local i=false;for j,k in pairs(e)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..j..'+"'"+'":'+"'"+'..k end;for j,k in pairs(f)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..j..'+"'"+'":'+"'"+'..k end;a=a..'+"'"+'},"requestSlots":{'+"'"+'i=false;for j,k in pairs(g)do if i then a=a..'+"'"+','+"'"+'else i=true end;a=a..'+"'"+'"'+"'"+'..k['+"'"+'name'+"'"+']..'+"'"+'":'+"'"+'..k['+"'"+'count'+"'"+']end;a=a..'+"'"+'}}'+"'"+'end end;a=a.."}}"game.write_file("'+outputFile+'",a)' /* - needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) { + needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {instanceID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) { // success? }); */ diff --git a/static/nodeDetails.js b/static/nodeDetails.js index abda1b6b..42662c76 100644 --- a/static/nodeDetails.js +++ b/static/nodeDetails.js @@ -42,7 +42,7 @@ setInterval(function(){ indicator.style.backgroundColor = "yellow"; indicator.title = "Master server unavailable"; // compare with Math.floor(x/100000) allows us to check if they are within 10s of each other - } else if(Math.floor(slaveData[getParameterByName("slaveID")].time/100000) == Math.floor(Date.now()/100000)){ + } else if(Math.floor(slaveData[getParameterByName("instanceID")].time/100000) == Math.floor(Date.now()/100000)){ indicator.style.backgroundColor = "green"; indicator.title = "Slave is online"; } else { @@ -54,9 +54,9 @@ setInterval(function(){ populateSlaveInfo(); function populateSlaveInfo(){ - let slaveID = getParameterByName("slaveID"); - if(!slaveID){ - throw "We need slaveID! GIVE US SLAVEID! ALL HAIL OUR NEW OVERLORDS!" + let instanceID = getParameterByName("instanceID"); + if(!instanceID){ + throw "We need instanceID! GIVE US SLAVEID! ALL HAIL OUR NEW OVERLORDS!" } getJSON("/api/slaves", function(err, slaveData){ /* @@ -83,7 +83,7 @@ function populateSlaveInfo(){ "mac":"44-85-00-D2-7E-D6"} } */ - let slave = slaveData[slaveID]; + let slave = slaveData[instanceID]; let HTML = "