mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Merge remote-tracking branch 'origin/next-minor' into next-major
This commit is contained in:
@ -424,6 +424,9 @@ class NetworkSession{
|
||||
}
|
||||
|
||||
public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{
|
||||
if(!$this->connected){
|
||||
return false;
|
||||
}
|
||||
//Basic safety restriction. TODO: improve this
|
||||
if(!$this->loggedIn && !$packet->canBeSentBeforeLogin()){
|
||||
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getDisplayName() . " too early");
|
||||
@ -544,28 +547,37 @@ class NetworkSession{
|
||||
$this->disconnectGuard = true;
|
||||
$func();
|
||||
$this->disconnectGuard = false;
|
||||
$this->flushSendBuffer(true);
|
||||
$this->sender->close("");
|
||||
foreach($this->disposeHooks as $callback){
|
||||
$callback();
|
||||
}
|
||||
$this->disposeHooks->clear();
|
||||
$this->setHandler(null);
|
||||
$this->connected = false;
|
||||
$this->manager->remove($this);
|
||||
$this->logger->info("Session closed due to $reason");
|
||||
|
||||
$this->invManager = null; //break cycles - TODO: this really ought to be deferred until it's safe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs actions after the session has been disconnected. By this point, nothing should be interacting with the
|
||||
* session, so it's safe to destroy any cycles and perform destructive cleanup.
|
||||
*/
|
||||
private function dispose() : void{
|
||||
$this->invManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the session, destroying the associated player (if it exists).
|
||||
*/
|
||||
public function disconnect(string $reason, bool $notify = true) : void{
|
||||
$this->tryDisconnect(function() use ($reason, $notify) : void{
|
||||
if($notify){
|
||||
$this->sendDataPacket(DisconnectPacket::create($reason));
|
||||
}
|
||||
if($this->player !== null){
|
||||
$this->player->onPostDisconnect($reason, null);
|
||||
}
|
||||
$this->doServerDisconnect($reason, $notify);
|
||||
}, $reason);
|
||||
}
|
||||
|
||||
@ -578,7 +590,6 @@ class NetworkSession{
|
||||
if($this->player !== null){
|
||||
$this->player->onPostDisconnect($reason, null);
|
||||
}
|
||||
$this->doServerDisconnect($reason, false);
|
||||
}, $reason);
|
||||
}
|
||||
|
||||
@ -587,21 +598,10 @@ class NetworkSession{
|
||||
*/
|
||||
public function onPlayerDestroyed(string $reason) : void{
|
||||
$this->tryDisconnect(function() use ($reason) : void{
|
||||
$this->doServerDisconnect($reason, true);
|
||||
$this->sendDataPacket(DisconnectPacket::create($reason));
|
||||
}, $reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper function used to handle server disconnections.
|
||||
*/
|
||||
private function doServerDisconnect(string $reason, bool $notify = true) : void{
|
||||
if($notify){
|
||||
$this->sendDataPacket(DisconnectPacket::create($reason !== "" ? $reason : null), true);
|
||||
}
|
||||
|
||||
$this->sender->close($notify ? $reason : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the network interface to close the session when the client disconnects without server input, for
|
||||
* example in a timeout condition or voluntary client disconnect.
|
||||
@ -1117,6 +1117,11 @@ class NetworkSession{
|
||||
}
|
||||
|
||||
public function tick() : void{
|
||||
if(!$this->isConnected()){
|
||||
$this->dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->info === null){
|
||||
if(time() >= $this->connectTime + 10){
|
||||
$this->disconnect("Login timeout");
|
||||
|
6
src/network/mcpe/cache/StaticPacketCache.php
vendored
6
src/network/mcpe/cache/StaticPacketCache.php
vendored
@ -27,9 +27,9 @@ use pocketmine\network\mcpe\protocol\AvailableActorIdentifiersPacket;
|
||||
use pocketmine\network\mcpe\protocol\BiomeDefinitionListPacket;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function file_get_contents;
|
||||
|
||||
class StaticPacketCache{
|
||||
use SingletonTrait;
|
||||
@ -38,9 +38,7 @@ class StaticPacketCache{
|
||||
* @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag>
|
||||
*/
|
||||
private static function loadCompoundFromFile(string $filePath) : CacheableNbt{
|
||||
$rawNbt = @file_get_contents($filePath);
|
||||
if($rawNbt === false) throw new \RuntimeException("Failed to read file");
|
||||
return new CacheableNbt((new NetworkNbtSerializer())->read($rawNbt)->mustGetCompoundTag());
|
||||
return new CacheableNbt((new NetworkNbtSerializer())->read(Filesystem::fileGetContents($filePath))->mustGetCompoundTag());
|
||||
}
|
||||
|
||||
private static function make() : self{
|
||||
|
@ -24,16 +24,15 @@ declare(strict_types=1);
|
||||
namespace pocketmine\network\mcpe\convert;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\serializer\ItemTypeDictionary;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use pocketmine\utils\Utils;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function file_get_contents;
|
||||
|
||||
final class GlobalItemTypeDictionary{
|
||||
use SingletonTrait;
|
||||
|
||||
private static function make() : self{
|
||||
$data = Utils::assumeNotFalse(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'required_item_list.json')), "Missing required resource file");
|
||||
$data = Filesystem::fileGetContents(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'required_item_list.json'));
|
||||
$dictionary = ItemTypeDictionaryFromDataHelper::loadFromString($data);
|
||||
return new self($dictionary);
|
||||
}
|
||||
|
@ -28,11 +28,10 @@ use pocketmine\data\bedrock\block\BlockStateSerializeException;
|
||||
use pocketmine\data\bedrock\block\BlockStateSerializer;
|
||||
use pocketmine\data\bedrock\block\BlockTypeNames;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\world\format\io\GlobalBlockStateHandlers;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
use function file_get_contents;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -51,11 +50,8 @@ final class RuntimeBlockMapping{
|
||||
private int $fallbackStateId;
|
||||
|
||||
private static function make() : self{
|
||||
$canonicalBlockStatesFile = Path::join(\pocketmine\BEDROCK_DATA_PATH, "canonical_block_states.nbt");
|
||||
$canonicalBlockStatesRaw = Utils::assumeNotFalse(file_get_contents($canonicalBlockStatesFile), "Missing required resource file");
|
||||
|
||||
$metaMappingFile = Path::join(\pocketmine\BEDROCK_DATA_PATH, 'block_state_meta_map.json');
|
||||
$metaMappingRaw = Utils::assumeNotFalse(file_get_contents($metaMappingFile), "Missing required resource file");
|
||||
$canonicalBlockStatesRaw = Filesystem::fileGetContents(Path::join(\pocketmine\BEDROCK_DATA_PATH, "canonical_block_states.nbt"));
|
||||
$metaMappingRaw = Filesystem::fileGetContents(Path::join(\pocketmine\BEDROCK_DATA_PATH, 'block_state_meta_map.json'));
|
||||
return new self(
|
||||
BlockStateDictionary::loadFromString($canonicalBlockStatesRaw, $metaMappingRaw),
|
||||
GlobalBlockStateHandlers::getSerializer()
|
||||
|
Reference in New Issue
Block a user