game/api/index.php

47 lines
1.1 KiB
PHP

<?php
use DarksLight2\Training\TrainingManager;
header('Content-type: application/json');
if (!defined('GAME_VERSION')) {
require_once '../_incl_data/autoload.php';
}
$user = User::start();
if($input = file_get_contents("php://input")) {
$data = json_decode($input);
}
if(!empty($user->info)) {
$training = TrainingManager::getInstance($user->info['id']);
if (!isset($data->token) || !password_verify(
$training->getDatabaseRecords()->api_token . $data->time . $user->info['id'],
$data->token
)) {
http_response_code(401);
die;
}
if (isset($_GET['get'])) {
switch ($_GET['get']) {
default:
http_response_code(400);
die;
case 'complete':
if ($training->{$data->short_name}->isComplete) {
http_response_code(400);
die;
}
$training->addPoint($data->short_name);
$training->nextStep();
$training->store();
die(json_encode(['status' => 'ok']));
}
}
}