summaryrefslogtreecommitdiff
path: root/online/index.php
blob: 27c277fef02c4078e4cd77984deabbcdcb311c6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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>