mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
#85 made instance directory configurable in config.json
This commit is contained in:
1 parent
a0e98ecb00
commit
c02bb6d58f
4 files changed
+18
-16
No files matched your search
@@ -25,8 +25,8 @@ const configManager = require("./lib/manager/configManager.js");
|
|||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var global = {};
|
var global = {};
|
||||||
|
|
||||||
if (!fs.existsSync("./instances/")) {
|
if (!fs.existsSync(config.instanceDirectory)) {
|
||||||
fs.mkdirSync("instances");
|
fs.mkdirSync(config.instanceDirectory);
|
||||||
}
|
}
|
||||||
if (!fs.existsSync("./sharedPlugins/")) {
|
if (!fs.existsSync("./sharedPlugins/")) {
|
||||||
fs.mkdirSync("sharedPlugins");
|
fs.mkdirSync("sharedPlugins");
|
||||||
@@ -35,7 +35,7 @@ if (!fs.existsSync("./sharedMods/")) {
|
|||||||
fs.mkdirSync("sharedMods");
|
fs.mkdirSync("sharedMods");
|
||||||
}
|
}
|
||||||
const instance = process.argv[3];
|
const instance = process.argv[3];
|
||||||
const instancedirectory = './instances/' + instance;
|
const instancedirectory = config.instanceDirectory + '/' + instance;
|
||||||
const command = process.argv[2];
|
const command = process.argv[2];
|
||||||
|
|
||||||
// Set the process title, shows up as the title of the CMD window on windows
|
// Set the process title, shows up as the title of the CMD window on windows
|
||||||
@@ -99,7 +99,7 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
console.error("node client.js manage");
|
console.error("node client.js manage");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if (command == "list") {
|
} else if (command == "list") {
|
||||||
let instanceNames = fileOps.getDirectoriesSync("./instances/");
|
let instanceNames = fileOps.getDirectoriesSync(config.instanceDirectory);
|
||||||
instanceNames.unshift("Name:");
|
instanceNames.unshift("Name:");
|
||||||
let longestInstanceName = 0;
|
let longestInstanceName = 0;
|
||||||
// determine longest instance name
|
// determine longest instance name
|
||||||
@@ -122,7 +122,7 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
if(instance.includes("Name:")){
|
if(instance.includes("Name:")){
|
||||||
factorioPort = "Port:"
|
factorioPort = "Port:"
|
||||||
} else {
|
} else {
|
||||||
factorioPort = require("./instances/"+instance+"/config").factorioPort;
|
factorioPort = require(config.instanceDirectory+"/"+instance+"/config").factorioPort;
|
||||||
}
|
}
|
||||||
factorioPorts.push(factorioPort);
|
factorioPorts.push(factorioPort);
|
||||||
});
|
});
|
||||||
@@ -201,8 +201,8 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
if (!process.argv[3]) {
|
if (!process.argv[3]) {
|
||||||
console.error("Usage: node client.js delete [instance]");
|
console.error("Usage: node client.js delete [instance]");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if (typeof process.argv[3] == "string" && fs.existsSync("./instances/" + process.argv[3]) && process.argv[3] != "/" && process.argv[3] != "") {
|
} else if (typeof process.argv[3] == "string" && fs.existsSync(config.instanceDirectory+"/" + process.argv[3]) && process.argv[3] != "/" && process.argv[3] != "") {
|
||||||
fileOps.deleteFolderRecursiveSync("./instances/" + process.argv[3]);
|
fileOps.deleteFolderRecursiveSync(config.instanceDirectory+"/" + process.argv[3]);
|
||||||
console.log("Deleted instance " + process.argv[3]);
|
console.log("Deleted instance " + process.argv[3]);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
@@ -241,7 +241,7 @@ if (!command || command == "help" || command == "--help") {
|
|||||||
// fs.symlinkSync('../../../sharedMods', instancedirectory + "/mods", 'junction') // This is broken because it can only take a file as first argument, not a folder
|
// fs.symlinkSync('../../../sharedMods', instancedirectory + "/mods", 'junction') // This is broken because it can only take a file as first argument, not a folder
|
||||||
fs.writeFileSync(instancedirectory + "/config.ini", "[path]\r\n\
|
fs.writeFileSync(instancedirectory + "/config.ini", "[path]\r\n\
|
||||||
read-data=__PATH__executable__/../../data\r\n\
|
read-data=__PATH__executable__/../../data\r\n\
|
||||||
write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
write-data=__PATH__executable__/../../../"+config.instanceDirectory+"/" + instance + "\r\n\
|
||||||
");
|
");
|
||||||
|
|
||||||
// this line is probably not needed anymore but Im not gonna remove it
|
// this line is probably not needed anymore but Im not gonna remove it
|
||||||
@@ -288,7 +288,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
console.log("Instance created!");
|
console.log("Instance created!");
|
||||||
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)) {
|
} else if (command == "start" && typeof instance == "string" && instance != "/" && fs.existsSync(instancedirectory)) {
|
||||||
// Exit if no instance specified (it should be, just a safeguard);
|
// Exit if no instance specified (it should be, just a safeguard);
|
||||||
if(instancedirectory != "./instances/undefined"){
|
if(instancedirectory != config.instanceDirectory+"/undefined"){
|
||||||
var instanceconfig = require(instancedirectory + '/config');
|
var instanceconfig = require(instancedirectory + '/config');
|
||||||
instanceconfig.unique = stringUtils.hashCode(instanceconfig.clientPassword);
|
instanceconfig.unique = stringUtils.hashCode(instanceconfig.clientPassword);
|
||||||
if(process.env.FACTORIOPORT){
|
if(process.env.FACTORIOPORT){
|
||||||
@@ -682,7 +682,7 @@ function instanceManagement() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var form = req.form();
|
var form = req.form();
|
||||||
form.append('file', fs.createReadStream("./instances/"+instance+"/mods/"+mod));
|
form.append('file', fs.createReadStream(config.instanceDirectory+"/"+instance+"/mods/"+mod));
|
||||||
} else {
|
} else {
|
||||||
console.log("Not sending mod: " + mod + " to master because config.uploadModsToMaster is not enabled")
|
console.log("Not sending mod: " + mod + " to master because config.uploadModsToMaster is not enabled")
|
||||||
}
|
}
|
||||||
@@ -967,7 +967,7 @@ function hashMods(instanceName, callback) {
|
|||||||
}
|
}
|
||||||
let hashedMods = [];
|
let hashedMods = [];
|
||||||
/*let mods = fs.readdirSync("./sharedMods/")*/
|
/*let mods = fs.readdirSync("./sharedMods/")*/
|
||||||
let instanceMods = fs.readdirSync("./instances/"+instanceName+"/mods/");
|
let instanceMods = fs.readdirSync(config.instanceDirectory+"/"+instanceName+"/mods/");
|
||||||
if(instanceMods.length == 0){
|
if(instanceMods.length == 0){
|
||||||
callback({}); // there are no mods installed, return an empty object
|
callback({}); // there are no mods installed, return an empty object
|
||||||
}
|
}
|
||||||
@@ -977,7 +977,7 @@ function hashMods(instanceName, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(let i=0; i<instanceMods.length; i++){
|
for(let i=0; i<instanceMods.length; i++){
|
||||||
let path = "./instances/"+instanceName+"/mods/"+instanceMods[i];
|
let path = config.instanceDirectory+"/"+instanceName+"/mods/"+instanceMods[i];
|
||||||
let name = instanceMods[i];
|
let name = instanceMods[i];
|
||||||
let options = {
|
let options = {
|
||||||
files:path,
|
files:path,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"__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.",
|
||||||
"factorioDirectory": "factorio",
|
"factorioDirectory": "factorio",
|
||||||
|
"instanceDirectory": "instances",
|
||||||
|
|
||||||
"__comment1": "IP players should connect to to join your servers, should be portforwarded and stuff",
|
"__comment1": "IP players should connect to to join your servers, should be portforwarded and stuff",
|
||||||
"publicIP": "localhost",
|
"publicIP": "localhost",
|
||||||
|
|||||||
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
const fileOps = require("_app/fileOps");
|
const fileOps = require("_app/fileOps");
|
||||||
|
const config = require("./../config");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sync: function(){
|
sync: function(){
|
||||||
let instances;
|
let instances;
|
||||||
try {
|
try {
|
||||||
instances = fileOps.getDirectoriesSync("./instances/");
|
instances = fileOps.getDirectoriesSync(config.instanceDirectory);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// there are no instances created yet, probably missing the folder
|
// there are no instances created yet, probably missing the folder
|
||||||
instances = [];
|
instances = [];
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ modManager.listMods("shared");
|
|||||||
*/
|
*/
|
||||||
module.exports.listMods = function(instance){
|
module.exports.listMods = function(instance){
|
||||||
if(instance && instances.includes(instance)){
|
if(instance && instances.includes(instance)){
|
||||||
factorioAPI.init(false, 'instances/'+instance+'/instanceMods', 'instances/'+instance+'/saves', '0.16.15');
|
factorioAPI.init(false, config.instanceDirectory+'/'+instance+'/instanceMods', config.instanceDirectory+'/'+instance+'/saves', '0.16.15');
|
||||||
factorioAPI.authenticate({
|
factorioAPI.authenticate({
|
||||||
username: config.username,
|
username: config.username,
|
||||||
token: config.token,
|
token: config.token,
|
||||||
@@ -118,7 +118,7 @@ module.exports.addMod = function(term, instance){
|
|||||||
if(instance == "shared"){ // modDirectory has to end in /
|
if(instance == "shared"){ // modDirectory has to end in /
|
||||||
var modDirectory = "sharedMods/";
|
var modDirectory = "sharedMods/";
|
||||||
} else {
|
} else {
|
||||||
var modDirectory = "instances/"+instance+"/instanceMods/";
|
var modDirectory = config.instanceDirectory+"/"+instance+"/instanceMods/";
|
||||||
}
|
}
|
||||||
if(term && term.length > 0){
|
if(term && term.length > 0){
|
||||||
if(term.includes("mods.factorio.com/mods/")){ // https://mods.factorio.com/mods/Danielv123/ChooChoo
|
if(term.includes("mods.factorio.com/mods/")){ // https://mods.factorio.com/mods/Danielv123/ChooChoo
|
||||||
@@ -186,7 +186,7 @@ module.exports.removeMod = function removeMod(term, instance, force = false){
|
|||||||
if(instance == "shared"){ // modDirectory has to end in /
|
if(instance == "shared"){ // modDirectory has to end in /
|
||||||
var modDirectory = "sharedMods/";
|
var modDirectory = "sharedMods/";
|
||||||
} else {
|
} else {
|
||||||
var modDirectory = "instances/"+instance+"/instanceMods/";
|
var modDirectory = config.instanceDirectory+"/"+instance+"/instanceMods/";
|
||||||
}
|
}
|
||||||
if(term && typeof term == "string" && term.length > 0){
|
if(term && typeof term == "string" && term.length > 0){
|
||||||
let mods = fs.readdirSync(modDirectory);
|
let mods = fs.readdirSync(modDirectory);
|
||||||
|
|||||||
Reference in new issue
Block a user