mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 00:09:39 +00:00
PlayerAuthInputPacket: added encode & decode, and some aux classes
This commit is contained in:
parent
85521f5e7a
commit
20b7418916
@ -25,17 +25,148 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\types\InputMode;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayMode;
|
||||
use function assert;
|
||||
|
||||
class PlayerAuthInputPacket extends DataPacket{
|
||||
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 Vector3 $position
|
||||
* @param float $pitch
|
||||
* @param float $yaw
|
||||
* @param float $headYaw
|
||||
* @param float $moveVecX
|
||||
* @param float $moveVecZ
|
||||
* @param int $inputFlags
|
||||
* @param int $inputMode @see InputMode
|
||||
* @param int $playMode @see PlayMode
|
||||
* @param Vector3|null $vrGazeDirection only used when PlayMode::VR
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
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){
|
||||
$this->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
|
||||
* @return int
|
||||
*/
|
||||
public function getInputMode() : int{
|
||||
return $this->inputMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PlayMode
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayMode() : int{
|
||||
return $this->playMode;
|
||||
}
|
||||
|
||||
public function getVrGazeDirection() : ?Vector3{
|
||||
return $this->vrGazeDirection;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
//TODO
|
||||
$this->yaw = $this->getLFloat();
|
||||
$this->pitch = $this->getLFloat();
|
||||
$this->position = $this->getVector3();
|
||||
$this->moveVecX = $this->getLFloat();
|
||||
$this->moveVecZ = $this->getLFloat();
|
||||
$this->headYaw = $this->getLFloat();
|
||||
$this->inputFlags = $this->getUnsignedVarLong();
|
||||
$this->inputMode = $this->getUnsignedVarInt();
|
||||
$this->playMode = $this->getUnsignedVarInt();
|
||||
if($this->playMode === PlayMode::VR){
|
||||
$this->vrGazeDirection = $this->getVector3();
|
||||
}
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
//TODO
|
||||
$this->putLFloat($this->yaw);
|
||||
$this->putLFloat($this->pitch);
|
||||
$this->putVector3($this->position);
|
||||
$this->putLFloat($this->moveVecX);
|
||||
$this->putLFloat($this->moveVecZ);
|
||||
$this->putLFloat($this->headYaw);
|
||||
$this->putUnsignedVarLong($this->inputFlags);
|
||||
$this->putUnsignedVarInt($this->inputMode);
|
||||
$this->putUnsignedVarInt($this->playMode);
|
||||
if($this->playMode === PlayMode::VR){
|
||||
assert($this->vrGazeDirection !== null);
|
||||
$this->putVector3($this->vrGazeDirection);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $handler) : bool{
|
||||
|
36
src/pocketmine/network/mcpe/protocol/types/InputMode.php
Normal file
36
src/pocketmine/network/mcpe/protocol/types/InputMode.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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;
|
||||
|
||||
final class InputMode{
|
||||
|
||||
private function __construct(){
|
||||
//NOOP
|
||||
}
|
||||
|
||||
public const MOUSE_KEYBOARD = 1;
|
||||
public const TOUCHSCREEN = 2;
|
||||
public const GAME_PAD = 3;
|
||||
public const MOTION_CONTROLLER = 4;
|
||||
}
|
45
src/pocketmine/network/mcpe/protocol/types/PlayMode.php
Normal file
45
src/pocketmine/network/mcpe/protocol/types/PlayMode.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Enum used by PlayerAuthInputPacket. Most of these names don't make any sense, but that isn't surprising.
|
||||
*/
|
||||
final class PlayMode{
|
||||
|
||||
private function __construct(){
|
||||
//NOOP
|
||||
}
|
||||
|
||||
public const NORMAL = 0;
|
||||
public const TEASER = 1;
|
||||
public const SCREEN = 2;
|
||||
public const VIEWER = 3;
|
||||
public const VR = 4;
|
||||
public const PLACEMENT = 5;
|
||||
public const LIVING_ROOM = 6;
|
||||
public const EXIT_LEVEL = 7;
|
||||
public const EXIT_LEVEL_LIVING_ROOM = 8;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user