From 4dbc20c7ed07d29f8cdaad4d90606719700b9cd0 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 24 Mar 2022 13:43:49 +0000 Subject: [PATCH] Added working Server Codes on latest HL Release --- app/assets/css/launcher.css | 166 +++++++++++++++++++++++++++++- app/assets/js/configmanager.js | 21 +++- app/assets/js/distromanager.js | 26 +++++ app/assets/js/scripts/landing.js | 71 +++++++++---- app/assets/js/scripts/overlay.js | 3 + app/assets/js/scripts/settings.js | 104 +++++++++++++++++++ app/settings.ejs | 13 +++ docs/distro.md | 4 + docs/sample_distribution.json | 4 + 9 files changed, 389 insertions(+), 23 deletions(-) diff --git a/app/assets/css/launcher.css b/app/assets/css/launcher.css index e67984e4..7eda6f03 100644 --- a/app/assets/css/launcher.css +++ b/app/assets/css/launcher.css @@ -1435,6 +1435,163 @@ input:checked + .toggleSwitchSlider:before { font-family: 'Avenir Medium'; } +/* Main container for File selectors. */ +.settingsServerCodeContainer { + display: flex; + flex-direction: column; + border-bottom: 1px solid rgba(255, 255, 255, 0.50); + margin-bottom: 20px; + margin-top: 20px; + width: 75%; +} + +/* Server Code title. */ +.settingsServerCodeTitle { + margin-bottom: 10px; + font-size: 14px; + font-family: 'Avenir Medium'; +} + +/* Wrapper container for the actionable elements. */ +.settingsServerCodeActions { + display: flex; + width: 60%; +} + +/* Enabled text field which stores the secret code if available. */ +.settingsInputServerCodeVal { + border-radius: 0px !important; + width: 100%; + padding: 5px 10px; + font-size: 12px; +} + +.settingsInputServerCodeButton { + border: 0px; + border-radius: 3px 3px 3px 3px; + font-size: 12px; + padding: 0px 5px; + margin-left: 10px; + cursor: pointer; + background: rgba(126, 126, 126, 0.57); + transition: 0.25s ease; + white-space: nowrap; + outline: none; +} +.settingsInputServerCodeButton:hover, +.settingInputServerCodeButton:focus { + text-shadow: 0px 0px 20px white; +} +.settingsInputServerCodeButton:active { + text-shadow: 0px 0px 20px rgba(255, 255, 255, 0.75); + color: rgba(255, 255, 255, 0.75); +} + +/* Description for the file selector. */ +.settingsServerCodesDesc { + margin: 20px 0px; + color: grey; + font-size: 10px; + width: 90%; +} + + +.settingsServerCodesDesc strong { + font-family: 'Avenir Medium'; +} + +#settingsServerCodesListContent { + font-size: 10px; + background: rgba(0, 0, 0, 0.25); + border-radius: 3px; + color: white; + margin-top: 10px; +} + +.settingsServerCode { + padding: 8px 0px 8px 8px; +} + +/* Main content container for server code element information. */ +.settingsServerCodeContent { + display: flex; + align-items: center; + justify-content: space-between; + transition: opacity 0.25s ease; +} + +/* Wrapper container for the left side of a server code element. */ +.settingsServerCodeMainWrapper { + display: flex; + align-items: center; +} + +.settingsServerCodeRemoveWrapper { + margin-right: 25px; +} + +/* Server code valid/invalid status. */ +.settingsServerCodeStatus { + width: 7px; + height: 7px; + border-radius: 50%; + background-color: #c32625; + margin-right: 15px; + transition: 0.25s ease; +} + +.settingsServerCode[valid] > .settingsServerCodeContent > .settingsServerCodeMainWrapper > .settingsServerCodeStatus { + background-color: #4ddd19; +} + +/* Mod details container. */ +.settingsServerCodeDetails { + display: flex; + flex-direction: column; +} + +.settingsServerCodeName { + display: flex; + flex-direction: column; + font-size: 12px; + font-weight: bold; +} + +.settingsServerCodeServerNamesContent { + max-width: 650px; +} + +.settingsServerCodeServerName { + margin-right: 35px; + font-size: 14px; +} + +.settingsServerCode:not([valid]) > .settingsServerCodeContent > .settingsServerCodeMainWrapper > .settingsServerCodeDetails > .settingsServerCodeServerNamesContent > .settingsServerCodeServerName { + color: red; +} + +/* Button to remove drop-in mods. */ +.settingsServerCodeRemoveButton { + background: none; + border: none; + font-size: 12px; + text-align: right; + padding: 0px; + color: grey; + cursor: pointer; + outline: none; + transition: 0.25s ease; + font-weight: bold; +} + +.settingsServerCodeRemoveButton:hover, +.settingsServerCodeRemoveButton:focus { + color: red; +} +.settingsServerCodeRemoveButton:active { + color: #9b1f1f; +} + /* * * * Settings View (Account Tab) * * */ @@ -1722,15 +1879,16 @@ input:checked + .toggleSwitchSlider:before { /* Mod elements. */ .settingsMod, -.settingsDropinMod { - padding: 10px; -} .settingsSubMod { padding: 10px 0px 10px 15px; margin-left: 20px; border-left: 1px solid rgba(255, 255, 255, 0.5); } +.settingsDropinMod { + padding: 10px; +} + /* Main content container for mod element information. */ .settingsModContent { display: flex; @@ -1775,7 +1933,7 @@ input:checked + .toggleSwitchSlider:before { /* Set the status color of an enabled mod. */ .settingsBaseMod[enabled] > .settingsModContent > .settingsModMainWrapper > .settingsModStatus { - background-color: rgb(165, 195, 37); + background-color: #4ddd19;; } /* Add opacity to submods of a disabled mod. */ diff --git a/app/assets/js/configmanager.js b/app/assets/js/configmanager.js index 3dff9502..aa20de61 100644 --- a/app/assets/js/configmanager.js +++ b/app/assets/js/configmanager.js @@ -39,6 +39,24 @@ exports.setDataDirectory = function(dataDirectory){ config.settings.launcher.dataDirectory = dataDirectory } +/** + * Get the launcher's available server codes. This will be used to load hidden servers. + * + * @returns {string[]} The server codes list that has been put into the launcher's configuration + */ + exports.getServerCodes = function(){ + return config.settings.launcher.serverCodes +} + +/** + * Set the new server code + * + * @param {string[]} serverCodes The new server code list. + */ +exports.setServerCodes = function(serverCodes){ + config.settings.launcher.serverCodes = serverCodes +} + 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, + serverCodes: [] } }, newsCache: { diff --git a/app/assets/js/distromanager.js b/app/assets/js/distromanager.js index 90a2ab8d..1bcbadb1 100644 --- a/app/assets/js/distromanager.js +++ b/app/assets/js/distromanager.js @@ -398,6 +398,13 @@ class Server { return this.mainServer } + /** + * @returns {string} The server code for this server + */ + getServerCode(){ + return this.serverCode + } + /** * @returns {boolean} Whether or not the server is autoconnect. * by default. @@ -499,6 +506,25 @@ class DistroIndex { return null } + + /** + * Get a server configuration by its ID. If it does not + * exist, null will be returned. + * + * @param {string} id The ID of the server. + * + * @returns {Server[]} The server configuration with the given ID or null. + */ + getServersFromCode(code){ + let servs = [] + for(let serv of this.servers){ + if(serv.serverCode === code){ + servs.push(serv) + } + } + return servs + } + /** * Get the main server. * diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index c15896c8..54797ed7 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -85,26 +85,28 @@ function setLaunchEnabled(val){ // Bind launch button document.getElementById('launch_button').addEventListener('click', function(e){ - loggerLanding.log('Launching game..') - const mcVersion = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion() - const jExe = ConfigManager.getJavaExecutable() - if(jExe == null){ - asyncSystemScan(mcVersion) - } else { + if(checkCurrentServer(true)){ + loggerLanding.log('Launching game..') + const mcVersion = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion() + const jExe = ConfigManager.getJavaExecutable() + if(jExe == null){ + asyncSystemScan(mcVersion) + } else { - setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) - toggleLaunchArea(true) - setLaunchPercentage(0, 100) + setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) + toggleLaunchArea(true) + setLaunchPercentage(0, 100) - const jg = new JavaGuard(mcVersion) - jg._validateJavaBinary(jExe).then((v) => { - loggerLanding.log('Java version meta', v) - if(v.valid){ - dlAsync() - } else { - asyncSystemScan(mcVersion) - } - }) + const jg = new JavaGuard(mcVersion) + jg._validateJavaBinary(jExe).then((v) => { + loggerLanding.log('Java version meta', v) + if(v.valid){ + dlAsync() + } else { + asyncSystemScan(mcVersion) + } + }) + } } }) @@ -764,6 +766,39 @@ function dlAsync(login = true){ }) } +/** + * Checks the current server to ensure that they still have permission to play it (checking server code, if applicable) and open up an error overlay if specified + * @Param {boolean} whether or not to show the error overlay + */ + function checkCurrentServer(errorOverlay = true){ + const selectedServId = ConfigManager.getSelectedServer() + if(selectedServId){ + const selectedServ = DistroManager.getDistribution().getServer(selectedServId) + if(selectedServ){ + if(selectedServ.getServerCode() && selectedServ.getServerCode() !== ''){ + if(!ConfigManager.getServerCodes().includes(selectedServ.getServerCode())){ + if(errorOverlay){ + setOverlayContent( + 'Current Server Restricted!', + 'It seems that you no longer have the server code required to access this server! Please switch to a different server to play on.

If you feel this is an error, please contact the server administrator', + 'Switch Server' + ) + setOverlayHandler(() => { + toggleServerSelection(true) + }) + setDismissHandler(() => { + toggleOverlay(false) + }) + toggleOverlay(true, true) + } + return false + } + } + } + return true + } +} + /** * News Loading Functions */ diff --git a/app/assets/js/scripts/overlay.js b/app/assets/js/scripts/overlay.js index cf2c5c98..8dd56a15 100644 --- a/app/assets/js/scripts/overlay.js +++ b/app/assets/js/scripts/overlay.js @@ -273,6 +273,9 @@ function populateServerListings(){ const servers = distro.getServers() let htmlString = '' for(const serv of servers){ + if(serv.getServerCode() && !ConfigManager.getServerCodes().includes(serv.getServerCode())){ + continue + } htmlString += ` + + + + ` + } + + document.getElementById('settingsServerCodesListContent').innerHTML = servCodes + + /* Server Names List */ + for(let ele of document.getElementsByClassName('settingsServerCodeServerNamesContent')){ + servNames = '' + const code = ele.getAttribute('code') + const servs = DistroManager.getDistribution().getServersFromCode(code) + const valid = servs && servs.length + loggerSettings.log('valid: ' + valid) + if(valid){ + for(let serv of servs){ + loggerSettings.log('server: ' + serv.getName()) + servNames += + ` + ${serv.getName()} + ` + } + } else { + servNames = + ` + Invalid Code + ` + } + + ele.innerHTML = servNames + } +} + /** * Bind the remove button for each loaded drop-in mod. */ @@ -1526,6 +1629,7 @@ function prepareSettings(first = false) { initSettingsValues() prepareAccountsTab() prepareJavaTab() + prepareLauncherTab() prepareAboutTab() } diff --git a/app/settings.ejs b/app/settings.ejs index 65a1796d..eb837807 100644 --- a/app/settings.ejs +++ b/app/settings.ejs @@ -295,6 +295,19 @@
All game files and local Java installations will be stored in the data directory.
Screenshots and world saves are stored in the instance folder for the corresponding server configuration.
+
+
Your Server Codes
+
+
+ + +
+
+
+ +
+
Specify server codes here to grant access to hidden servers that wouldn't be available to all users by default.
+