mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Avoid crashing on every 2nd launch due to #40 fix
This commit is contained in:
1 parent
4f1cfce39c
commit
f435a792de
1 file changed
+18
-6
@@ -137,7 +137,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move mods from ./sharedMods to the instances mod directory
|
// move mods from ./sharedMods to the instances mod directory
|
||||||
console.log("Moving shared mods...")
|
console.log("Clusterio | Moving shared mods...")
|
||||||
//ncp("./sharedMods/", instancedirectory + "/mods", function (err) {
|
//ncp("./sharedMods/", instancedirectory + "/mods", function (err) {
|
||||||
|
|
||||||
|
|
||||||
@@ -186,12 +186,24 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
timeout: 0
|
timeout: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// clean old log file to avoid crash
|
||||||
|
// file exists, delete so we don't get in trouble
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(instancedirectory+'/factorio-current.log')
|
||||||
|
} catch (err){
|
||||||
|
if(err){
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
console.log("Clusterio | Deleting old logs...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check the logfile to see if the RCON interface is running as there is no way to continue without it
|
// check the logfile to see if the RCON interface is running as there is no way to continue without it
|
||||||
// we read the log every 2 seconds and stop looping when we start connecting to factorio
|
// we read the log every 2 seconds and stop looping when we start connecting to factorio
|
||||||
function checkRcon() {
|
function checkRcon() {
|
||||||
fs.readFile(instancedirectory+"/factorio-current.log", function (err, data) {
|
fs.readFile(instancedirectory+"/factorio-current.log", function (err, data) {
|
||||||
if (err) throw err;
|
// if (err) console.log(err);
|
||||||
if(data.indexOf('Starting RCON interface') > 0){
|
if(data && data.indexOf('Starting RCON interface') > 0){
|
||||||
client.connect();
|
client.connect();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
@@ -203,13 +215,13 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
checkRcon();
|
checkRcon();
|
||||||
|
|
||||||
client.on('authenticated', function () {
|
client.on('authenticated', function () {
|
||||||
console.log('Authenticated!');
|
console.log('Clusterio | Authenticated!');
|
||||||
instanceManagement(); // start using rcons
|
instanceManagement(); // start using rcons
|
||||||
}).on('connected', function () {
|
}).on('connected', function () {
|
||||||
console.log('Connected!');
|
console.log('Clusterio | Connected!');
|
||||||
// getID();
|
// getID();
|
||||||
}).on('disconnected', function () {
|
}).on('disconnected', function () {
|
||||||
console.log('Disconnected!');
|
console.log('Clusterio | Disconnected!');
|
||||||
// now reconnect
|
// now reconnect
|
||||||
client.connect();
|
client.connect();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user