2016-09-05 20:25:38 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\session\models\protocols;
|
|
|
|
|
|
|
|
class LegacyJoin extends BaseJoin {
|
|
|
|
|
|
|
|
private $user;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2016-09-05 20:25:38 +05:30
|
|
|
private $sessionId;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2016-09-05 20:25:38 +05:30
|
|
|
private $serverId;
|
|
|
|
|
|
|
|
private $accessToken;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2016-09-05 20:25:38 +05:30
|
|
|
private $uuid;
|
|
|
|
|
|
|
|
public function __construct(string $user, string $sessionId, string $serverId) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$this->user = trim($user);
|
|
|
|
$this->sessionId = trim($sessionId);
|
|
|
|
$this->serverId = trim($serverId);
|
2016-09-05 20:25:38 +05:30
|
|
|
|
|
|
|
$this->parseSessionId($this->sessionId);
|
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function getAccessToken(): string {
|
2016-09-05 20:25:38 +05:30
|
|
|
return $this->accessToken;
|
|
|
|
}
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function getSelectedProfile(): string {
|
2016-09-05 20:25:38 +05:30
|
|
|
return $this->uuid ?: $this->user;
|
|
|
|
}
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function getServerId(): string {
|
2016-09-05 20:25:38 +05:30
|
|
|
return $this->serverId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-09-19 22:36:16 +05:30
|
|
|
public function validate(): bool {
|
|
|
|
return !$this->isEmpty($this->accessToken) && !$this->isEmpty($this->user) && !$this->isEmpty($this->serverId);
|
2016-09-05 20:25:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-15 04:29:56 +05:30
|
|
|
* The method initializes field values to meet the general naming conventions in the project
|
2016-09-05 20:25:38 +05:30
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Split by ':' to take into account authorization in modern launchers and login to an legacy version of the game.
|
|
|
|
* The sessionId is passed on as "token:{accessToken}:{uuid}", so it needs to be processed
|
2016-09-05 20:25:38 +05:30
|
|
|
*/
|
2017-09-19 22:36:16 +05:30
|
|
|
private function parseSessionId(string $sessionId) {
|
2016-09-05 20:25:38 +05:30
|
|
|
$parts = explode(':', $sessionId);
|
|
|
|
if (count($parts) === 3) {
|
|
|
|
$this->accessToken = $parts[1];
|
|
|
|
$this->uuid = $parts[2];
|
|
|
|
} else {
|
|
|
|
$this->accessToken = $this->sessionId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|