1
0

/admin/ highscores

This commit is contained in:
2018-01-26 23:52:55 +01:00
parent 82bb16be57
commit e1fec28368
14 changed files with 295 additions and 106 deletions

View File

@@ -59,31 +59,31 @@ global $OPTIONS;
<div class="bc_data about_circles">
<a class="iconbutton" href="https://github.com/Mikescher">
<a class="iconbutton_light" href="https://github.com/Mikescher">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<use xlink:href="/data/images/icons.svg#github"></use>
</svg>
<span>Github</span>
</a>
<a class="iconbutton" href="https://www.goodreads.com/C4terpillar">
<a class="iconbutton_light" href="https://www.goodreads.com/C4terpillar">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<use xlink:href="/data/images/icons.svg#goodreads"></use>
</svg>
<span>Goodreads</span>
</a>
<a class="iconbutton" href="https://stackoverflow.com/users/1761622/mikescher">
<a class="iconbutton_light" href="https://stackoverflow.com/users/1761622/mikescher">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<use xlink:href="/data/images/icons.svg#stackoverflow"></use>
</svg>
<span>Stackoverflow</span>
</a>
<a class="iconbutton" href="https://www.reddit.com/user/M1kescher/">
<a class="iconbutton_light" href="https://www.reddit.com/user/M1kescher/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<use xlink:href="/data/images/icons.svg#reddit"></use>
</svg>
<span>Reddit</span>
</a>
<a class="iconbutton" href="http://www.delphipraxis.net/members/46235-mikescher.html">
<a class="iconbutton_light" href="http://www.delphipraxis.net/members/46235-mikescher.html">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<use xlink:href="/data/images/icons.svg#delphipraxis"></use>
</svg>

View File

@@ -2,6 +2,11 @@
<html lang="en">
<?php
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/highscores.php');
require_once (__DIR__ . '/../internals/alephnoteStatistics.php');
Database::connect();
?>
<head>
<meta charset="utf-8">
@@ -23,18 +28,22 @@ require_once (__DIR__ . '/../internals/base.php');
<div class="contentheader"><h1>Admin</h1><hr/></div>
<!------------------------------------------>
<div class="boxedcontent">
<div class="bc_header">Version</div>
<div class="bc_data">
<div><b style="display:inline-block; min-width: 100px">Branch:&nbsp;</b><span><?php echo exec('git rev-parse --abbrev-ref HEAD'); ?></span></div>
<div><b style="display:inline-block; min-width: 100px">Commit:&nbsp;</b><span><?php echo exec('git rev-parse HEAD'); ?></span></div>
<div><b style="display:inline-block; min-width: 100px">Date:&nbsp;</b><span><?php echo exec('git log -1 --format=%cd'); ?></span></div>
<div><b style="display:inline-block; min-width: 100px">Message:&nbsp;</b><span><?php echo nl2br(exec('git log -1')); ?></span></div>
<div class="bc_data keyvaluelist kvl_100">
<div><span>Branch:</span> <span><?php echo exec('git rev-parse --abbrev-ref HEAD'); ?></span></div>
<div><span>Commit:</span> <span><?php echo exec('git rev-parse HEAD'); ?></span></div>
<div><span>Date:</span> <span><?php echo exec('git log -1 --format=%cd'); ?></span></div>
<div><span>Message:</span><span><?php echo nl2br(trim(exec('git log -1'))); ?></span></div>
</div>
</div>
<!------------------------------------------>
<div class="boxedcontent">
<div class="bc_header">ExtendedGitGraph</div>
@@ -46,6 +55,46 @@ require_once (__DIR__ . '/../internals/base.php');
</div>
</div>
<div class="boxedcontent">
<div class="bc_header">AlephNote</div>
<div class="bc_data">
<div class="keyvaluelist kvl_200">
<div><span>Total users:</span> <span><?php echo 0; ?></span></div>
<div><span>Users on latest version:</span> <span><?php echo 0; ?></span></div>
<div><span>Active users:</span> <span><?php echo 0; ?></span></div>
</div>
<div id="an_ajax_target"></div>
<a class="button" href="javascript:showAlephNoteData('<?php echo $CONFIG['ajax_secret'] ?>')">Show</a>
</div>
</div>
<div class="boxedcontent">
<div class="bc_header">Highscores</div>
<div class="bc_data keyvaluelist kvl_300">
<?php foreach (Highscores::getAllGames() as $game): ?>
<div><span><?php echo '[' . $game['NAME'] . '] Entries:' ?></span> <span><a href="/Highscores/list?gameid=<?php echo $game['ID']; ?>"><?php echo Highscores::getEntryCountFromGame($game['ID']); ?></a></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Highscore:' ?></span> <span><?php
$hs = Highscores::getOrderedEntriesFromGame($game['ID'], 1)[0];
echo $hs['POINTS'] . ' (' . $hs['PLAYER'] . ') @ ' . $hs['TIMESTAMP'];
?></span></div>
<div><span><?php echo '[' . $game['NAME'] . '] Last Update:' ?></span> <span><?php echo Highscores::getNewestEntriesFromGame($game['ID'], 1)[0]['TIMESTAMP']; ?></span></div>
<hr />
<?php endforeach; ?>
</div>
</div>
</div>

View File

@@ -16,24 +16,11 @@
if (! is_numeric($gameid)) httpError(400, 'Invalid Request');
if (! is_numeric($points)) httpError(400, 'Invalid Request');
$game = Database::sql_query_single_prep('SELECT * FROM ms4_highscoregames WHERE ID = :id',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ],
]);
$game = Highscores::getGameByID($gameid);
if ($game == NULL) httpError(400, 'Invalid Request');
$checksum_generated = Highscores::generateChecksum($rand, $name, -1, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
Database::sql_exec_prep('INSERT INTO ms4_highscoreentries (GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP) VALUES (:gid, :p, :pn, :pid, :cs, :ts, :ip)',
[
[':gid', $gameid, PDO::PARAM_INT],
[':p', $points, PDO::PARAM_INT],
[':pn', $name, PDO::PARAM_STR],
[':pid', -1, PDO::PARAM_INT],
[':cs', $check, PDO::PARAM_STR],
[':ts', time(), PDO::PARAM_STR],
[':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR],
]);
Highscores::insert($gameid, $points, $name, -1, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';

View File

@@ -22,16 +22,9 @@
$highlight= intval(htmlspecialchars($_GET["highlight"]));
}
$game = Database::sql_query_single_prep('SELECT * FROM ms4_highscoregames WHERE ID = :id',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ]
]);
$game = Highscores::getGameByID($OPTIONS['gameid']);
$entries = Database::sql_query_assoc_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ]
]);
$entries = Highscores::getOrderedEntriesFromGame($OPTIONS['gameid']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@@ -7,7 +7,7 @@
Database::connect();
$games = Database::sql_query_assoc('SELECT * FROM ms4_highscoregames');
$games = Highscores::getAllGames();
?>
<html>

View File

@@ -7,10 +7,7 @@
Database::connect();
$newid = Database::sql_query_num_prep('SELECT MAX(PLAYERID)+1 AS NID FROM ms4_highscoreentries WHERE GAME_ID = :gid',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ]
]);
$newid = Highscores::getNextPlayerID($OPTIONS['gameid']);
if ($newid < 1024) $newid = 1024;

View File

@@ -7,10 +7,7 @@
Database::connect();
$entries = Database::sql_query_single_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC LIMIT 50',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ]
]);
$entries = Highscores::getOrderedEntriesFromGame($OPTIONS['gameid'], 50);
for ($i = 0; $i < count($entries); $i++)
{

View File

@@ -18,48 +18,21 @@
if (! is_numeric($nameid)) httpError(400, 'Invalid Request');
if (! is_numeric($points)) httpError(400, 'Invalid Request');
$game = Database::sql_query_single_prep('SELECT * FROM ms4_highscoregames WHERE ID = :id',
[
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ],
]);
$game = Highscores::getGameByID($OPTIONS['gameid']);
if ($game == NULL) httpError(400, 'Invalid Request');
$checksum_generated = Highscores::generateChecksum($rand, $name, $nameid, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
$old = Database::sql_query_single_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :gid AND PLAYERID = :pid',
[
[ ':gid', $OPTIONS['gameid'], PDO::PARAM_INT ],
[ ':pid', $OPTIONS['nameid'], PDO::PARAM_INT ],
]);
$old = Highscores::getSpecificScore($gameid, $nameid);
if ($old == null)
{
Database::sql_exec_prep('INSERT INTO ms4_highscoreentries (GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP) VALUES (:gid, :p, :pn, :pid, :cs, :ts, :ip)',
[
[':gid', $gameid, PDO::PARAM_INT],
[':p', $points, PDO::PARAM_INT],
[':pn', $name, PDO::PARAM_STR],
[':pid', $nameid, PDO::PARAM_INT],
[':cs', $check, PDO::PARAM_STR],
[':ts', time(), PDO::PARAM_STR],
[':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR],
]);
Highscores::insert($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}
else
{
Database::sql_exec_prep('UPDATE ms4_highscoreentries SET POINTS = :p, PLAYER = :pn, CHECKSUM = :cs, IP = :ip, TIMESTAMP = :ts WHERE GAME_ID = :gid AND PLAYERID = :pid',
[
[':gid', $gameid, PDO::PARAM_INT],
[':p', $points, PDO::PARAM_INT],
[':pn', $name, PDO::PARAM_STR],
[':pid', $nameid, PDO::PARAM_INT],
[':cs', $check], PDO::PARAM_STR,
[':ts', time(), PDO::PARAM_STR],
[':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR],
]);
Highscores::update($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}