From 701e2156e5e872e2f2234cc630b0b821b149ca31 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 17:04:02 +0100 Subject: Commit --- app.js | 868 +++---- online/global.js | 746 +++--- online/server.json | 8 +- views/script/game_music.js | 16 +- views/script/menu_music.js | 10 +- views/splash.svg | 5662 ++++++++++++++++++++++---------------------- 6 files changed, 3655 insertions(+), 3655 deletions(-) diff --git a/app.js b/app.js index dde2133..cba0dcd 100644 --- a/app.js +++ b/app.js @@ -1,434 +1,434 @@ -console.log(" _ __ _ _ _ \n| |/ /__ _ _ __| |_(_) | __\n| ' // _` | '__| __| | |/ /\n| . \\ (_| | | | |_| | < \n|_|\\_\\__,_|_| \\__|_|_|\\_\\\n "); -switch (require('./package.json').channel) { - case "stable": - console.log(" Kartik " + require('./package.json').version + " (Official Release) [stable]\n"); - break; - case "eap": - console.log(" Kartik " + require('./package.json').version + " (Early Access Release) [eap]\n"); - break; - case "nightly": - console.log(" Kartik " + require('./package.json').version + " (Rawhide Release) [nightly]\n"); - break; - case "beta": - console.log(" Kartik " + require('./package.json').version + " (Branched Release) [beta]\n"); - break; - case "git": - console.log(" Kartik " + require('./package.json').version + " (Trunk Build) [git]\n"); - break; -} - -global.start = new Date(); -global.KartikRoot = __dirname; -global.shouldExitIfClosed = false; -const { app, BrowserWindow } = require('electron'); -const fs = require("fs"); - -(async () => { - process.on('uncaughtException', (error) => { - console.log(" * Starting recovery procedure: E_ERROR: " + error.message); - id = new Date().toISOString().replaceAll(":", "-"); - - require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack); - if (require('os').platform() === "win32") { - require('child_process').exec("runtime\\kartik-crash.bat " + id); - } else if (require('os').platform() === "darwin") { - require('child_process').exec("./runtime/kartik-crash-mac.sh " + id); - } else { - require('child_process').exec("./runtime/kartik-crash.sh " + id); - } - process.exit(2); - }) - - process.on('unhandledRejection', (reason) => { - console.log(" * Starting recovery procedure: E_PROMISE: " + reason); - id = new Date().toISOString(); - - require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason); - if (require('os').platform() === "win32") { - require('child_process').exec("runtime\\kartik-crash.bat"); - } else if (require('os').platform() === "darwin") { - require('child_process').exec("./runtime/kartik-crash-mac.sh"); - } else { - require('child_process').exec("./runtime/kartik-crash.sh"); - } - process.exit(2); - }) - - if (process.argv[2] === "m") { - console.log(" * *******************************************"); - console.log(" * * DATA MITIGATION MODE *"); - console.log(" * * *"); - console.log(" * * Unless you ABSOLUTELY need this, please *"); - console.log(" * * consider starting Kartik normally. *"); - console.log(" * *******************************************"); - if (!require('fs').existsSync(__dirname + "/data")) { - require('fs').mkdirSync(__dirname + "/data"); - } - global.homedir = __dirname + "/data"; - } else { - global.homedir = require('os').userInfo().homedir; - } - - /* --------------------- */ - - console.log(" * Preparing application paths"); - app.setAppLogsPath(homedir + "/.kartik/logs"); - app.setPath("crashDumps", homedir + "/.kartik/dumps"); - app.setPath('userData', homedir + "/.kartik/storage"); - app.whenReady().then(async () => { - if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git" && !require('fs').existsSync(homedir + "/.kartik/current.kfn")) { - console.log(" * Opening save data conversion dialog"); - global.converting = true; - btn = require('electron').dialog.showMessageBoxSync( - { - type: "warning", - title: "Migrating save data to Kartik Fox Nest required", - message: "Your save data needs to be converted", - buttons: [ - "Use a new game directory (recommended)", - "Convert existing save data", - "Quit without doing anything" - ], - cancelId: 2, - detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do." - } - ) - - switch (btn) { - case 2: - process.exit(2); - break; - case 1: - break; - case 0: - if (process.argv[2] === "m") { - console.log(" * *******************************************"); - console.log(" * * DATA MITIGATION MODE *"); - console.log(" * * *"); - console.log(" * * Unless you ABSOLUTELY need this, please *"); - console.log(" * * consider starting Kartik normally. *"); - console.log(" * *******************************************"); - if (!require('fs').existsSync(__dirname + "/data")) { - require('fs').mkdirSync(__dirname + "/data"); - } - global.homedir = __dirname + "/data/.KartikStaging$"; - } else { - global.homedir = require('os').userInfo().homedir + "/.KartikStaging$"; - } - app.setAppLogsPath(homedir + "/.kartik/logs"); - app.setPath("crashDumps", homedir + "/.kartik/dumps"); - app.setPath('userData', homedir + "/.kartik/storage"); - if (!require('fs').existsSync(homedir)) { - require('fs').mkdirSync(homedir); - } - break; - } - } - - console.log(" * Gathering language"); - slpm = require('os-locale'); - slpw = await slpm(); - slpo = slpw.substr(0, 2); - slng = require('./lang/languages.json'); - if (Object.keys(slng).includes(slpo)) { - dlp = slpo; - } else { - dlp = "en"; - } - - console.log(" * Saving to " + homedir); - - if (!require('fs').existsSync(homedir + "/.kartik")) { - require('fs').mkdirSync(homedir + "/.kartik") - } - - if (!require('fs').existsSync(homedir + "/.kartik/crashes")) { - require('fs').mkdirSync(homedir + "/.kartik/crashes") - } - - if (!require('fs').existsSync(homedir + "/.kartik/mods")) { - require('fs').mkdirSync(homedir + "/.kartik/mods") - } - - if (require('fs').existsSync(homedir + "/.kartik/build")) { - require('fs').rmSync(homedir + "/.kartik/build", { recursive: true }) - } - require('fs').mkdirSync(homedir + "/.kartik/build") - - console.log(" * Creating configuration"); - - const fs = require('fs'); - const Nest = require('./nest/abi'); - - if (fs.existsSync(homedir + "/.kartik/config") && fs.existsSync(homedir + "/.kartik/config/voice.txt") && fs.existsSync(homedir + "/.kartik/config/online.txt") && fs.existsSync(homedir + "/.kartik/config/music.txt") && fs.existsSync(homedir + "/.kartik/config/lang.txt") && fs.existsSync(homedir + "/.kartik/stats.json")) { - console.log(" * Found complete Config V1, migrating to Kartik Fox Nest..."); - Nest.convert(homedir + "/.kartik/current.kfn", homedir + "/.kartik"); - } else { - if (!fs.existsSync(homedir + "/.kartik/current.kfn")) { - console.log(" * No Kartik Fox Nest found, generating one..."); - Nest.generate(homedir + "/.kartik/current.kfn"); - } else { - fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.kfn"); - } - } - - global.currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - console.log(" * Kartik Fox Nest loaded, " + fs.readFileSync(homedir + "/.kartik/current.kfn").toString().length + " bytes, last loaded in Kartik " + currentNest._version); - - currentNest._version = require('./package.json').version; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - - /* --------------------- */ - - require('@electron/remote/main').initialize(); - - function createWindow () { - console.log(" * Checking configuration"); - - lp = currentNest.config.lang - - time = new Date() - start; - console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); - console.log(" * Why are you EVEN reading this?"); - global.shouldExitIfClosed = true; - - console.log(" * Starting IPC engine"); - win.pwidth = 720; - win.pheight = 540; - win.log = console.log; - - win.debug = process.argv[2] === "d"; - win.channel = channel; - win.cmdlineargs = process.argv; - win.scale = 1.2; - win.update = dimga; - win.gamepads = []; - win.controllerAttached = false; - win.webview = null; - win.dstate = "Kartik"; - win.ddetails = "Kartik"; - win.mods = mods; - - win.invalidfiles = invalidfiles; - win.modsfiles = compiledTypeScriptFiles; - win.homedir = homedir; - - win.lp = lp; - win.music = currentNest.config.music; - win.voice = currentNest.config.voice; - - win.online = currentNest.config.online; - win.nest = currentNest; - - win.resources = resources; - global.currentSongValue = null; - - console.log(" * Starting language preloader"); - require('./lang/preload.js'); - console.log(" * Starting Discord RPC"); - require('./discord/client.js'); - - if (win.debug) { - console.log(" * *******************************************"); - console.log(" * * KARTIK DEBUG MODE *"); - console.log(" * *******************************************"); - win.openDevTools(); - } - - setTimeout(() => { - win.webContents.send('ready', true); - }, 3000) - - win.webContents.on('dom-ready', () => { - musicIpc = require('electron').ipcMain; - musicIpc.on('newmusic', (event, value) => { - if (music) { - win.webContents.send('setmusic', value); - } - }) - - musicIpc.on('reloadNest', (event) => { - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - }) - - const LevelsAPI = require('./views/script/global_levelsapi'); - const lvl = new LevelsAPI(); - - stats = currentNest.stats; - musicIpc.on('addstats', (event, value) => { - currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - - if (value.key === "laps" && currentNest.auth) { - auth = currentNest.auth; - level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; - - if (level !== auth.level) { - currentNest.auth.level = level; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - if (level < 200) { - win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); - } else { - win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); - } - } - } - }) - musicIpc.on('addstatsandclose', (event, value) => { - currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; - Nest.export(homedir + "/.kartik/current.kfn", currentNest); - currentNest = Nest.load(homedir + "/.kartik/current.kfn"); - win.nest = currentNest; - win.destroy(); - }) - }) - } - - console.log(" * Starting splash screen"); - - console.log(" * Checking channel"); - if (require('./package.json').channel === "stable") { - logo = "logo/logo.png"; - channel = " "; - global.dimg = "official"; - global.dimga = "stable"; - global.dchan = "Kartik Stable"; - } else if (require('./package.json').channel === "beta") { - logo = "logo/logo-beta.png"; - channel = " Beta "; - global.dimg = "beta"; - global.dimga = "beta"; - global.dchan = "Kartik Beta"; - } else if (require('./package.json').channel === "nightly") { - logo = "logo/logo-nightly.png"; - channel = " Nightly "; - global.dimg = "nightly"; - global.dimga = "nightly"; - global.dchan = "Kartik Nightly"; - } else if (require('./package.json').channel === "eap") { - logo = "logo/logo-eap.png"; - channel = " EAP "; - global.dimg = "eap"; - global.dimga = "eap"; - global.dchan = "Kartik EAP"; - } else if (require('./package.json').channel === "git") { - logo = "logo/logo-git.png"; - channel = " Trunk "; - global.dimg = "git"; - global.dimga = "git"; - global.dchan = "Kartik Trunk"; - try { - pk = require('./package.json'); - pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); - fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) - } catch (e) {} - } - - global.win = new BrowserWindow({ - width: 1220, - height: 720, - minWidth: 720, - minHeight: 540, - resizeable: true, - resizable: true, - maximizable: true, - show: false, - enableLargerThanScreen: true, - icon: logo, - backgroundColor: "#000000", - title: "Kartik", - webPreferences: { - nodeIntegration: true, - contextIsolation: false, - enableRemoteModule: true, - webviewTag: true, - disableBlinkFeatures: "MediaSessionService", - } - }) - console.log(" * Loading view"); - win.loadFile('./index.html') - win.setMenu(null); - win.webContents.once('dom-ready', () => { - console.log(" * Showing splash screen"); - win.show(); - setTimeout(() => { - console.log(" * Checking signatures"); - - invalidfiles = []; - - sigdb = require("./bin/signatures.json"); - total = Object.keys(sigdb["v1"]).length * 3; - processed = 0; - for (file in sigdb["v1"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v1"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V1 hash for " + file); - } - } - - processed++; - win.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v2"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v2"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V2 hash for " + file); - } - } - - processed++; - win.webContents.send('progress', (processed/total)*100); - } - for (file in sigdb["v3"]) { - if (fs.existsSync(file) && !invalidfiles.includes(file)) { - try { - hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); - if (hash !== sigdb["v3"][file]) { - invalidfiles.push(file); - } - } catch (e) { - console.warn(" ! Could not compute V3 hash for " + file); - } - } - - processed++; - win.webContents.send('progress', (processed/total)*100); - } - - global.importedTypeScriptFiles = []; - global.compiledTypeScriptFiles = []; - console.log(" * Generating resources pack"); - require('./modding/resources'); - console.log(" * Starting Kartik Modding Platform"); - require('./modding/parser'); - console.log(" * Compiling KMP API TypeScript files"); - require('./modding/compiler'); - console.log(" * Loading KMP TypeScript mods"); - require('./typescript/preloader'); - createWindow(); - }, 5000) - }) - }) - - app.on('window-all-closed', () => { - if (shouldExitIfClosed) { - console.log(" * Bye!"); - app.quit() - } - }) -})(); +console.log(" _ __ _ _ _ \n| |/ /__ _ _ __| |_(_) | __\n| ' // _` | '__| __| | |/ /\n| . \\ (_| | | | |_| | < \n|_|\\_\\__,_|_| \\__|_|_|\\_\\\n "); +switch (require('./package.json').channel) { + case "stable": + console.log(" Kartik " + require('./package.json').version + " (Official Release) [stable]\n"); + break; + case "eap": + console.log(" Kartik " + require('./package.json').version + " (Early Access Release) [eap]\n"); + break; + case "nightly": + console.log(" Kartik " + require('./package.json').version + " (Rawhide Release) [nightly]\n"); + break; + case "beta": + console.log(" Kartik " + require('./package.json').version + " (Branched Release) [beta]\n"); + break; + case "git": + console.log(" Kartik " + require('./package.json').version + " (Trunk Build) [git]\n"); + break; +} + +global.start = new Date(); +global.KartikRoot = __dirname; +global.shouldExitIfClosed = false; +const { app, BrowserWindow } = require('electron'); +const fs = require("fs"); + +(async () => { + process.on('uncaughtException', (error) => { + console.log(" * Starting recovery procedure: E_ERROR: " + error.message); + id = new Date().toISOString().replaceAll(":", "-"); + + require('fs').writeFileSync(require('os').userInfo().homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash\n\n" + error.stack); + if (require('os').platform() === "win32") { + require('child_process').exec("runtime\\kartik-crash.bat " + id); + } else if (require('os').platform() === "darwin") { + require('child_process').exec("./runtime/kartik-crash-mac.sh " + id); + } else { + require('child_process').exec("./runtime/kartik-crash.sh " + id); + } + process.exit(2); + }) + + process.on('unhandledRejection', (reason) => { + console.log(" * Starting recovery procedure: E_PROMISE: " + reason); + id = new Date().toISOString(); + + require('fs').writeFileSync(homedir + "/.kartik/crashes/" + id + ".txt", "Kartik Bootstraper Crash (in promise)\n\n" + reason); + if (require('os').platform() === "win32") { + require('child_process').exec("runtime\\kartik-crash.bat"); + } else if (require('os').platform() === "darwin") { + require('child_process').exec("./runtime/kartik-crash-mac.sh"); + } else { + require('child_process').exec("./runtime/kartik-crash.sh"); + } + process.exit(2); + }) + + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data"; + } else { + global.homedir = require('os').userInfo().homedir; + } + + /* --------------------- */ + + console.log(" * Preparing application paths"); + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + app.whenReady().then(async () => { + if (require('./package.json').channel !== "stable" && require('./package.json').channel !== "git" && !require('fs').existsSync(homedir + "/.kartik/current.kfn")) { + console.log(" * Opening save data conversion dialog"); + global.converting = true; + btn = require('electron').dialog.showMessageBoxSync( + { + type: "warning", + title: "Migrating save data to Kartik Fox Nest required", + message: "Your save data needs to be converted", + buttons: [ + "Use a new game directory (recommended)", + "Convert existing save data", + "Quit without doing anything" + ], + cancelId: 2, + detail: "Kartik Fox Nest (the new save data format) has been introduced in this version, and it requires converting from the old save data format. Because it is not possible to downgrade from Kartik Fox Nest to the old save data format, you have to choose what to do." + } + ) + + switch (btn) { + case 2: + process.exit(2); + break; + case 1: + break; + case 0: + if (process.argv[2] === "m") { + console.log(" * *******************************************"); + console.log(" * * DATA MITIGATION MODE *"); + console.log(" * * *"); + console.log(" * * Unless you ABSOLUTELY need this, please *"); + console.log(" * * consider starting Kartik normally. *"); + console.log(" * *******************************************"); + if (!require('fs').existsSync(__dirname + "/data")) { + require('fs').mkdirSync(__dirname + "/data"); + } + global.homedir = __dirname + "/data/.KartikStaging$"; + } else { + global.homedir = require('os').userInfo().homedir + "/.KartikStaging$"; + } + app.setAppLogsPath(homedir + "/.kartik/logs"); + app.setPath("crashDumps", homedir + "/.kartik/dumps"); + app.setPath('userData', homedir + "/.kartik/storage"); + if (!require('fs').existsSync(homedir)) { + require('fs').mkdirSync(homedir); + } + break; + } + } + + console.log(" * Gathering language"); + slpm = require('os-locale'); + slpw = await slpm(); + slpo = slpw.substr(0, 2); + slng = require('./lang/languages.json'); + if (Object.keys(slng).includes(slpo)) { + dlp = slpo; + } else { + dlp = "en"; + } + + console.log(" * Saving to " + homedir); + + if (!require('fs').existsSync(homedir + "/.kartik")) { + require('fs').mkdirSync(homedir + "/.kartik") + } + + if (!require('fs').existsSync(homedir + "/.kartik/crashes")) { + require('fs').mkdirSync(homedir + "/.kartik/crashes") + } + + if (!require('fs').existsSync(homedir + "/.kartik/mods")) { + require('fs').mkdirSync(homedir + "/.kartik/mods") + } + + if (require('fs').existsSync(homedir + "/.kartik/build")) { + require('fs').rmSync(homedir + "/.kartik/build", { recursive: true }) + } + require('fs').mkdirSync(homedir + "/.kartik/build") + + console.log(" * Creating configuration"); + + const fs = require('fs'); + const Nest = require('./nest/abi'); + + if (fs.existsSync(homedir + "/.kartik/config") && fs.existsSync(homedir + "/.kartik/config/voice.txt") && fs.existsSync(homedir + "/.kartik/config/online.txt") && fs.existsSync(homedir + "/.kartik/config/music.txt") && fs.existsSync(homedir + "/.kartik/config/lang.txt") && fs.existsSync(homedir + "/.kartik/stats.json")) { + console.log(" * Found complete Config V1, migrating to Kartik Fox Nest..."); + Nest.convert(homedir + "/.kartik/current.kfn", homedir + "/.kartik"); + } else { + if (!fs.existsSync(homedir + "/.kartik/current.kfn")) { + console.log(" * No Kartik Fox Nest found, generating one..."); + Nest.generate(homedir + "/.kartik/current.kfn"); + } else { + fs.copyFileSync(homedir + "/.kartik/current.kfn", homedir + "/.kartik/latest.kfn"); + } + } + + global.currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + console.log(" * Kartik Fox Nest loaded, " + fs.readFileSync(homedir + "/.kartik/current.kfn").toString().length + " bytes, last loaded in Kartik " + currentNest._version); + + currentNest._version = require('./package.json').version; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + + /* --------------------- */ + + require('@electron/remote/main').initialize(); + + function createWindow () { + console.log(" * Checking configuration"); + + lp = currentNest.config.lang + + time = new Date() - start; + console.log(" * Started successfully in " + Math.round(time/1000) + " seconds"); + console.log(" * Why are you EVEN reading this?"); + global.shouldExitIfClosed = true; + + console.log(" * Starting IPC engine"); + win.pwidth = 720; + win.pheight = 540; + win.log = console.log; + + win.debug = process.argv[2] === "d"; + win.channel = channel; + win.cmdlineargs = process.argv; + win.scale = 1.2; + win.update = dimga; + win.gamepads = []; + win.controllerAttached = false; + win.webview = null; + win.dstate = "Kartik"; + win.ddetails = "Kartik"; + win.mods = mods; + + win.invalidfiles = invalidfiles; + win.modsfiles = compiledTypeScriptFiles; + win.homedir = homedir; + + win.lp = lp; + win.music = currentNest.config.music; + win.voice = currentNest.config.voice; + + win.online = currentNest.config.online; + win.nest = currentNest; + + win.resources = resources; + global.currentSongValue = null; + + console.log(" * Starting language preloader"); + require('./lang/preload.js'); + console.log(" * Starting Discord RPC"); + require('./discord/client.js'); + + if (win.debug) { + console.log(" * *******************************************"); + console.log(" * * KARTIK DEBUG MODE *"); + console.log(" * *******************************************"); + win.openDevTools(); + } + + setTimeout(() => { + win.webContents.send('ready', true); + }, 3000) + + win.webContents.on('dom-ready', () => { + musicIpc = require('electron').ipcMain; + musicIpc.on('newmusic', (event, value) => { + if (music) { + win.webContents.send('setmusic', value); + } + }) + + musicIpc.on('reloadNest', (event) => { + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + }) + + const LevelsAPI = require('./views/script/global_levelsapi'); + const lvl = new LevelsAPI(); + + stats = currentNest.stats; + musicIpc.on('addstats', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + + if (value.key === "laps" && currentNest.auth) { + auth = currentNest.auth; + level = lvl.correspond(currentNest.stats["ingame"]["laps"], "256") - 1 + 1; + + if (level !== auth.level) { + currentNest.auth.level = level; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + if (level < 200) { + win.webContents.send("notification", {title: lang.polymer.levelup[0], message: lang.polymer.levelup[1] + " " + level + " " + lang.polymer.levelup[2]}); + } else { + win.webContents.send("notification", {title: lang.polymer.finished[0], message: lang.polymer.finished[1]}); + } + } + } + }) + musicIpc.on('addstatsandclose', (event, value) => { + currentNest.stats[value.catalog][value.key] = currentNest.stats[value.catalog][value.key] + value.add; + Nest.export(homedir + "/.kartik/current.kfn", currentNest); + currentNest = Nest.load(homedir + "/.kartik/current.kfn"); + win.nest = currentNest; + win.destroy(); + }) + }) + } + + console.log(" * Starting splash screen"); + + console.log(" * Checking channel"); + if (require('./package.json').channel === "stable") { + logo = "logo/logo.png"; + channel = " "; + global.dimg = "official"; + global.dimga = "stable"; + global.dchan = "Kartik Stable"; + } else if (require('./package.json').channel === "beta") { + logo = "logo/logo-beta.png"; + channel = " Beta "; + global.dimg = "beta"; + global.dimga = "beta"; + global.dchan = "Kartik Beta"; + } else if (require('./package.json').channel === "nightly") { + logo = "logo/logo-nightly.png"; + channel = " Nightly "; + global.dimg = "nightly"; + global.dimga = "nightly"; + global.dchan = "Kartik Nightly"; + } else if (require('./package.json').channel === "eap") { + logo = "logo/logo-eap.png"; + channel = " EAP "; + global.dimg = "eap"; + global.dimga = "eap"; + global.dchan = "Kartik EAP"; + } else if (require('./package.json').channel === "git") { + logo = "logo/logo-git.png"; + channel = " Trunk "; + global.dimg = "git"; + global.dimga = "git"; + global.dchan = "Kartik Trunk"; + try { + pk = require('./package.json'); + pk.version = require('fs').readFileSync("./.git/refs/heads/trunk").toString().substr(0, 7); + fs.writeFileSync("./package.json", JSON.stringify(pk, 2)) + } catch (e) {} + } + + global.win = new BrowserWindow({ + width: 1220, + height: 720, + minWidth: 720, + minHeight: 540, + resizeable: true, + resizable: true, + maximizable: true, + show: false, + enableLargerThanScreen: true, + icon: logo, + backgroundColor: "#000000", + title: "Kartik", + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + enableRemoteModule: true, + webviewTag: true, + disableBlinkFeatures: "MediaSessionService", + } + }) + console.log(" * Loading view"); + win.loadFile('./index.html') + win.setMenu(null); + win.webContents.once('dom-ready', () => { + console.log(" * Showing splash screen"); + win.show(); + setTimeout(() => { + console.log(" * Checking signatures"); + + invalidfiles = []; + + sigdb = require("./bin/signatures.json"); + total = Object.keys(sigdb["v1"]).length * 3; + processed = 0; + for (file in sigdb["v1"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('sha512').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v1"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V1 hash for " + file); + } + } + + processed++; + win.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v2"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('sha1').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v2"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V2 hash for " + file); + } + } + + processed++; + win.webContents.send('progress', (processed/total)*100); + } + for (file in sigdb["v3"]) { + if (fs.existsSync(file) && !invalidfiles.includes(file)) { + try { + hash = require('crypto').createHash('md5').update(fs.readFileSync(file)).digest('base64'); + if (hash !== sigdb["v3"][file]) { + invalidfiles.push(file); + } + } catch (e) { + console.warn(" ! Could not compute V3 hash for " + file); + } + } + + processed++; + win.webContents.send('progress', (processed/total)*100); + } + + global.importedTypeScriptFiles = []; + global.compiledTypeScriptFiles = []; + console.log(" * Generating resources pack"); + require('./modding/resources'); + console.log(" * Starting Kartik Modding Platform"); + require('./modding/parser'); + console.log(" * Compiling KMP API TypeScript files"); + require('./modding/compiler'); + console.log(" * Loading KMP TypeScript mods"); + require('./typescript/preloader'); + createWindow(); + }, 5000) + }) + }) + + app.on('window-all-closed', () => { + if (shouldExitIfClosed) { + console.log(" * Bye!"); + app.quit() + } + }) +})(); diff --git a/online/global.js b/online/global.js index 0cdb6f4..afe4562 100644 --- a/online/global.js +++ b/online/global.js @@ -1,374 +1,374 @@ -global.pingStart = null; -global.connecting = false; -global.role = null; -global.online = true; -global.guestInfo = { - hostCar: null, - guestCar: null, - circuit: null, - music: null -}; -global.onlineInitDone = false; - -function max(input) { - if (toString.call(input) !== "[object Array]") - return false; - return Math.max.apply(null, input); -} - -pingHistory = []; -function updatePing(ping) { - if (ping < 100000) { - document.getElementById('ping').innerText = ping + " ms"; - - pingHistory.push(ping); - while (pingHistory.length > 70) { - pingHistory.shift(); - } - - dom = ""; - highest = max(pingHistory); - pingHistory.forEach((p) => { - high = 1 - perc = (p/highest)*100 - if (ping > 70 && ping < 150) { - dom = dom + ``; - } else if (ping > 150) { - dom = dom + ``; - } else { - dom = dom + ``; - } - }) - - document.getElementById('ping-chart').innerHTML = dom; - } -} - -window.addEventListener('load', () => { - document.getElementById('credits').style.backgroundColor = "#000000"; - document.getElementById('cars-n1').innerText = lang.online.car0; - document.getElementById('cars-n2').innerText = lang.online.car1; - - class MessageBuffer { - constructor(delimiter) { - this.delimiter = delimiter - this.buffer = "" - } - - isFinished() { - if ( - this.buffer.length === 0 || - this.buffer.indexOf(this.delimiter) === -1 - ) { - return true - } - return false - } - - push(data) { - this.buffer += data - } - - getMessage() { - const delimiterIndex = this.buffer.indexOf(this.delimiter) - if (delimiterIndex !== -1) { - const message = this.buffer.slice(0, delimiterIndex) - this.buffer = this.buffer.replace(message + this.delimiter, "") - return message - } - return null - } - - handleData() { - /** - * Try to accumulate the buffer with messages - * - * If the server isnt sending delimiters for some reason - * then nothing will ever come back for these requests - */ - const message = this.getMessage() - return message - } - } - - const sampleData = { - _type: "init", - name: "Kartik Core", - version: require('../package.json').version, - id: null, - modded: false - } - - global.clientWriter = (data) => { - client.write(data + "\n"); - } - - function crash(e) { - console.error(e); - if (!quitting) { - location.href = "online.html#" + btoa(lang.online.error.connection); - } - } - - var net = require('net'); - - var host = require('../online/server.json').hostname; - var port = require('../online/server.json').port; - - global.client = new net.Socket(); - client.initialized = false; - - client.connect(port, host, () => { - console.log("Connected to " + host + ":" + port); - clientWriter(JSON.stringify(sampleData) + "|"); - setInterval(() => { - if (role === null) { - clientWriter(JSON.stringify({ - _type: "ping" - }) + "|") - } else { - clientWriter(JSON.stringify({ - _type: "ipc", - action: "Ping", - message: null - }) + "|") - } - global.pingCrash = setTimeout(() => { - location.href = "online.html#" + btoa(lang.online.timeout); - }, 10000); - global.pingStart = new Date(); - }, 1000) - }) - - let received = new MessageBuffer("\n") - client.on("data", chunk => { - received.push(chunk) - while (!received.isFinished()) { - const data = received.handleData() - - raw = data.toString().replaceAll("}{", "}|{"); - datas = raw.split("|").filter(i => i.trim() !== ""); - datas.forEach((data) => { - try { - inf = JSON.parse(data); - } catch (e) { - console.dir(data); - throw e; - } - - if (typeof inf['_type'] != "string") { - crash(new Error("Invalid JSON data")); - } - if (!client.initialized) { - switch (inf['_type']) { - case "init": - if (inf['name'] !== "Kartik Server") { - crash(new Error("Invalid server")); - } - console.log("Connection initialized. Server running " + inf.name + " version " + inf.version + ", client ID " + inf.id); - document.getElementById("serveraddr").innerText = host + ":" + port; - if (inf.version.endsWith("-iridium")) { - document.getElementById("servername").innerText = "Iridium " + inf.version.substr(0, inf.version.length - "-iridium".length); - document.getElementById("servericon").src = "../logo/iridium.png"; - } else { - document.getElementById("servername").innerText = "Kartik Legacy Server " + inf.version; - document.getElementById("servericon").src = "../logo/server.png"; - } - document.getElementById('yourid').innerText = inf.id.toUpperCase(); - document.getElementById('intro').style.display = ""; - document.getElementById('connecting').style.display = "none"; - document.getElementById('loading').style.display = "none"; - client.initialized = true; - break; - case "error": - console.log(inf['type'] + ": " + inf['message']); - break; - default: - crash(new Error("Trying to receive data but client not initialized")); - break; - } - } else { - switch (inf['_type']) { - case "init": - crash(new Error("Trying to initialize client but client is already initialized")); - break; - case "error": - console.log(inf['type'] + ": " + inf['message']); - location.href = "online.html#" + btoa(inf['type'] + ": " + inf['message']); - break; - case "linked": - console.log("Now hooked into link: (H) " + inf['ids']['host'] + " <-> " + inf['ids']['guest'] + " (G)"); - document.getElementById('intro').style.display = "none"; - document.getElementById('connecting').style.display = "none"; - document.getElementById('loading').style.display = ""; - document.getElementById('loading').innerText = lang.online.generate; - global.role = inf['role']; - if (role === "host") { - startHooks.forEach((hook) => { - hook(this); - }) - $("#online-login").fadeOut(200); - } - break; - default: - if (inf['_type'] === "ipc" && inf['action'] === "Ping") { - clientWriter(JSON.stringify({ - _type: "ipc", - action: "Pong", - message: null - }) + "|") - return; - } - if ((inf['_type'] === "ipc" && inf['action'] === "Pong") || inf['_type'] === "pong") { - pingEnd = new Date(); - ping = Math.round(pingEnd - pingStart); - global.pingStart = null; - clearTimeout(global.pingCrash); - updatePing(ping); - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "posTop") { - try { - document.getElementById('car1').style.top = inf['message']; - } catch (e) {} - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "progressLaps") { - try { - document.getElementById("laps-car1").innerText = inf['message']; - } catch (e) {} - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "progressLose") { - global.quitting = true; - location.href = "win.html?sp#car1"; - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "posLeft") { - try { - document.getElementById('car1').style.left = inf['message']; - } catch (e) {} - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "gameIsReady") { - startgame(); - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "abort") { - location.href = "online.html#" + btoa(lang.online.aborted); - return; - } - if (inf['_type'] === "ipc" && inf['action'] === "posRot") { - try { - document.getElementById('car1').style.transform = inf['message']; - } catch (e) {} - return; - } - if (inf['_type'] === "ipc" && inf['action'].startsWith("RaceData:")) { - rd = inf['action'].substr(9); - switch (rd) { - case "hostCar": - guestInfo.hostCar = inf['message']; - if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { - onlineInitDone = true; - startHooks.forEach((hook) => { - hook(this); - }) - $("#online-login").fadeOut(200); - } - break; - case "guestCar": - guestInfo.guestCar = inf['message']; - if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { - onlineInitDone = true; - startHooks.forEach((hook) => { - hook(this); - }) - $("#online-login").fadeOut(200); - } - break; - case "circuit": - guestInfo.circuit = inf['message']; - if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { - onlineInitDone = true; - startHooks.forEach((hook) => { - hook(this); - }) - $("#online-login").fadeOut(200); - } - break; - case "music": - guestInfo.music = inf['message']; - if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { - onlineInitDone = true; - startHooks.forEach((hook) => { - hook(this); - }) - $("#online-login").fadeOut(200); - } - break; - } - return; - } - break; - } - } - }) - } - }) - - client.on('close', () => { - console.log("Kicked from server"); - }) - - client.on('error', (e) => { - switch (e.code) { - case "ECONNREFUSED": - location.href = "online.html#" + btoa(lang.online.unable); - break; - default: - location.href = "online.html#" + btoa(lang.online.internal); - break; - } - crash(e); - }) - - setInterval(() => { - if (pingStart !== null && new Date() - pingStart >= 10000) { - location.href = "online.html#" + btoa(lang.online.timeout); - } - }, 50) -}) - -function checkOnlineLogin() { - document.getElementById('theirid').value = document.getElementById('theirid').value.toUpperCase(); - if (/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890]/gm.test(document.getElementById('theirid').value)) { - document.getElementById('theirid').value = ""; - } - if (document.getElementById('theirid').value.length === 8) { - if (document.getElementById('theirid').value === document.getElementById('yourid').innerText) { - document.getElementById('theirid').value = ""; - } else { - if (!connecting) { - connecting = true; - document.getElementById('intro').style.display = "none"; - document.getElementById('connecting').style.display = "none"; - document.getElementById('loading').style.display = ""; - console.log("Linking to client " + document.getElementById('theirid').value + "...") - clientWriter(JSON.stringify({ - _type: "link", - client: document.getElementById('theirid').value.toLowerCase() - })); - } - } - } -} - -$("#theirid").keydown(function(e) { - if (e.keyCode === 27) { // esc - $("body").fadeOut(200); - setTimeout(() => { - location.href = "menu.html?back"; - }, 250) - } +global.pingStart = null; +global.connecting = false; +global.role = null; +global.online = true; +global.guestInfo = { + hostCar: null, + guestCar: null, + circuit: null, + music: null +}; +global.onlineInitDone = false; + +function max(input) { + if (toString.call(input) !== "[object Array]") + return false; + return Math.max.apply(null, input); +} + +pingHistory = []; +function updatePing(ping) { + if (ping < 100000) { + document.getElementById('ping').innerText = ping + " ms"; + + pingHistory.push(ping); + while (pingHistory.length > 70) { + pingHistory.shift(); + } + + dom = ""; + highest = max(pingHistory); + pingHistory.forEach((p) => { + high = 1 + perc = (p/highest)*100 + if (ping > 70 && ping < 150) { + dom = dom + ``; + } else if (ping > 150) { + dom = dom + ``; + } else { + dom = dom + ``; + } + }) + + document.getElementById('ping-chart').innerHTML = dom; + } +} + +window.addEventListener('load', () => { + document.getElementById('credits').style.backgroundColor = "#000000"; + document.getElementById('cars-n1').innerText = lang.online.car0; + document.getElementById('cars-n2').innerText = lang.online.car1; + + class MessageBuffer { + constructor(delimiter) { + this.delimiter = delimiter + this.buffer = "" + } + + isFinished() { + if ( + this.buffer.length === 0 || + this.buffer.indexOf(this.delimiter) === -1 + ) { + return true + } + return false + } + + push(data) { + this.buffer += data + } + + getMessage() { + const delimiterIndex = this.buffer.indexOf(this.delimiter) + if (delimiterIndex !== -1) { + const message = this.buffer.slice(0, delimiterIndex) + this.buffer = this.buffer.replace(message + this.delimiter, "") + return message + } + return null + } + + handleData() { + /** + * Try to accumulate the buffer with messages + * + * If the server isnt sending delimiters for some reason + * then nothing will ever come back for these requests + */ + const message = this.getMessage() + return message + } + } + + const sampleData = { + _type: "init", + name: "Kartik Core", + version: require('../package.json').version, + id: null, + modded: false + } + + global.clientWriter = (data) => { + client.write(data + "\n"); + } + + function crash(e) { + console.error(e); + if (!quitting) { + location.href = "online.html#" + btoa(lang.online.error.connection); + } + } + + var net = require('net'); + + var host = require('../online/server.json').hostname; + var port = require('../online/server.json').port; + + global.client = new net.Socket(); + client.initialized = false; + + client.connect(port, host, () => { + console.log("Connected to " + host + ":" + port); + clientWriter(JSON.stringify(sampleData) + "|"); + setInterval(() => { + if (role === null) { + clientWriter(JSON.stringify({ + _type: "ping" + }) + "|") + } else { + clientWriter(JSON.stringify({ + _type: "ipc", + action: "Ping", + message: null + }) + "|") + } + global.pingCrash = setTimeout(() => { + location.href = "online.html#" + btoa(lang.online.timeout); + }, 10000); + global.pingStart = new Date(); + }, 1000) + }) + + let received = new MessageBuffer("\n") + client.on("data", chunk => { + received.push(chunk) + while (!received.isFinished()) { + const data = received.handleData() + + raw = data.toString().replaceAll("}{", "}|{"); + datas = raw.split("|").filter(i => i.trim() !== ""); + datas.forEach((data) => { + try { + inf = JSON.parse(data); + } catch (e) { + console.dir(data); + throw e; + } + + if (typeof inf['_type'] != "string") { + crash(new Error("Invalid JSON data")); + } + if (!client.initialized) { + switch (inf['_type']) { + case "init": + if (inf['name'] !== "Kartik Server") { + crash(new Error("Invalid server")); + } + console.log("Connection initialized. Server running " + inf.name + " version " + inf.version + ", client ID " + inf.id); + document.getElementById("serveraddr").innerText = host + ":" + port; + if (inf.version.endsWith("-iridium")) { + document.getElementById("servername").innerText = "Iridium " + inf.version.substr(0, inf.version.length - "-iridium".length); + document.getElementById("servericon").src = "../logo/iridium.png"; + } else { + document.getElementById("servername").innerText = "Kartik Legacy Server " + inf.version; + document.getElementById("servericon").src = "../logo/server.png"; + } + document.getElementById('yourid').innerText = inf.id.toUpperCase(); + document.getElementById('intro').style.display = ""; + document.getElementById('connecting').style.display = "none"; + document.getElementById('loading').style.display = "none"; + client.initialized = true; + break; + case "error": + console.log(inf['type'] + ": " + inf['message']); + break; + default: + crash(new Error("Trying to receive data but client not initialized")); + break; + } + } else { + switch (inf['_type']) { + case "init": + crash(new Error("Trying to initialize client but client is already initialized")); + break; + case "error": + console.log(inf['type'] + ": " + inf['message']); + location.href = "online.html#" + btoa(inf['type'] + ": " + inf['message']); + break; + case "linked": + console.log("Now hooked into link: (H) " + inf['ids']['host'] + " <-> " + inf['ids']['guest'] + " (G)"); + document.getElementById('intro').style.display = "none"; + document.getElementById('connecting').style.display = "none"; + document.getElementById('loading').style.display = ""; + document.getElementById('loading').innerText = lang.online.generate; + global.role = inf['role']; + if (role === "host") { + startHooks.forEach((hook) => { + hook(this); + }) + $("#online-login").fadeOut(200); + } + break; + default: + if (inf['_type'] === "ipc" && inf['action'] === "Ping") { + clientWriter(JSON.stringify({ + _type: "ipc", + action: "Pong", + message: null + }) + "|") + return; + } + if ((inf['_type'] === "ipc" && inf['action'] === "Pong") || inf['_type'] === "pong") { + pingEnd = new Date(); + ping = Math.round(pingEnd - pingStart); + global.pingStart = null; + clearTimeout(global.pingCrash); + updatePing(ping); + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "posTop") { + try { + document.getElementById('car1').style.top = inf['message']; + } catch (e) {} + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "progressLaps") { + try { + document.getElementById("laps-car1").innerText = inf['message']; + } catch (e) {} + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "progressLose") { + global.quitting = true; + location.href = "win.html?sp#car1"; + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "posLeft") { + try { + document.getElementById('car1').style.left = inf['message']; + } catch (e) {} + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "gameIsReady") { + startgame(); + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "abort") { + location.href = "online.html#" + btoa(lang.online.aborted); + return; + } + if (inf['_type'] === "ipc" && inf['action'] === "posRot") { + try { + document.getElementById('car1').style.transform = inf['message']; + } catch (e) {} + return; + } + if (inf['_type'] === "ipc" && inf['action'].startsWith("RaceData:")) { + rd = inf['action'].substr(9); + switch (rd) { + case "hostCar": + guestInfo.hostCar = inf['message']; + if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { + onlineInitDone = true; + startHooks.forEach((hook) => { + hook(this); + }) + $("#online-login").fadeOut(200); + } + break; + case "guestCar": + guestInfo.guestCar = inf['message']; + if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { + onlineInitDone = true; + startHooks.forEach((hook) => { + hook(this); + }) + $("#online-login").fadeOut(200); + } + break; + case "circuit": + guestInfo.circuit = inf['message']; + if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { + onlineInitDone = true; + startHooks.forEach((hook) => { + hook(this); + }) + $("#online-login").fadeOut(200); + } + break; + case "music": + guestInfo.music = inf['message']; + if (guestInfo.music !== null && guestInfo.circuit !== null && guestInfo.guestCar !== null && guestInfo.hostCar !== null && !onlineInitDone) { + onlineInitDone = true; + startHooks.forEach((hook) => { + hook(this); + }) + $("#online-login").fadeOut(200); + } + break; + } + return; + } + break; + } + } + }) + } + }) + + client.on('close', () => { + console.log("Kicked from server"); + }) + + client.on('error', (e) => { + switch (e.code) { + case "ECONNREFUSED": + location.href = "online.html#" + btoa(lang.online.unable); + break; + default: + location.href = "online.html#" + btoa(lang.online.internal); + break; + } + crash(e); + }) + + setInterval(() => { + if (pingStart !== null && new Date() - pingStart >= 10000) { + location.href = "online.html#" + btoa(lang.online.timeout); + } + }, 50) +}) + +function checkOnlineLogin() { + document.getElementById('theirid').value = document.getElementById('theirid').value.toUpperCase(); + if (/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890]/gm.test(document.getElementById('theirid').value)) { + document.getElementById('theirid').value = ""; + } + if (document.getElementById('theirid').value.length === 8) { + if (document.getElementById('theirid').value === document.getElementById('yourid').innerText) { + document.getElementById('theirid').value = ""; + } else { + if (!connecting) { + connecting = true; + document.getElementById('intro').style.display = "none"; + document.getElementById('connecting').style.display = "none"; + document.getElementById('loading').style.display = ""; + console.log("Linking to client " + document.getElementById('theirid').value + "...") + clientWriter(JSON.stringify({ + _type: "link", + client: document.getElementById('theirid').value.toLowerCase() + })); + } + } + } +} + +$("#theirid").keydown(function(e) { + if (e.keyCode === 27) { // esc + $("body").fadeOut(200); + setTimeout(() => { + location.href = "menu.html?back"; + }, 250) + } }) \ No newline at end of file diff --git a/online/server.json b/online/server.json index 4ba17eb..cd9b0df 100644 --- a/online/server.json +++ b/online/server.json @@ -1,4 +1,4 @@ -{ - "hostname": "kartik.hopto.org", - "port": 8408 -} +{ + "hostname": "kartik.minteck.org", + "port": 8408 +} diff --git a/views/script/game_music.js b/views/script/game_music.js index 7d43a25..beed4a0 100644 --- a/views/script/game_music.js +++ b/views/script/game_music.js @@ -1,8 +1,8 @@ -startHooks.push(() => { - info("MusicMgr", "Playing game" + i + ".mp3"); - if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['game' + i].file); -}) - -if (location.search === "?online") { - if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['prepare'].file); -} +startHooks.push(() => { + info("MusicMgr", "Playing game" + i + ".mp3"); + if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['game' + i].file); +}) + +if (location.search === "?online") { + if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['prepare'].file); +} diff --git a/views/script/menu_music.js b/views/script/menu_music.js index d650478..e6ef323 100644 --- a/views/script/menu_music.js +++ b/views/script/menu_music.js @@ -1,5 +1,5 @@ -if (location.search !== "?noreset") { - console.log("back"); - if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['title'].file); -} -info("MenuWindow", "Menu opened"); +if (location.search !== "?noreset") { + console.log("back"); + if (require('@electron/remote').getCurrentWindow().music) require('electron').ipcRenderer.send('newmusic', kresources.music['title'].file); +} +info("MenuWindow", "Menu opened"); diff --git a/views/splash.svg b/views/splash.svg index e9bfac3..3fc0572 100644 --- a/views/splash.svg +++ b/views/splash.svg @@ -1,2831 +1,2831 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit