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