summaryrefslogtreecommitdiff
path: root/online/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'online/index.php')
-rw-r--r--online/index.php184
1 files changed, 184 insertions, 0 deletions
diff --git a/online/index.php b/online/index.php
new file mode 100644
index 0000000..27c277f
--- /dev/null
+++ b/online/index.php
@@ -0,0 +1,184 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/telemetry/private/dom.php";
+
+if (!isset($_COOKIE["kartik_online_token"])) {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback&scope=hub&request_credentials=default&access_type=offline");
+ die();
+} else if (ctype_xdigit($_COOKIE["kartik_online_token"]) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token'])) {
+ $_DATA = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/tokens/" . $_COOKIE['kartik_online_token']), true);
+} else {
+ header("Location: https://jetbrains.minteck.ro.lt:1024/hub/hub/api/rest/oauth2/auth?client_id=2d3ca3a8-38b7-4193-990a-a9454bb8d44c&response_type=code&redirect_uri=https://kartik.hopto.org/online/callback&scope=hub&request_credentials=default&access_type=offline");
+ die();
+}
+
+function secondsToTime($seconds) {
+ $dtF = new \DateTime('@0');
+ $dtT = new \DateTime("@$seconds");
+
+ $hours = $dtF->diff($dtT)->format('%h');
+ $rest = $dtF->diff($dtT)->format("%i " . l("min, ", "mn, ") . " %s " . l("secs", "sec"));
+ $hours = ($dtF->diff($dtT)->format('%a') * $hours) . " " . l("hrs, ", "hr, ");
+
+ return $hours . $rest;
+}
+
+function l($fr, $en) {
+ if (isset($_GET['lang'])) {
+ if ($_GET['lang'] == "en") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
+ } else if ($_GET['lang'] == "fr") {
+ $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr";
+ }
+ }
+ if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "fr") {
+ return $fr;
+ } else {
+ return $en;
+ }
+}
+
+?>
+<!DOCTYPE html>
+<html lang="en" style="height:100%;">
+<head>
+ <meta charset="UTF-8">
+ <title>Kartik Online</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="icon" href="/static/favicon.png">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="stylesheet" href="/appsicons.css">
+ <style>
+ .col-sm-4 {
+ padding: 15px;
+ }
+ </style>
+</head>
+<body style="height:100%;">
+
+<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
+
+ <a class="navbar-brand" href="/">
+ <img src="/static/logo.png" alt="Kartik" style="height:32px;"><span style="vertical-align: middle;font-size: 14px;">Online</span>
+ </a>
+
+ <div class="collapse navbar-collapse" id="collapsibleNavbar">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link" href="/">← <?= l("Retourner au site de Kartik", "Go back to Kartik website") ?></a>
+ </li>
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/apps.php"; ?>
+ </ul>
+ </div>
+</nav>
+
+<div id="separator"></div>
+
+<div class="container" style="margin-top:25px;">
+ <br>
+ <div class="alert alert-warning">
+ <b><?= l("Note :", "Notice:") ?></b> <?= l("Assurez-vous que vous disposez de la version 21.08.2 ou suivant de Kartik pour pouvoir utiliser les nouvelles fonctionnalités en ligne.", "Make sure you have Kartik version 21.08.2 or later to use the new online features.") ?>
+ </div>
+ <h2 style="text-align: center;"><?= l("Vous revoilà", "Welcome back") ?> <?= $_DATA["name"] ?><?= l(" !", "!") ?></h2>
+ <h4 style="text-align: center;"><?= l("Connectez-vous à ce compte Minteck Hub sur votre copie de Kartik pour accéder à plus de fonctionnalités en ligne.", "Log in to this Minteck Hub account on your copy of Kartik to get access to more online features.") ?></h4>
+
+ <div class="row">
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Connexions", "Logins"); ?></h5>
+ <ul class="list-group">
+ <?php $connected = false; foreach (scandir($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens") as $token): ?>
+ <?php if (trim($token) !== "." && trim($token) !== ".." && json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/gametokens/" . $token), true)["id"] === $_DATA["id"]): ?>
+ <?php $connected = true; ?>
+ <li class="list-group-item">
+ <code><?= substr($token, 0, 8) ?></code>
+ <a href="/online/logout/?_=<?= substr($token, 0, 20) ?>" style="float:right;"><?= l("Déconnecter", "Logout") ?></a>
+ </li>
+ <?php endif;endforeach; ?>
+ </ul>
+ <?php if (!$connected): ?>
+ <p style="text-align: center;"><i><?= l("Après vous être connecté à votre compte sur votre copie de Kartik, vous avez la possibilité de vous déconnecter à partir d'ici.", "After logging into your account from your copy of Kartik, you have the choice to log out from here.") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Statistiques", "Statistics"); ?></h5>
+ <?php $prettynames = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/statsnames.json"), true); if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"])): ?>
+ <?php
+
+ // Calculate insights
+ $stats = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/stats/" . $_DATA["id"]), true);
+ $totalTimes = $stats["times"]["single"] + $stats["times"]["local"] + $stats["times"]["online"];
+
+ $stats["results"]["total"] = $stats["results"]["wins"] + $stats["results"]["loses"];
+
+ ?>
+ <ul class="list-group">
+ <?php foreach($stats as $category => $items): ?>
+ <?php foreach($items as $item => $value): ?>
+ <li class="list-group-item">
+ <?php if ($value === 0 && $category !== "times"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br>-
+ <?php else: ?>
+ <?php if ($category === "times"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= secondsToTime($value); ?> (<?= round(($value / $totalTimes) * 100, 2) ?>%)
+ <?php else: ?>
+ <?php if ($category === "results" && ($item === "wins" || $item === "loses")): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (<?= round(($value / $stats["results"]["total"]) * 100, 2) ?>%)
+ <?php elseif ($category === "results" && $item === "total"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (~<?= round(($totalTimes / $value) / 60, 2) ?> <?= l("min/partie", "mn/game") ?>)
+ <?php elseif ($category === "ingame" && $item === "walls"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php if ($stats["results"]["total"] !== 0): ?>
+ (~<?= round(($value / $stats["results"]["total"]), 2) ?> <?= l(" par partie", " per game") ?>)
+ <?php endif; ?>
+ <?php elseif ($category === "ingame" && $item === "laps"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php if ($stats["results"]["total"] !== 0): ?>
+ (~<?= round(($value / $stats["results"]["total"]), 2) ?> <?= l(" par partie", " per game") ?>)
+ <?php endif; ?>
+ <?php elseif ($category === "ingame" && $item === "turns"): ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?> (~<?= round(($value / $stats["ingame"]["laps"]), 2) ?> <?= l(" par tour", " per lap") ?>)
+ <?php else: ?>
+ <b><?= $prettynames[$category . "." . $item][l("fr", "en")] ?? $category . "." . $item ?><?= l(" :", ":"); ?></b><br><?= $value ?>
+ <?php endif; ?>
+ <?php endif; ?>
+ <?php endif; ?>
+ </li>
+ <?php endforeach; ?>
+ <?php endforeach; ?>
+ </ul>
+ <?php else: ?>
+ <p style="text-align: center;"><i><?= l("Des statistiques sur votre niveau dans Kartik apparaîtront ici au fur et à mesure que vous jouez", "Stats about your level in Kartik will appear here as you play") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-4">
+ <div class="card">
+ <div class="card-body">
+ <h5><?= l("Progression", "Progress"); ?></h5>
+ <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"])): ?>
+ <p><b><?= l("Niveau", "Level") ?> <?= (int)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) < 200 ? file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) : l("Dieu", "God") ?></b></p>
+ <div class="progress">
+ <div class="progress-bar bg-success" style="width:<?= (int)file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) < 200 ? file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/online/private/levels/" . $_DATA["id"]) / 2 : "100" ?>%"></div>
+ </div>
+ <?php else: ?>
+ <p style="text-align: center;"><i><?= l("En progressant dans le jeu, vous passez des niveaux. Votre progression s'affichera ici au fur et à mesure que vous jouez.", "By progressing in the game, you pass levels. Your progress will show here as you play.") ?></i></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
+</body>
+</html>
+