mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
1 parent
1e65eb40c5
commit
da9d2c14dc
2 files changed
+31
-36
No files matched your search
@@ -12,6 +12,10 @@ var client = new Rcon({
|
|||||||
timeout: 0
|
timeout: 0
|
||||||
}).connect();
|
}).connect();
|
||||||
|
|
||||||
|
if (!fs.existsSync(config.factorioDirectory + "/script-output/")){
|
||||||
|
fs.mkdirSync(config.factorioDirectory + "/script-output/");
|
||||||
|
}
|
||||||
|
fs.writeFileSync(config.factorioDirectory + "/script-output/output.txt", "")
|
||||||
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
||||||
|
|
||||||
client.on('authenticated', function() {
|
client.on('authenticated', function() {
|
||||||
@@ -48,60 +52,50 @@ fs.watch(config.factorioDirectory + "/script-output/output.txt", "utf8", functio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
// get array of lines in file
|
// get array of lines in file
|
||||||
items = fs.readFileSync(config.factorioDirectory + "/script-output/orders.txt", "utf8").split("\n");
|
items = fs.readFileSync(config.factorioDirectory + "/script-output/orders.txt", "utf8").split("\n");
|
||||||
// if you found anything, reset the file
|
// if we actually got anything from the file, proceed and reset file
|
||||||
if(items[0]) {
|
if(items[0]) {
|
||||||
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "");
|
||||||
for(i = 0;i < items.length; i++) {
|
// prepare a package of all our requested items in a more tranfer friendly format
|
||||||
|
var preparedPackage = {};
|
||||||
|
for(i = 2;i < items.length; i++) {
|
||||||
(function(i){
|
(function(i){
|
||||||
if(items[i]) {
|
if(items[i]) {
|
||||||
items[i] = items[i].split(" ");
|
items[i] = items[i].split(" ");
|
||||||
items[i][0] = items[i][0].replace("\u0000", "");
|
items[i][0] = items[i][0].replace("\u0000", "");
|
||||||
items[i][0] = items[i][0].replace(",", "");
|
items[i][0] = items[i][0].replace(",", "");
|
||||||
// send our entity and count to the master for him to keep track of
|
if(preparedPackage[items[i][0]]){
|
||||||
needle.post(config.masterIP + ":" + config.masterPort + '/remove', {name:items[i][0], count:items[i][1]}, function(err, response, body){
|
if(typeof Number(preparedPackage[items[i][0]].count) == "number" && typeof Number(items[i][1]) == "number") {
|
||||||
if(response && response.body && typeof response.body == "object") {
|
preparedPackage[items[i][0]] = {"name":items[i][0], "count":Number(preparedPackage[items[i][0]].count) + Number(items[i][1])};
|
||||||
// buffer confirmed orders
|
} else if (typeof Number(items[i][1]) == "number") {
|
||||||
confirmedOrders[confirmedOrders.length] = {[response.body.name]: response.body.count}
|
preparedPackage[items[i][0]] = {"name":items[i][0], "count":Number(items[i][1])};
|
||||||
}
|
}
|
||||||
/*if(response && response.body === "successier"){
|
} else if (typeof Number(items[i][1]) == "number") {
|
||||||
console.log(response.body + " : importing: " + JSON.stringify({[items[i][0]]: items[i][1]}));
|
preparedPackage[items[i][0]] = {"name":items[i][0], "count":Number(items[i][1])};
|
||||||
// buffer confirmed orders
|
}
|
||||||
confirmedOrders[confirmedOrders.length] = {[items[i][0]]: items[i][1]}
|
|
||||||
//client.exec("/c remote.call('clusterio', 'importMany', '[" + JSON.stringify(jsonobject) + "]')")
|
|
||||||
} else {
|
|
||||||
console.log("ERROR: "+JSON.stringify({[items[i][0]]: items[i][1]}));
|
|
||||||
}*/
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})(i);
|
})(i);
|
||||||
}
|
}
|
||||||
|
// request our items, one item at a time
|
||||||
|
for(i = 0;i<Object.keys(preparedPackage).length;i++){
|
||||||
|
console.log(preparedPackage[Object.keys(preparedPackage)[i]])
|
||||||
|
needle.post(config.masterIP + ":" + config.masterPort + '/remove', preparedPackage[Object.keys(preparedPackage)[i]], function(err, response, body){
|
||||||
|
if(response && response.body && typeof response.body == "object") {
|
||||||
|
// buffer confirmed orders
|
||||||
|
confirmedOrders[confirmedOrders.length] = {[response.body.name]: response.body.count}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
// if we got some confirmed orders
|
// if we got some confirmed orders
|
||||||
console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
||||||
sadas = JSON.stringify(confirmedOrders)
|
sadas = JSON.stringify(confirmedOrders)
|
||||||
confirmedOrders = [];
|
confirmedOrders = [];
|
||||||
// send our RCON command
|
// send our RCON command with whatever we got
|
||||||
client.exec("/c remote.call('clusterio', 'importMany', '" + sadas + "')");
|
client.exec("/c remote.call('clusterio', 'importMany', '" + sadas + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*for(i = 0;i < items.length; i++) {
|
|
||||||
if(items[i]) {
|
|
||||||
g = items[i].split(" ");
|
|
||||||
g[0] = g[0].replace("\u0000", "");
|
|
||||||
g[0] = g[0].replace(",", "");
|
|
||||||
console.log(g);
|
|
||||||
// send our entity and count to the master for him to keep track of
|
|
||||||
needle.post(config.masterIP + ":" + config.masterPort + '/remove', {name:g[0], count:g[1]}, function(err, resp, body){
|
|
||||||
console.log(body);
|
|
||||||
if(body == "success"){
|
|
||||||
client.exec("/c remote.call('clusterio', 'import', '" + g[0] + "', " + g[1] + ")")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}, 10000)
|
}, 10000)
|
||||||
/*
|
/*
|
||||||
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ app.post("/remove", function(req, res) {
|
|||||||
"name": object.name,
|
"name": object.name,
|
||||||
"count": Number(doc.count) - Number(object.count),
|
"count": Number(doc.count) - Number(object.count),
|
||||||
};
|
};
|
||||||
db.items.update(doc, objectUpdate, {multi:true}, function (err, numReplaced) {});
|
// db.items.update(doc, objectUpdate, {multi:true}, function (err, numReplaced) {});
|
||||||
|
db.items.update(doc, {$inc:{count:object.count*-1}}, {multi:true}, function (err, numReplaced) {});
|
||||||
// res.send("successier");
|
// res.send("successier");
|
||||||
res.send(object);
|
res.send(object);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user