Setup the server code in the configuration

This commit is contained in:
TheFlash787 2020-08-12 23:50:21 +01:00
parent d51b79a399
commit 411c9fce34
3 changed files with 25 additions and 4 deletions

View File

@ -39,6 +39,24 @@ exports.setDataDirectory = function(dataDirectory){
config.settings.launcher.dataDirectory = dataDirectory
}
/**
* Get the launcher's server code if set. This will be used to load hidden servers.
*
* @returns {string} The server code that has been put into the launcher
*/
exports.getServerCode = function(def = false){
return !def ? config.settings.launcher.serverCode : DEFAULT_CONFIG.settings.launcher.serverCode
}
/**
* Set the new server code
*
* @param {string} serverCode The new server code.
*/
exports.setServerCode = function(serverCode){
config.settings.launcher.serverCode = serverCode
}
const configPath = path.join(exports.getLauncherDirectory(), 'config.json')
const configPathLEGACY = path.join(dataPath, 'config.json')
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
@ -91,7 +109,8 @@ const DEFAULT_CONFIG = {
},
launcher: {
allowPrerelease: false,
dataDirectory: dataPath
dataDirectory: dataPath,
serverCode: null
}
},
newsCache: {

View File

@ -136,6 +136,8 @@ function initSettingsValues(){
v.value = gFn()
} else if (cVal === 'DataDirectory'){
v.value = gFn()
} else if (cVal === 'ServerCode'){
v.value = gFn()
} else if(cVal === 'JVMOptions'){
v.value = gFn().join(' ')
} else {

View File

@ -270,7 +270,7 @@
<div class="settingsServerCodeTitle">Server Code</div>
<div class="settingsServerCodeContent">
<div class="settingsServerCodeActions">
<input class="settingsServerCodeVal" id="settingsJavaExecVal" type="text" value="" cValue="ServerCode">
<input class="settingsServerCodeVal" type="text" value="" cValue="ServerCode">
</div>
</div>
<div class="settingsServerCodeDesc">Any server code here (if valid) will grant you access to certain modpacks or servers that are set up to use the code.</div>