Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Authentication #41

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bin/
dist/
ext/
temp/
tools/
resources/js/neutralino.js
resources/bg/official

Expand Down
10 changes: 6 additions & 4 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
"scriptsSectionTitle": "Scripts",
"killswitchOption": "Kill Switch",
"killswitchSubtitle": "Only for those very paranoid about bans. Kills the game process *and your internet* if something happens to the proxy.",
"proxyOption": "Proxy",
"proxySubtitle": "Install the proxy server via the install script",
"proxyOption": "Run Installer",
"proxySubtitle": "Install (or reinstall) the proxy server and mtools via the install script.",
"updateOption": "Update",
"updateSubtitle": "Auto updating is temporarily disabled. Check GitHub for the newest release.",
"languageOption": "Language",
"languageSubtitle": "Select your language!",
"languageSubtitle": "Select your language",
"enableServerLauncherOption": "Enable Server Launcher",
"enableServerLauncherSubtitle": "Enable to server launcher tile for launching a local Grasscutter instance.",
"httpsOption": "Use HTTPS",
"httpsSubtitle": "Choose between using HTTPS or HTTP.",
"registryOption": "Login via Windows Registry",
"registrySubtitle": "Instead of copying login tokens when authenticating, you can login via a modification to the registry. Clears the registry data on game close. Registry tool courtesy of Asnxthaony.",

"introSen1": "Looks like this is your first time opening GrassClipper!",
"introSen2": "First of all, welcome, happy to see you here! :)",
"introSen3": "Would you like to run the proxy installer?",
"introSen3": "Would you like to run the first-time installer?",
"introSen4": "(required to connect to servers)",

"updateBtn": "Update",
Expand Down
14 changes: 12 additions & 2 deletions resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel" id="proxyTitle">Install Proxy Server</span>
<span class="settingLabel" id="proxyTitle">Run Installer</span>
<button class="smolBtn" onclick="runInstallScript()" id="proxyInstall">Install</button>
</div>
<span class="settingSubtitle" id="proxySubtitle">
Install the proxy server via the install script.
Install the proxy server and mtools via the install script.
</span>
</div>
<div class="settingsRow">
Expand Down Expand Up @@ -182,6 +182,16 @@
Choose between using HTTPS or HTTP.
</span>
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel", id="registryLoginTitle">Login via Windows Registry</span>
<input type="checkbox" id="registryOption" onchange="toggleRegistryLogin()" />
</select>
</div>
<span class="settingSubtitle" id="registrySubtitle">
Instead of copying login tokens when authenticating, you can login via a modification to the registry. Clears the registry data on game close. Registry tool courtesy of Asnxthaony.
</span>
</div>
</div>
</div>

Expand Down
27 changes: 27 additions & 0 deletions resources/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
serverLaunchPanel: false,
language: 'en',
useHttps: true,
registryLogin: true
}
const cfgStr = await Neutralino.storage.getData('config').catch(e => {
// The data isn't set, so this is our first time opening
Expand Down Expand Up @@ -102,6 +103,32 @@ async function openGrasscutterFolder() {
openInExplorer(folder)
}

async function getRegistryLoginDetails() {
const results = await Neutralino.os.execCommand('.\\tools\\mtools.exe show')
const out = results.stdErr

if (!out) return {}

const parsed = JSON.parse(out)

return parsed.data
}

async function clearRegistryLoginDetails() {
createCmdWindow(`.\\tools\\mtools.exe set -a "" -u "" -t "" -d "" -n ""`)
}

async function setRegistryLoginDetails(tokenOrAccount, loginUid, name) {
const accList = await getRegistryLoginDetails()
const cur = accList.find(a => a.is_login) || accList[0]

// Required fields: uid, token, account, deviceId

const { token, deviceId } = cur

createCmdWindow(`.\\tools\\mtools.exe set -a "${tokenOrAccount}" -u "${loginUid}" -t "${token}" -d "${deviceId}" -n "${name}"`)
}

/**
* Minimize the window
*/
Expand Down
2 changes: 2 additions & 0 deletions resources/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ async function openSettings() {
const killSwitch = document.querySelector('#killswitchOption')
const serverLaunch = document.querySelector('#serverLaunchOption')
const httpsCheckbox = document.querySelector('#httpsOption')
const registryCheckbox = document.querySelector('#registryOption')

killSwitch.checked = config.enableKillswitch
serverLaunch.checked = config.serverLaunchPanel
httpsCheckbox.checked = config.useHttps
registryCheckbox.checked = config.registryLogin

// Load languages
getLanguages()
Expand Down
5 changes: 4 additions & 1 deletion resources/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ async function login() {
await Neutralino.clipboard.writeText(tkData.token)

displayLoginAlert(localeObj.alertLoginSuccess || 'Login successful! Token copied to clipboard. Paste this token into the username field of the game to log in.', 'success', 8000);
launchPrivate()

await setRegistryLoginDetails(tkData.token, tkData.uid, username)
await launchPrivate()

break;
}
}
Expand Down
9 changes: 9 additions & 0 deletions resources/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ async function handleLanguageChange(elm) {
Neutralino.storage.setData('config', JSON.stringify(config))
}

async function toggleRegistryLogin() {
const registryCheckbox = document.querySelector('#registryOption')
const config = await getCfg()

config.registryLogin = registryCheckbox.checked

Neutralino.storage.setData('config', JSON.stringify(config))
}

/**
* Add the current value of the IP input to the favorites list
* OR
Expand Down
3 changes: 3 additions & 0 deletions resources/js/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ async function doTranslation() {
set('serverSubtitle', 'enableServerLauncherSubtitle')
set('httpsTitle', 'httpsOption')
set('httpsSubtitle', 'httpsSubtitle')
set('registryLoginTitle', 'registryOption')
set('registrySubtitle', 'registrySubtitle')

// Intro popup
const popup = document.getElementById('firstTimeNotice')
Expand All @@ -73,6 +75,7 @@ async function doTranslation() {
introSpan.innerHTML += localeObj.introSen3 + '<br>'
introSpan.innerHTML += localeObj.introSen4 + '<br>'

// First time popup
set('firstTimeInstallBtn', 'proxyInstallBtn')
set('firstTimeDenyBtn', 'proxyInstallDeny')

Expand Down
4 changes: 2 additions & 2 deletions resources/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ a {
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px 10%;
padding: 0 10%;
}

.settingsRow {
Expand All @@ -206,7 +206,7 @@ a {
display:inline-block;
font-size: 1em;
font-weight: normal;
margin: 10px 0px;
margin: 6px 0px;
}

.settingSubtitle {
Expand Down
5 changes: 5 additions & 0 deletions scripts/install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cd "%ORIGIN%"

if not exist "%ORIGIN%/ext" mkdir "%ORIGIN%/ext"
if not exist "%ORIGIN%/temp" mkdir "%ORIGIN%/temp
if not exist "%ORIGIN%/tools" mkdir "%ORIGIN%/tools"

:: Begin by retrieving mitmproxy 7.0.4
powershell Invoke-WebRequest -Uri https://snapshots.mitmproxy.org/7.0.4/mitmproxy-7.0.4-windows.zip -OutFile "'%ORIGIN%/temp/mitmproxy-7.0.4-windows.zip'"
Expand Down Expand Up @@ -44,6 +45,10 @@ echo Adding ceritifcate...
echo ============================================================================================================
)

echo Grabbing registry login tool...

powershell Invoke-WebRequest -Uri https://github.com/SpikeHD/miHoYoTools/releases/download/v1.0.1/mtools.exe -OutFile "'%ORIGIN%/tools/mtools.exe'"

echo Done! You can now open GrassClipper.exe!

pause
Expand Down
2 changes: 1 addition & 1 deletion scripts/private_server_launch.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ taskkill /f /im mitmdump.exe
echo Done, see you next time

:: Just in case the user has corutils installed, use this hacky timeout instead of the timeout command
ping 127.0.0.1 -n 2 > nul
ping 127.0.0.1 -n 1 > nul

:: Attempt to kill either
taskkill /f /fi "WINDOWTITLE eq Administrator: PS Launcher Script"
Expand Down