Tried to cache rcon requests, ended up with dupe machine

Me needs help, I don't understand where the game is getting free items from.
This commit is contained in:
Danielv123 committed 2016-08-25 20:50:00 +02:00
1 parent e326ae093a
commit 129ef8d2f8
3 files changed
+37 -7

No files matched your search

+35 -5
View File
@@ -12,6 +12,8 @@ var client = new Rcon({
timeout: 0
}).connect();
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
client.on('authenticated', function() {
console.log('Authenticated!');
}).on('connected', function() {
@@ -22,10 +24,11 @@ client.on('authenticated', function() {
client.connect();
});
// set some globals
confirmedOrders = [];
// trigger when something happens to output.txt
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(config.factorioDirectory + "/script-output/output.txt", "utf8").split("\n");
// if you found anything, reset the file
@@ -36,11 +39,11 @@ fs.watch(config.factorioDirectory + "/script-output/output.txt", "utf8", functio
if(items[i]) {
g = items[i].split(" ");
g[0] = g[0].replace("\u0000", "");
console.log(g);
console.log("exporting " + JSON.stringify(g));
// send our entity and count to the master for him to keep track of
needle.post(config.masterIP + ":" + config.masterPort + '/place', {name:g[0], count:g[1]},
function(err, resp, body){
console.log(body);
// console.log(body);
});
}
}
@@ -53,7 +56,34 @@ fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", functio
if(items[0]) {
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
}
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]) {
g = items[i].split(" ");
g[0] = g[0].replace("\u0000", "");
@@ -67,5 +97,5 @@ fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", functio
}
});
}
}
})
}*/
})
+1 -1
View File
@@ -1,7 +1,7 @@
{
"__comment": "",
"__comment": "IP and port and password the factorio server runs at for rcon connection",
"clientIP": "81.167.2.56",
"clientIP": "localhost",
"clientPort": "12345",
"clientPassword": "123",
"__comment": "Where factorio folder. Should be in the same folder as this config file.",
+1 -1
View File
@@ -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 testmap.zip --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json
cd ..
cd ..
cd ..