aboutsummaryrefslogtreecommitdiff
path: root/views/script/menu_login.js
diff options
context:
space:
mode:
Diffstat (limited to 'views/script/menu_login.js')
-rw-r--r--views/script/menu_login.js114
1 files changed, 83 insertions, 31 deletions
diff --git a/views/script/menu_login.js b/views/script/menu_login.js
index 7f50101..2af88b2 100644
--- a/views/script/menu_login.js
+++ b/views/script/menu_login.js
@@ -54,7 +54,7 @@ function startLogin() {
loggingIn = false;
document.getElementById('loggingIn').style.display = "none";
currentNest.auth = playerData;
- Nest.export(homedir + "/.kartik/current.kfn", currentNest);
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
keysEnabled = false;
require('electron').ipcRenderer.send('prefademusic', "");
$("#box").fadeOut(500);
@@ -109,49 +109,101 @@ window.addEventListener('load', () => {
})
function postOnlineMode() {
- if (currentNest.auth === null || !onlineMode) {
- $(document).keydown(function(e) {
- if (e.keyCode === 76 && !loggingIn && onlineMode) {
- startLogin();
+ try {
+ if (currentNest.auth === null || !onlineMode) {
+ $(document).keydown(function(e) {
+ if (e.keyCode === 76 && !loggingIn && onlineMode) {
+ startLogin();
+ }
+ })
+ } else {
+ authData = currentNest.auth;
+
+ 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;
+ currentNest.auth = authData;
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
}
- })
- } else {
- authData = currentNest.auth;
- document.getElementById('loginIntro').style.display = "none";
- document.getElementById('loginUser').style.display = "grid";
+ ostats = JSON.parse($.ajax({
+ type: "GET",
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token,
+ async: false,
+ error: (e) => { throw e; }
+ }).responseText.trim())
- 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 (ostats === null) {
+ cstats = currentNest.stats;
+ } else {
+ cstats = {};
+
+ for (group in currentNest.stats) {
+ cstats[group] = {};
+
+ for (item in currentNest.stats[group]) {
+ if (ostats[group][item]) {
+ if (ostats[group][item] > currentNest.stats[group][item]) {
+ cstats[group][item] = ostats[group][item];
+ } else {
+ cstats[group][item] = currentNest.stats[group][item];
+ }
+ } else {
+ cstats[group][item] = currentNest.stats[group][item];
+ }
+ }
+ }
+ }
- 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,
+ url: 'https://kartik.hopto.org/online/ingame/api/set.stats.php?kartik_online_token=' + authData.token + "&stats=" + Buffer.from(JSON.stringify(cstats)).toString("base64"),
async: false,
error: (e) => { throw e; }
});
- } else if (authData.level < olevel) {
- authData.level = $.ajax({
+
+ currentNest.stats = JSON.parse($.ajax({
type: "GET",
- url: 'https://kartik.hopto.org/online/ingame/api/profile.level.php?kartik_online_token=' + authData.token,
+ url: 'https://kartik.hopto.org/online/ingame/api/profile.stats.php?kartik_online_token=' + authData.token,
async: false,
error: (e) => { throw e; }
- }).responseText.trim() - 1 + 1;
- currentNest.auth = authData;
- Nest.export(homedir + "/.kartik/current.kfn", currentNest);
- }
+ }).responseText.trim());
+ Nest.export(homedir + "/.kartik/current.kfn", currentNest);require('electron').ipcRenderer.send("reloadNest")
- 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;
+ 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;
+ }
}
+ } catch (e) {
+ require('@electron/remote').getCurrentWindow().webContents.send("notification", {title: lang.polymer.error[0], message: lang.polymer.error[1]});
+ console.error(e);
+ onlineMode = false;
+ document.getElementById("loginIntro").innerText = lang.polymer.error[2];
+ document.getElementById("online").parentElement.parentElement.outerHTML = "";
}
} \ No newline at end of file