1
0

Highscores

This commit is contained in:
2020-01-17 00:55:41 +01:00
parent 81e129effa
commit 85f107e8bd
10 changed files with 230 additions and 191 deletions

View File

@@ -1,26 +1,30 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
Database::connect();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$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');
$gameid = $ROUTE->parameter['gameid'];
$check = $ROUTE->parameter['check'];
$name = $ROUTE->parameter['name'];
$rand = $ROUTE->parameter['rand'];
$points = $ROUTE->parameter['points'];
$game = Highscores::getGameByID($gameid);
if ($game == NULL) httpError(400, 'Invalid Request');
if (! is_numeric($gameid)) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
if (! is_numeric($points)) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
$checksum_generated = Highscores::generateChecksum($rand, $name, -1, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
$game = $SITE->modules->Highscores()->getGameByID($gameid);
if ($game == NULL) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
Highscores::insert($gameid, $points, $name, -1, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
$checksum_generated = $SITE->modules->Highscores()->generateChecksum($rand, $name, -1, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
$SITE->modules->Highscores()->insert($gameid, $points, $name, -1, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';

View File

@@ -1,30 +1,35 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
Database::connect();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$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"]));
}
$pagesize = 20;
$start = 0;
$highlight = 0;
$game = Highscores::getGameByID($OPTIONS['gameid']);
if (isset($_GET["start"]))
{
$start = intval(htmlspecialchars($_GET["start"])) - 1;
if ($start < 0) $start = 0;
}
$entries = Highscores::getOrderedEntriesFromGame($OPTIONS['gameid']);
if (isset($_GET["highlight"]))
{
$highlight= intval(htmlspecialchars($_GET["highlight"]));
}
$game = $SITE->modules->Highscores()->getGameByID($ROUTE->parameter['gameid']);
$entries = $SITE->modules->Highscores()->getOrderedEntriesFromGame($ROUTE->parameter['gameid']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@@ -1,14 +1,16 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
require_once (__DIR__ . '/../internals/website.php');
Database::connect();
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
$games = Highscores::getAllGames();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$games = $SITE->modules->Highscores()->getAllGames();
?>
<html>
<head>

View File

@@ -1,14 +1,18 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
Database::connect();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$newid = Highscores::getNextPlayerID($OPTIONS['gameid']);
if ($newid < 1024) $newid = 1024;
print $newid;
$newid = $SITE->modules->Highscores()->getNextPlayerID($ROUTE->parameter['gameid']);
if ($newid < 1024) $newid = 1024;
print $newid;

View File

@@ -1,13 +1,17 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
Database::connect();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$entries = Highscores::getOrderedEntriesFromGame($OPTIONS['gameid'], 50);
$entries = $SITE->modules->Highscores()->getOrderedEntriesFromGame($ROUTE->parameter['gameid'], 50);
for ($i = 0; $i < count($entries); $i++)
{

View File

@@ -1,38 +1,42 @@
<?php
global $OPTIONS;
require_once (__DIR__ . '/../internals/website.php');
require_once (__DIR__ . '/../internals/base.php');
require_once (__DIR__ . '/../internals/database.php');
require_once (__DIR__ . '/../internals/highscores.php');
/** @var PageFrameOptions $FRAME_OPTIONS */ global $FRAME_OPTIONS;
/** @var URLRoute $ROUTE */ global $ROUTE;
/** @var Website $SITE */ global $SITE;
Database::connect();
$FRAME_OPTIONS->title = null;
$FRAME_OPTIONS->canonical_url = null;
$FRAME_OPTIONS->activeHeader = null;
$FRAME_OPTIONS->frame = 'api_frame.php';
$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');
$gameid = $ROUTE->parameter['gameid'];
$check = $ROUTE->parameter['check'];
$name = $ROUTE->parameter['name'];
$nameid = $ROUTE->parameter['nameid'];
$rand = $ROUTE->parameter['rand'];
$points = $ROUTE->parameter['points'];
$game = Highscores::getGameByID($OPTIONS['gameid']);
if ($game == NULL) httpError(400, 'Invalid Request');
if (! is_numeric($gameid)) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
if (! is_numeric($nameid)) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
if (! is_numeric($points)) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
$checksum_generated = Highscores::generateChecksum($rand, $name, $nameid, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
$game = $SITE->modules->Highscores()->getGameByID($ROUTE->parameter['gameid']);
if ($game == NULL) { $FRAME_OPTIONS->forceResult(400, 'Invalid Request'); return; }
$old = Highscores::getSpecificScore($gameid, $nameid);
$checksum_generated = $SITE->modules->Highscores()->generateChecksum($rand, $name, $nameid, $points, $game['SALT']);
if ($checksum_generated != $check) die('Nice try !');
if ($old == null)
{
Highscores::insert($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}
else
{
Highscores::update($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}
$old = $SITE->modules->Highscores()->getSpecificScore($gameid, $nameid);
if ($old == null)
{
$SITE->modules->Highscores()->insert($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}
else
{
$SITE->modules->Highscores()->update($gameid, $points, $name, $nameid, $check, date("Y-m-d H:m:s", time()), $_SERVER['REMOTE_ADDR']);
echo 'ok.';
}