PocketMine-MP 5.15.1 git-fb9a74e8799c71ed8292cfa53abe7a4c9204629d
PacketPool.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
19
21 protected static ?PacketPool $instance = null;
22
23 public static function getInstance() : self{
24 if(self::$instance === null){
25 self::$instance = new self;
26 }
27 return self::$instance;
28 }
29
31 protected \SplFixedArray $pool;
32
33 public function __construct(){
34 $this->pool = new \SplFixedArray(512);
35
36 $this->registerPacket(new LoginPacket());
37 $this->registerPacket(new PlayStatusPacket());
38 $this->registerPacket(new ServerToClientHandshakePacket());
39 $this->registerPacket(new ClientToServerHandshakePacket());
40 $this->registerPacket(new DisconnectPacket());
41 $this->registerPacket(new ResourcePacksInfoPacket());
42 $this->registerPacket(new ResourcePackStackPacket());
43 $this->registerPacket(new ResourcePackClientResponsePacket());
44 $this->registerPacket(new TextPacket());
45 $this->registerPacket(new SetTimePacket());
46 $this->registerPacket(new StartGamePacket());
47 $this->registerPacket(new AddPlayerPacket());
48 $this->registerPacket(new AddActorPacket());
49 $this->registerPacket(new RemoveActorPacket());
50 $this->registerPacket(new AddItemActorPacket());
51 $this->registerPacket(new ServerPlayerPostMovePositionPacket());
52 $this->registerPacket(new TakeItemActorPacket());
53 $this->registerPacket(new MoveActorAbsolutePacket());
54 $this->registerPacket(new MovePlayerPacket());
55 $this->registerPacket(new PassengerJumpPacket());
56 $this->registerPacket(new UpdateBlockPacket());
57 $this->registerPacket(new AddPaintingPacket());
58 $this->registerPacket(new TickSyncPacket());
59 $this->registerPacket(new LevelSoundEventPacketV1());
60 $this->registerPacket(new LevelEventPacket());
61 $this->registerPacket(new BlockEventPacket());
62 $this->registerPacket(new ActorEventPacket());
63 $this->registerPacket(new MobEffectPacket());
64 $this->registerPacket(new UpdateAttributesPacket());
65 $this->registerPacket(new InventoryTransactionPacket());
66 $this->registerPacket(new MobEquipmentPacket());
67 $this->registerPacket(new MobArmorEquipmentPacket());
68 $this->registerPacket(new InteractPacket());
69 $this->registerPacket(new BlockPickRequestPacket());
70 $this->registerPacket(new ActorPickRequestPacket());
71 $this->registerPacket(new PlayerActionPacket());
72 $this->registerPacket(new HurtArmorPacket());
73 $this->registerPacket(new SetActorDataPacket());
74 $this->registerPacket(new SetActorMotionPacket());
75 $this->registerPacket(new SetActorLinkPacket());
76 $this->registerPacket(new SetHealthPacket());
77 $this->registerPacket(new SetSpawnPositionPacket());
78 $this->registerPacket(new AnimatePacket());
79 $this->registerPacket(new RespawnPacket());
80 $this->registerPacket(new ContainerOpenPacket());
81 $this->registerPacket(new ContainerClosePacket());
82 $this->registerPacket(new PlayerHotbarPacket());
83 $this->registerPacket(new InventoryContentPacket());
84 $this->registerPacket(new InventorySlotPacket());
85 $this->registerPacket(new ContainerSetDataPacket());
86 $this->registerPacket(new CraftingDataPacket());
87 $this->registerPacket(new GuiDataPickItemPacket());
88 $this->registerPacket(new BlockActorDataPacket());
89 $this->registerPacket(new PlayerInputPacket());
90 $this->registerPacket(new LevelChunkPacket());
91 $this->registerPacket(new SetCommandsEnabledPacket());
92 $this->registerPacket(new SetDifficultyPacket());
93 $this->registerPacket(new ChangeDimensionPacket());
94 $this->registerPacket(new SetPlayerGameTypePacket());
95 $this->registerPacket(new PlayerListPacket());
96 $this->registerPacket(new SimpleEventPacket());
97 $this->registerPacket(new LegacyTelemetryEventPacket());
98 $this->registerPacket(new SpawnExperienceOrbPacket());
99 $this->registerPacket(new ClientboundMapItemDataPacket());
100 $this->registerPacket(new MapInfoRequestPacket());
101 $this->registerPacket(new RequestChunkRadiusPacket());
102 $this->registerPacket(new ChunkRadiusUpdatedPacket());
103 $this->registerPacket(new GameRulesChangedPacket());
104 $this->registerPacket(new CameraPacket());
105 $this->registerPacket(new BossEventPacket());
106 $this->registerPacket(new ShowCreditsPacket());
107 $this->registerPacket(new AvailableCommandsPacket());
108 $this->registerPacket(new CommandRequestPacket());
109 $this->registerPacket(new CommandBlockUpdatePacket());
110 $this->registerPacket(new CommandOutputPacket());
111 $this->registerPacket(new UpdateTradePacket());
112 $this->registerPacket(new UpdateEquipPacket());
113 $this->registerPacket(new ResourcePackDataInfoPacket());
114 $this->registerPacket(new ResourcePackChunkDataPacket());
115 $this->registerPacket(new ResourcePackChunkRequestPacket());
116 $this->registerPacket(new TransferPacket());
117 $this->registerPacket(new PlaySoundPacket());
118 $this->registerPacket(new StopSoundPacket());
119 $this->registerPacket(new SetTitlePacket());
120 $this->registerPacket(new AddBehaviorTreePacket());
121 $this->registerPacket(new StructureBlockUpdatePacket());
122 $this->registerPacket(new ShowStoreOfferPacket());
123 $this->registerPacket(new PurchaseReceiptPacket());
124 $this->registerPacket(new PlayerSkinPacket());
125 $this->registerPacket(new SubClientLoginPacket());
126 $this->registerPacket(new AutomationClientConnectPacket());
127 $this->registerPacket(new SetLastHurtByPacket());
128 $this->registerPacket(new BookEditPacket());
129 $this->registerPacket(new NpcRequestPacket());
130 $this->registerPacket(new PhotoTransferPacket());
131 $this->registerPacket(new ModalFormRequestPacket());
132 $this->registerPacket(new ModalFormResponsePacket());
133 $this->registerPacket(new ServerSettingsRequestPacket());
134 $this->registerPacket(new ServerSettingsResponsePacket());
135 $this->registerPacket(new ShowProfilePacket());
136 $this->registerPacket(new SetDefaultGameTypePacket());
137 $this->registerPacket(new RemoveObjectivePacket());
138 $this->registerPacket(new SetDisplayObjectivePacket());
139 $this->registerPacket(new SetScorePacket());
140 $this->registerPacket(new LabTablePacket());
141 $this->registerPacket(new UpdateBlockSyncedPacket());
142 $this->registerPacket(new MoveActorDeltaPacket());
143 $this->registerPacket(new SetScoreboardIdentityPacket());
144 $this->registerPacket(new SetLocalPlayerAsInitializedPacket());
145 $this->registerPacket(new UpdateSoftEnumPacket());
146 $this->registerPacket(new NetworkStackLatencyPacket());
147 $this->registerPacket(new SpawnParticleEffectPacket());
148 $this->registerPacket(new AvailableActorIdentifiersPacket());
149 $this->registerPacket(new LevelSoundEventPacketV2());
150 $this->registerPacket(new NetworkChunkPublisherUpdatePacket());
151 $this->registerPacket(new BiomeDefinitionListPacket());
152 $this->registerPacket(new LevelSoundEventPacket());
153 $this->registerPacket(new LevelEventGenericPacket());
154 $this->registerPacket(new LecternUpdatePacket());
155 $this->registerPacket(new ClientCacheStatusPacket());
156 $this->registerPacket(new OnScreenTextureAnimationPacket());
157 $this->registerPacket(new MapCreateLockedCopyPacket());
158 $this->registerPacket(new StructureTemplateDataRequestPacket());
159 $this->registerPacket(new StructureTemplateDataResponsePacket());
160 $this->registerPacket(new ClientCacheBlobStatusPacket());
161 $this->registerPacket(new ClientCacheMissResponsePacket());
162 $this->registerPacket(new EducationSettingsPacket());
163 $this->registerPacket(new EmotePacket());
164 $this->registerPacket(new MultiplayerSettingsPacket());
165 $this->registerPacket(new SettingsCommandPacket());
166 $this->registerPacket(new AnvilDamagePacket());
167 $this->registerPacket(new CompletedUsingItemPacket());
168 $this->registerPacket(new NetworkSettingsPacket());
169 $this->registerPacket(new PlayerAuthInputPacket());
170 $this->registerPacket(new CreativeContentPacket());
171 $this->registerPacket(new PlayerEnchantOptionsPacket());
172 $this->registerPacket(new ItemStackRequestPacket());
173 $this->registerPacket(new ItemStackResponsePacket());
174 $this->registerPacket(new PlayerArmorDamagePacket());
175 $this->registerPacket(new CodeBuilderPacket());
176 $this->registerPacket(new UpdatePlayerGameTypePacket());
177 $this->registerPacket(new EmoteListPacket());
178 $this->registerPacket(new PositionTrackingDBServerBroadcastPacket());
179 $this->registerPacket(new PositionTrackingDBClientRequestPacket());
180 $this->registerPacket(new DebugInfoPacket());
181 $this->registerPacket(new PacketViolationWarningPacket());
182 $this->registerPacket(new MotionPredictionHintsPacket());
183 $this->registerPacket(new AnimateEntityPacket());
184 $this->registerPacket(new CameraShakePacket());
185 $this->registerPacket(new PlayerFogPacket());
186 $this->registerPacket(new CorrectPlayerMovePredictionPacket());
187 $this->registerPacket(new ItemComponentPacket());
188 $this->registerPacket(new ClientboundDebugRendererPacket());
189 $this->registerPacket(new SyncActorPropertyPacket());
190 $this->registerPacket(new AddVolumeEntityPacket());
191 $this->registerPacket(new RemoveVolumeEntityPacket());
192 $this->registerPacket(new SimulationTypePacket());
193 $this->registerPacket(new NpcDialoguePacket());
194 $this->registerPacket(new EduUriResourcePacket());
195 $this->registerPacket(new CreatePhotoPacket());
196 $this->registerPacket(new UpdateSubChunkBlocksPacket());
197 $this->registerPacket(new SubChunkPacket());
198 $this->registerPacket(new SubChunkRequestPacket());
199 $this->registerPacket(new PlayerStartItemCooldownPacket());
200 $this->registerPacket(new ScriptMessagePacket());
201 $this->registerPacket(new CodeBuilderSourcePacket());
202 $this->registerPacket(new TickingAreasLoadStatusPacket());
203 $this->registerPacket(new DimensionDataPacket());
204 $this->registerPacket(new AgentActionEventPacket());
205 $this->registerPacket(new ChangeMobPropertyPacket());
206 $this->registerPacket(new LessonProgressPacket());
207 $this->registerPacket(new RequestAbilityPacket());
208 $this->registerPacket(new RequestPermissionsPacket());
209 $this->registerPacket(new ToastRequestPacket());
210 $this->registerPacket(new UpdateAbilitiesPacket());
211 $this->registerPacket(new UpdateAdventureSettingsPacket());
212 $this->registerPacket(new DeathInfoPacket());
213 $this->registerPacket(new EditorNetworkPacket());
214 $this->registerPacket(new FeatureRegistryPacket());
215 $this->registerPacket(new ServerStatsPacket());
216 $this->registerPacket(new RequestNetworkSettingsPacket());
217 $this->registerPacket(new GameTestRequestPacket());
218 $this->registerPacket(new GameTestResultsPacket());
219 $this->registerPacket(new UpdateClientInputLocksPacket());
220 $this->registerPacket(new CameraPresetsPacket());
221 $this->registerPacket(new UnlockedRecipesPacket());
222 $this->registerPacket(new CameraInstructionPacket());
223 $this->registerPacket(new CompressedBiomeDefinitionListPacket());
224 $this->registerPacket(new TrimDataPacket());
225 $this->registerPacket(new OpenSignPacket());
226 $this->registerPacket(new AgentAnimationPacket());
227 $this->registerPacket(new RefreshEntitlementsPacket());
228 $this->registerPacket(new PlayerToggleCrafterSlotRequestPacket());
229 $this->registerPacket(new SetPlayerInventoryOptionsPacket());
230 $this->registerPacket(new SetHudPacket());
231 }
232
233 public function registerPacket(Packet $packet) : void{
234 $this->pool[$packet->pid()] = clone $packet;
235 }
236
237 public function getPacketById(int $pid) : ?Packet{
238 return isset($this->pool[$pid]) ? clone $this->pool[$pid] : null;
239 }
240
244 public function getPacket(string $buffer) : ?Packet{
245 $offset = 0;
246 return $this->getPacketById(Binary::readUnsignedVarInt($buffer, $offset) & DataPacket::PID_MASK);
247 }
248}
static readUnsignedVarInt(string $buffer, int &$offset)
Definition: Binary.php:403