diff --git a/client.js b/client.js index a7c8ee97..8c1035e4 100644 --- a/client.js +++ b/client.js @@ -152,6 +152,7 @@ function getID() { }) } +setInterval(getID, 10000) // provide items -------------------------------------------------------------- // trigger when something happens to output.txt fs.watch(instancedirectory + "/script-output/output.txt", function(eventType, filename) { diff --git a/master.js b/master.js index 55a86494..5131370f 100644 --- a/master.js +++ b/master.js @@ -45,6 +45,7 @@ db.items.additem = function(object) { } var slaves = {} // world ID management +// slaves post here to tell the server they exist app.post("/getID", function(req,res) { // request.body should be an object // {rconPort, rconPassword, serverPort, mac, time} @@ -55,7 +56,6 @@ app.post("/getID", function(req,res) { console.log("Slave: " + req.body.mac + " : " + req.body.serverPort) } }); - // endpoint for getting information about all our slaves app.get("/slaves", function(req, res) { res.header("Access-Control-Allow-Origin", "*"); diff --git a/static/main.js b/static/main.js index 0b2591b4..ee568da4 100644 --- a/static/main.js +++ b/static/main.js @@ -1,4 +1,4 @@ - +var g = {} contents = { "iron-plate":100, "copper-plate":7312, @@ -70,6 +70,7 @@ function display(page) { // setTimeout is used to put this processing in the back of the queue, after the HTML canvas is done window.onload = function () { + display("storage") // dataPoints var dataPoints1 = []; var dataPoints2 = []; @@ -221,19 +222,32 @@ setInterval(function() { Date.prototype.yyyymmdd = function() { // http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); - return [this.getFullYear(), !mm[1] && '0', mm, !dd[1] && '0', dd].join(''); // padding + if(mm<10)mm = "0"+mm + if(dd<10)dd = "0"+dd + console.log(this.getFullYear()) + return this.getFullYear()+""+mm+""+dd+ ""; // padding }; var date = new Date(); + +// ask master for slaves setInterval(function() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { var slaveData = JSON.parse(xmlhttp.responseText); - var HTML = "

Latest connections:

" + var HTML = "

Current connections:

" for(i=0;i

Last seen: "+date.yyyymmdd(slaveData[key].time)+"

Port: "+slaveData[key].serverPort+"

Host: "+slaveData[key].mac+"

" + if(Date.now() - slaveData[key].time < 12000) { + // Display ISO 6801 compliant date to please Zarthus + // maybe include an option to use y-ymd-ymd-y for Trangar compatibility as well + var seenDate = date.yyyymmdd(slaveData[key].time) + if(g.trangarTime == true){ + var seenDate = (seenDate+"")[0]+"-"+(seenDate+"")[1]+(seenDate+"")[4]+(seenDate+"")[6]+"-"+(seenDate+"")[2]+(seenDate+"")[5]+(seenDate+"")[7]+"-"+(seenDate+"")[3] + } + HTML += "

ID: " + slaveData[key].unique + "

Last seen: "+seenDate+"

Port: "+slaveData[key].serverPort+"

Host: "+slaveData[key].mac+"

" + } } document.querySelector("#slaves > #display").innerHTML = HTML } @@ -244,6 +258,7 @@ setInterval(function() { // image data // key is the name of the item in the database, value is the name of the image on wiki.factorio.com/images/* +// this list has to include all entities that doesn't just follow the simple capitalize first letter convention var imagedata = { ["empty-barrel"]: "Barrel-empty", ["transport-belt"]: "Basic-transport-belt",