mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
researchSync removed node-lua dependency
This commit is contained in:
1 parent
12bf445579
commit
7a4ea69cbb
2 files changed
+7
-26
No files matched your search
@@ -47,7 +47,6 @@
|
||||
"node-factorio-api": "^0.3.1-alpha",
|
||||
"node-forge": "^0.7.1",
|
||||
"prom-client": "^10.2.3",
|
||||
"node-lua": "^1.0.4",
|
||||
"request": "^2.83.0",
|
||||
"right-pad": "^1.0.1",
|
||||
"rmdir-sync": "^1.0.1",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var fs = require('fs');
|
||||
const nodelua = require('node-lua');
|
||||
const fs = require('fs');
|
||||
const needle = require("needle");
|
||||
|
||||
|
||||
@@ -11,32 +10,24 @@ class ResearchSync {
|
||||
this.messageInterface = messageInterface;
|
||||
|
||||
this.research = {};
|
||||
this.lua = new nodelua.LuaState();
|
||||
|
||||
messageInterface("ResearchSync enabled");
|
||||
setInterval(function () {
|
||||
this.pollResearch.call(this);
|
||||
setTimeout(this.doSync.bind(this), 2)
|
||||
}.bind(this), 2000);
|
||||
|
||||
setInterval(() => {
|
||||
this.pollResearch();
|
||||
setTimeout(this.doSync, 2)
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
pollResearch() {
|
||||
this.messageInterface("Polling Research\n")
|
||||
this.messageInterface(this.functions.dumpResearch);
|
||||
|
||||
}
|
||||
|
||||
doSync() {
|
||||
|
||||
|
||||
|
||||
needle.post(this.config.masterIP + ':' + this.config.masterPort + '/api/getSlavesMeta', {
|
||||
password: this.config.clientPassword,
|
||||
}, function (err, resp, body) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
if (err) throw err;
|
||||
|
||||
if (resp.statusCode != 200){
|
||||
console.log("got error when calling getSlaveMeta", resp.statusCode, resp.body);
|
||||
@@ -55,7 +46,6 @@ class ResearchSync {
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
var difference = this.diff(this.research, needResearch);
|
||||
|
||||
Object.keys(difference).forEach((key) => {
|
||||
@@ -73,20 +63,15 @@ class ResearchSync {
|
||||
// success?
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
}
|
||||
|
||||
diff(array1, array2) {
|
||||
var diff = {};
|
||||
|
||||
|
||||
|
||||
Object.keys(array2).forEach((element) => {
|
||||
if (array2[element] != array1[element]){
|
||||
diff[element] = array2[element];
|
||||
}
|
||||
});
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -101,11 +86,8 @@ class ResearchSync {
|
||||
}
|
||||
scriptOutput(data){
|
||||
try {
|
||||
this.lua.DoString("a = " + data);
|
||||
this.lua.GetGlobal("a");
|
||||
let currentResearch = this.lua.ToValue(-1);
|
||||
let research = JSON.parse(data.replace("=",":").replace("[","").replace("]",""));
|
||||
this.research = Object.assign(this.research, currentResearch);
|
||||
this.lua.Pop();
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user