2016-09-03 04:24:22 +05:30
|
|
|
|
<?php
|
|
|
|
|
namespace api\modules\session\controllers;
|
|
|
|
|
|
|
|
|
|
use api\controllers\ApiController;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
use api\modules\session\exceptions\ForbiddenOperationException;
|
|
|
|
|
use api\modules\session\exceptions\SessionServerException;
|
2016-09-06 15:26:39 +05:30
|
|
|
|
use api\modules\session\models\HasJoinedForm;
|
2016-09-03 04:24:22 +05:30
|
|
|
|
use api\modules\session\models\JoinForm;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
use api\modules\session\models\protocols\LegacyJoin;
|
2016-09-06 15:26:39 +05:30
|
|
|
|
use api\modules\session\models\protocols\ModernHasJoined;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
use api\modules\session\models\protocols\ModernJoin;
|
2016-09-06 15:26:39 +05:30
|
|
|
|
use common\models\Textures;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
use Yii;
|
|
|
|
|
use yii\web\Response;
|
2016-09-03 04:24:22 +05:30
|
|
|
|
|
|
|
|
|
class SessionController extends ApiController {
|
|
|
|
|
|
|
|
|
|
public function behaviors() {
|
|
|
|
|
$behaviors = parent::behaviors();
|
|
|
|
|
unset($behaviors['authenticator']);
|
|
|
|
|
|
|
|
|
|
return $behaviors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionJoin() {
|
2016-09-05 20:25:38 +05:30
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
|
|
|
|
|
|
|
$data = Yii::$app->request->post();
|
|
|
|
|
if (empty($data)) {
|
|
|
|
|
// TODO: помнится у Yii2 есть механизм парсинга данных входящего запроса. Лучше будет сделать это там
|
|
|
|
|
$data = json_decode(Yii::$app->request->getRawBody(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$protocol = new ModernJoin($data['accessToken'] ?? '', $data['selectedProfile'] ?? '', $data['serverId'] ?? '');
|
|
|
|
|
$joinForm = new JoinForm($protocol);
|
2016-09-03 04:24:22 +05:30
|
|
|
|
$joinForm->join();
|
|
|
|
|
|
|
|
|
|
return ['id' => 'OK'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionJoinLegacy() {
|
2016-09-05 20:25:38 +05:30
|
|
|
|
Yii::$app->response->format = Response::FORMAT_RAW;
|
|
|
|
|
|
|
|
|
|
$data = Yii::$app->request->get();
|
|
|
|
|
$protocol = new LegacyJoin($data['user'] ?? '', $data['sessionId'] ?? '', $data['serverId'] ?? '');
|
|
|
|
|
$joinForm = new JoinForm($protocol);
|
|
|
|
|
try {
|
|
|
|
|
$joinForm->join();
|
|
|
|
|
} catch (SessionServerException $e) {
|
|
|
|
|
Yii::$app->response->statusCode = $e->statusCode;
|
|
|
|
|
if ($e instanceof ForbiddenOperationException) {
|
|
|
|
|
$message = 'Ely.by authorization required';
|
|
|
|
|
} else {
|
|
|
|
|
$message = $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'OK';
|
2016-09-03 04:24:22 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 15:26:39 +05:30
|
|
|
|
public function actionHasJoined() {
|
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
|
|
|
|
|
|
|
$data = Yii::$app->request->get();
|
|
|
|
|
$protocol = new ModernHasJoined($data['username'] ?? '', $data['serverId'] ?? '');
|
|
|
|
|
$hasJoinedForm = new HasJoinedForm($protocol);
|
|
|
|
|
$account = $hasJoinedForm->hasJoined();
|
|
|
|
|
$textures = new Textures($account);
|
|
|
|
|
|
|
|
|
|
return $textures->getMinecraftResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function actionHasJoinedLegacy() {
|
|
|
|
|
Yii::$app->response->format = Response::FORMAT_RAW;
|
|
|
|
|
|
|
|
|
|
$data = Yii::$app->request->get();
|
|
|
|
|
$protocol = new ModernHasJoined($data['user'] ?? '', $data['serverId'] ?? '');
|
|
|
|
|
$hasJoinedForm = new HasJoinedForm($protocol);
|
|
|
|
|
try {
|
|
|
|
|
$hasJoinedForm->hasJoined();
|
|
|
|
|
} catch (SessionServerException $e) {
|
|
|
|
|
Yii::$app->response->statusCode = $e->statusCode;
|
|
|
|
|
if ($e instanceof ForbiddenOperationException) {
|
|
|
|
|
$message = 'NO';
|
|
|
|
|
} else {
|
|
|
|
|
$message = $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'YES';
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-03 04:24:22 +05:30
|
|
|
|
}
|