mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-10 13:35:29 +00:00
77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\network\mcpe\handler;
|
|
|
|
use pocketmine\lang\KnownTranslationFactory;
|
|
use pocketmine\network\mcpe\NetworkSession;
|
|
use pocketmine\network\mcpe\protocol\NetworkSettingsPacket;
|
|
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
|
|
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
|
use pocketmine\network\mcpe\protocol\RequestNetworkSettingsPacket;
|
|
use pocketmine\network\mcpe\protocol\types\CompressionAlgorithm;
|
|
use pocketmine\Server;
|
|
|
|
final class SessionStartPacketHandler extends PacketHandler{
|
|
|
|
/**
|
|
* @phpstan-param \Closure() : void $onSuccess
|
|
*/
|
|
public function __construct(
|
|
private Server $server,
|
|
private NetworkSession $session,
|
|
private \Closure $onSuccess
|
|
){}
|
|
|
|
public function handleRequestNetworkSettings(RequestNetworkSettingsPacket $packet) : bool{
|
|
$protocolVersion = $packet->getProtocolVersion();
|
|
if(!$this->isCompatibleProtocol($protocolVersion)){
|
|
$this->session->sendDataPacket(PlayStatusPacket::create($protocolVersion < ProtocolInfo::CURRENT_PROTOCOL ? PlayStatusPacket::LOGIN_FAILED_CLIENT : PlayStatusPacket::LOGIN_FAILED_SERVER), true);
|
|
|
|
//This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client)
|
|
$this->session->disconnect(
|
|
$this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_disconnect_incompatibleProtocol((string) $protocolVersion)),
|
|
false
|
|
);
|
|
|
|
return true;
|
|
}
|
|
|
|
//TODO: we're filling in the defaults to get pre-1.19.30 behaviour back for now, but we should explore the new options in the future
|
|
$this->session->sendDataPacket(NetworkSettingsPacket::create(
|
|
NetworkSettingsPacket::COMPRESS_EVERYTHING,
|
|
CompressionAlgorithm::ZLIB,
|
|
false,
|
|
0,
|
|
0
|
|
));
|
|
($this->onSuccess)();
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function isCompatibleProtocol(int $protocolVersion) : bool{
|
|
return $protocolVersion === ProtocolInfo::CURRENT_PROTOCOL;
|
|
}
|
|
}
|