mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
WIP, still not working
This commit is contained in:
1 parent
129ef8d2f8
commit
06a4d49884
3 files changed
+55
-55
No files matched your search
@@ -48,40 +48,39 @@ fs.watch(config.factorioDirectory + "/script-output/output.txt", "utf8", functio
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||
setInterval(function() {
|
||||
// get array of lines in file
|
||||
items = fs.readFileSync(config.factorioDirectory + "/script-output/orders.txt", "utf8").split("\n");
|
||||
// if you found anything, reset the file
|
||||
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]}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// if we got some confirmed orders
|
||||
console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
||||
sadas = JSON.stringify(confirmedOrders)
|
||||
confirmedOrders = [];
|
||||
// send our RCON command
|
||||
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(",", "");
|
||||
// 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){
|
||||
if(body == "success"){
|
||||
console.log("importing: " + JSON.stringify({[g[0]]: g[1]}));
|
||||
// buffer confirmed orders
|
||||
confirmedOrders[confirmedOrders.length] = {[g[0]]: g[1]}
|
||||
//client.exec("/c remote.call('clusterio', 'importMany', '[" + JSON.stringify(jsonobject) + "]')")
|
||||
} else {
|
||||
console.log("ERROR: " + body)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// if we got some confirmed orders
|
||||
console.log("Importing " + confirmedOrders.length + " items! " + JSON.stringify(confirmedOrders));
|
||||
if(confirmedOrders[1]) {
|
||||
// send our RCON command
|
||||
client.exec("/c remote.call('clusterio', 'importMany', '" + JSON.stringify(confirmedOrders) + "')");
|
||||
confirmedOrders = [];
|
||||
}
|
||||
|
||||
/*for(i = 0;i < items.length; i++) {
|
||||
if(items[i]) {
|
||||
@@ -98,4 +97,9 @@ fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", functio
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}, 10000)
|
||||
/*
|
||||
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||
|
||||
})
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
cd "Factorio 0.13.9"
|
||||
cd "Factorio_0.13.17"
|
||||
@RD /S /Q "temp"
|
||||
cd "bin/x64/"
|
||||
start factorio.exe --start-server testmap.zip --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json
|
||||
@@ -6,8 +6,8 @@ cd ..
|
||||
cd ..
|
||||
cd ..
|
||||
|
||||
start cmd /C node client.js
|
||||
start cmd /C node master.js
|
||||
::start cmd /C node client.js
|
||||
::start cmd /C node master.js
|
||||
|
||||
::cd "Factorio 0.13.9 - Copy/bin/x64"
|
||||
::@start factorio.exe
|
||||
|
||||
@@ -40,30 +40,6 @@ db.items.additem = function(object) {
|
||||
}
|
||||
})
|
||||
}
|
||||
db.items.removeitem = function(object, res) {
|
||||
db.items.findOne({name:object.name}, function (err, doc) {
|
||||
// console.dir(doc);
|
||||
if (err) {
|
||||
res.send('failure');
|
||||
return false
|
||||
} else {
|
||||
if (doc) {
|
||||
// Update existing items if item name already exists
|
||||
if(Number(doc.count) > Number(object.count)) {
|
||||
console.log("removed: " + object.name + " " + object.count);
|
||||
object.count = Number(doc.count) - Number(object.count);
|
||||
db.items.update(doc, object, {multi:true}, function (err, numReplaced) {});
|
||||
res.send("success");
|
||||
return true;
|
||||
} else {
|
||||
res.send('failure');
|
||||
}
|
||||
} else {
|
||||
res.send('failure');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// endpoint to send items to
|
||||
app.post("/place", function(req, res) {
|
||||
@@ -81,7 +57,27 @@ app.post("/remove", function(req, res) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
// save items we get
|
||||
db.items.removeitem(req.body, res);
|
||||
var object = req.body;
|
||||
db.items.findOne({name:object.name}, function (err, doc) {
|
||||
// console.dir(doc);
|
||||
if (err) {
|
||||
console.log('failure');
|
||||
} else {
|
||||
if (doc) {
|
||||
// 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");
|
||||
} else {
|
||||
console.log('failure');
|
||||
}
|
||||
} else {
|
||||
console.log('failure ' + object.name);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
// endpoint for getting an inventory of what we got
|
||||
app.get("/inventory", function(req, res) {
|
||||
|
||||
Reference in new issue
Block a user