/admin/ highscores
This commit is contained in:
parent
82bb16be57
commit
e1fec28368
@ -124,22 +124,41 @@ body {
|
||||
text-decoration: none;
|
||||
border: 1px solid #000;
|
||||
margin: 5px 0; }
|
||||
|
||||
.iconbutton:hover {
|
||||
cursor: pointer;
|
||||
background-color: #555; }
|
||||
|
||||
.iconbutton svg {
|
||||
width: 14pt;
|
||||
height: 14pt;
|
||||
margin: 0 4px;
|
||||
fill: #CCC; }
|
||||
|
||||
.iconbutton span {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
font-size: 14pt; }
|
||||
|
||||
.iconbutton_light {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: #888;
|
||||
color: #222;
|
||||
text-decoration: none;
|
||||
border: 1px solid #000;
|
||||
margin: 5px 0; }
|
||||
.iconbutton_light:hover {
|
||||
cursor: pointer;
|
||||
background-color: #555; }
|
||||
.iconbutton_light svg {
|
||||
width: 14pt;
|
||||
height: 14pt;
|
||||
margin: 0 4px;
|
||||
fill: #000; }
|
||||
.iconbutton_light span {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
font-size: 14pt; }
|
||||
|
||||
/* 400px */
|
||||
#headerdiv {
|
||||
z-index: 999;
|
||||
@ -975,7 +994,7 @@ html, body {
|
||||
|
||||
.about_circles a {
|
||||
margin: 5px 0; }
|
||||
.about_circles .iconbutton span {
|
||||
.about_circles .iconbutton_light span {
|
||||
text-align: left; }
|
||||
|
||||
/* 400px */
|
||||
@ -997,6 +1016,25 @@ html, body {
|
||||
resize: none;
|
||||
height: 300px; }
|
||||
|
||||
.keyvaluelist {
|
||||
display: flex;
|
||||
flex-direction: column; }
|
||||
.keyvaluelist div {
|
||||
display: flex;
|
||||
flex-direction: row; }
|
||||
.keyvaluelist div span:first-child {
|
||||
font-weight: bold;
|
||||
min-width: 500px; }
|
||||
|
||||
.kvl_100 div span:first-child {
|
||||
min-width: 100px; }
|
||||
|
||||
.kvl_200 div span:first-child {
|
||||
min-width: 200px; }
|
||||
|
||||
.kvl_300 div span:first-child {
|
||||
min-width: 300px; }
|
||||
|
||||
/* 400px */
|
||||
#loginform div {
|
||||
display: flex;
|
||||
|
12
www/data/css/styles.min.css
vendored
12
www/data/css/styles.min.css
vendored
@ -27,6 +27,10 @@ body{background-color:#EEE;color:#CCC;font-family:serif}
|
||||
.iconbutton:hover{cursor:pointer;background-color:#555}
|
||||
.iconbutton svg{width:14pt;height:14pt;margin:0 4px;fill:#CCC}
|
||||
.iconbutton span{flex-grow:1;text-align:center;font-size:14pt}
|
||||
.iconbutton_light{display:flex;justify-content:center;align-items:center;background:#888;color:#222;text-decoration:none;border:1px solid #000;margin:5px 0}
|
||||
.iconbutton_light:hover{cursor:pointer;background-color:#555}
|
||||
.iconbutton_light svg{width:14pt;height:14pt;margin:0 4px;fill:#000}
|
||||
.iconbutton_light span{flex-grow:1;text-align:center;font-size:14pt}
|
||||
#headerdiv{z-index:999;background-color:#333;display:flex;border-bottom:1px solid #111;box-shadow:0 0 8px #000;position:fixed;width:100%}
|
||||
#headerdiv .logowrapper{flex:initial;margin:0;padding:0;height:42px}
|
||||
#headerdiv .logowrapper .logo{min-width:197.5px;height:30px;margin:4px 0 8px 6px;flex:initial}
|
||||
@ -240,10 +244,16 @@ html,body{margin:0;padding:0;height:100%}
|
||||
.egg_footer>a:hover{text-decoration:none;color:#22F}
|
||||
.about_circles{display:flex;flex-direction:column}
|
||||
.about_circles a{margin:5px 0}
|
||||
.about_circles .iconbutton span{text-align:left}
|
||||
.about_circles .iconbutton_light span{text-align:left}
|
||||
.admincontent{display:block;width:100%}
|
||||
.admincontent .boxedcontent{margin-bottom:20px}
|
||||
.egh_ajaxOutput{display:flex;box-sizing:border-box;width:100%;align-self:center;justify-self:center;margin-left:auto;margin-right:auto;resize:none;height:300px}
|
||||
.keyvaluelist{display:flex;flex-direction:column}
|
||||
.keyvaluelist div{display:flex;flex-direction:row}
|
||||
.keyvaluelist div span:first-child{font-weight:bold;min-width:500px}
|
||||
.kvl_100 div span:first-child{min-width:100px}
|
||||
.kvl_200 div span:first-child{min-width:200px}
|
||||
.kvl_300 div span:first-child{min-width:300px}
|
||||
#loginform div{display:flex;flex-direction:column}
|
||||
#loginform div button{margin:10px 0;padding:0}
|
||||
.loginerror{display:flex;background:#f44;font-weight:bold;padding:0 5px;margin:5px 0 20px 0}
|
||||
|
@ -112,6 +112,6 @@
|
||||
|
||||
a { margin: 5px 0; }
|
||||
|
||||
.iconbutton span {text-align: left;}
|
||||
.iconbutton_light span {text-align: left;}
|
||||
|
||||
}
|
@ -21,3 +21,27 @@
|
||||
resize: none;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.keyvaluelist {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
div {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
span:first-child {
|
||||
font-weight: bold;
|
||||
min-width: 500px;
|
||||
}
|
||||
|
||||
span:last-child {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.kvl_100 div span:first-child { min-width: 100px; }
|
||||
.kvl_200 div span:first-child { min-width: 200px; }
|
||||
.kvl_300 div span:first-child { min-width: 300px; }
|
@ -132,24 +132,55 @@ body {
|
||||
border: 1px solid #000;
|
||||
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.iconbutton:hover {
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
background-color: #555;
|
||||
}
|
||||
|
||||
.iconbutton svg {
|
||||
svg {
|
||||
width: 14pt;
|
||||
height: 14pt;
|
||||
margin: 0 4px;
|
||||
|
||||
fill: $COL_TEXT_NORMAL;
|
||||
}
|
||||
|
||||
.iconbutton span {
|
||||
span {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
|
||||
font-size: 14pt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.iconbutton_light {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
background: #888;
|
||||
color: $COL_TEXT_DARK_DARKER;
|
||||
text-decoration: none;
|
||||
border: 1px solid #000;
|
||||
|
||||
margin: 5px 0;
|
||||
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
background-color: #555;
|
||||
}
|
||||
svg {
|
||||
width: 14pt;
|
||||
height: 14pt;
|
||||
margin: 0 4px;
|
||||
|
||||
fill: #000;
|
||||
}
|
||||
span {
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
|
||||
font-size: 14pt;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
||||
|
||||
require_once (__DIR__ . '/../internals/database.php');
|
||||
|
||||
class Highscores
|
||||
{
|
||||
public static function generateChecksum($rand, $player, $playerid, $points, $gamesalt)
|
||||
@ -9,4 +11,92 @@ class Highscores
|
||||
else
|
||||
return md5($rand . $player . $points . $gamesalt);
|
||||
}
|
||||
|
||||
public static function insert($gameid, $points, $name, $playerid, $check, $time, $ip)
|
||||
{
|
||||
return 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', $playerid, PDO::PARAM_INT],
|
||||
[':cs', $check, PDO::PARAM_STR],
|
||||
[':ts', $time, PDO::PARAM_STR],
|
||||
[':ip', $ip, PDO::PARAM_STR],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function update($gameid, $points, $name, $playerid, $check, $time, $ip)
|
||||
{
|
||||
return 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', $playerid, PDO::PARAM_INT],
|
||||
[':cs', $check, PDO::PARAM_STR],
|
||||
[':ts', $time, PDO::PARAM_STR],
|
||||
[':ip', $ip, PDO::PARAM_STR],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getGameByID($gameid)
|
||||
{
|
||||
return Database::sql_query_single_prep('SELECT * FROM ms4_highscoregames WHERE ID = :id',
|
||||
[
|
||||
[ ':id', $gameid, PDO::PARAM_INT ],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getOrderedEntriesFromGame($gameid, $limit = null)
|
||||
{
|
||||
$sql = 'SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC';
|
||||
if ($limit !== null) $sql .= " LIMIT $limit";
|
||||
|
||||
return Database::sql_query_assoc_prep($sql,
|
||||
[
|
||||
[ ':id', $gameid, PDO::PARAM_INT ]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getNewestEntriesFromGame($gameid, $limit = null)
|
||||
{
|
||||
$sql = 'SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY TIMESTAMP DESC';
|
||||
if ($limit !== null) $sql .= " LIMIT $limit";
|
||||
|
||||
return Database::sql_query_assoc_prep($sql,
|
||||
[
|
||||
[ ':id', $gameid, PDO::PARAM_INT ]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEntryCountFromGame($gameid)
|
||||
{
|
||||
return Database::sql_query_num_prep('SELECT COUNT(*) FROM ms4_highscoreentries WHERE GAME_ID = :id',
|
||||
[
|
||||
[ ':id', $gameid, PDO::PARAM_INT ]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getAllGames()
|
||||
{
|
||||
return Database::sql_query_assoc('SELECT * FROM ms4_highscoregames');
|
||||
}
|
||||
|
||||
public static function getNextPlayerID($gameid)
|
||||
{
|
||||
return Database::sql_query_num_prep('SELECT MAX(PLAYERID)+1 AS NID FROM ms4_highscoreentries WHERE GAME_ID = :gid',
|
||||
[
|
||||
[ ':id', $gameid, PDO::PARAM_INT ]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getSpecificScore($gameid, $playerid)
|
||||
{
|
||||
return Database::sql_query_single_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :gid AND PLAYERID = :pid',
|
||||
[
|
||||
[ ':gid', $gameid, PDO::PARAM_INT ],
|
||||
[ ':pid', $playerid, PDO::PARAM_INT ],
|
||||
]);
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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: </b><span><?php echo exec('git rev-parse --abbrev-ref HEAD'); ?></span></div>
|
||||
<div><b style="display:inline-block; min-width: 100px">Commit: </b><span><?php echo exec('git rev-parse HEAD'); ?></span></div>
|
||||
<div><b style="display:inline-block; min-width: 100px">Date: </b><span><?php echo exec('git log -1 --format=%cd'); ?></span></div>
|
||||
<div><b style="display:inline-block; min-width: 100px">Message: </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>
|
||||
|
@ -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.';
|
@ -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 ]
|
||||
]);
|
||||
|
||||
$entries = Database::sql_query_assoc_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC',
|
||||
[
|
||||
[ ':id', $OPTIONS['gameid'], PDO::PARAM_INT ]
|
||||
]);
|
||||
$game = Highscores::getGameByID($OPTIONS['gameid']);
|
||||
|
||||
$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">
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
Database::connect();
|
||||
|
||||
$games = Database::sql_query_assoc('SELECT * FROM ms4_highscoregames');
|
||||
$games = Highscores::getAllGames();
|
||||
|
||||
?>
|
||||
<html>
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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++)
|
||||
{
|
||||
|
@ -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.';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user