Added working Server Codes on latest HL Release

This commit is contained in:
Peter 2022-03-24 13:43:49 +00:00
parent 6d5e7aa7ac
commit 4dbc20c7ed
9 changed files with 389 additions and 23 deletions

View File

@ -1435,6 +1435,163 @@ input:checked + .toggleSwitchSlider:before {
font-family: 'Avenir Medium'; 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) * Settings View (Account Tab)
* * */ * * */
@ -1722,15 +1879,16 @@ input:checked + .toggleSwitchSlider:before {
/* Mod elements. */ /* Mod elements. */
.settingsMod, .settingsMod,
.settingsDropinMod {
padding: 10px;
}
.settingsSubMod { .settingsSubMod {
padding: 10px 0px 10px 15px; padding: 10px 0px 10px 15px;
margin-left: 20px; margin-left: 20px;
border-left: 1px solid rgba(255, 255, 255, 0.5); border-left: 1px solid rgba(255, 255, 255, 0.5);
} }
.settingsDropinMod {
padding: 10px;
}
/* Main content container for mod element information. */ /* Main content container for mod element information. */
.settingsModContent { .settingsModContent {
display: flex; display: flex;
@ -1775,7 +1933,7 @@ input:checked + .toggleSwitchSlider:before {
/* Set the status color of an enabled mod. */ /* Set the status color of an enabled mod. */
.settingsBaseMod[enabled] > .settingsModContent > .settingsModMainWrapper > .settingsModStatus { .settingsBaseMod[enabled] > .settingsModContent > .settingsModMainWrapper > .settingsModStatus {
background-color: rgb(165, 195, 37); background-color: #4ddd19;;
} }
/* Add opacity to submods of a disabled mod. */ /* Add opacity to submods of a disabled mod. */

View File

@ -39,6 +39,24 @@ exports.setDataDirectory = function(dataDirectory){
config.settings.launcher.dataDirectory = 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 configPath = path.join(exports.getLauncherDirectory(), 'config.json')
const configPathLEGACY = path.join(dataPath, 'config.json') const configPathLEGACY = path.join(dataPath, 'config.json')
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY) const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
@ -91,7 +109,8 @@ const DEFAULT_CONFIG = {
}, },
launcher: { launcher: {
allowPrerelease: false, allowPrerelease: false,
dataDirectory: dataPath dataDirectory: dataPath,
serverCodes: []
} }
}, },
newsCache: { newsCache: {

View File

@ -398,6 +398,13 @@ class Server {
return this.mainServer return this.mainServer
} }
/**
* @returns {string} The server code for this server
*/
getServerCode(){
return this.serverCode
}
/** /**
* @returns {boolean} Whether or not the server is autoconnect. * @returns {boolean} Whether or not the server is autoconnect.
* by default. * by default.
@ -499,6 +506,25 @@ class DistroIndex {
return null 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. * Get the main server.
* *

View File

@ -85,26 +85,28 @@ function setLaunchEnabled(val){
// Bind launch button // Bind launch button
document.getElementById('launch_button').addEventListener('click', function(e){ document.getElementById('launch_button').addEventListener('click', function(e){
loggerLanding.log('Launching game..') if(checkCurrentServer(true)){
const mcVersion = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion() loggerLanding.log('Launching game..')
const jExe = ConfigManager.getJavaExecutable() const mcVersion = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion()
if(jExe == null){ const jExe = ConfigManager.getJavaExecutable()
asyncSystemScan(mcVersion) if(jExe == null){
} else { asyncSystemScan(mcVersion)
} else {
setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait'))
toggleLaunchArea(true) toggleLaunchArea(true)
setLaunchPercentage(0, 100) setLaunchPercentage(0, 100)
const jg = new JavaGuard(mcVersion) const jg = new JavaGuard(mcVersion)
jg._validateJavaBinary(jExe).then((v) => { jg._validateJavaBinary(jExe).then((v) => {
loggerLanding.log('Java version meta', v) loggerLanding.log('Java version meta', v)
if(v.valid){ if(v.valid){
dlAsync() dlAsync()
} else { } else {
asyncSystemScan(mcVersion) 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.<br><br>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 * News Loading Functions
*/ */

View File

@ -273,6 +273,9 @@ function populateServerListings(){
const servers = distro.getServers() const servers = distro.getServers()
let htmlString = '' let htmlString = ''
for(const serv of servers){ for(const serv of servers){
if(serv.getServerCode() && !ConfigManager.getServerCodes().includes(serv.getServerCode())){
continue
}
htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? 'selected' : ''}> htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? 'selected' : ''}>
<img class="serverListingImg" src="${serv.getIcon()}"/> <img class="serverListingImg" src="${serv.getIcon()}"/>
<div class="serverListingDetails"> <div class="serverListingDetails">

View File

@ -5,6 +5,7 @@ const semver = require('semver')
const { JavaGuard } = require('./assets/js/assetguard') const { JavaGuard } = require('./assets/js/assetguard')
const DropinModUtil = require('./assets/js/dropinmodutil') const DropinModUtil = require('./assets/js/dropinmodutil')
const { MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR } = require('./assets/js/ipcconstants') const { MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR } = require('./assets/js/ipcconstants')
const loggerSettings = require('./assets/js/loggerutil')('%c[Settings]', 'color: #353232; font-weight: bold')
const settingsState = { const settingsState = {
invalid: new Set() invalid: new Set()
@ -137,6 +138,8 @@ function initSettingsValues(){
v.value = gFn() v.value = gFn()
} else if (cVal === 'DataDirectory'){ } else if (cVal === 'DataDirectory'){
v.value = gFn() v.value = gFn()
} else if (cVal === 'ServerCode'){
v.value = gFn()
} else if(cVal === 'JVMOptions'){ } else if(cVal === 'JVMOptions'){
v.value = gFn().join(' ') v.value = gFn().join(' ')
} else { } else {
@ -423,6 +426,44 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => {
} }
}) })
/**
* Binds the functionality within the server codes section of the launcher settings
*/
function bindServerCodeButtons(){
// Sets up the onclick listeners for the button to add codes
document.getElementById('settingsAddServerCode').onclick = () => {
for(let ele of document.getElementsByClassName('settingsInputServerCodeVal')){
const code = ele.value
ele.value = ''
if(!ConfigManager.getServerCodes().includes(code) && code){
ConfigManager.getServerCodes().push(code)
ConfigManager.save()
loggerSettings.log('Added server code to configuration and saved it')
prepareLauncherTab()
} else {
loggerSettings.log('Server code already exists or is empty, not adding.')
}
}
}
// Sets up the onclick listeners for each remove code buttons
const sEls = document.querySelectorAll('[remcode]')
Array.from(sEls).map((v, index, arr) => {
v.onclick = () => {
if(v.hasAttribute('remcode')){
const code = v.getAttribute('remcode')
if(ConfigManager.getServerCodes().includes(code)){
ConfigManager.getServerCodes().splice(ConfigManager.getServerCodes().indexOf(code), 1)
ConfigManager.save()
loggerSettings.log('Added removed code from configuration and saved it')
prepareLauncherTab()
}
}
loggerSettings.log('Server code doesnt exist!, not removing.')
}
})
}
/** /**
* Bind functionality for the account selection buttons. If another account * Bind functionality for the account selection buttons. If another account
* is selected, the UI of the previously selected account will be updated. * is selected, the UI of the previously selected account will be updated.
@ -662,6 +703,14 @@ function prepareAccountsTab() {
bindAuthAccountLogOut() bindAuthAccountLogOut()
} }
/**
* Prepare the launcher tab for display.
*/
function prepareLauncherTab() {
resolveServerCodesForUI()
bindServerCodeButtons()
}
/** /**
* Minecraft Tab * Minecraft Tab
*/ */
@ -864,6 +913,60 @@ function resolveDropinModsForUI(){
document.getElementById('settingsDropinModsContent').innerHTML = dropinMods document.getElementById('settingsDropinModsContent').innerHTML = dropinMods
} }
function resolveServerCodesForUI(){
/* Server Codes */
let servCodes = ''
for(let servCode of ConfigManager.getServerCodes()){
const servs = DistroManager.getDistribution().getServersFromCode(servCode)
const valid = servs && servs.length
servCodes +=
`
<div id="${servCode}" class="settingsServerCode" ${valid ? 'valid' : ''}>
<div class="settingsServerCodeContent">
<div class="settingsServerCodeMainWrapper">
<div class="settingsServerCodeStatus"></div>
<div class="settingsServerCodeDetails">
<span class="settingsServerCodeName">${servCode}</span>
<div class="settingsServerCodeServerNamesContent" code="${servCode}">
</div>
</div>
</div>
<div class="settingsServerCodeRemoveWrapper">
<button class="settingsServerCodeRemoveButton" id="settingsRemoveServerCode" remcode="${servCode}">Remove</button>
</div>
</div>
</div>
`
}
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 +=
`
<span class="settingsServerCodeServerName">${serv.getName()}</span>
`
}
} else {
servNames =
`
<span class="settingsServerCodeServerName">Invalid Code</span>
`
}
ele.innerHTML = servNames
}
}
/** /**
* Bind the remove button for each loaded drop-in mod. * Bind the remove button for each loaded drop-in mod.
*/ */
@ -1526,6 +1629,7 @@ function prepareSettings(first = false) {
initSettingsValues() initSettingsValues()
prepareAccountsTab() prepareAccountsTab()
prepareJavaTab() prepareJavaTab()
prepareLauncherTab()
prepareAboutTab() prepareAboutTab()
} }

View File

@ -295,6 +295,19 @@
</div> </div>
<div class="settingsFileSelDesc">All game files and local Java installations will be stored in the data directory.<br>Screenshots and world saves are stored in the instance folder for the corresponding server configuration.</div> <div class="settingsFileSelDesc">All game files and local Java installations will be stored in the data directory.<br>Screenshots and world saves are stored in the instance folder for the corresponding server configuration.</div>
</div> </div>
<div class="settingsServerCodeContainer">
<div class="settingsServerCodeTitle">Your Server Codes</div>
<div class="settingsServerCodeContent">
<div class="settingsServerCodeActions">
<input class="settingsInputServerCodeVal" placeholder="Enter Code" type="text">
<button class="settingsInputServerCodeButton" id="settingsAddServerCode">Add Code</button>
</div>
</div>
<div id="settingsServerCodesListContent">
</div>
<div class="settingsServerCodesDesc">Specify server codes here to grant access to hidden servers that wouldn't be available to all users by default.</div>
</div>
</div> </div>
<div id="settingsTabAbout" class="settingsTab" style="display: none;"> <div id="settingsTabAbout" class="settingsTab" style="display: none;">
<div class="settingsTabHeader"> <div class="settingsTabHeader">

View File

@ -143,6 +143,10 @@ Only one server in the array should have the `mainServer` property enabled. This
Whether or not the server can be autoconnected to. If false, the server will not be autoconnected to even when the user has the autoconnect setting enabled. Whether or not the server can be autoconnected to. If false, the server will not be autoconnected to even when the user has the autoconnect setting enabled.
### `Server.serverCode: string`
A code that allows you to privately distribute certain servers on the launcher. Players will only be able to see the server in their launcher if they have specified the code in the settings. If left blank, all players can see the server.
### `Server.modules: Module[]` ### `Server.modules: Module[]`
An array of module objects. An array of module objects.

View File

@ -24,6 +24,7 @@
"largeImageKey": "server-prod" "largeImageKey": "server-prod"
}, },
"mainServer": true, "mainServer": true,
"serverCode": "",
"autoconnect": true, "autoconnect": true,
"modules": [ "modules": [
{ {
@ -438,6 +439,7 @@
"largeImageKey": "server-test" "largeImageKey": "server-test"
}, },
"mainServer": false, "mainServer": false,
"serverCode": "",
"autoconnect": true, "autoconnect": true,
"modules": [ "modules": [
{ {
@ -852,6 +854,7 @@
"largeImageKey": "server-test" "largeImageKey": "server-test"
}, },
"mainServer": false, "mainServer": false,
"serverCode": "",
"autoconnect": true, "autoconnect": true,
"modules": [ "modules": [
{ {
@ -1283,6 +1286,7 @@
"largeImageKey": "server-test" "largeImageKey": "server-test"
}, },
"mainServer": false, "mainServer": false,
"serverCode": "",
"autoconnect": false, "autoconnect": false,
"modules": [ "modules": [
{ {