2023-01-15 21:47:19 +00:00
|
|
|
<?php
|
|
|
|
|
2023-01-18 11:43:45 +00:00
|
|
|
use DarksLight2\Training\Steps\ChatFirstStep;
|
|
|
|
use DarksLight2\Training\Steps\MyUserFirstQuest;
|
|
|
|
use DarksLight2\Training\TrainingException;
|
2023-01-15 21:47:19 +00:00
|
|
|
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)) {
|
|
|
|
|
2023-01-18 11:43:45 +00:00
|
|
|
$training = TrainingManager::getInstance($user->info['id'], false);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$training->createDatabaseRecord();
|
|
|
|
$training->register([
|
|
|
|
new MyUserFirstQuest(),
|
|
|
|
new ChatFirstStep()
|
|
|
|
]);
|
|
|
|
} catch (TrainingException $e) {
|
|
|
|
}
|
2023-01-15 21:47:19 +00:00
|
|
|
|
|
|
|
if (!isset($data->token) || !password_verify(
|
2023-01-18 11:43:45 +00:00
|
|
|
$training->getDatabaseData()->api_token . $data->time . $user->info['id'],
|
2023-01-15 21:47:19 +00:00
|
|
|
$data->token
|
|
|
|
)) {
|
|
|
|
http_response_code(401);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_GET['get'])) {
|
|
|
|
switch ($_GET['get']) {
|
|
|
|
default:
|
|
|
|
http_response_code(400);
|
|
|
|
die;
|
|
|
|
case 'complete':
|
2023-01-18 11:43:45 +00:00
|
|
|
if ($training->getDatabaseData()['data'][$training->getCurrentStepName()]['completed']) {
|
2023-01-15 21:47:19 +00:00
|
|
|
http_response_code(400);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2023-01-18 11:43:45 +00:00
|
|
|
if($training->getRegistered()[$data->short_name]->isInfo()) {
|
|
|
|
|
|
|
|
$training->addPoint($training->getCurrentStepName());
|
|
|
|
}
|
|
|
|
|
2023-01-15 21:47:19 +00:00
|
|
|
$training->nextStep();
|
2023-01-18 11:43:45 +00:00
|
|
|
|
2023-01-15 21:47:19 +00:00
|
|
|
$training->store();
|
|
|
|
|
|
|
|
die(json_encode(['status' => 'ok']));
|
2023-01-18 11:43:45 +00:00
|
|
|
|
|
|
|
case 'go_back':
|
|
|
|
$training->previousStep();
|
|
|
|
$training->store();
|
|
|
|
die(json_encode(['status' => 'ok', 'message' => 'Вы указал не верный ответ!']));
|
|
|
|
|
2023-01-15 21:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|