summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
authorLawnCable <lawncable.tmw2@simonlaux.de>2018-06-25 20:53:27 +0200
committerLawnCable <lawncable.tmw2@simonlaux.de>2018-06-25 20:53:27 +0200
commit7be0e01fe22883e32a7e060a38c1a5aa3a2397b6 (patch)
treeb64565ea1314d04b3c453e8d16095e3553b28a69 /src/renderer
parent957f18303641220e106d2f98f91ecc3ecab727fb (diff)
downloadelectron-7be0e01fe22883e32a7e060a38c1a5aa3a2397b6.tar.gz
electron-7be0e01fe22883e32a7e060a38c1a5aa3a2397b6.tar.bz2
electron-7be0e01fe22883e32a7e060a38c1a5aa3a2397b6.tar.xz
electron-7be0e01fe22883e32a7e060a38c1a5aa3a2397b6.zip
improved un/installer for windows
Included TOS Check
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/gameserver/TOSCheck.ts66
-rw-r--r--src/renderer/gameserver/data.ts9
-rw-r--r--src/renderer/gameserver/server.ts3
-rw-r--r--src/renderer/serverView.ts30
4 files changed, 101 insertions, 7 deletions
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[]=[];