PocketMine-MP 5.27.1 git-9af3cde03fabbe4129c79e46dc87ffa0fff446e6
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
18
20 public const NETWORK_ID = ProtocolInfo::PLAYER_VIDEO_CAPTURE_PACKET;
21
22 private bool $recording;
23 private ?int $frameRate;
24 private ?string $filePrefix;
25
29 private static function create(bool $recording, ?int $frameRate, ?string $filePrefix) : self{
30 $result = new self;
31 $result->recording = $recording;
32 $result->frameRate = $frameRate;
33 $result->filePrefix = $filePrefix;
34 return $result;
35 }
36
37 public static function createStartRecording(int $frameRate, string $filePrefix) : self{
38 return self::create(true, $frameRate, $filePrefix);
39 }
40
41 public static function createStopRecording() : self{
42 return self::create(false, null, null);
43 }
44
45 public function isRecording() : bool{ return $this->recording; }
46
47 public function getFrameRate() : ?int{ return $this->frameRate; }
48
49 public function getFilePrefix() : ?string{ return $this->filePrefix; }
50
51 protected function decodePayload(PacketSerializer $in) : void{
52 $this->recording = $in->getBool();
53 if($this->recording){
54 $this->frameRate = $in->getLInt();
55 $this->filePrefix = $in->getString();
56 }
57 }
58
59 protected function encodePayload(PacketSerializer $out) : void{
60 $out->putBool($this->recording);
61 if($this->recording){
62 if($this->frameRate === null){ // this should never be the case
63 throw new \LogicException("PlayerUpdateEntityOverridesPacket with recording=true require a frame rate to be provided");
64 }
65
66 if($this->filePrefix === null){ // this should never be the case
67 throw new \LogicException("PlayerUpdateEntityOverridesPacket with recording=true require a file prefix to be provided");
68 }
69
70 $out->putLInt($this->frameRate);
71 $out->putString($this->filePrefix);
72 }
73 }
74
75 public function handle(PacketHandlerInterface $handler) : bool{
76 return $handler->handlePlayerVideoCapturePacket($this);
77 }
78}