mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 08:23:13 +09:00
4 files changed
+31
-18
No files matched your search
@@ -39,6 +39,7 @@ mod_cache.json
|
|||||||
static/pictures/spritesheet.js
|
static/pictures/spritesheet.js
|
||||||
static/pictures/spritesheet.png
|
static/pictures/spritesheet.png
|
||||||
static/external
|
static/external
|
||||||
|
saves
|
||||||
|
|
||||||
# weird pattern to ignore sharedPlugins except not ignore some core modules
|
# weird pattern to ignore sharedPlugins except not ignore some core modules
|
||||||
!sharedPlugins/
|
!sharedPlugins/
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function messageInterface(command, callback) {
|
|||||||
command = command.toString('utf8');
|
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:
|
to send to stdin, use:
|
||||||
serverprocess.stdin.write("/c command;\n")
|
serverprocess.stdin.write("/c command;\n")
|
||||||
@@ -381,7 +381,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
});
|
});
|
||||||
|
|
||||||
// connect to the server with rcon
|
// connect to the server with rcon
|
||||||
if(process.platform != "linux"){
|
if(true || process.platform != "linux"){
|
||||||
// IP, port, password
|
// IP, port, password
|
||||||
client = new Rcon({
|
client = new Rcon({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
@@ -619,20 +619,20 @@ function instanceManagement() {
|
|||||||
|
|
||||||
function callback(err, mac) {
|
function callback(err, mac) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
mac = "unknown";
|
||||||
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
|
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){
|
if(global.mac){
|
||||||
callback(undefined, global.mac);
|
callback(undefined, global.mac);
|
||||||
@@ -834,13 +834,14 @@ function instanceManagement() {
|
|||||||
for(let i=0;i<confirmedOrders.length;i++)
|
for(let i=0;i<confirmedOrders.length;i++)
|
||||||
{
|
{
|
||||||
cmd+='{"'+confirmedOrders[i].name+'"'+":"+confirmedOrders[i].count+"},";
|
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)+"]"+ "')");
|
messageInterface("/silent-command remote.call('clusterio', 'importMany', '"+cmd.slice(0, -1)+"]"+ "')");
|
||||||
cmd="[";
|
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);
|
}, 1000);
|
||||||
// COMBINATOR SIGNALS ---------------------------------------------------------
|
// COMBINATOR SIGNALS ---------------------------------------------------------
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var fs = require('fs');
|
|||||||
|
|
||||||
var modManager = require("./manager/modManager.js");
|
var modManager = require("./manager/modManager.js");
|
||||||
|
|
||||||
modManager.addMod("clusterio", "shared");
|
// modManager.addMod("clusterio", "shared");
|
||||||
|
|
||||||
function makeDirectory(path){
|
function makeDirectory(path){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -291,6 +291,8 @@ POST Get metadata from a single slave. For whenever you find the data returned b
|
|||||||
@alias /api/getSlaveMeta
|
@alias /api/getSlaveMeta
|
||||||
*/
|
*/
|
||||||
app.post("/api/getSlaveMeta", function (req, res) {
|
app.post("/api/getSlaveMeta", function (req, res) {
|
||||||
|
endpointHitCounter.labels(req.route.path).inc();
|
||||||
|
let reqStartTime = Date.now();
|
||||||
console.log("body", req.body);
|
console.log("body", req.body);
|
||||||
if(req.body && req.body.instanceID && req.body.password){
|
if(req.body && req.body.instanceID && req.body.password){
|
||||||
console.log("returning meta for ", req.body.instanceID);
|
console.log("returning meta for ", req.body.instanceID);
|
||||||
@@ -299,6 +301,7 @@ app.post("/api/getSlaveMeta", function (req, res) {
|
|||||||
res.status(400);
|
res.status(400);
|
||||||
res.send('{"INVALID REQUEST":1}');
|
res.send('{"INVALID REQUEST":1}');
|
||||||
}
|
}
|
||||||
|
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
|
||||||
});
|
});
|
||||||
// mod management
|
// mod management
|
||||||
// should handle uploading and checking if mods are uploaded
|
// 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"){
|
} else if(req.body.statistic == "remove"){
|
||||||
console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`);
|
console.log(`sending remove data for instanceID ${req.body.instanceID} ${req.body.itemName}`);
|
||||||
// Gather data
|
// Gather data
|
||||||
console.log(sentItemStatisticsBySlaveID)
|
// console.log(sentItemStatisticsBySlaveID)
|
||||||
let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID];
|
let itemStats = sentItemStatisticsBySlaveID[req.body.instanceID];
|
||||||
console.log(itemStats)
|
console.log(itemStats)
|
||||||
if(typeof itemStats == "object"){
|
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:{}}
|
@returns {object} Status {auth: bool, message: "Informative error", data:{}}
|
||||||
*/
|
*/
|
||||||
app.post("/api/runCommand", (req,res) => {
|
app.post("/api/runCommand", (req,res) => {
|
||||||
|
endpointHitCounter.labels(req.route.path).inc();
|
||||||
|
let reqStartTime = Date.now();
|
||||||
var token = req.headers['x-access-token'];
|
var token = req.headers['x-access-token'];
|
||||||
if(!token) return res.status(401).send({ auth: false, message: 'No token provided.' });
|
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);
|
wsSlaves[instanceID].runCommand(body.command);
|
||||||
}
|
}
|
||||||
res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"});
|
res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"});
|
||||||
|
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
|
||||||
} else if (
|
} else if (
|
||||||
body.instanceID
|
body.instanceID
|
||||||
&& wsSlaves[body.instanceID]
|
&& wsSlaves[body.instanceID]
|
||||||
@@ -818,9 +824,11 @@ app.post("/api/runCommand", (req,res) => {
|
|||||||
// execute command
|
// execute command
|
||||||
wsSlaves[body.instanceID].runCommand(body.command, data => {
|
wsSlaves[body.instanceID].runCommand(body.command, data => {
|
||||||
res.status(200).send({auth: true, message: "success", data});
|
res.status(200).send({auth: true, message: "success", data});
|
||||||
|
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send({auth: true, message: "Error: invalid request.body"});
|
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
|
// handle command return values
|
||||||
this.commandsWaitingForReturn = {};
|
this.commandsWaitingForReturn = {};
|
||||||
this.socket.on("runCommandReturnValue", resp => {
|
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"){
|
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);
|
this.commandsWaitingForReturn[resp.commandID].callback(resp.body);
|
||||||
delete this.commandsWaitingForReturn[resp.commandID];
|
delete this.commandsWaitingForReturn[resp.commandID];
|
||||||
@@ -942,6 +951,7 @@ class wsSlave {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on("gameChat", data => {
|
this.socket.on("gameChat", data => {
|
||||||
|
prometheusWsUsageCounter.labels('gameChat').inc();
|
||||||
if(typeof data === "object"){
|
if(typeof data === "object"){
|
||||||
data.timestamp = Date.now();
|
data.timestamp = Date.now();
|
||||||
if(!global.wsChatRecievers) global.wsChatRecievers = [];
|
if(!global.wsChatRecievers) global.wsChatRecievers = [];
|
||||||
@@ -952,6 +962,7 @@ class wsSlave {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on("alert", alert => {
|
this.socket.on("alert", alert => {
|
||||||
|
prometheusWsUsageCounter.labels('alert').inc();
|
||||||
if(typeof alert === "object"){
|
if(typeof alert === "object"){
|
||||||
alert.timestamp = Date.now();
|
alert.timestamp = Date.now();
|
||||||
if(!global.wsAlertRecievers) global.wsAlertRecievers = [];
|
if(!global.wsAlertRecievers) global.wsAlertRecievers = [];
|
||||||
|
|||||||
Reference in new issue
Block a user