Skip to content

Commit

Permalink
MSA support (needs improvement)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Oct 22, 2021
1 parent aceea30 commit faf8bba
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
10 changes: 9 additions & 1 deletion html/mainPage/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ function loginDialog(callback) {
callback({
cancelled: false,
email: document.getElementById('login-email').value,
password: document.getElementById('login-password').value
password: document.getElementById('login-password').value,
method: document.getElementById('msa').checked ? 'microsoft' : 'mojang'
})
closeDialog()
}
Expand All @@ -377,6 +378,7 @@ function loginDialog(callback) {
document.getElementById('dialog').className='dialog dialog-medium'
document.getElementById('dialog').innerHTML =
`<form onsubmit="loginFormHandler(event); return false;"> <!-- TODO: prevent page reload? and handle login -->
<!-- TODO: Change message in manual auth mode -->
<h2>This server is in online mode</h2>
Please log in to your Minecraft account then reconnect.
<br><br>
Expand All @@ -385,6 +387,12 @@ function loginDialog(callback) {
<input placeholder="Email" type="text" style="width: calc(100% - 24px);" id="login-email">
<br><br>
<input placeholder="Password" type="password" style="width: calc(100% - 24px);" id="login-password">
<br><br>
<label for="msa">Use Microsoft auth?</label>
<label class="switch" style="padding: 0; bottom: 4px; left: 8px;">
<input id="msa" type="checkbox" value="consent">
<span class="slider round"></span>
</label>
<br>
<input style="margin-top: 16px; margin-right: 8px;" type="submit" value="Log in">
Expand Down
4 changes: 2 additions & 2 deletions html/mainPage/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ div.dialog-small {
}

div.dialog-medium {
top: calc(50% - 160px);
top: calc(50% - 180px);
left: calc(50% - 250px);
height: 320px;
height: 360px;
width: 500px;
}

Expand Down
6 changes: 3 additions & 3 deletions html/startPage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ <h1 class='title'>pakkit</h1>
</p>
<br><br>
<p>
<label for="manualOnline">Manual online mode:</label>
<span style="display: table-cell; width: 1px;">Asks for login credentials in a dialog box on join instead of automatically detecting them</span>
<label for="manual-auth">Manual auth:</label>
<span style="display: table-cell; width: 1px;">Asks for login credentials in a dialog box on join instead of automatically detecting them. Also forces online mode.</span>
</p>
<br>
<p>
<div style="display: table-cell;"></div>
<label class="switch" style="padding: 0;">
<input id="manualOnline" type="checkbox" value="manualOnline">
<input id="manual-auth" type="checkbox">
<span class="slider round"></span>
</label>
</p>
Expand Down
6 changes: 5 additions & 1 deletion html/startPage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function loadSettings (newPlatform) {
loadSetting(newPlatform + 'LastConnectAddress', 'connectAddress', 'connect-address', '127.0.0.1')
loadSetting(newPlatform + 'LastConnectPort', 'connectPort', 'connect-port', platform === 'java' ? '25565' : '19132')
loadSetting(newPlatform + 'LastListenPort', 'listenPort', 'listen-port', platform === 'java' ? '25566' : '19142')
loadSetting(newPlatform + 'LastManualAuth', 'manualAuth', 'manual-auth', platform === 'java' ? '25566' : '19142')
}

function saveSettings (thePlatform) {
Expand All @@ -40,6 +41,7 @@ function saveSettings (thePlatform) {
store.set(thePlatform + 'LastConnectAddress', connectAddress)
store.set(thePlatform + 'LastConnectPort', connectPort)
store.set(thePlatform + 'LastListenPort', listenPort)
store.set(thePlatform + 'LastManualAuth', manualAuth)
}

function loadSetting (name, varname, elementID, defaultValue) {
Expand All @@ -54,6 +56,7 @@ function loadSetting (name, varname, elementID, defaultValue) {
function updateVars () {
connectAddress = document.getElementById('connect-address').value
connectPort = document.getElementById('connect-port').value
manualAuth = document.getElementById('manual-auth').value
listenPort = document.getElementById('listen-port').value
platform = document.getElementById('platform').value
version = document.getElementById('version').value
Expand Down Expand Up @@ -101,8 +104,9 @@ window.startProxy = function (event) {
consent: store.get('authConsentGiven'),
connectAddress: connectAddress,
connectPort: connectPort,
manualAuth: manualAuth,
listenPort: listenPort,
platform: platform,
version: version
version: version,
}))
}
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function createWindow() {
consent: false,
connectAddress: options.connect,
connectPort: options.connectPort,
manualAuth: options.manualAuth,
listenPort: options.listenPort,
platform: options.platform,
version: options.version
Expand Down Expand Up @@ -209,7 +210,7 @@ function requestManualAuth () {

ipcMain.on('setManualAuth', (event, arg) => {
const ipcMessage = JSON.parse(arg)
proxy.setManualAuth(true, ipcMessage.email, ipcMessage.password)
proxy.setManualAuth(true, ipcMessage.email, ipcMessage.password, ipcMessage.method)
})

function startProxy (args) {
Expand All @@ -225,7 +226,7 @@ function startProxy (args) {
proxy.startProxy(args.connectAddress, args.connectPort, args.listenPort, args.version,
args.consent, packetHandler.packetHandler, packetHandler.messageHandler , dataFolder, () => {
win.send('updateFiltering', '')
}, requestManualAuth)
}, requestManualAuth, args.manualAuth)

win.loadFile('html/mainPage/index.html')

Expand Down
2 changes: 1 addition & 1 deletion src/proxy/bedrock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function handleError (chunk) {
}

exports.startProxy = function (passedHost, passedPort, passedListenPort, version, authConsent, passedPacketCallback,
passedMessageCallback, passedDataFolder, passedUpdateFilteringCallback, manualAuthCallback) {
passedMessageCallback, passedDataFolder, passedUpdateFilteringCallback, manualAuthCallback, manualAuth) {
host = passedHost
port = passedPort
listenPort = passedListenPort
Expand Down
18 changes: 15 additions & 3 deletions src/proxy/java/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,22 @@ exports.capabilities = {
let manualAuthEnabled = false
let manualAuthEmail = undefined
let manualAuthPassword = undefined
let manualAuthMethod = undefined

exports.setManualAuth = function (enabled, email, password) {
let authWindowOpen = false

exports.setManualAuth = function (enabled, email, password, method) {
authWindowOpen = false
manualAuthEnabled = enabled
if (enabled) {
manualAuthEmail = email
manualAuthPassword = password
manualAuthMethod = method
}
}

exports.startProxy = function (host, port, listenPort, version, authConsent, callback, messageCallback, dataFolder,
updateFilteringCallback, manualAuthCallback) {
updateFilteringCallback, manualAuthCallback, manualAuth) {
storedCallback = callback

// . cannot be in a JSON property name with electron-store
Expand Down Expand Up @@ -122,20 +127,26 @@ exports.startProxy = function (host, port, listenPort, version, authConsent, cal
} else {
console.warn('Consent not given to use launcher_profiles.json - automatic online mode will not work')
}
if (manualAuth && !manualAuthEmail) {
authWindowOpen = true
manualAuthCallback()
}
const clientOptions = {
host: host,
port: port,
username: manualAuthEnabled ? manualAuthEmail : client.username,
password: manualAuthEnabled ? manualAuthPassword : undefined,
keepAlive: false,
version: version,
profilesFolder: (authConsent && !manualAuthEnabled) ? minecraftFolder : dataFolder
profilesFolder: (authConsent && !manualAuthEnabled) ? minecraftFolder : dataFolder,
auth: manualAuthMethod
}
let targetClient = mc.createClient(clientOptions)
realServer = targetClient
targetClient.on('noAuth', () => {
// Request manual authentication
console.log('Automatic auth failed - manual auth needed')
authWindowOpen = true
manualAuthCallback()
})

Expand Down Expand Up @@ -254,6 +265,7 @@ exports.startProxy = function (host, port, listenPort, version, authConsent, cal
endedTargetClient = true
console.log('Connection error by server', '(' + host + ':' + port + ') ', err)
console.log(err.stack)
if (authWindowOpen) return
let header = 'Unable to connect to server'
let message = err.message
if (err.message.includes('ECONNREFUSED')) {
Expand Down

0 comments on commit faf8bba

Please sign in to comment.