diff options
-rw-r--r-- | LawncableLauncher.nsi | 53 | ||||
-rw-r--r-- | assets/index.html | 12 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/renderer/gameserver/TOSCheck.ts | 66 | ||||
-rw-r--r-- | src/renderer/gameserver/data.ts | 9 | ||||
-rw-r--r-- | src/renderer/gameserver/server.ts | 3 | ||||
-rw-r--r-- | src/renderer/serverView.ts | 30 |
7 files changed, 158 insertions, 17 deletions
diff --git a/LawncableLauncher.nsi b/LawncableLauncher.nsi index 7ec1d96..e88c792 100644 --- a/LawncableLauncher.nsi +++ b/LawncableLauncher.nsi @@ -1,5 +1,6 @@ ;-------------------------------- ;Include Modern UI +;http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html !include "MUI2.nsh" @@ -9,12 +10,13 @@ ;Name and file Name "ManaLauncher" OutFile "InstallManaLauncher.exe" + !define MUI_ICON "assets\media\icon.ico" ;Default installation folder InstallDir "$PROGRAMFILES\ManaLauncher" ;Get installation folder from registry if available - InstallDirRegKey HKCU "Software\ManaLauncher" "" + InstallDirRegKey HKCU "Software\LawnCablesManaLauncher" "" ;Request application privileges for Windows Vista RequestExecutionLevel admin @@ -45,20 +47,41 @@ !insertmacro MUI_PAGE_INSTFILES - !insertmacro MUI_UNPAGE_CONFIRM - !insertmacro MUI_UNPAGE_INSTFILES - Function finishpageaction CreateShortcut "$Desktop\LawnCablesManaLauncher.lnk" "$INSTDIR\LawnCablesManaLauncher.exe" FunctionEnd + !define MUI_FINISHPAGE_RUN $INSTDIR\LawnCablesManaLauncher.exe + !define MUI_FINISHPAGE_RUN_TEXT "Launch ManaLauncher" + !define MUI_FINISHPAGE_SHOWREADME "" - !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut" !define MUI_FINISHPAGE_SHOWREADME_FUNCTION finishpageaction !insertmacro MUI_PAGE_FINISH + !define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnWelcome + !define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.LeaveUnWelcome + !insertmacro MUI_UNPAGE_WELCOME + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES + + Var checkbox + var CheckboxState + Function un.onInit + StrCpy $CheckboxState ${BST_CHECKED} + FunctionEnd + Function un.ModifyUnWelcome + ${NSD_CreateCheckbox} 120u -20u 50% 20u "Keep Gamedata and Configuration Files" + Pop $checkbox + SetCtlColors $checkbox "" ${MUI_BGCOLOR} + ${NSD_SetState} $checkbox $CheckboxState + FunctionEnd + + Function un.LeaveUnWelcome + ${NSD_GetState} $checkbox $CheckboxState + FunctionEnd + ;-------------------------------- ;Languages @@ -67,18 +90,27 @@ ;-------------------------------- ;Installer Sections +!define REG_UNISTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\LawnCablesManaLauncher" + Section "Install" SetOutPath "$INSTDIR" File /r "out\LawnCablesManaLauncher-win32-x64\*" + File "assets\media\icon.ico" + ;Store installation folder WriteRegStr HKCU "Software\LawnCablesManaLauncher" "" $INSTDIR ;Create uninstaller WriteUninstaller "$INSTDIR\Uninstall.exe" + WriteRegStr HKLM ${REG_UNISTALL_KEY} "DisplayName" "LawnCable's ManaLauncher" + WriteRegStr HKLM ${REG_UNISTALL_KEY} "Publisher" "TMW2.ORG -> ManaLauncher Team" + WriteRegStr HKLM ${REG_UNISTALL_KEY} "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" + WriteRegStr HKLM ${REG_UNISTALL_KEY} "DisplayIcon" "$\"$INSTDIR\icon.ico$\"" + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application ;Create shortcuts @@ -99,11 +131,12 @@ SectionEnd Section "Uninstall" - ;ADD YOUR OWN FILES HERE... + RMDir /r "$INSTDIR" - Delete "$INSTDIR\Uninstall.exe" - RMDir /r "$INSTDIR" + ${If} $CheckboxState <> ${BST_CHECKED} + RMDir /r "$APPDATA\mana-launcher" + ${EndIf} !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder @@ -114,4 +147,8 @@ Section "Uninstall" DeleteRegKey /ifempty HKCU "Software\LawnCablesManaLauncher" + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LawnCablesManaLauncher" + Delete "$INSTDIR\Uninstall.exe" + RMDir /r "$INSTDIR" + SectionEnd diff --git a/assets/index.html b/assets/index.html index e79a51b..52fc8fc 100644 --- a/assets/index.html +++ b/assets/index.html @@ -33,7 +33,17 @@ <progress id="progress" value="0" max="100"></progress> </div> </div> - + <dialog id="TOSDialog"> + <form method="dialog"> + You have to <b>accept</b> the <b>Terms & Rules</b> of this Gameserver to play on it.<br> + If you allready accepted them they probably got <b>updated</b>. + <menu> + <button id="TOSCancel">No</button> + <button id="TOSOpen">Open Terms</button> + <button id="TOSAccept">Accept</button> + </menu> + </form> + </dialog> <script> require('../dist/renderer/index.js'); require('../dist/renderer/CustomEvents.js'); diff --git a/package.json b/package.json index 53aef23..ab88f22 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "tsc", "start": "npm run build && electron .", - "package": "npm run build && electron-packager . LawnCablesManaLauncher --arch=x64 --out=./out --overwrite --ignore=mana-launcher/src --icon=assets/media/icon.ico" + "package": "npm run build && electron-packager . LawnCablesManaLauncher --arch=x64 --out=./out --overwrite --ignore=\"LawncableLauncher.nsi|Readme.md|tsconfig.json|tslint.json|.gitignore|InstallManaLauncher.exe\" --icon=assets/media/icon.ico" }, "author": "LawnCable", "license": "GNU GPLv3", diff --git a/src/renderer/gameserver/TOSCheck.ts b/src/renderer/gameserver/TOSCheck.ts new file mode 100644 index 0000000..8dc29f2 --- /dev/null +++ b/src/renderer/gameserver/TOSCheck.ts @@ -0,0 +1,66 @@ +import GameServer from './server'; +import { ipcRenderer } from 'electron'; + +let LAST_TOS = ""; + +export default async function CheckNAcceptTOS(server:GameServer):Promise<boolean>{ + try{ + let thisVersion = await getTOSVersion(server.TOSLink); + console.log(server.TOSLink,thisVersion); + LAST_TOS=thisVersion; + return (localStorage.getItem(server.TOSLink) == thisVersion); + + } catch (err) { + console.log("TOS check Error",err); + return true + } + +} + +async function getTOSVersion(address:string):Promise<string>{ + // Returns date or if not found the hash of the whole page + const PageContent = await request(address); + const date = PageContent.match(/Last Update: \d\d\d\d-\d\d-\d\d/g); + let hash:string; + if(!date || date.length > 1){ + hash = HashString(PageContent.replace(/ |\t|\n/g,"").replace(/<.+?>/g, "r")).toString(16); + } else { + hash = date[0].replace(/ /g,""); + } + + return hash; +} + +function request(url:string):Promise<string>{ + return new Promise((res, rej)=>{ + var xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.onload = function() { + if (xhr.status === 200) { + res(xhr.responseText); + } + else { + rej(new Error(`xhr.status: ${xhr.status} != 200`)); + } + }; + xhr.send(); + }); +} + + + +// Hash function from http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ +function HashString (s:string){ + let hash = 0; + if (s.length == 0) return hash; + for (let i = 0; i < s.length; i++) { + let char = s.charCodeAt(i); + hash = ((hash<<5)-hash)+char; + hash = hash & hash; // Convert to 32bit integer + } + return hash; +} + +export function acceptLastTOS(server:GameServer){ + localStorage.setItem(server.TOSLink, LAST_TOS); +} diff --git a/src/renderer/gameserver/data.ts b/src/renderer/gameserver/data.ts index 92cf250..a07c717 100644 --- a/src/renderer/gameserver/data.ts +++ b/src/renderer/gameserver/data.ts @@ -28,7 +28,8 @@ const TMW2 = new GameServer( new socialLink("fab fa-steam","Steam Group","http://steamcommunity.com/groups/TheManaWorld2"), new socialLink("fab fa-twitter","Twitter","https://twitter.com/TheManaWorld2"), new socialLink("fab fa-gitlab","Gitlab","https://gitlab.com/TMW2"), - ] + ], + "https://tmw2.org/legal" ); const Evol = new GameServer( @@ -46,7 +47,8 @@ const Evol = new GameServer( "evol/icon.png", [ new socialLink("fas fa-home","Website","https://evolonline.org/"), - ] + ], + "http://wiki.evolonline.org/rules/gamerules" ); const TMW = new GameServer( @@ -65,7 +67,8 @@ const TMW = new GameServer( [ new socialLink("fas fa-home","Website","https://www.themanaworld.org/"), new socialLink("fas fa-users","Forum","https://forums.themanaworld.org/"), - ] + ], + "https://wiki.themanaworld.org/index.php/The_Mana_World:Terms_and_Conditions" ); export const GameServers = [ diff --git a/src/renderer/gameserver/server.ts b/src/renderer/gameserver/server.ts index 19450b7..91944b1 100644 --- a/src/renderer/gameserver/server.ts +++ b/src/renderer/gameserver/server.ts @@ -14,7 +14,8 @@ export default class GameServer { public newsLatestPage:{url:string,type:NewsType}, public backgrounds:{isVideo:boolean,file:string}[], public icon:string, - public socialLinks:socialLink[] + public socialLinks:socialLink[], + public TOSLink:string ){} getMenuEntry():HTMLElement{ diff --git a/src/renderer/serverView.ts b/src/renderer/serverView.ts index 2250680..225d092 100644 --- a/src/renderer/serverView.ts +++ b/src/renderer/serverView.ts @@ -2,14 +2,38 @@ import { ipcRenderer, shell } from 'electron'; import GameServer from './gameserver/server'; import { switchPage } from './CustomEvents'; +import CheckNAcceptTOS from './gameserver/TOSCheck'; +import { acceptLastTOS } from './gameserver/TOSCheck'; + let GameServerList:GameServer[] = null; let SelectedGameserver:GameServer = null; const playBtn:HTMLButtonElement = document.getElementById('play') as (HTMLButtonElement); -playBtn.addEventListener('click', () => { - SelectedGameserver.play(); -}); +const TOSDialog:HTMLDialogElement = document.getElementById('TOSDialog') as (HTMLDialogElement); +playBtn.addEventListener('click', async () => { + if( await CheckNAcceptTOS(SelectedGameserver)){ + SelectedGameserver.play(); + } else { + //Open Please accept TOS window + TOSDialog.showModal(); + } +}); +const TOSCancel:HTMLButtonElement = document.getElementById('TOSCancel') as (HTMLButtonElement); +TOSCancel.addEventListener('click', function() { + TOSDialog.close(); +}); +const TOSOpen:HTMLButtonElement = document.getElementById('TOSOpen') as (HTMLButtonElement); +TOSOpen.addEventListener('click', function(e) { + e.preventDefault(); + shell.openExternal(SelectedGameserver.TOSLink); +}); +const TOSAccept:HTMLButtonElement = document.getElementById('TOSAccept') as (HTMLButtonElement); +TOSAccept.addEventListener('click', function() { + acceptLastTOS(SelectedGameserver); + SelectedGameserver.play(); + TOSDialog.close(); +}); const sidebarReference = document.getElementById('sidebar'); let clickableMenueEntries:HTMLElement[]=[]; |