Backport usage of SetLocalPlayerAsInitializedPacket to 3.4 (#2558)

This fixes various problems, such as forms not working on PlayerJoinEvent.
This commit is contained in:
Dylan T 2018-12-13 20:07:17 +00:00 committed by GitHub
parent 1d71f5edb3
commit 660d42e8d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -276,7 +276,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var int */ /** @var int */
protected $spawnThreshold; protected $spawnThreshold;
/** @var int */ /** @var int */
protected $chunkLoadCount = 0; protected $spawnChunkLoadCount = 0;
/** @var int */ /** @var int */
protected $chunksPerTick; protected $chunksPerTick;
@ -962,8 +962,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
$this->usedChunks[Level::chunkHash($x, $z)] = true; $this->usedChunks[Level::chunkHash($x, $z)] = true;
$this->chunkLoadCount++;
$this->dataPacket($payload); $this->dataPacket($payload);
if($this->spawned){ if($this->spawned){
@ -974,8 +972,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
if($this->chunkLoadCount >= $this->spawnThreshold and !$this->spawned){ if($this->spawnChunkLoadCount !== -1 and ++$this->spawnChunkLoadCount >= $this->spawnThreshold){
$this->doFirstSpawn(); $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN);
$this->spawnChunkLoadCount = -1;
} }
} }
@ -1013,11 +1012,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
Timings::$playerChunkSendTimer->stopTiming(); Timings::$playerChunkSendTimer->stopTiming();
} }
protected function doFirstSpawn(){ public function doFirstSpawn(){
if($this->spawned){
return; //avoid player spawning twice (this can only happen on 3.x with a custom malicious client)
}
$this->spawned = true; $this->spawned = true;
$this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN);
if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){
PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
} }

View File

@ -58,6 +58,7 @@ use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket; use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
@ -280,4 +281,9 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{
return false; //TODO: GUI stuff return false; //TODO: GUI stuff
} }
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
$this->player->doFirstSpawn();
return true;
}
} }