mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Changed up the tranfer format, everything works!
This commit is contained in:
1 parent
06a4d49884
commit
1e65eb40c5
2 files changed
+29
-20
No files matched your search
@@ -55,23 +55,28 @@ setInterval(function() {
|
||||
if(items[0]) {
|
||||
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
||||
for(i = 0;i < items.length; i++) {
|
||||
if(items[i]) {
|
||||
items[i] = items[i].split(" ");
|
||||
items[i][0] = items[i][0].replace("\u0000", "");
|
||||
items[i][0] = items[i][0].replace(",", "");
|
||||
console.log(items)
|
||||
// send our entity and count to the master for him to keep track of
|
||||
needle.post(config.masterIP + ":" + config.masterPort + '/remove', {name:items[i][0], count:items[i][1]}, function(err, response, body){
|
||||
if(response && response.body === "successier"){
|
||||
console.log(response.body + " : importing: " + JSON.stringify({[items[i][0]]: 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]}));
|
||||
}
|
||||
});
|
||||
}
|
||||
(function(i){
|
||||
if(items[i]) {
|
||||
items[i] = items[i].split(" ");
|
||||
items[i][0] = items[i][0].replace("\u0000", "");
|
||||
items[i][0] = items[i][0].replace(",", "");
|
||||
// send our entity and count to the master for him to keep track of
|
||||
needle.post(config.masterIP + ":" + config.masterPort + '/remove', {name:items[i][0], count:items[i][1]}, 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(response && response.body === "successier"){
|
||||
console.log(response.body + " : importing: " + JSON.stringify({[items[i][0]]: 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);
|
||||
}
|
||||
// if we got some confirmed orders
|
||||
console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
||||
|
||||
@@ -67,9 +67,13 @@ app.post("/remove", function(req, res) {
|
||||
// Update existing items if item name already exists
|
||||
if(Number(doc.count) > Number(object.count)) {
|
||||
console.log("removed: " + object.name + " " + object.count + " . " + doc.count);
|
||||
object.count = Number(doc.count) - Number(object.count);
|
||||
db.items.update(doc, object, {multi:true}, function (err, numReplaced) {});
|
||||
res.send("successier");
|
||||
objectUpdate = {
|
||||
"name": object.name,
|
||||
"count": Number(doc.count) - Number(object.count),
|
||||
};
|
||||
db.items.update(doc, objectUpdate, {multi:true}, function (err, numReplaced) {});
|
||||
// res.send("successier");
|
||||
res.send(object);
|
||||
} else {
|
||||
console.log('failure');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user