mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
remove NullPacketHandler
this is a waste of LOC
This commit is contained in:
parent
b6214744d5
commit
549940d8a7
@ -46,7 +46,6 @@ use pocketmine\network\mcpe\handler\DeathPacketHandler;
|
||||
use pocketmine\network\mcpe\handler\HandshakePacketHandler;
|
||||
use pocketmine\network\mcpe\handler\InGamePacketHandler;
|
||||
use pocketmine\network\mcpe\handler\LoginPacketHandler;
|
||||
use pocketmine\network\mcpe\handler\NullPacketHandler;
|
||||
use pocketmine\network\mcpe\handler\PacketHandler;
|
||||
use pocketmine\network\mcpe\handler\PreSpawnPacketHandler;
|
||||
use pocketmine\network\mcpe\handler\ResourcePacksPacketHandler;
|
||||
@ -126,8 +125,8 @@ class NetworkSession{
|
||||
/** @var int|null */
|
||||
private $ping = null;
|
||||
|
||||
/** @var PacketHandler */
|
||||
private $handler;
|
||||
/** @var PacketHandler|null */
|
||||
private $handler = null;
|
||||
|
||||
/** @var bool */
|
||||
private $connected = true;
|
||||
@ -258,14 +257,16 @@ class NetworkSession{
|
||||
$this->ping = $ping;
|
||||
}
|
||||
|
||||
public function getHandler() : PacketHandler{
|
||||
public function getHandler() : ?PacketHandler{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
public function setHandler(PacketHandler $handler) : void{
|
||||
public function setHandler(?PacketHandler $handler) : void{
|
||||
if($this->connected){ //TODO: this is fine since we can't handle anything from a disconnected session, but it might produce surprises in some cases
|
||||
$this->handler = $handler;
|
||||
$this->handler->setUp();
|
||||
if($this->handler !== null){
|
||||
$this->handler->setUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +351,7 @@ class NetworkSession{
|
||||
|
||||
$ev = new DataPacketReceiveEvent($this, $packet);
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled() and !$packet->handle($this->handler)){
|
||||
if(!$ev->isCancelled() and ($this->handler === null or !$packet->handle($this->handler))){
|
||||
$this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($stream->getBuffer()));
|
||||
}
|
||||
}finally{
|
||||
@ -459,7 +460,7 @@ class NetworkSession{
|
||||
$this->disconnectGuard = true;
|
||||
$func();
|
||||
$this->disconnectGuard = false;
|
||||
$this->setHandler(NullPacketHandler::getInstance());
|
||||
$this->setHandler(null);
|
||||
$this->connected = false;
|
||||
$this->manager->remove($this);
|
||||
$this->logger->info("Session closed due to $reason");
|
||||
|
@ -195,7 +195,7 @@ class LoginPacketHandler extends PacketHandler{
|
||||
*/
|
||||
protected function processLogin(LoginPacket $packet, bool $authRequired) : void{
|
||||
$this->server->getAsyncPool()->submitTask(new ProcessLoginTask($packet, $authRequired, $this->authCallback));
|
||||
$this->session->setHandler(NullPacketHandler::getInstance()); //drop packets received during login verification
|
||||
$this->session->setHandler(null); //drop packets received during login verification
|
||||
}
|
||||
|
||||
protected function isCompatibleProtocol(int $protocolVersion) : bool{
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Handler which simply ignores all packets received.
|
||||
*/
|
||||
final class NullPacketHandler extends PacketHandler{
|
||||
/** @var self|null */
|
||||
private static $instance = null;
|
||||
|
||||
public static function getInstance() : self{
|
||||
return self::$instance ?? (self::$instance = new self);
|
||||
}
|
||||
|
||||
private function __construct(){
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user