mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
NetworkSession: do not expose setPlayerInfo()
This commit is contained in:
parent
9ba47f90d1
commit
e86c243db5
@ -162,7 +162,11 @@ class NetworkSession{
|
||||
|
||||
$this->connectTime = time();
|
||||
|
||||
$this->setHandler(new LoginPacketHandler($this->server, $this));
|
||||
$this->setHandler(new LoginPacketHandler($this->server, $this, function(PlayerInfo $info) : void{
|
||||
$this->info = $info;
|
||||
$this->logger->info("Player: " . TextFormat::AQUA . $info->getUsername() . TextFormat::RESET);
|
||||
$this->logger->setPrefix($this->getLogPrefix());
|
||||
}));
|
||||
|
||||
$this->manager->add($this);
|
||||
$this->logger->info("Session opened");
|
||||
@ -204,20 +208,6 @@ class NetworkSession{
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: this shouldn't be accessible after the initial login phase
|
||||
*
|
||||
* @throws \InvalidStateException
|
||||
*/
|
||||
public function setPlayerInfo(PlayerInfo $info) : void{
|
||||
if($this->info !== null){
|
||||
throw new \InvalidStateException("Player info has already been set");
|
||||
}
|
||||
$this->info = $info;
|
||||
$this->logger->info("Player: " . TextFormat::AQUA . $info->getUsername() . TextFormat::RESET);
|
||||
$this->logger->setPrefix($this->getLogPrefix());
|
||||
}
|
||||
|
||||
public function isConnected() : bool{
|
||||
return $this->connected;
|
||||
}
|
||||
|
@ -50,10 +50,19 @@ class LoginPacketHandler extends PacketHandler{
|
||||
private $server;
|
||||
/** @var NetworkSession */
|
||||
private $session;
|
||||
/**
|
||||
* @var \Closure
|
||||
* @phpstan-var \Closure(PlayerInfo) : void
|
||||
*/
|
||||
private $playerInfoConsumer;
|
||||
|
||||
public function __construct(Server $server, NetworkSession $session){
|
||||
/**
|
||||
* @phpstan-param \Closure(PlayerInfo) : void $playerInfoConsumer
|
||||
*/
|
||||
public function __construct(Server $server, NetworkSession $session, \Closure $playerInfoConsumer){
|
||||
$this->session = $session;
|
||||
$this->server = $server;
|
||||
$this->playerInfoConsumer = $playerInfoConsumer;
|
||||
}
|
||||
|
||||
public function handleLogin(LoginPacket $packet) : bool{
|
||||
@ -117,7 +126,7 @@ class LoginPacketHandler extends PacketHandler{
|
||||
}catch(\InvalidArgumentException $e){
|
||||
throw BadPacketException::wrap($e, "Failed to parse login UUID");
|
||||
}
|
||||
$this->session->setPlayerInfo(new PlayerInfo(
|
||||
($this->playerInfoConsumer)(new PlayerInfo(
|
||||
$packet->extraData->displayName,
|
||||
$uuid,
|
||||
$skin,
|
||||
|
Loading…
x
Reference in New Issue
Block a user