mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Working on #7 configs
This commit is contained in:
1 parent
601d5edb27
commit
0e9fb267c4
3 files changed
+36
-21
No files matched your search
@@ -1,35 +1,36 @@
|
||||
var fs = require('fs');
|
||||
var needle = require("needle")
|
||||
|
||||
var needle = require("needle");
|
||||
// require config.json
|
||||
var config = require('./config');
|
||||
// connect us to the server with rcon
|
||||
// IP, port, password
|
||||
var Rcon = require('simple-rcon');
|
||||
var client = new Rcon({
|
||||
host: '81.167.2.56',
|
||||
port: '12345',
|
||||
password: '123',
|
||||
timeout: 0
|
||||
host: config.clientIP,
|
||||
port: config.clientPort,
|
||||
password: config.clientPassword,
|
||||
timeout: 0
|
||||
}).connect();
|
||||
|
||||
client.on('authenticated', function() {
|
||||
console.log('Authenticated!');
|
||||
console.log('Authenticated!');
|
||||
}).on('connected', function() {
|
||||
console.log('Connected!');
|
||||
console.log('Connected!');
|
||||
}).on('disconnected', function() {
|
||||
console.log('Disconnected!');
|
||||
// now reconnect
|
||||
client.connect();
|
||||
console.log('Disconnected!');
|
||||
// now reconnect
|
||||
client.connect();
|
||||
});
|
||||
|
||||
|
||||
// trigger when something happens to output.txt
|
||||
fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType, filename) {
|
||||
fs.watch(config.factorioDirectory + "/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");
|
||||
items = fs.readFileSync(config.factorioDirectory + "/script-output/output.txt", "utf8").split("\n");
|
||||
// if you found anything, reset the file
|
||||
if(items[0]) {
|
||||
fs.writeFileSync("Factorio 0.13.9/script-output/output.txt", "")
|
||||
fs.writeFileSync(config.factorioDirectory + "/script-output/output.txt", "")
|
||||
}
|
||||
for(i = 0;i < items.length; i++) {
|
||||
if(items[i]) {
|
||||
@@ -37,7 +38,7 @@ fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType,
|
||||
g[0] = g[0].replace("\u0000", "");
|
||||
console.log(g);
|
||||
// send our entity and count to the master for him to keep track of
|
||||
needle.post('localhost:8080/place', {name:g[0], count:g[1]},
|
||||
needle.post(config.masterIP + ":" + config.masterPort + '/place', {name:g[0], count:g[1]},
|
||||
function(err, resp, body){
|
||||
console.log(body);
|
||||
});
|
||||
@@ -45,12 +46,12 @@ fs.watch("Factorio 0.13.9/script-output/output.txt", "utf8", function(eventType,
|
||||
}
|
||||
})
|
||||
|
||||
fs.watch("Factorio 0.13.9/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||
// get array of lines in file
|
||||
items = fs.readFileSync("Factorio 0.13.9/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(items[0]) {
|
||||
fs.writeFileSync("Factorio 0.13.9/script-output/orders.txt", "")
|
||||
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
||||
}
|
||||
for(i = 0;i < items.length; i++) {
|
||||
if(items[i]) {
|
||||
@@ -59,7 +60,7 @@ fs.watch("Factorio 0.13.9/script-output/orders.txt", "utf8", function(eventType,
|
||||
g[0] = g[0].replace(",", "");
|
||||
console.log(g);
|
||||
// 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(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] + ")")
|
||||
|
||||
Reference in new issue
Block a user