mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
messageInterface now takes a second arg for rcon return values (from rcon.print())
This commit is contained in:
1 parent
1d9b6a26a6
commit
ce6dc3af28
2 files changed
+24
-20
No files matched your search
@@ -6,7 +6,7 @@ const path = require('path');
|
|||||||
const syncRequest = require('sync-request');
|
const syncRequest = require('sync-request');
|
||||||
const request = require("request");
|
const request = require("request");
|
||||||
const ncp = require('ncp').ncp;
|
const ncp = require('ncp').ncp;
|
||||||
const Rcon = require('simple-rcon');
|
const Rcon = require('rcon-client').Rcon;
|
||||||
const hashFiles = require('hash-files');
|
const hashFiles = require('hash-files');
|
||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
const deepmerge = require("deepmerge");
|
const deepmerge = require("deepmerge");
|
||||||
@@ -73,14 +73,16 @@ function messageInterfaceInternal(command, callback) {
|
|||||||
if(typeof callback == "function"){
|
if(typeof callback == "function"){
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
} else if(typeof command == "string" && client && client.exec && typeof client.exec == "function") {
|
} else if(typeof command == "string" && client && client.send && typeof client.send == "function") {
|
||||||
try {
|
try {
|
||||||
client.exec(command+"\n", callback);
|
client.send(command+"\n").then(str => {
|
||||||
|
if(typeof callback == "function") callback(str)
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
if(typeof callback == "function"){
|
||||||
if(typeof callback == "function"){
|
callback();
|
||||||
callback();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,12 +387,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
// connect to the server with rcon
|
// connect to the server with rcon
|
||||||
if(true || process.platform != "linux"){
|
if(true || process.platform != "linux"){
|
||||||
// IP, port, password
|
// IP, port, password
|
||||||
client = new Rcon({
|
client = new Rcon();
|
||||||
host: 'localhost',
|
|
||||||
port: Number(process.env.RCONPORT) || instanceconfig.clientPort,
|
|
||||||
password: instanceconfig.clientPassword,
|
|
||||||
timeout: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -398,23 +395,30 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
fs.readFile(instancedirectory+"/factorio-current.log", function (err, data) {
|
fs.readFile(instancedirectory+"/factorio-current.log", function (err, data) {
|
||||||
// if (err) console.log(err);
|
// if (err) console.log(err);
|
||||||
if(data && data.indexOf('Starting RCON interface') > 0){
|
if(data && data.indexOf('Starting RCON interface') > 0){
|
||||||
client.connect();
|
client.connect({
|
||||||
|
host: 'localhost',
|
||||||
|
port: Number(process.env.RCONPORT) || instanceconfig.clientPort,
|
||||||
|
password: instanceconfig.clientPassword,
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
checkRcon();
|
checkRcon();
|
||||||
},2000);
|
},5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setTimeout(checkRcon, 5000);
|
setTimeout(checkRcon, 5000);
|
||||||
|
|
||||||
client.on('authenticated', function () {
|
client.onDidAuthenticate(() => {
|
||||||
console.log('Clusterio | RCON Authenticated!');
|
console.log('Clusterio | RCON Authenticated!');
|
||||||
instanceManagement(); // start using rcons
|
instanceManagement(); // start using rcons
|
||||||
}).on('connected', function () {
|
});
|
||||||
|
client.onDidConnect(() => {
|
||||||
console.log('Clusterio | RCON Connected!');
|
console.log('Clusterio | RCON Connected!');
|
||||||
// getID();
|
// getID();
|
||||||
}).on('disconnected', function () {
|
});
|
||||||
|
client.onDidDisconnect(() => {
|
||||||
console.log('Clusterio | RCON Disconnected!');
|
console.log('Clusterio | RCON Disconnected!');
|
||||||
process.exit(0); // exit because RCON disconnecting is undefined behaviour and we rather just wanna restart now
|
process.exit(0); // exit because RCON disconnecting is undefined behaviour and we rather just wanna restart now
|
||||||
});
|
});
|
||||||
@@ -462,11 +466,11 @@ function instanceManagement() {
|
|||||||
if(pluginConfig.binary == "nodePackage"){
|
if(pluginConfig.binary == "nodePackage"){
|
||||||
// require index.js.main() of plugin and execute it as a class
|
// require index.js.main() of plugin and execute it as a class
|
||||||
let pluginClass = require("./sharedPlugins/" + pluginDirectories[I] + "/index.js");
|
let pluginClass = require("./sharedPlugins/" + pluginDirectories[I] + "/index.js");
|
||||||
plugins[I] = new pluginClass(combinedConfig, function(data){
|
plugins[I] = new pluginClass(combinedConfig, function(data, callback){
|
||||||
if(data.toString('utf8')[0] != "/") {
|
if(data.toString('utf8')[0] != "/") {
|
||||||
log("Stdout: " + data.toString('utf8'));
|
log("Stdout: " + data.toString('utf8'));
|
||||||
} else {
|
} else {
|
||||||
messageInterface(data.toString('utf8'));
|
messageInterface(data.toString('utf8'), callback);
|
||||||
}
|
}
|
||||||
}, { // extra functions to pass in object. Should have done it like this from the start, but won't break backwards compat.
|
}, { // extra functions to pass in object. Should have done it like this from the start, but won't break backwards compat.
|
||||||
socket, // socket.io connection to master (and ES6 destructuring, yay)
|
socket, // socket.io connection to master (and ES6 destructuring, yay)
|
||||||
|
|||||||
+1
-1
@@ -48,10 +48,10 @@
|
|||||||
"node-factorio-api": "^0.3.1-alpha",
|
"node-factorio-api": "^0.3.1-alpha",
|
||||||
"node-forge": "^0.7.1",
|
"node-forge": "^0.7.1",
|
||||||
"prom-client": "^10.2.3",
|
"prom-client": "^10.2.3",
|
||||||
|
"rcon-client": "^3.0.2",
|
||||||
"request": "^2.83.0",
|
"request": "^2.83.0",
|
||||||
"right-pad": "^1.0.1",
|
"right-pad": "^1.0.1",
|
||||||
"rmdir-sync": "^1.0.1",
|
"rmdir-sync": "^1.0.1",
|
||||||
"simple-rcon": "^0.3.1",
|
|
||||||
"single-line-log": "^1.1.2",
|
"single-line-log": "^1.1.2",
|
||||||
"socket.io": "^2.0.4",
|
"socket.io": "^2.0.4",
|
||||||
"socket.io-client": "^2.0.4",
|
"socket.io-client": "^2.0.4",
|
||||||
|
|||||||
Reference in new issue
Block a user