2016-09-05 20:25:38 +05:30
|
|
|
<?php
|
|
|
|
namespace api\modules\session\models\protocols;
|
|
|
|
|
|
|
|
class LegacyJoin extends BaseJoin {
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private readonly string $user;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private string $sessionId;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private readonly string $serverId;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
|
|
|
private $accessToken;
|
2018-04-18 02:17:25 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private ?string $uuid = null;
|
2016-09-05 20:25:38 +05:30
|
|
|
|
|
|
|
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
|
|
|
*/
|
2024-12-02 15:40:55 +05:30
|
|
|
private function parseSessionId(string $sessionId): void {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|