1
0

urlmanager

This commit is contained in:
2017-11-09 17:43:34 +01:00
parent faee825af9
commit 8fb7bb51b0
115 changed files with 1512 additions and 181 deletions

View File

@@ -0,0 +1,21 @@
<?php
function get_client_ip() {
if (getenv('HTTP_CLIENT_IP')) return getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR')) return getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED')) return getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR')) return getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED')) return getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR')) return getenv('REMOTE_ADDR');
else if (isset($_SERVER['HTTP_CLIENT_IP'])) return $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) return $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED'])) return $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) return $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED'])) return $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR'])) return $_SERVER['REMOTE_ADDR'];
else return 'UNKNOWN';
}
//TODO setSelfAdress
echo 'Ok.';

3
www/pages/api_test.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
echo "{}";

View File

@@ -0,0 +1,18 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
$name = $OPTIONS['name'];
Database::connect();
$data = Database::sql_query_single_prep('SELECT * FROM ms4_updates WHERE Name = :n',
[
[':n', $name, PDO::PARAM_STR],
]);
if ($data == NULL) httpError(404, 'Invalid Request - [Name] not found');
print($data['Name']."<hr>".$data['Version']."<hr>".$data['Link']);

View File

@@ -0,0 +1,39 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
Database::connect();
$gameid = $OPTIONS['gameid'];
$check = $OPTIONS['check'];
$name = $OPTIONS['name'];
$rand = $OPTIONS['rand'];
$points = $OPTIONS['points'];
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 ],
]);
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],
]);
echo 'ok.';

View File

@@ -0,0 +1,129 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
Database::connect();
$pagesize = 20;
$start = 0;
$highlight = 0;
if (isset($_GET["start"]))
{
$start = intval(htmlspecialchars($_GET["start"])) - 1;
if ($start < 0) $start = 0;
}
if (isset($_GET["highlight"]))
{
$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 ]
]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta charset="utf-8"/>
<title>highscores</title>
<style type="text/css">
<!--
body {
background-color: #DDF;
padding: 1em 1em 0em;
}
table {
margin: auto;
width: 80%;
text-align: center;
border-spacing: 0px;
}
table td { padding: 2px 0px; }
table td { width: 25%; }
table td:last-child { width: 50%; }
caption {
font-weight: bolder;
text-decoration: underline;
font-size: x-large;
}
a {
color: #008;
text-decoration: underline;
}
a:hover { text-decoration: none; }
#headline > td { text-decoration: underline; }
#highlight {
font-weight: bolder;
background-color: #CCF;
}
-->
</style>
</head>
<body>
<table>
<caption><?php echo $game['NAME']; ?></caption>
<tr id="headline" >
<td>rank</td>
<td>points</td>
<td>name</td>
</tr>
<?php
$current = 0;
foreach ($entries as $entry)
{
$current++;
if ($current >= $start && $current - $start <= $pagesize)
{
if ($current == $highlight)
echo '<tr id="highlight">';
else
echo "<tr>";
echo "<td>$current</td>";
echo "<td>".$entry['POINTS']."</td>";
echo "<td>".$entry['PLAYER']."</td>";
echo "</tr>";
}
}
$more = max(0, $start - $pagesize);
$less = $start + $pagesize;
echo '<tr>';
if ($start > 0)
echo '<td><a href="' . "/Highscores/list?gameid=".$game['ID']."&start=$more&highlight=$highlight" . '">[more points]</a></td>';
else
echo '<td></td>';
echo '<td></td>';
if ($start + $pagesize < count($entries))
echo '<td><a href="' . "/Highscores/list?gameid=".$game['ID']."&start=$less&highlight=$highlight" . '">[less points]</a></td>';
else
echo '<td></td>';
echo '</tr>';
?>
</table>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
Database::connect();
$games = Database::sql_query_assoc('SELECT * FROM ms4_highscoregames');
?>
<html>
<head>
<meta charset="utf-8"/>
<title>highscores</title>
<style type="text/css">
<!--
body {
background-color: #DDF;
padding: 1em 1em 0em;
}
a {
color: #008;
text-decoration: underline;
}
a:hover { text-decoration: none; }
-->
</style>
</head>
<body>
<?php
foreach ($games as $game)
{
echo '<a href="/Highscores/list?gameid=' . $game['ID'] . '">' . $game['NAME'] . '</a><br>' . "\r\n";
}
?>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
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 ]
]);
if ($newid < 1024) $newid = 1024;
print $newid;

View File

@@ -0,0 +1,18 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
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 ]
]);
for ($i = 0; $i < count($entries); $i++)
{
print($entries[$i]['POINTS'] . '||' . htmlentities($entries[$i]['PLAYER']) . "\r\n");
}

View File

@@ -0,0 +1,65 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
Database::connect();
$gameid = $OPTIONS['gameid'];
$check = $OPTIONS['check'];
$name = $OPTIONS['name'];
$nameid = $OPTIONS['nameid'];
$rand = $OPTIONS['rand'];
$points = $OPTIONS['points'];
if (! is_numeric($gameid)) httpError(400, 'Invalid Request');
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 ],
]);
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 ],
]);
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],
]);
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],
]);
echo 'ok.';
}

View File

@@ -1,23 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<?php require __DIR__ . '/../internals/base.php' ?>
<?php require_once (__DIR__ . '/../internals/base.php'); ?>
<head>
<meta charset="utf-8">
<title>Mikescher.com</title>
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
<link rel="icon" type="image/png" href="/images/favicon.png"/>
<link rel="stylesheet" href="/data/styles.css"/>
<meta charset="utf-8">
<title>Mikescher.com</title>
<meta name="google-site-verification" content="pZOhmjeJcQbRMNa8xRLam4dwJ2oYwMwISY1lRKreSSs"/>
<link rel="icon" type="image/png" href="/data/images/favicon.png"/>
<link rel="stylesheet" href="/data/css/styles.css"/>
</head>
<body>
<?php include (__DIR__ . '/../fragments/header.php'); ?>
<?php include (__DIR__ . '/../fragments/header.php'); ?>
<div id="content">
<div id="content">
<?php include (__DIR__ . '/../fragments/eulerpanel.php'); ?>
</div>
</div>
<?php include (__DIR__ . '/../fragments/footer.php'); ?>
<?php include (__DIR__ . '/../fragments/footer.php'); ?>
</body>
</html>