Skip to content

Commit

Permalink
Merge branch 'private-servers' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-luchack committed Jul 4, 2022
2 parents 923a2f7 + 3747198 commit 1d8f0c0
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 27 deletions.
176 changes: 174 additions & 2 deletions app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ body, button {
}
.settingsFieldDesc {
font-size: 12px;
color: rgba(255, 255, 255, .95);
color: gray;
margin-top: 5px;
}
.settingsDivider {
Expand Down Expand Up @@ -1428,13 +1428,185 @@ input:checked + .toggleSwitchSlider:before {
.settingsFileSelDesc {
font-size: 10px;
margin: 20px 0px;
color: lightgrey;
color: gray;
width: 89%;
}
.settingsFileSelDesc strong {
font-family: 'Avenir Medium';
}

/* Server code */
.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. */
.settingsServerCodesTitle {
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 3px 3px 0px !important;
width: 100%;
padding: 5px 10px;
font-size: 12px;
}

/* File selector icon settings. */
.settingsServerCodeIcon {
display: flex;
align-items: center;
background: rgba(126, 126, 126, 0.57);
border-radius: 3px 0px 0px 3px;
padding: 5px;
transition: 0.25s ease;
}
.settingsServerCodeSVG {
width: 20px;
height: 20px;
fill: white;
}

.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: 12px;
width: 90%;
}


.settingsServerCodesDesc strong {
font-family: 'Avenir Medium';
}

#settingsServerCodesListContent {
font-size: 16px;
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: 14px;
font-weight: bold;
}

.settingsServerCodeServerNamesContent {
max-width: 650px;
}

.settingsServerCodeServerName {
margin-right: 35px;
font-size: 12px;
}

.settingsServerCode:not([valid]) > .settingsServerCodeContent > .settingsServerCodeMainWrapper > .settingsServerCodeDetails > .settingsServerCodeServerNamesContent > .settingsServerCodeServerName {
color: red;
}

/* Button to remove drop-in mods. */
.settingsServerCodeRemoveButton {
background: none;
border: none;
font-size: 14px;
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)
* * */
Expand Down
21 changes: 20 additions & 1 deletion app/assets/js/configmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -93,7 +111,8 @@ const DEFAULT_CONFIG = {
launcher: {
allowPrerelease: false,
discordIntegration: true,
dataDirectory: dataPath
dataDirectory: dataPath,
serverCodes: []
}
},
newsCache: {
Expand Down
25 changes: 25 additions & 0 deletions app/assets/js/distromanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -499,6 +506,24 @@ 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.
*
Expand Down
79 changes: 57 additions & 22 deletions app/assets/js/scripts/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,32 @@ function setLaunchEnabled(val){

// Bind launch button
document.getElementById('launch_button').addEventListener('click', function(e){
if(ConfigManager.getConsoleOnLaunch()){
let window = remote.getCurrentWindow()
window.toggleDevTools()
}
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)){
if(ConfigManager.getConsoleOnLaunch()){
let window = remote.getCurrentWindow()
window.toggleDevTools()
}
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)
}
})
}
}
})

Expand Down Expand Up @@ -804,6 +806,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(
'Serveur actuel restreint !',
'Il semble que vous n\'ayez plus le code serveur requis pour accéder à ce serveur ! Veuillez passer à un autre serveur pour jouer.<br><br>Si vous pensez qu\'il s\'agit d\'une erreur, veuillez contacter l\'administrateur du serveur.',
'Changer de serveur'
)
setOverlayHandler(() => {
toggleServerSelection(true)
})
setDismissHandler(() => {
toggleOverlay(false)
})
toggleOverlay(true, true)
}
return false
}
}
}
return true
}
}

/**
* News Loading Functions
*/
Expand Down
3 changes: 3 additions & 0 deletions app/assets/js/scripts/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ function populateServerListings(){
const servers = distro.getServers()
let htmlString = ''
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' : ''}>
<img class="serverListingImg" src="${serv.getIcon()}"/>
<div class="serverListingDetails">
Expand Down
Loading

0 comments on commit 1d8f0c0

Please sign in to comment.