2017-11-09 17:43:34 +01:00
|
|
|
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
|
|
|
|
2018-01-26 23:52:55 +01:00
|
|
|
require_once (__DIR__ . '/../internals/database.php');
|
|
|
|
|
2017-11-09 17:43:34 +01:00
|
|
|
class Highscores
|
|
|
|
{
|
|
|
|
public static function generateChecksum($rand, $player, $playerid, $points, $gamesalt)
|
|
|
|
{
|
|
|
|
if ($playerid >= 0)
|
|
|
|
return md5($rand . $player . $playerid . $points . $gamesalt);
|
|
|
|
else
|
|
|
|
return md5($rand . $player . $points . $gamesalt);
|
|
|
|
}
|
2018-01-26 23:52:55 +01:00
|
|
|
|
|
|
|
public static function insert($gameid, $points, $name, $playerid, $check, $time, $ip)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_exec_prep('INSERT INTO highscoreentries (GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP) VALUES (:gid, :p, :pn, :pid, :cs, :ts, :ip)',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[':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)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_exec_prep('UPDATE highscoreentries SET POINTS = :p, PLAYER = :pn, CHECKSUM = :cs, IP = :ip, TIMESTAMP = :ts WHERE GAME_ID = :gid AND PLAYERID = :pid',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[':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)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_query_single_prep('SELECT * FROM highscoregames WHERE ID = :id',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[ ':id', $gameid, PDO::PARAM_INT ],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getOrderedEntriesFromGame($gameid, $limit = null)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
$sql = 'SELECT * FROM highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC';
|
2018-01-26 23:52:55 +01:00
|
|
|
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)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
$sql = 'SELECT * FROM highscoreentries WHERE GAME_ID = :id ORDER BY TIMESTAMP DESC';
|
2018-01-26 23:52:55 +01:00
|
|
|
if ($limit !== null) $sql .= " LIMIT $limit";
|
|
|
|
|
|
|
|
return Database::sql_query_assoc_prep($sql,
|
|
|
|
[
|
|
|
|
[ ':id', $gameid, PDO::PARAM_INT ]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getEntryCountFromGame($gameid)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_query_num_prep('SELECT COUNT(*) FROM highscoreentries WHERE GAME_ID = :id',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[ ':id', $gameid, PDO::PARAM_INT ]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAllGames()
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_query_assoc('SELECT * FROM highscoregames');
|
2018-01-26 23:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getNextPlayerID($gameid)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_query_num_prep('SELECT MAX(PLAYERID)+1 AS NID FROM highscoreentries WHERE GAME_ID = :gid',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[ ':id', $gameid, PDO::PARAM_INT ]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getSpecificScore($gameid, $playerid)
|
|
|
|
{
|
2018-02-03 14:53:30 +01:00
|
|
|
return Database::sql_query_single_prep('SELECT * FROM highscoreentries WHERE GAME_ID = :gid AND PLAYERID = :pid',
|
2018-01-26 23:52:55 +01:00
|
|
|
[
|
|
|
|
[ ':gid', $gameid, PDO::PARAM_INT ],
|
|
|
|
[ ':pid', $playerid, PDO::PARAM_INT ],
|
|
|
|
]);
|
|
|
|
}
|
2017-11-09 17:43:34 +01:00
|
|
|
}
|