mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Move the contents of node_modules/_app into lib/ as there shouldn't be any content in node_modules. This directory is automatically managed and pruned by npm. Add lib/ as a local package in package.json, this allows scripts everywhere to require it's content as "lib/path" instead of relying on local paths. This shadows the StdLib Node.js Bindings package, but I could care less. Change all requires with lib as a local path and _app to use just lib.
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
const needle = require("needle");
|
|
const fs = require("fs-extra");
|
|
const path = require("path");
|
|
|
|
const clusterTools = require("lib/clusterTools")();
|
|
const pluginConfig = require("./config");
|
|
|
|
module.exports = class remoteCommands {
|
|
constructor(mergedConfig, messageInterface, extras){
|
|
this.messageInterface = messageInterface;
|
|
this.config = mergedConfig;
|
|
|
|
const needleOptionsWithTokenAuthHeader = {
|
|
headers: {
|
|
'x-access-token': this.config.masterAuthToken
|
|
},
|
|
};
|
|
|
|
// Gather and submit statistics every 15 seconds
|
|
setInterval(async () => {
|
|
let stats = await this.getStats();
|
|
stats.forEach(force => {
|
|
// I have no idea why I need to do JSON.stringify before passing it to needle.post,
|
|
// but if you do forceData: force.data, it doesn't work...
|
|
let request = {
|
|
instanceID: this.config.unique,
|
|
force: force.forceName,
|
|
forceData: JSON.stringify(force.data),
|
|
};
|
|
needle.post(`${mergedConfig.masterIP}:${mergedConfig.masterPort}/api/logStats`,
|
|
request,
|
|
needleOptionsWithTokenAuthHeader, (err, resp) => {
|
|
if(!err && resp.body && resp.body.ok == false) console.log("Error calling /api/logStats: " + resp.body);
|
|
}
|
|
);
|
|
});
|
|
}, 15000);
|
|
}
|
|
async getStats(){
|
|
let command = fs.readFileSync(path.join(__dirname, "Lua/exportStatistics.lua"), "utf8")//clusterTools.getLua(path.join(__dirname, "Lua/exportStatistics.lua"), false);
|
|
let string = await this.messageInterface(`/silent-command ${command}`);
|
|
var data;
|
|
eval(`data = ${string}`);
|
|
return data;
|
|
}
|
|
}
|