Merge pull request #1 from Danielv123/dev

Dev
This commit is contained in:
MCRcortex authored and GitHub committed 2018-05-01 08:10:37 +10:00
commit 5c064e4609
4 files changed
+31 -18

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ mod_cache.json
static/pictures/spritesheet.js
static/pictures/spritesheet.png
static/external
saves
# weird pattern to ignore sharedPlugins except not ignore some core modules
!sharedPlugins/
+17 -16
View File
@@ -64,7 +64,7 @@ function messageInterface(command, callback) {
command = command.toString('utf8');
}
if(process.platform == "linux" && typeof command == "string" && serverprocess) {
if(false && process.platform == "linux" && typeof command == "string" && serverprocess) {
/*
to send to stdin, use:
serverprocess.stdin.write("/c command;\n")
@@ -381,7 +381,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
});
// connect to the server with rcon
if(process.platform != "linux"){
if(true || process.platform != "linux"){
// IP, port, password
client = new Rcon({
host: 'localhost',
@@ -619,20 +619,20 @@ function instanceManagement() {
function callback(err, mac) {
if (err) {
mac = "unknown";
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
} else {
payload.mac = mac
console.log("Registered our precense with master "+config.masterIP+" at " + payload.time);
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) {
if (err && err.code != "ECONNRESET"){
console.error("We got problems, something went wrong when contacting master");
console.error(err);
} else if (response && response.body) {
// In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care.
console.log(response.body);
}
});
}
payload.mac = mac;
console.log("Registered our precense with master "+config.masterIP+" at " + payload.time);
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) {
if (err && err.code != "ECONNRESET"){
console.error("We got problems, something went wrong when contacting master");
console.error(err);
} else if (response && response.body) {
// In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care.
console.log(response.body);
}
});
}
if(global.mac){
callback(undefined, global.mac);
@@ -834,13 +834,14 @@ function instanceManagement() {
for(let i=0;i<confirmedOrders.length;i++)
{
cmd+='{"'+confirmedOrders[i].name+'"'+":"+confirmedOrders[i].count+"},";
if(cmd.length>400)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS
if(cmd.length>8000)//450 //ITS SMALL SO FACTORIO DOESNT SPILT IT INTO MULTIPLE PACKETS
{
messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");
cmd="[";
}
}
if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");}confirmedOrders=[];
if (!(cmd=="[")){messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");}
confirmedOrders=[];
}
}, 1000);
// COMBINATOR SIGNALS ---------------------------------------------------------
+1 -1
View File
@@ -5,7 +5,7 @@ var fs = require('fs');
var modManager = require("./manager/modManager.js");
modManager.addMod("clusterio", "shared");
// modManager.addMod("clusterio", "shared");
function makeDirectory(path){
return new Promise((resolve, reject) => {
+12 -1
View File
@@ -291,6 +291,8 @@ POST Get metadata from a single slave. For whenever you find the data returned b
@alias /api/getSlaveMeta
*/
app.post("/api/getSlaveMeta", function (req, res) {
endpointHitCounter.labels(req.route.path).inc();
let reqStartTime = Date.now();
console.log("body", req.body);
if(req.body && req.body.instanceID && req.body.password){
console.log("returning meta for ", req.body.instanceID);
@@ -299,6 +301,7 @@ app.post("/api/getSlaveMeta", function (req, res) {
res.status(400);
res.send('{"INVALID REQUEST":1}');
}
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
});
// mod management
// should handle uploading and checking if mods are uploaded
@@ -699,7 +702,7 @@ app.post("/api/getStats", function(req,res) {
} else if(req.body.statistic == "remove"){
console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`);
// Gather data
console.log(sentItemStatisticsBySlaveID)
// console.log(sentItemStatisticsBySlaveID)
let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID];
console.log(itemStats)
if(typeof itemStats == "object"){
@@ -786,6 +789,8 @@ Requires x-access-token header to be set. Find you api token in secret-api-token
@returns {object} Status {auth: bool, message: "Informative error", data:{}}
*/
app.post("/api/runCommand", (req,res) => {
endpointHitCounter.labels(req.route.path).inc();
let reqStartTime = Date.now();
var token = req.headers['x-access-token'];
if(!token) return res.status(401).send({ auth: false, message: 'No token provided.' });
@@ -808,6 +813,7 @@ app.post("/api/runCommand", (req,res) => {
wsSlaves[instanceID].runCommand(body.command);
}
res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
} else if (
body.instanceID
&& wsSlaves[body.instanceID]
@@ -818,9 +824,11 @@ app.post("/api/runCommand", (req,res) => {
// execute command
wsSlaves[body.instanceID].runCommand(body.command, data => {
res.status(200).send({auth: true, message: "success", data});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
});
} else {
res.status(400).send({auth: true, message: "Error: invalid request.body"});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
}
});
});
@@ -935,6 +943,7 @@ class wsSlave {
// handle command return values
this.commandsWaitingForReturn = {};
this.socket.on("runCommandReturnValue", resp => {
prometheusWsUsageCounter.labels('runCommandReturnValue').inc();
if(resp.commandID && resp.body && this.commandsWaitingForReturn[resp.commandID] && this.commandsWaitingForReturn[resp.commandID].callback && typeof this.commandsWaitingForReturn[resp.commandID].callback == "function"){
this.commandsWaitingForReturn[resp.commandID].callback(resp.body);
delete this.commandsWaitingForReturn[resp.commandID];
@@ -942,6 +951,7 @@ class wsSlave {
});
this.socket.on("gameChat", data => {
prometheusWsUsageCounter.labels('gameChat').inc();
if(typeof data === "object"){
data.timestamp = Date.now();
if(!global.wsChatRecievers) global.wsChatRecievers = [];
@@ -952,6 +962,7 @@ class wsSlave {
});
this.socket.on("alert", alert => {
prometheusWsUsageCounter.labels('alert').inc();
if(typeof alert === "object"){
alert.timestamp = Date.now();
if(!global.wsAlertRecievers) global.wsAlertRecievers = [];