mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 19:41:54 +00:00
this is not complete yet, but the final change (having the binarystream actually come from outside) is a little more disruptive, and some extra changes need to be made. This will grant some sanity in the meantime without breaking too much stuff.
166 lines
4.5 KiB
PHP
166 lines
4.5 KiB
PHP
<?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;
|
|
|
|
#include <rules/DataPacket.h>
|
|
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\network\mcpe\handler\PacketHandler;
|
|
use pocketmine\network\mcpe\protocol\types\InputMode;
|
|
use pocketmine\network\mcpe\protocol\types\PlayMode;
|
|
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
|
|
use function assert;
|
|
|
|
class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
|
|
public const NETWORK_ID = ProtocolInfo::PLAYER_AUTH_INPUT_PACKET;
|
|
|
|
/** @var Vector3 */
|
|
private $position;
|
|
/** @var float */
|
|
private $pitch;
|
|
/** @var float */
|
|
private $yaw;
|
|
/** @var float */
|
|
private $headYaw;
|
|
/** @var float */
|
|
private $moveVecX;
|
|
/** @var float */
|
|
private $moveVecZ;
|
|
/** @var int */
|
|
private $inputFlags;
|
|
/** @var int */
|
|
private $inputMode;
|
|
/** @var int */
|
|
private $playMode;
|
|
/** @var Vector3|null */
|
|
private $vrGazeDirection = null;
|
|
|
|
/**
|
|
* @param int $inputMode @see InputMode
|
|
* @param int $playMode @see PlayMode
|
|
* @param Vector3|null $vrGazeDirection only used when PlayMode::VR
|
|
*/
|
|
public static function create(Vector3 $position, float $pitch, float $yaw, float $headYaw, float $moveVecX, float $moveVecZ, int $inputFlags, int $inputMode, int $playMode, ?Vector3 $vrGazeDirection = null) : self{
|
|
if($playMode === PlayMode::VR and $vrGazeDirection === null){
|
|
//yuck, can we get a properly written packet just once? ...
|
|
throw new \InvalidArgumentException("Gaze direction must be provided for VR play mode");
|
|
}
|
|
$result = new self;
|
|
$result->position = $position->asVector3();
|
|
$result->pitch = $pitch;
|
|
$result->yaw = $yaw;
|
|
$result->headYaw = $headYaw;
|
|
$result->moveVecX = $moveVecX;
|
|
$result->moveVecZ = $moveVecZ;
|
|
$result->inputFlags = $inputFlags;
|
|
$result->inputMode = $inputMode;
|
|
$result->playMode = $playMode;
|
|
if($vrGazeDirection !== null){
|
|
$result->vrGazeDirection = $vrGazeDirection->asVector3();
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function getPosition() : Vector3{
|
|
return $this->position;
|
|
}
|
|
|
|
public function getPitch() : float{
|
|
return $this->pitch;
|
|
}
|
|
|
|
public function getYaw() : float{
|
|
return $this->yaw;
|
|
}
|
|
|
|
public function getHeadYaw() : float{
|
|
return $this->headYaw;
|
|
}
|
|
|
|
public function getMoveVecX() : float{
|
|
return $this->moveVecX;
|
|
}
|
|
|
|
public function getMoveVecZ() : float{
|
|
return $this->moveVecZ;
|
|
}
|
|
|
|
public function getInputFlags() : int{
|
|
return $this->inputFlags;
|
|
}
|
|
|
|
/**
|
|
* @see InputMode
|
|
*/
|
|
public function getInputMode() : int{
|
|
return $this->inputMode;
|
|
}
|
|
|
|
/**
|
|
* @see PlayMode
|
|
*/
|
|
public function getPlayMode() : int{
|
|
return $this->playMode;
|
|
}
|
|
|
|
public function getVrGazeDirection() : ?Vector3{
|
|
return $this->vrGazeDirection;
|
|
}
|
|
|
|
protected function decodePayload(NetworkBinaryStream $in) : void{
|
|
$this->yaw = $in->getLFloat();
|
|
$this->pitch = $in->getLFloat();
|
|
$this->position = $in->getVector3();
|
|
$this->moveVecX = $in->getLFloat();
|
|
$this->moveVecZ = $in->getLFloat();
|
|
$this->headYaw = $in->getLFloat();
|
|
$this->inputFlags = $in->getUnsignedVarLong();
|
|
$this->inputMode = $in->getUnsignedVarInt();
|
|
$this->playMode = $in->getUnsignedVarInt();
|
|
if($this->playMode === PlayMode::VR){
|
|
$this->vrGazeDirection = $in->getVector3();
|
|
}
|
|
}
|
|
|
|
protected function encodePayload(NetworkBinaryStream $out) : void{
|
|
$out->putLFloat($this->yaw);
|
|
$out->putLFloat($this->pitch);
|
|
$out->putVector3($this->position);
|
|
$out->putLFloat($this->moveVecX);
|
|
$out->putLFloat($this->moveVecZ);
|
|
$out->putLFloat($this->headYaw);
|
|
$out->putUnsignedVarLong($this->inputFlags);
|
|
$out->putUnsignedVarInt($this->inputMode);
|
|
$out->putUnsignedVarInt($this->playMode);
|
|
if($this->playMode === PlayMode::VR){
|
|
assert($this->vrGazeDirection !== null);
|
|
$out->putVector3($this->vrGazeDirection);
|
|
}
|
|
}
|
|
|
|
public function handle(PacketHandler $handler) : bool{
|
|
return $handler->handlePlayerAuthInput($this);
|
|
}
|
|
}
|