mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 15:04:52 +09:00
Fixed js, items are now created correctly and dupe/loss glitches removed
This commit is contained in:
1 parent
440ecfad30
commit
44e311feea
3 files changed
+24
-23
No files matched your search
@@ -24,6 +24,7 @@ client.on('authenticated', function() {
|
||||
|
||||
// trigger when something happens to output.txt
|
||||
fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType, filename) {
|
||||
console.log('hit output')
|
||||
// get array of lines in file
|
||||
items = fs.readFileSync("Factorio 0.13.9/script-output/output.txt", "utf8").split("\n");
|
||||
// if you found anything, reset the file
|
||||
@@ -60,7 +61,7 @@ fs.watch("Factorio 0.13.9/script-output/orders.txt", "utf8", function(eventType,
|
||||
// send our entity and count to the master for him to keep track of
|
||||
needle.post('localhost:8080/remove', {name:g[0], count:g[1]}, function(err, resp, body){
|
||||
console.log(body);
|
||||
if(body){
|
||||
if(body == "success"){
|
||||
client.exec("/c remote.call('clusterio', 'import', '" + g[0] + "', " + g[1] + ")")
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
cd "Factorio 0.13.9"
|
||||
@RD /S /Q "temp"
|
||||
cd "bin/x64/"
|
||||
start factorio.exe --start-server-load-latest --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json --no-auto-pause
|
||||
start factorio.exe --start-server-load-latest --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json --no-auto-pause
|
||||
cd ..
|
||||
cd ..
|
||||
cd ..
|
||||
|
||||
@@ -34,20 +34,26 @@ db.items.additem = function(object) {
|
||||
}
|
||||
})
|
||||
}
|
||||
db.items.removeitem = function(object) {
|
||||
db.items.removeitem = function(object, res) {
|
||||
db.items.findOne({name:object.name}, function (err, doc) {
|
||||
// console.dir(doc);
|
||||
if (doc) {
|
||||
// Update existing items if item name already exists
|
||||
if(Number(doc.count) > Number(object.count)) {
|
||||
object.count = Number(doc.count) - Number(object.count);
|
||||
db.items.update(doc, object, {multi:true}, function (err, numReplaced) {});
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (err) {
|
||||
res.send('failure');
|
||||
return false
|
||||
} else {
|
||||
return false;
|
||||
if (doc) {
|
||||
// Update existing items if item name already exists
|
||||
if(Number(doc.count) > Number(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');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -56,26 +62,20 @@ db.items.removeitem = function(object) {
|
||||
app.post("/place", function(req, res) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
console.log("added: " + req.body);
|
||||
console.log("added: " + req.body.name + " " + req.body.count);
|
||||
// save items we get
|
||||
db.items.additem(req.body)
|
||||
// Attempt confirming
|
||||
res.send("success!");
|
||||
res.send("success");
|
||||
});
|
||||
|
||||
// endpoint to remove items from DB when client orders items
|
||||
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");
|
||||
console.log("removed: " + req.body);
|
||||
console.log("removed: " + req.body.name + " " + req.body.count);
|
||||
// save items we get
|
||||
temp = db.items.removeitem(req.body);
|
||||
if(temp) {
|
||||
// if true, the action was successfull
|
||||
res.send("success");
|
||||
} else {
|
||||
res.send('failure');
|
||||
}
|
||||
db.items.removeitem(req.body, res);
|
||||
});
|
||||
|
||||
var server = app.listen(8080, function () {
|
||||
|
||||
Reference in new issue
Block a user