PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
PlayerVideoCapturePacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
21
23 public const NETWORK_ID = ProtocolInfo::PLAYER_VIDEO_CAPTURE_PACKET;
24
25 private bool $recording;
26 private ?int $frameRate;
27 private ?string $filePrefix;
28
32 private static function create(bool $recording, ?int $frameRate, ?string $filePrefix) : self{
33 $result = new self;
34 $result->recording = $recording;
35 $result->frameRate = $frameRate;
36 $result->filePrefix = $filePrefix;
37 return $result;
38 }
39
40 public static function createStartRecording(int $frameRate, string $filePrefix) : self{
41 return self::create(true, $frameRate, $filePrefix);
42 }
43
44 public static function createStopRecording() : self{
45 return self::create(false, null, null);
46 }
47
48 public function isRecording() : bool{ return $this->recording; }
49
50 public function getFrameRate() : ?int{ return $this->frameRate; }
51
52 public function getFilePrefix() : ?string{ return $this->filePrefix; }
53
54 protected function decodePayload(ByteBufferReader $in) : void{
55 $this->recording = CommonTypes::getBool($in);
56 if($this->recording){
57 $this->frameRate = LE::readUnsignedInt($in);
58 $this->filePrefix = CommonTypes::getString($in);
59 }
60 }
61
62 protected function encodePayload(ByteBufferWriter $out) : void{
63 CommonTypes::putBool($out, $this->recording);
64 if($this->recording){
65 if($this->frameRate === null){ // this should never be the case
66 throw new \LogicException("PlayerUpdateEntityOverridesPacket with recording=true require a frame rate to be provided");
67 }
68
69 if($this->filePrefix === null){ // this should never be the case
70 throw new \LogicException("PlayerUpdateEntityOverridesPacket with recording=true require a file prefix to be provided");
71 }
72
73 LE::writeUnsignedInt($out, $this->frameRate);
74 CommonTypes::putString($out, $this->filePrefix);
75 }
76 }
77
78 public function handle(PacketHandlerInterface $handler) : bool{
79 return $handler->handlePlayerVideoCapture($this);
80 }
81}