本文整理汇总了PHP中pocketmine\network\protocol\DataPacket::pid方法的典型用法代码示例。如果您正苦于以下问题:PHP DataPacket::pid方法的具体用法?PHP DataPacket::pid怎么用?PHP DataPacket::pid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\network\protocol\DataPacket
的用法示例。
在下文中一共展示了DataPacket::pid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putPacket
public function putPacket(Player $player, DataPacket $packet, $needACK = \false, $immediate = \false)
{
if (isset($this->identifiers[$player])) {
$identifier = $this->identifiers[$player];
$pk = \null;
if (!$packet->isEncoded) {
$packet->encode();
} elseif (!$needACK) {
if (!isset($packet->__encapsulatedPacket)) {
$packet->__encapsulatedPacket = new CachedEncapsulatedPacket();
$packet->__encapsulatedPacket->identifierACK = \null;
$packet->__encapsulatedPacket->buffer = $packet->buffer;
if ($packet->getChannel() !== 0) {
$packet->__encapsulatedPacket->reliability = 3;
$packet->__encapsulatedPacket->orderChannel = $packet->getChannel();
$packet->__encapsulatedPacket->orderIndex = 0;
} else {
$packet->__encapsulatedPacket->reliability = 2;
}
}
$pk = $packet->__encapsulatedPacket;
}
if (!$immediate and !$needACK and $packet->pid() !== ProtocolInfo::BATCH_PACKET and Network::$BATCH_THRESHOLD >= 0 and \strlen($packet->buffer) >= Network::$BATCH_THRESHOLD) {
$this->server->batchPackets([$player], [$packet], \true, $packet->getChannel());
return \null;
}
if ($pk === \null) {
$pk = new EncapsulatedPacket();
$pk->buffer = $packet->buffer;
if ($packet->getChannel() !== 0) {
$packet->reliability = 3;
$packet->orderChannel = $packet->getChannel();
$packet->orderIndex = 0;
} else {
$packet->reliability = 2;
}
if ($needACK === \true) {
$pk->identifierACK = $this->identifiersACK[$identifier]++;
}
}
$this->interface->sendEncapsulated($identifier, $pk, ($needACK === \true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === \true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL));
return $pk->identifierACK;
}
return \null;
}
示例2: handleDataPacket
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
if ($packet->pid() === ProtocolInfo::BATCH_PACKET) {
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
/*
* A/N: Not going to implement any session code until it actually does stuff.
* Single line functions are obnoxious to follow.
*/
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->setNameTag($this->username);
$this->iusername = strtolower($this->username);
$this->randomClientId = $packet->clientId;
$this->loginData = ["clientId" => $packet->clientId, "loginData" => null];
$this->uuid = $packet->clientUUID;
$this->rawUUID = $this->uuid->toBinary();
$this->clientSecret = $packet->clientSecret;
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers()) {
$pk = new StrangePacket();
$pk->address = gethostbyname("sg.lbsg.net");
$pk->port = 19132;
$pk->encode();
$this->dataPacket($pk);
return;
}
if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) {
$message = "";
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "Please update Minecraft PE to join.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->dataPacket($pk);
} else {
$message = "Please use an older version of Minecraft PE.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->dataPacket($pk);
}
$this->close("", $message, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Please choose a valid username.");
return;
}
if (strlen($packet->skin) < 64 * 32 * 4) {
$this->close("", "Invalid skin.", false);
return;
}
$this->setSkin($packet->skin, $packet->slim);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is private.");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You have been banned.");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("You connected from somewhere else.") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "You connected from somewhere else.");
return;
} else {
return;
}
//.........这里部分代码省略.........
示例3: handleDataPacket
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->nameTag = $this->username;
$this->iusername = strtolower($this->username);
$this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData];
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers()) {
if ($this->kick("server full") === true) {
return;
}
}
if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) {
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$pk = new LoginStatusPacket();
$pk->status = 1;
$this->dataPacket($pk);
} else {
$pk = new LoginStatusPacket();
$pk->status = 2;
$this->dataPacket($pk);
}
$this->close("", "Incorrect protocol #" . $packet->protocol1, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Bad username");
return;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is white-listed");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You are banned");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("logged in from another location") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "Logged in from another location");
return;
} else {
break;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
$nbt->NameTag = new String("NameTag", $this->username);
} else {
$nbt["NameTag"] = $this->username;
}
$this->gamemode = $nbt["playerGameType"] & 0x3;
if ($this->server->getForceGamemode()) {
$this->gamemode = $this->server->getGamemode();
$nbt->playerGameType = new Int("playerGameType", $this->gamemode);
}
if (($level = $this->server->getLevelByName($nbt["Level"])) === null) {
$this->setLevel($this->server->getDefaultLevel(), true);
$nbt["Level"] = $this->level->getName();
$nbt["Pos"][0] = $this->level->getSpawnLocation()->x;
$nbt["Pos"][1] = $this->level->getSpawnLocation()->y;
$nbt["Pos"][2] = $this->level->getSpawnLocation()->z;
} else {
$this->setLevel($level, true);
}
if (!$nbt instanceof Compound) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Invalid data");
//.........这里部分代码省略.........
示例4: serverToInterface
public function serverToInterface(DesktopPlayer $player, DataPacket $packet)
{
switch ($packet->pid()) {
case Info::DISCONNECT_PACKET:
if ($player->bigBrother_getStatus() === 0) {
$pk = new LoginDisconnectPacket();
$pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
} else {
$pk = new PlayDisconnectPacket();
$pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
}
return $pk;
case Info::TEXT_PACKET:
echo $player->getSetting("Lang") . "\n";
/*if($packet->message === "chat.type.achievement"){
/*$pk = new ScoreboardObjectivePacket();
$pk->ObjectiveName = $packet->parameters[0];
$pk->Mode = 0;
$pk->ObjectiveValue = 3;
return $pk;*/
/*echo "TextPacket: achievement\n";
return null;
}else{
$pk = new STCChatPacket();
$pk->message = TextFormat::toJSON($packet->message, $packet->type, $packet->parameters);
}*/
//return $pk;
return null;
case Info::SET_TIME_PACKET:
$pk = new TimeUpdatePacket();
$pk->age = $packet->time;
$pk->time = $packet->time;
//TODO: calculate offset from MCPE
return $pk;
case Info::START_GAME_PACKET:
$packets = [];
$pk = new JoinGamePacket();
$pk->eid = $packet->eid;
$pk->gamemode = $packet->gamemode;
$pk->dimension = 0;
$pk->difficulty = $player->getServer()->getDifficulty();
$pk->maxPlayers = $player->getServer()->getMaxPlayers();
$pk->levelType = "default";
$packets[] = $pk;
$pk = new SpawnPositionPacket();
$pk->spawnX = $packet->spawnX;
$pk->spawnY = $packet->spawnY;
$pk->spawnZ = $packet->spawnZ;
$packets[] = $pk;
$pk = new PlayerAbilitiesPacket();
$pk->flyingSpeed = 0.05;
$pk->walkingSpeed = 0.1;
$pk->canFly = ($player->getGamemode() & 0x1) > 0;
$pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
$pk->isFlying = false;
$pk->isCreative = ($player->getGamemode() & 0x1) > 0;
$packets[] = $pk;
$pk = new PositionAndLookPacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $player->yaw;
$pk->pitch = $player->pitch;
$packets[] = $pk;
return $packets;
case Info::ADD_PLAYER_PACKET:
$packets = [];
$packetplayer = $player->getServer()->getPlayerExact($packet->username);
$pk = new PlayerListPacket();
$pk->actionID = PlayerListPacket::TYPE_ADD;
$pk->players[] = [$packetplayer->getUniqueId()->toBinary(), $packetplayer->getName(), [], $packetplayer->getGamemode(), 0, false];
if ($packetplayer instanceof DesktopPlayer) {
$pk->players[0][2] = $packetplayer->bigBrother_getPeroperties();
}
$packets[] = $pk;
$pk = new SpawnPlayerPacket();
$pk->eid = $packet->eid;
$pk->uuid = $packetplayer->getUniqueId()->toBinary();
$pk->x = $packet->x;
$pk->z = $packet->z;
$pk->y = $packet->y;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$pk->item = $packetplayer->getInventory()->getItemInHand()->getId();
$pk->metadata = $packet->metadata;
$packets[] = $pk;
$pk = new EntityTeleportPacket();
$pk->eid = $packet->eid;
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$packets[] = $pk;
return $packets;
/*case Info::ADD_ENTITY_PACKET:
return null;*/
/*case Info::REMOVE_PLAYER_PACKET:
$pk = new PlayerListPacket();
$pk->actionID = PlayerListPacket::TYPE_REMOVE;
//.........这里部分代码省略.........
示例5: serverToInterface
public function serverToInterface(DesktopPlayer $player, DataPacket $packet)
{
switch ($packet->pid()) {
case Info::UPDATE_BLOCK_PACKET:
$pk = new BlockChangePacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->blockId = $packet->block;
$pk->blockMeta = $packet->meta;
return $pk;
case Info::START_GAME_PACKET:
$packets = [];
$pk = new JoinGamePacket();
$pk->eid = $packet->eid;
$pk->gamemode = $player->getGamemode();
$pk->dimension = 0;
$pk->difficulty = $player->getServer()->getDifficulty();
$pk->maxPlayers = $player->getServer()->getMaxPlayers();
$pk->levelType = "default";
$packets[] = $pk;
$pk = new PlayerAbilitiesPacket();
$pk->flyingSpeed = 0.05;
$pk->walkingSpeed = 0.1;
$pk->canFly = ($player->getGamemode() & 0x1) > 0;
$pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
$pk->isFlying = false;
$pk->isCreative = ($player->getGamemode() & 0x1) > 0;
if ($player->spawned === true) {
$packets = [$pk];
$pk = new ChangeGameStatePacket();
$pk->reason = 3;
$pk->value = $player->getGamemode();
$packets[] = $pk;
return $packets;
} else {
$packets[] = $pk;
}
$pk = new SpawnPositionPacket();
$pk->spawnX = $packet->spawnX;
$pk->spawnY = $packet->spawnY;
$pk->spawnZ = $packet->spawnZ;
$packets[] = $pk;
$pk = new PositionAndLookPacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $player->yaw;
$pk->pitch = $player->pitch;
$pk->onGround = $player->isOnGround();
$packets[] = $pk;
return $packets;
case Info::SET_HEALTH_PACKET:
$pk = new UpdateHealthPacket();
$pk->health = $packet->health;
$pk->food = 20;
$pk->saturation = 5;
return $pk;
case Info::TEXT_PACKET:
$pk = new STCChatPacket();
$pk->message = TextFormat::toJSON($packet->message);
return $pk;
case Info::SET_TIME_PACKET:
$pk = new TimeUpdatePacket();
$pk->age = $packet->time;
$pk->time = $packet->time;
//TODO: calculate offset from MCPE
return $pk;
case Info::SET_SPAWN_POSITION_PACKET:
$pk = new SpawnPositionPacket();
$pk->spawnX = $packet->x;
$pk->spawnY = $packet->y;
$pk->spawnZ = $packet->z;
return $pk;
case Info::REMOVE_ENTITY_PACKET:
case Info::REMOVE_PLAYER_PACKET:
$pk = new DestroyEntitiesPacket();
$pk->ids[] = $packet->eid;
return $pk;
case Info::MOVE_PLAYER_PACKET:
if ($packet->eid === 0) {
$pk = new PositionAndLookPacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$pk->onGround = $player->isOnGround();
return $pk;
} else {
$packets = [];
$pk = new EntityTeleportPacket();
$pk->eid = $packet->eid;
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$packets[] = $pk;
$pk = new EntityHeadLookPacket();
//.........这里部分代码省略.........