mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
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:
1 parent
e326ae093a
commit
129ef8d2f8
3 files changed
+37
-7
No files matched your search
@@ -12,6 +12,8 @@ var client = new Rcon({
|
|||||||
timeout: 0
|
timeout: 0
|
||||||
}).connect();
|
}).connect();
|
||||||
|
|
||||||
|
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
||||||
|
|
||||||
client.on('authenticated', function() {
|
client.on('authenticated', function() {
|
||||||
console.log('Authenticated!');
|
console.log('Authenticated!');
|
||||||
}).on('connected', function() {
|
}).on('connected', function() {
|
||||||
@@ -22,10 +24,11 @@ client.on('authenticated', function() {
|
|||||||
client.connect();
|
client.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// set some globals
|
||||||
|
confirmedOrders = [];
|
||||||
|
|
||||||
// trigger when something happens to output.txt
|
// trigger when something happens to output.txt
|
||||||
fs.watch(config.factorioDirectory + "/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
|
// get array of lines in file
|
||||||
items = fs.readFileSync(config.factorioDirectory + "/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 you found anything, reset the file
|
||||||
@@ -36,11 +39,11 @@ fs.watch(config.factorioDirectory + "/script-output/output.txt", "utf8", functio
|
|||||||
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", "");
|
||||||
console.log(g);
|
console.log("exporting " + JSON.stringify(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(config.masterIP + ":" + config.masterPort + '/place', {name:g[0], count:g[1]},
|
needle.post(config.masterIP + ":" + config.masterPort + '/place', {name:g[0], count:g[1]},
|
||||||
function(err, resp, body){
|
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]) {
|
if(items[0]) {
|
||||||
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
fs.writeFileSync(config.factorioDirectory + "/script-output/orders.txt", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0;i < items.length; i++) {
|
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]) {
|
if(items[i]) {
|
||||||
g = items[i].split(" ");
|
g = items[i].split(" ");
|
||||||
g[0] = g[0].replace("\u0000", "");
|
g[0] = g[0].replace("\u0000", "");
|
||||||
@@ -67,5 +97,5 @@ fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", functio
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
})
|
})
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"__comment": "",
|
"__comment": "",
|
||||||
"__comment": "IP and port and password the factorio server runs at for rcon connection",
|
"__comment": "IP and port and password the factorio server runs at for rcon connection",
|
||||||
"clientIP": "81.167.2.56",
|
"clientIP": "localhost",
|
||||||
"clientPort": "12345",
|
"clientPort": "12345",
|
||||||
"clientPassword": "123",
|
"clientPassword": "123",
|
||||||
"__comment": "Where factorio folder. Should be in the same folder as this config file.",
|
"__comment": "Where factorio folder. Should be in the same folder as this config file.",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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 testmap.zip --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json
|
||||||
cd ..
|
cd ..
|
||||||
cd ..
|
cd ..
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
Reference in new issue
Block a user