mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-27 21:25:41 +00:00
Cleaned up PlayerList handling
This commit is contained in:
parent
e5e76d4c93
commit
e0307411da
@ -82,6 +82,7 @@ use pocketmine\network\mcpe\protocol\BatchPacket;
|
||||
use pocketmine\network\mcpe\protocol\DataPacket;
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\network\mcpe\RakLibInterface;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\network\query\QueryHandler;
|
||||
@ -2252,32 +2253,45 @@ class Server{
|
||||
if(isset($this->playerList[$player->getRawUniqueId()])){
|
||||
unset($this->playerList[$player->getRawUniqueId()]);
|
||||
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries[] = [$player->getUniqueId()];
|
||||
$this->broadcastPacket($this->playerList, $pk);
|
||||
$this->removePlayerListData($player->getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinId, $skinData, array $players = null){
|
||||
/**
|
||||
* @param UUID $uuid
|
||||
* @param int $entityId
|
||||
* @param string $name
|
||||
* @param string $skinId
|
||||
* @param string $skinData
|
||||
* @param Player[]|null $players
|
||||
*/
|
||||
public function updatePlayerListData(UUID $uuid, int $entityId, string $name, string $skinId, string $skinData, array $players = null){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
$pk->entries[] = [$uuid, $entityId, $name, $skinId, $skinData];
|
||||
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($uuid, $entityId, $name, $skinId, $skinData);
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $uuid
|
||||
* @param Player[]|null $players
|
||||
*/
|
||||
public function removePlayerListData(UUID $uuid, array $players = null){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries[] = [$uuid];
|
||||
$pk->entries[] = PlayerListEntry::createRemovalEntry($uuid);
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $p
|
||||
*/
|
||||
public function sendFullPlayerListData(Player $p){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
foreach($this->playerList as $player){
|
||||
$pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData()];
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData());
|
||||
}
|
||||
|
||||
$p->dataPacket($pk);
|
||||
|
@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
|
||||
class PlayerListPacket extends DataPacket{
|
||||
const NETWORK_ID = ProtocolInfo::PLAYER_LIST_PACKET;
|
||||
@ -34,8 +35,7 @@ class PlayerListPacket extends DataPacket{
|
||||
const TYPE_ADD = 0;
|
||||
const TYPE_REMOVE = 1;
|
||||
|
||||
//REMOVE: UUID, ADD: UUID, entity id, name, skinId, skin, geometric model, geometry data
|
||||
/** @var array[] */
|
||||
/** @var PlayerListEntry[] */
|
||||
public $entries = [];
|
||||
/** @var int */
|
||||
public $type;
|
||||
@ -49,39 +49,42 @@ class PlayerListPacket extends DataPacket{
|
||||
$this->type = $this->getByte();
|
||||
$count = $this->getUnsignedVarInt();
|
||||
for($i = 0; $i < $count; ++$i){
|
||||
$this->entries[$i] = [];
|
||||
$entry = new PlayerListEntry();
|
||||
|
||||
if($this->type === self::TYPE_ADD){
|
||||
$this->entries[$i][0] = $this->getUUID();
|
||||
$this->entries[$i][1] = $this->getEntityUniqueId();
|
||||
$this->entries[$i][2] = $this->getString(); //name
|
||||
$this->entries[$i][3] = $this->getString(); //skin id
|
||||
$this->entries[$i][4] = $this->getString(); //skin data
|
||||
$this->entries[$i][5] = $this->getString(); //cape data
|
||||
$this->entries[$i][6] = $this->getString(); //geometric model
|
||||
$this->entries[$i][7] = $this->getString(); //geometry data (json)
|
||||
$this->entries[$i][8] = $this->getString(); //???
|
||||
$entry->uuid = $this->getUUID();
|
||||
$entry->entityUniqueId = $this->getEntityUniqueId();
|
||||
$entry->username = $this->getString();
|
||||
$entry->skinId = $this->getString();
|
||||
$entry->skinData = $this->getString();
|
||||
$entry->capeData = $this->getString();
|
||||
$entry->geometryModel = $this->getString();
|
||||
$entry->geometryData = $this->getString();
|
||||
$entry->xboxUserId = $this->getString();
|
||||
}else{
|
||||
$this->entries[$i][0] = $this->getUUID();
|
||||
$entry->uuid = $this->getUUID();
|
||||
}
|
||||
|
||||
$this->entries[$i] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
protected function encodePayload(){
|
||||
$this->putByte($this->type);
|
||||
$this->putUnsignedVarInt(count($this->entries));
|
||||
foreach($this->entries as $d){
|
||||
foreach($this->entries as $entry){
|
||||
if($this->type === self::TYPE_ADD){
|
||||
$this->putUUID($d[0]);
|
||||
$this->putEntityUniqueId($d[1]);
|
||||
$this->putString($d[2]); //name
|
||||
$this->putString($d[3]); //skin id
|
||||
$this->putString($d[4]); //skin data
|
||||
$this->putString($d[5] ?? ""); //cape data
|
||||
$this->putString($d[6] ?? ""); //geometric model
|
||||
$this->putString($d[7] ?? ""); //geometry data (json)
|
||||
$this->putString($d[8] ?? ""); //???
|
||||
$this->putUUID($entry->uuid);
|
||||
$this->putEntityUniqueId($entry->entityUniqueId);
|
||||
$this->putString($entry->username);
|
||||
$this->putString($entry->skinId);
|
||||
$this->putString($entry->skinData);
|
||||
$this->putString($entry->capeData);
|
||||
$this->putString($entry->geometryModel);
|
||||
$this->putString($entry->geometryData);
|
||||
$this->putString($entry->xboxUserId);
|
||||
}else{
|
||||
$this->putUUID($d[0]);
|
||||
$this->putUUID($entry->uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
<?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\protocol\types;
|
||||
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class PlayerListEntry{
|
||||
|
||||
/** @var UUID */
|
||||
public $uuid;
|
||||
/** @var int */
|
||||
public $entityUniqueId;
|
||||
/** @var string */
|
||||
public $username;
|
||||
/** @var string */
|
||||
public $skinId;
|
||||
/** @var string */
|
||||
public $skinData;
|
||||
/** @var string */
|
||||
public $capeData; //TODO
|
||||
/** @var string */
|
||||
public $geometryModel; //TODO
|
||||
/** @var string */
|
||||
public $geometryData; //TODO
|
||||
/** @var string */
|
||||
public $xboxUserId; //TODO
|
||||
|
||||
public static function createRemovalEntry(UUID $uuid) : PlayerListEntry{
|
||||
$entry = new PlayerListEntry();
|
||||
$entry->uuid = $uuid;
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public static function createAdditionEntry(
|
||||
UUID $uuid,
|
||||
int $entityUniqueId,
|
||||
string $username,
|
||||
string $skinId,
|
||||
string $skinData,
|
||||
string $capeData = "",
|
||||
string $geometryModel = "",
|
||||
string $geometryData = "",
|
||||
string $xboxUserId = ""
|
||||
) : PlayerListEntry{
|
||||
$entry = new PlayerListEntry();
|
||||
$entry->uuid = $uuid;
|
||||
$entry->entityUniqueId = $entityUniqueId;
|
||||
$entry->username = $username;
|
||||
$entry->skinId = $skinId;
|
||||
$entry->skinData = $skinData;
|
||||
$entry->capeData = $capeData;
|
||||
$entry->geometryModel = $geometryModel;
|
||||
$entry->geometryData = $geometryData;
|
||||
$entry->xboxUserId = $xboxUserId;
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user