Bug fixes
This commit is contained in:
parent
e2980b465c
commit
d2f1eeb8b0
2 changed files with 24 additions and 15 deletions
|
@ -29,15 +29,14 @@ class APIv1 extends CustomModule
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'PUT')
|
if ($_SERVER['REQUEST_METHOD'] == 'PUT')
|
||||||
{
|
{
|
||||||
parse_str(file_get_contents("php://input"), $_PUT);
|
parse_str(file_get_contents("php://input"), $_PUT);
|
||||||
|
$_REQUEST = array_merge($_REQUEST, $_PUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['key']) || isset($_PUT['key']))
|
if (isset($_REQUEST['key']))
|
||||||
{
|
{
|
||||||
$api_key = isset($_PUT['key']) ? $_PUT['key'] : $_REQUEST['key'];
|
if (strlen($_REQUEST['key']) == 40)
|
||||||
|
|
||||||
if (strlen($api_key) == 40)
|
|
||||||
{
|
{
|
||||||
$uid = $this->redis->get('user:api:' . $api_key);
|
$uid = $this->redis->get('user:api:' . $_REQUEST['key']);
|
||||||
|
|
||||||
if ($uid)
|
if ($uid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,8 @@ class api_v1_leaderboard extends APIv1
|
||||||
throw new Exception('Missing UID.');
|
throw new Exception('Missing UID.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$leaderboard_key = 'leaderboard:' . $_GET['uid'];
|
$leaderboard_uid = $_GET['uid'];
|
||||||
|
$leaderboard_key = 'leaderboard:' . $leaderboard_uid;
|
||||||
|
|
||||||
// Checks that the UID is valid and belongs to the key
|
// Checks that the UID is valid and belongs to the key
|
||||||
$leaderboard = $this->redis->hgetall($leaderboard_key);
|
$leaderboard = $this->redis->hgetall($leaderboard_key);
|
||||||
|
@ -75,35 +76,44 @@ class api_v1_leaderboard extends APIv1
|
||||||
$this->redis->zadd($leaderboard_key . ':' . $suffix, $_POST['score'], $_POST['member']);
|
$this->redis->zadd($leaderboard_key . ':' . $suffix, $_POST['score'], $_POST['member']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis->exec();
|
$timestamp = time();
|
||||||
|
|
||||||
|
foreach (array('', 'user:' . $this->uid . ':') as $prefix)
|
||||||
|
{
|
||||||
|
$this->redis->zadd($prefix . 'leaderboards:updated', $timestamp, $leaderboard_uid);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Increments a score of a member
|
// Increments a score of a member
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
// Hack because _PUT doesn't exist in PHP land
|
|
||||||
parse_str(file_get_contents("php://input"), $_PUT);
|
|
||||||
|
|
||||||
$increment = 1;
|
$increment = 1;
|
||||||
|
|
||||||
if (!isset($_PUT['member']))
|
if (!isset($_REQUEST['member']))
|
||||||
{
|
{
|
||||||
throw new Exception('Missing member.');
|
throw new Exception('Missing member.');
|
||||||
}
|
}
|
||||||
elseif (isset($_PUT['value']))
|
elseif (isset($_REQUEST['value']))
|
||||||
{
|
{
|
||||||
if (!preg_match('/^-?\d+$/', $_PUT['value']))
|
if (!preg_match('/^-?\d+$/', $_REQUEST['value']))
|
||||||
{
|
{
|
||||||
throw new Exception('Value must be an integer.');
|
throw new Exception('Value must be an integer.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$increment = $_PUT['value'];
|
$increment = $_REQUEST['value'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis->multi();
|
$this->redis->multi();
|
||||||
|
|
||||||
foreach ($suffixes as $suffix)
|
foreach ($suffixes as $suffix)
|
||||||
{
|
{
|
||||||
$this->redis->zincrby($leaderboard_key . ':' . $suffix, $increment, $_PUT['member']);
|
$this->redis->zincrby($leaderboard_key . ':' . $suffix, $increment, $_REQUEST['member']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$timestamp = time();
|
||||||
|
|
||||||
|
foreach (array('', 'user:' . $this->uid . ':') as $prefix)
|
||||||
|
{
|
||||||
|
$this->redis->zadd($prefix . 'leaderboards:updated', $timestamp, $leaderboard_uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis->exec();
|
$this->redis->exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue