diff options
Diffstat (limited to 'views/script')
-rw-r--r-- | views/script/core_compatlayer.js | 4 | ||||
-rw-r--r-- | views/script/global_compatlayer.js | 4 | ||||
-rw-r--r-- | views/script/global_levelsapi.js | 47 | ||||
-rw-r--r-- | views/script/loader_global.js | 7 | ||||
-rw-r--r-- | views/script/menu_global.js | 2 | ||||
-rw-r--r-- | views/script/menu_login.js | 155 |
6 files changed, 213 insertions, 6 deletions
diff --git a/views/script/core_compatlayer.js b/views/script/core_compatlayer.js index 206aa28..c6794f3 100644 --- a/views/script/core_compatlayer.js +++ b/views/script/core_compatlayer.js @@ -76,7 +76,7 @@ window.addEventListener("load", () => { gpuperct = (gpuscore / maxscore) * 100; - if (gpuperct < 50) { + if (gpuperct < 30) { console.warn("Bad GPU support, disabling GPU-accelerated content"); var head = document.getElementsByTagName('HEAD')[0]; var link = document.createElement('link'); @@ -86,4 +86,4 @@ window.addEventListener("load", () => { head.appendChild(link); } } -})
\ No newline at end of file +}) diff --git a/views/script/global_compatlayer.js b/views/script/global_compatlayer.js index 8545a29..7431cea 100644 --- a/views/script/global_compatlayer.js +++ b/views/script/global_compatlayer.js @@ -76,7 +76,7 @@ window.addEventListener("load", () => { gpuperct = (gpuscore / maxscore) * 100; - if (gpuperct < 50) { + if (gpuperct < 30) { console.warn("Bad GPU support, disabling GPU-accelerated content"); var head = document.getElementsByTagName('HEAD')[0]; var link = document.createElement('link'); @@ -86,4 +86,4 @@ window.addEventListener("load", () => { head.appendChild(link); } } -})
\ No newline at end of file +}) diff --git a/views/script/global_levelsapi.js b/views/script/global_levelsapi.js new file mode 100644 index 0000000..ebd969d --- /dev/null +++ b/views/script/global_levelsapi.js @@ -0,0 +1,47 @@ +module.exports = class LevelsAPI { + + associates; + + constructor() { + + let assocs_raw; + let assocs_lines; + let assocs_base; + let assocs; + let score; + let cline; + let line; + let clvl; + + assocs_raw = require('fs').readFileSync("./online/levels.txt"); + assocs_lines = assocs_raw.toString().split("\n"); + assocs_base = {}; + + for (line of assocs_lines) { + cline = line.split(":"); + assocs_base[cline[1].trim()] = cline[0].trim() - 1 + 1; + } + + assocs = {}; + + clvl = 0; + for (let c = 0; c <= 5051; c++) { + if (assocs_base[c.toString()] !== undefined) { + clvl = assocs_base[c.toString()]; + } + assocs[c.toString()] = clvl.toString() + } + + this.associates = assocs; + + } + + correspond(score, god) { + if (score <= 5051) { + return this.associates[score].toString(); + } else { + return god; + } + } + +}
\ No newline at end of file diff --git a/views/script/loader_global.js b/views/script/loader_global.js index 7c89d0f..db70d3b 100644 --- a/views/script/loader_global.js +++ b/views/script/loader_global.js @@ -9,13 +9,13 @@ window.addEventListener('load', () => { window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { data.blob().then((a) => { a.text().then((b) => { - if (require('@electron/remote').getCurrentWindow().update == "git") { + if (require('@electron/remote').getCurrentWindow().update === "git") { document.getElementById('updates').style.backgroundColor = "lightsalmon"; document.getElementById('updates').innerText = lang.updates.git; } else { console.log(b); console.log(require('../package.json').version); - if (b == require('../package.json').version) { + if (b === require('../package.json').version) { document.getElementById('updates').style.backgroundColor = "lightgreen"; document.getElementById('updates').innerText = lang.updates.ok; } else { @@ -42,6 +42,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; @@ -61,6 +62,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; @@ -80,6 +82,7 @@ window.addEventListener('load', () => { console.warn(e); document.getElementById('updates').style.backgroundColor = "lightcoral"; document.getElementById('updates').innerText = lang.updates.error; + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.updateError[0], message: lang.polymer.updateError[1]}); setTimeout(() => { document.getElementById('banner').style.width = "380px"; document.getElementById('banner').style.height = "auto"; diff --git a/views/script/menu_global.js b/views/script/menu_global.js index 3713591..8561fe3 100644 --- a/views/script/menu_global.js +++ b/views/script/menu_global.js @@ -11,6 +11,8 @@ window.addEventListener('load', () => { $("body").focus(); keysEnabled = true; $(document).keydown(function(e) { + if (loggingIn) { return; } + if (keysEnabled) { if (e.keyCode === 13 || e.keyCode === 88 || e.keyCode === 32) { // enter if ($(".services").is(":visible")) { diff --git a/views/script/menu_login.js b/views/script/menu_login.js new file mode 100644 index 0000000..b0a31e9 --- /dev/null +++ b/views/script/menu_login.js @@ -0,0 +1,155 @@ +global.loggingIn = false; +homedir = require('@electron/remote').getCurrentWindow().homedir; + +function startLogin() { + loggingIn = true; + + document.getElementById('loggingIn').style.display = "flex"; + var http = require('http'); + + reqid = 0; + + var server = http.createServer(function (req, res) { + + const queryObject = require('querystring').parse(req.url,true); + token = queryObject[Object.keys(queryObject)[0]]; + res.end(lang.polymer.loginClose); + reqid++; + + if (reqid === 1) { + document.getElementById("loggingIn").innerText = lang.polymer.gatheringLogin + require('@electron/remote').getCurrentWindow().focus(); + server.close(); + + playerData = { + "picture": null, + "name": null, + "level": -1, + "token": token + }; + + playerData.picture = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.picture.php?kartik_online_token=' + token, + async: false, + error: (e) => { throw e; } + }).responseText.trim(); + + playerData.name = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.name.php?kartik_online_token=' + token, + async: false, + error: (e) => { throw e; } + }).responseText.trim(); + + playerData.level = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + + if (playerData.level >= 0 && playerData.name !== null && playerData.picture !== null) { + console.log(playerData); + loggingIn = false; + document.getElementById('loggingIn').style.display = "none"; + require('fs').writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(playerData)); + keysEnabled = false; + require('electron').ipcRenderer.send('prefademusic', ""); + $("#box").fadeOut(500); + setTimeout(() => { + location.href = "menu.html"; + }, 1000) + } else { + throw new Error("Incomplete information received"); + } + } + + }); + + server.listen(14552); + + console.log('Waiting for login requests on port 14552') + require('open')("https://kartik.hopto.org/online/ingame"); +} + +window.addEventListener('load', () => { + onlineMode = false; + + window.fetch("https://kartik.hopto.org/latest.php?v=" + require('@electron/remote').getCurrentWindow().update).then((data) => { + data.blob().then((a) => { + a.text().then((b) => { + onlineMode = true; + postOnlineMode(); + }).catch((e) => { + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); + console.error(e); + onlineMode = false; + postOnlineMode(); + document.getElementById("loginIntro").innerText = lang.polymer.error[2]; + document.getElementById("online").parentElement.parentElement.outerHTML = ""; + }) + }).catch((e) => { + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); + console.error(e); + onlineMode = false; + postOnlineMode(); + document.getElementById("loginIntro").innerText = lang.polymer.error[2]; + document.getElementById("online").parentElement.parentElement.outerHTML = ""; + }) + }).catch((e) => { + require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]}); + console.error(e); + onlineMode = false; + postOnlineMode(); + document.getElementById("loginIntro").innerText = lang.polymer.error[2]; + document.getElementById("online").parentElement.parentElement.outerHTML = ""; + }) +}) + +function postOnlineMode() { + if (!require('fs').existsSync(homedir + "/.kartik/authentication.json") || !onlineMode) { + $(document).keydown(function(e) { + if (e.keyCode === 76 && !loggingIn && onlineMode) { + startLogin(); + } + }) + } else { + authData = JSON.parse(require('fs').readFileSync(homedir + "/.kartik/authentication.json")); + + document.getElementById('loginIntro').style.display = "none"; + document.getElementById('loginUser').style.display = "grid"; + + olevel = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + + if (authData.level > olevel) { + $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/set.level.php?kartik_online_token=' + authData.token + "&level=" + authData.level, + async: false, + error: (e) => { throw e; } + }); + } else if (authData.level < olevel) { + authData.level = $.ajax({ + type: "GET", + url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token, + async: false, + error: (e) => { throw e; } + }).responseText.trim() - 1 + 1; + fs.writeFileSync(homedir + "/.kartik/authentication.json", JSON.stringify(authData)); + } + + document.getElementById('kto-picture').src = authData.picture; + document.getElementById('kto-username').innerText = authData.name; + if (authData.level < 200) { + document.getElementById('kto-level').innerText = authData.level; + } else { + document.getElementById('kto-level').innerText = lang.polymer.ktoMaxLevel; + } + } +}
\ No newline at end of file |