mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-26 00:33:12 +09:00
UPSdisplay now uses rcon return value instead of game.write_file
This commit is contained in:
1 parent
88e8ab454f
commit
da6f96a34b
2 files changed
+14
-15
No files matched your search
@@ -290,8 +290,8 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
console.log("Instance created!");
|
console.log("Instance created!");
|
||||||
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)) {
|
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)) {
|
||||||
// Exit if no instance specified (it should be, just a safeguard);
|
// Exit if no instance specified (it should be, just a safeguard);
|
||||||
if(instancedirectory != "./instances/undefined"){
|
if(instancedirectory != config.instanceDirectory+"/undefined"){
|
||||||
var instanceconfig = require(instancedirectory + '/config');
|
var instanceconfig = require(path.resolve(instancedirectory,'config'));
|
||||||
instanceconfig.unique = stringUtils.hashCode(instanceconfig.clientPassword);
|
instanceconfig.unique = stringUtils.hashCode(instanceconfig.clientPassword);
|
||||||
if(process.env.FACTORIOPORT){
|
if(process.env.FACTORIOPORT){
|
||||||
instanceconfig.factorioPort = process.env.FACTORIOPORT;
|
instanceconfig.factorioPort = process.env.FACTORIOPORT;
|
||||||
|
|||||||
@@ -3,12 +3,20 @@ const needle = require("needle");
|
|||||||
|
|
||||||
|
|
||||||
class UPSdisplay {
|
class UPSdisplay {
|
||||||
constructor(slaveConfig, msgInterface){
|
constructor(slaveConfig, msgInterface, extras){
|
||||||
this.config = slaveConfig;
|
this.config = slaveConfig;
|
||||||
this.messageInterface = msgInterface;
|
this.messageInterface = msgInterface;
|
||||||
|
this.socket = extras.socket;
|
||||||
|
|
||||||
this.historicalTicks = [];
|
this.historicalTicks = [];
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.messageInterface("/silent-command game.write_file('UPSdisplay.txt', game.tick, true, 0)");
|
this.messageInterface("/silent-command rcon.print(game.tick)", data => {
|
||||||
|
this.tick = Number(data);
|
||||||
|
this.historicalTicks[this.historicalTicks.length] = {tick:Number(data), timestamp:Date.now()};
|
||||||
|
if(this.historicalTicks.length > 30){
|
||||||
|
this.historicalTicks.shift(); // delete last element in array (position 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
},1000);
|
},1000);
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if(this.historicalTicks && this.historicalTicks[0]){
|
if(this.historicalTicks && this.historicalTicks[0]){
|
||||||
@@ -17,24 +25,15 @@ class UPSdisplay {
|
|||||||
let UPS = Math.round(ticksInPeriod / (timePeriod/1000));
|
let UPS = Math.round(ticksInPeriod / (timePeriod/1000));
|
||||||
// console.log("UPS: " + UPS);
|
// console.log("UPS: " + UPS);
|
||||||
try{
|
try{
|
||||||
needle.post(this.config.masterIP+':'+this.config.masterPort+'/api/editSlaveMeta', {instanceID: this.config.unique, password: this.config.clientPassword, meta: {UPS:UPS}}, {headers: {'x-access-token': this.config.masterAuthToken}}, function(err, resp) {
|
needle.post(this.config.masterIP+':'+this.config.masterPort+'/api/editSlaveMeta', {instanceID: this.config.unique, password: this.config.clientPassword, meta: {UPS:UPS, tick:this.tick}}, {headers: {'x-access-token': this.config.masterAuthToken}}, function(err, resp) {
|
||||||
// success?
|
// success?
|
||||||
});
|
});
|
||||||
} catch (err){
|
} catch (err){
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 10000);
|
}, 5000);
|
||||||
this.messageInterface("/silent-command game.print('UPSdisplay enabled')");
|
this.messageInterface("/silent-command game.print('UPSdisplay enabled')");
|
||||||
}
|
}
|
||||||
scriptOutput(data){
|
|
||||||
if (data !== null && !isNaN(data)){
|
|
||||||
// console.log("Tick: " + data);
|
|
||||||
this.historicalTicks[this.historicalTicks.length] = {tick:Number(data), timestamp:Date.now()};
|
|
||||||
if(this.historicalTicks.length > 30){
|
|
||||||
this.historicalTicks.shift(); // delete last element in array (position 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
module.exports = UPSdisplay;
|
module.exports = UPSdisplay;
|
||||||
Reference in new issue
Block a user