mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Merge remote-tracking branch 'refs/remotes/Danielv123/master'
This commit is contained in:
commit
2fe0844fd8
4 files changed
+48
-47
No files matched your search
@@ -211,7 +211,7 @@ end
|
|||||||
function ExportOutputList()
|
function ExportOutputList()
|
||||||
local exportStrings = {}
|
local exportStrings = {}
|
||||||
for k,v in pairs(global.outputList) do
|
for k,v in pairs(global.outputList) do
|
||||||
exportStrings[#exportStrings + 1] = k..", "..v.."\n"
|
exportStrings[#exportStrings + 1] = k.." "..v.."\n"
|
||||||
end
|
end
|
||||||
global.outputList = {}
|
global.outputList = {}
|
||||||
if #exportStrings > 0 then
|
if #exportStrings > 0 then
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var needle = require("needle")
|
var needle = require("needle")
|
||||||
var Rcon = require('rcon')
|
|
||||||
|
|
||||||
// connect us to the server with rcon
|
// connect us to the server with rcon
|
||||||
// IP, port, password
|
// IP, port, password
|
||||||
var conn = new Rcon('localhost', 12345, '123');
|
var Rcon = require('simple-rcon');
|
||||||
conn.on('auth', function() {
|
var client = new Rcon({
|
||||||
console.log("Authed!");
|
host: '81.167.2.56',
|
||||||
|
port: '12345',
|
||||||
}).on('response', function(str) {
|
password: '123',
|
||||||
console.log("Got response: " + str);
|
timeout: 0
|
||||||
|
}).connect();
|
||||||
}).on('end', function() {
|
|
||||||
console.log("Socket closed!");
|
|
||||||
process.exit();
|
|
||||||
|
|
||||||
|
client.on('authenticated', function() {
|
||||||
|
console.log('Authenticated!');
|
||||||
|
}).on('connected', function() {
|
||||||
|
console.log('Connected!');
|
||||||
|
}).on('disconnected', function() {
|
||||||
|
console.log('Disconnected!');
|
||||||
|
// now reconnect
|
||||||
|
client.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
conn.connect();
|
|
||||||
|
|
||||||
// trigger when something happens to output.txt
|
// trigger when something happens to output.txt
|
||||||
fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType, filename) {
|
fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType, filename) {
|
||||||
|
console.log('hit output')
|
||||||
// get array of lines in file
|
// get array of lines in file
|
||||||
items = fs.readFileSync("Factorio 0.13.9/script-output/output.txt", "utf8").split("\n");
|
items = fs.readFileSync("Factorio 0.13.9/script-output/output.txt", "utf8").split("\n");
|
||||||
// if you found anything, reset the file
|
// if you found anything, reset the file
|
||||||
@@ -52,12 +56,13 @@ fs.watch("Factorio 0.13.9/script-output/orders.txt", "utf8", function(eventType,
|
|||||||
if(items[i]) {
|
if(items[i]) {
|
||||||
g = items[i].split(" ");
|
g = items[i].split(" ");
|
||||||
g[0] = g[0].replace("\u0000", "");
|
g[0] = g[0].replace("\u0000", "");
|
||||||
|
g[0] = g[0].replace(",", "");
|
||||||
console.log(g);
|
console.log(g);
|
||||||
// send our entity and count to the master for him to keep track of
|
// 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){
|
needle.post('localhost:8080/remove', {name:g[0], count:g[1]}, function(err, resp, body){
|
||||||
console.log(body);
|
console.log(body);
|
||||||
if(body){
|
if(body == "success"){
|
||||||
//conn.send("/c remote.call('clusterio', 'import', '" + g[0] + "', " + g[1] + ")")
|
client.exec("/c remote.call('clusterio', 'import', '" + g[0] + "', " + g[1] + ")")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-11
@@ -1,19 +1,15 @@
|
|||||||
start nodemon client.js
|
|
||||||
start nodemon master.js
|
|
||||||
|
|
||||||
cd "Factorio 0.13.9 - Copy/bin/x64"
|
|
||||||
start factorio.exe
|
|
||||||
cd ..
|
|
||||||
cd ..
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
cd "Factorio 0.13.9"
|
cd "Factorio 0.13.9"
|
||||||
@RD /S /Q "temp"
|
@RD /S /Q "temp"
|
||||||
cd "bin/x64"
|
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 ..
|
cd ..
|
||||||
cd ..
|
cd ..
|
||||||
@mcrcon.exe -t -H 81.167.2.56 -P 12345 -p 123
|
|
||||||
|
start cmd /C node client.js
|
||||||
|
start cmd /C node master.js
|
||||||
|
|
||||||
|
::cd "Factorio 0.13.9 - Copy/bin/x64"
|
||||||
|
::@start factorio.exe
|
||||||
|
|
||||||
pause
|
pause
|
||||||
@@ -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) {
|
db.items.findOne({name:object.name}, function (err, doc) {
|
||||||
// console.dir(doc);
|
// console.dir(doc);
|
||||||
if (doc) {
|
if (err) {
|
||||||
// Update existing items if item name already exists
|
res.send('failure');
|
||||||
if(Number(doc.count) > Number(object.count)) {
|
return false
|
||||||
object.count = Number(doc.count) - Number(object.count);
|
|
||||||
db.items.update(doc, object, {multi:true}, function (err, numReplaced) {});
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} 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) {
|
app.post("/place", function(req, res) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
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
|
// save items we get
|
||||||
db.items.additem(req.body)
|
db.items.additem(req.body)
|
||||||
// Attempt confirming
|
// Attempt confirming
|
||||||
res.send("success!");
|
res.send("success");
|
||||||
});
|
});
|
||||||
|
|
||||||
// endpoint to remove items from DB when client orders items
|
// endpoint to remove items from DB when client orders items
|
||||||
app.post("/remove", function(req, res) {
|
app.post("/remove", function(req, res) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
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
|
// save items we get
|
||||||
temp = db.items.removeitem(req.body);
|
db.items.removeitem(req.body, res);
|
||||||
if(temp) {
|
|
||||||
// if true, the action was successfull
|
|
||||||
res.send("success");
|
|
||||||
} else {
|
|
||||||
res.send('failure');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = app.listen(8080, function () {
|
var server = app.listen(8080, function () {
|
||||||
|
|||||||
Reference in new issue
Block a user