mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 21:59:52 +00:00
Move some things out of LoginPacket and into the handler
This commit is contained in:
parent
3902a3c28c
commit
0a891f5408
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\network\mcpe\handler;
|
namespace pocketmine\network\mcpe\handler;
|
||||||
|
|
||||||
|
use pocketmine\entity\Skin;
|
||||||
use pocketmine\event\player\PlayerPreLoginEvent;
|
use pocketmine\event\player\PlayerPreLoginEvent;
|
||||||
use pocketmine\network\mcpe\NetworkCipher;
|
use pocketmine\network\mcpe\NetworkCipher;
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
@ -31,7 +32,10 @@ use pocketmine\network\mcpe\protocol\LoginPacket;
|
|||||||
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
|
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
|
||||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\PlayerInfo;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
|
use pocketmine\utils\UUID;
|
||||||
|
use function base64_decode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the initial login phase of the session. This handler is used as the initial state.
|
* Handles the initial login phase of the session. This handler is used as the initial state.
|
||||||
@ -50,8 +54,6 @@ class LoginSessionHandler extends SessionHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handleLogin(LoginPacket $packet) : bool{
|
public function handleLogin(LoginPacket $packet) : bool{
|
||||||
$this->session->setPlayerInfo($packet->playerInfo);
|
|
||||||
|
|
||||||
if(!$this->isCompatibleProtocol($packet->protocol)){
|
if(!$this->isCompatibleProtocol($packet->protocol)){
|
||||||
$pk = new PlayStatusPacket();
|
$pk = new PlayStatusPacket();
|
||||||
$pk->status = $packet->protocol < ProtocolInfo::CURRENT_PROTOCOL ?
|
$pk->status = $packet->protocol < ProtocolInfo::CURRENT_PROTOCOL ?
|
||||||
@ -67,20 +69,36 @@ class LoginSessionHandler extends SessionHandler{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Player::isValidUserName($packet->playerInfo->getUsername())){
|
if(!Player::isValidUserName($packet->extraData[LoginPacket::I_USERNAME])){
|
||||||
$this->session->disconnect("disconnectionScreen.invalidName");
|
$this->session->disconnect("disconnectionScreen.invalidName");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$packet->playerInfo->getSkin()->isValid()){
|
$skin = new Skin(
|
||||||
|
$packet->clientData[LoginPacket::I_SKIN_ID],
|
||||||
|
base64_decode($packet->clientData[LoginPacket::I_SKIN_DATA]),
|
||||||
|
base64_decode($packet->clientData[LoginPacket::I_CAPE_DATA]),
|
||||||
|
$packet->clientData[LoginPacket::I_GEOMETRY_NAME],
|
||||||
|
base64_decode($packet->clientData[LoginPacket::I_GEOMETRY_DATA])
|
||||||
|
);
|
||||||
|
if(!$skin->isValid()){
|
||||||
$this->session->disconnect("disconnectionScreen.invalidSkin");
|
$this->session->disconnect("disconnectionScreen.invalidSkin");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->session->setPlayerInfo(new PlayerInfo(
|
||||||
|
$packet->extraData[LoginPacket::I_USERNAME],
|
||||||
|
UUID::fromString($packet->extraData[LoginPacket::I_UUID]),
|
||||||
|
$skin,
|
||||||
|
$packet->clientData[LoginPacket::I_LANGUAGE_CODE],
|
||||||
|
$packet->extraData[LoginPacket::I_XUID],
|
||||||
|
$packet->clientData[LoginPacket::I_CLIENT_RANDOM_ID]
|
||||||
|
));
|
||||||
|
|
||||||
$ev = new PlayerPreLoginEvent(
|
$ev = new PlayerPreLoginEvent(
|
||||||
$packet->playerInfo,
|
$this->session->getPlayerInfo(),
|
||||||
$this->session->getIp(),
|
$this->session->getIp(),
|
||||||
$this->session->getPort(),
|
$this->session->getPort(),
|
||||||
$this->server->requiresAuthentication()
|
$this->server->requiresAuthentication()
|
||||||
@ -88,10 +106,10 @@ class LoginSessionHandler extends SessionHandler{
|
|||||||
if($this->server->getNetwork()->getConnectionCount() > $this->server->getMaxPlayers()){
|
if($this->server->getNetwork()->getConnectionCount() > $this->server->getMaxPlayers()){
|
||||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, "disconnectionScreen.serverFull");
|
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_FULL, "disconnectionScreen.serverFull");
|
||||||
}
|
}
|
||||||
if(!$this->server->isWhitelisted($packet->playerInfo->getUsername())){
|
if(!$this->server->isWhitelisted($this->session->getPlayerInfo()->getUsername())){
|
||||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, "Server is whitelisted");
|
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, "Server is whitelisted");
|
||||||
}
|
}
|
||||||
if($this->server->getNameBans()->isBanned($packet->playerInfo->getUsername()) or $this->server->getIPBans()->isBanned($this->session->getIp())){
|
if($this->server->getNameBans()->isBanned($this->session->getPlayerInfo()->getUsername()) or $this->server->getIPBans()->isBanned($this->session->getIp())){
|
||||||
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_BANNED, "You are banned");
|
$ev->setKickReason(PlayerPreLoginEvent::KICK_REASON_BANNED, "You are banned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,16 +27,12 @@ namespace pocketmine\network\mcpe\protocol;
|
|||||||
|
|
||||||
|
|
||||||
use Particle\Validator\Validator;
|
use Particle\Validator\Validator;
|
||||||
use pocketmine\entity\Skin;
|
|
||||||
use pocketmine\network\BadPacketException;
|
use pocketmine\network\BadPacketException;
|
||||||
use pocketmine\network\mcpe\handler\SessionHandler;
|
use pocketmine\network\mcpe\handler\SessionHandler;
|
||||||
use pocketmine\PlayerInfo;
|
|
||||||
use pocketmine\utils\BinaryDataException;
|
use pocketmine\utils\BinaryDataException;
|
||||||
use pocketmine\utils\BinaryStream;
|
use pocketmine\utils\BinaryStream;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\utils\UUID;
|
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
use function base64_decode;
|
|
||||||
use function count;
|
use function count;
|
||||||
use function implode;
|
use function implode;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
@ -65,9 +61,6 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
public $protocol;
|
public $protocol;
|
||||||
|
|
||||||
/** @var PlayerInfo */
|
|
||||||
public $playerInfo;
|
|
||||||
|
|
||||||
/** @var string[] array of encoded JWT */
|
/** @var string[] array of encoded JWT */
|
||||||
public $chainDataJwt = [];
|
public $chainDataJwt = [];
|
||||||
/** @var array|null extraData index of whichever JWT has it */
|
/** @var array|null extraData index of whichever JWT has it */
|
||||||
@ -183,21 +176,6 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
|
|||||||
self::validate($v, 'clientData', $clientData);
|
self::validate($v, 'clientData', $clientData);
|
||||||
|
|
||||||
$this->clientData = $clientData;
|
$this->clientData = $clientData;
|
||||||
|
|
||||||
$this->playerInfo = new PlayerInfo(
|
|
||||||
$this->extraData[self::I_USERNAME],
|
|
||||||
UUID::fromString($this->extraData[self::I_UUID]),
|
|
||||||
new Skin(
|
|
||||||
$this->clientData[self::I_SKIN_ID],
|
|
||||||
base64_decode($this->clientData[self::I_SKIN_DATA]),
|
|
||||||
base64_decode($this->clientData[self::I_CAPE_DATA]),
|
|
||||||
$this->clientData[self::I_GEOMETRY_NAME],
|
|
||||||
base64_decode($this->clientData[self::I_GEOMETRY_DATA])
|
|
||||||
),
|
|
||||||
$this->clientData[self::I_LANGUAGE_CODE],
|
|
||||||
$this->extraData[self::I_XUID],
|
|
||||||
$this->clientData[self::I_CLIENT_RANDOM_ID]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function encodePayload() : void{
|
protected function encodePayload() : void{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user