accounts/api/modules/session/models/protocols/LegacyJoin.php

60 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace api\modules\session\models\protocols;
class LegacyJoin extends BaseJoin {
private $user;
2018-04-18 02:17:25 +05:30
private $sessionId;
2018-04-18 02:17:25 +05:30
private $serverId;
private $accessToken;
2018-04-18 02:17:25 +05:30
private $uuid;
public function __construct(string $user, string $sessionId, string $serverId) {
$this->user = trim($user);
$this->sessionId = trim($sessionId);
$this->serverId = trim($serverId);
$this->parseSessionId($this->sessionId);
}
2018-04-18 02:17:25 +05:30
public function getAccessToken(): string {
return $this->accessToken;
}
public function getSelectedProfile(): string {
return $this->uuid ?: $this->user;
}
public function getServerId(): string {
return $this->serverId;
}
/**
* @return bool
*/
public function validate(): bool {
return !$this->isEmpty($this->accessToken) && !$this->isEmpty($this->user) && !$this->isEmpty($this->serverId);
}
/**
* The method initializes field values to meet the general naming conventions in the project
*
* 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
*/
private function parseSessionId(string $sessionId) {
$parts = explode(':', $sessionId);
if (count($parts) === 3) {
$this->accessToken = $parts[1];
$this->uuid = $parts[2];
} else {
$this->accessToken = $this->sessionId;
}
}
}