mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +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
@@ -3,12 +3,20 @@ const needle = require("needle");
|
||||
|
||||
|
||||
class UPSdisplay {
|
||||
constructor(slaveConfig, msgInterface){
|
||||
constructor(slaveConfig, msgInterface, extras){
|
||||
this.config = slaveConfig;
|
||||
this.messageInterface = msgInterface;
|
||||
this.socket = extras.socket;
|
||||
|
||||
this.historicalTicks = [];
|
||||
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);
|
||||
setInterval(() => {
|
||||
if(this.historicalTicks && this.historicalTicks[0]){
|
||||
@@ -17,24 +25,15 @@ class UPSdisplay {
|
||||
let UPS = Math.round(ticksInPeriod / (timePeriod/1000));
|
||||
// console.log("UPS: " + UPS);
|
||||
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?
|
||||
});
|
||||
} catch (err){
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
}, 10000);
|
||||
}, 5000);
|
||||
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;
|
||||
Reference in new issue
Block a user