mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Move too-early-send check to NetworkSession
This commit is contained in:
parent
26a5d97499
commit
ebfe9caca3
@ -2506,11 +2506,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Basic safety restriction. TODO: improve this
|
|
||||||
if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){
|
|
||||||
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->networkSession->sendDataPacket($packet, $immediate);
|
return $this->networkSession->sendDataPacket($packet, $immediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ use pocketmine\Server;
|
|||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\BinaryDataException;
|
use pocketmine\utils\BinaryDataException;
|
||||||
use function bin2hex;
|
use function bin2hex;
|
||||||
|
use function get_class;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
use function substr;
|
use function substr;
|
||||||
use function time;
|
use function time;
|
||||||
@ -76,6 +77,8 @@ class NetworkSession{
|
|||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $connected = true;
|
private $connected = true;
|
||||||
|
/** @var bool */
|
||||||
|
private $loggedIn = false;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $connectTime;
|
private $connectTime;
|
||||||
|
|
||||||
@ -276,6 +279,11 @@ class NetworkSession{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{
|
public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{
|
||||||
|
//Basic safety restriction. TODO: improve this
|
||||||
|
if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){
|
||||||
|
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getDisplayName() . " too early");
|
||||||
|
}
|
||||||
|
|
||||||
$timings = Timings::getSendDataPacketTimings($packet);
|
$timings = Timings::getSendDataPacketTimings($packet);
|
||||||
$timings->startTiming();
|
$timings->startTiming();
|
||||||
try{
|
try{
|
||||||
@ -435,6 +443,8 @@ class NetworkSession{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onLoginSuccess() : void{
|
public function onLoginSuccess() : void{
|
||||||
|
$this->loggedIn = true;
|
||||||
|
|
||||||
$pk = new PlayStatusPacket();
|
$pk = new PlayStatusPacket();
|
||||||
$pk->status = PlayStatusPacket::LOGIN_SUCCESS;
|
$pk->status = PlayStatusPacket::LOGIN_SUCCESS;
|
||||||
$this->sendDataPacket($pk);
|
$this->sendDataPacket($pk);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user