PocketMine-MP 5.28.1 git-88cdc2eb67c40075559c3ef51418b418cd5488e9
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
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 UpdateBlockPacket());
56 $this->registerPacket(new AddPaintingPacket());
57 $this->registerPacket(new LevelEventPacket());
58 $this->registerPacket(new BlockEventPacket());
59 $this->registerPacket(new ActorEventPacket());
60 $this->registerPacket(new MobEffectPacket());
61 $this->registerPacket(new UpdateAttributesPacket());
62 $this->registerPacket(new InventoryTransactionPacket());
63 $this->registerPacket(new MobEquipmentPacket());
64 $this->registerPacket(new MobArmorEquipmentPacket());
65 $this->registerPacket(new InteractPacket());
66 $this->registerPacket(new BlockPickRequestPacket());
67 $this->registerPacket(new ActorPickRequestPacket());
68 $this->registerPacket(new PlayerActionPacket());
69 $this->registerPacket(new HurtArmorPacket());
70 $this->registerPacket(new SetActorDataPacket());
71 $this->registerPacket(new SetActorMotionPacket());
72 $this->registerPacket(new SetActorLinkPacket());
73 $this->registerPacket(new SetHealthPacket());
74 $this->registerPacket(new SetSpawnPositionPacket());
75 $this->registerPacket(new AnimatePacket());
76 $this->registerPacket(new RespawnPacket());
77 $this->registerPacket(new ContainerOpenPacket());
78 $this->registerPacket(new ContainerClosePacket());
79 $this->registerPacket(new PlayerHotbarPacket());
80 $this->registerPacket(new InventoryContentPacket());
81 $this->registerPacket(new InventorySlotPacket());
82 $this->registerPacket(new ContainerSetDataPacket());
83 $this->registerPacket(new CraftingDataPacket());
84 $this->registerPacket(new GuiDataPickItemPacket());
85 $this->registerPacket(new BlockActorDataPacket());
86 $this->registerPacket(new LevelChunkPacket());
87 $this->registerPacket(new SetCommandsEnabledPacket());
88 $this->registerPacket(new SetDifficultyPacket());
89 $this->registerPacket(new ChangeDimensionPacket());
90 $this->registerPacket(new SetPlayerGameTypePacket());
91 $this->registerPacket(new PlayerListPacket());
92 $this->registerPacket(new SimpleEventPacket());
93 $this->registerPacket(new LegacyTelemetryEventPacket());
94 $this->registerPacket(new SpawnExperienceOrbPacket());
95 $this->registerPacket(new ClientboundMapItemDataPacket());
96 $this->registerPacket(new MapInfoRequestPacket());
97 $this->registerPacket(new RequestChunkRadiusPacket());
98 $this->registerPacket(new ChunkRadiusUpdatedPacket());
99 $this->registerPacket(new GameRulesChangedPacket());
100 $this->registerPacket(new CameraPacket());
101 $this->registerPacket(new BossEventPacket());
102 $this->registerPacket(new ShowCreditsPacket());
103 $this->registerPacket(new AvailableCommandsPacket());
104 $this->registerPacket(new CommandRequestPacket());
105 $this->registerPacket(new CommandBlockUpdatePacket());
106 $this->registerPacket(new CommandOutputPacket());
107 $this->registerPacket(new UpdateTradePacket());
108 $this->registerPacket(new UpdateEquipPacket());
109 $this->registerPacket(new ResourcePackDataInfoPacket());
110 $this->registerPacket(new ResourcePackChunkDataPacket());
111 $this->registerPacket(new ResourcePackChunkRequestPacket());
112 $this->registerPacket(new TransferPacket());
113 $this->registerPacket(new PlaySoundPacket());
114 $this->registerPacket(new StopSoundPacket());
115 $this->registerPacket(new SetTitlePacket());
116 $this->registerPacket(new AddBehaviorTreePacket());
117 $this->registerPacket(new StructureBlockUpdatePacket());
118 $this->registerPacket(new ShowStoreOfferPacket());
119 $this->registerPacket(new PurchaseReceiptPacket());
120 $this->registerPacket(new PlayerSkinPacket());
121 $this->registerPacket(new SubClientLoginPacket());
122 $this->registerPacket(new AutomationClientConnectPacket());
123 $this->registerPacket(new SetLastHurtByPacket());
124 $this->registerPacket(new BookEditPacket());
125 $this->registerPacket(new NpcRequestPacket());
126 $this->registerPacket(new PhotoTransferPacket());
127 $this->registerPacket(new ModalFormRequestPacket());
128 $this->registerPacket(new ModalFormResponsePacket());
129 $this->registerPacket(new ServerSettingsRequestPacket());
130 $this->registerPacket(new ServerSettingsResponsePacket());
131 $this->registerPacket(new ShowProfilePacket());
132 $this->registerPacket(new SetDefaultGameTypePacket());
133 $this->registerPacket(new RemoveObjectivePacket());
134 $this->registerPacket(new SetDisplayObjectivePacket());
135 $this->registerPacket(new SetScorePacket());
136 $this->registerPacket(new LabTablePacket());
137 $this->registerPacket(new UpdateBlockSyncedPacket());
138 $this->registerPacket(new MoveActorDeltaPacket());
139 $this->registerPacket(new SetScoreboardIdentityPacket());
140 $this->registerPacket(new SetLocalPlayerAsInitializedPacket());
141 $this->registerPacket(new UpdateSoftEnumPacket());
142 $this->registerPacket(new NetworkStackLatencyPacket());
143 $this->registerPacket(new SpawnParticleEffectPacket());
144 $this->registerPacket(new AvailableActorIdentifiersPacket());
145 $this->registerPacket(new NetworkChunkPublisherUpdatePacket());
146 $this->registerPacket(new BiomeDefinitionListPacket());
147 $this->registerPacket(new LevelSoundEventPacket());
148 $this->registerPacket(new LevelEventGenericPacket());
149 $this->registerPacket(new LecternUpdatePacket());
150 $this->registerPacket(new ClientCacheStatusPacket());
151 $this->registerPacket(new OnScreenTextureAnimationPacket());
152 $this->registerPacket(new MapCreateLockedCopyPacket());
153 $this->registerPacket(new StructureTemplateDataRequestPacket());
154 $this->registerPacket(new StructureTemplateDataResponsePacket());
155 $this->registerPacket(new ClientCacheBlobStatusPacket());
156 $this->registerPacket(new ClientCacheMissResponsePacket());
157 $this->registerPacket(new EducationSettingsPacket());
158 $this->registerPacket(new EmotePacket());
159 $this->registerPacket(new MultiplayerSettingsPacket());
160 $this->registerPacket(new SettingsCommandPacket());
161 $this->registerPacket(new AnvilDamagePacket());
162 $this->registerPacket(new CompletedUsingItemPacket());
163 $this->registerPacket(new NetworkSettingsPacket());
164 $this->registerPacket(new PlayerAuthInputPacket());
165 $this->registerPacket(new CreativeContentPacket());
166 $this->registerPacket(new PlayerEnchantOptionsPacket());
167 $this->registerPacket(new ItemStackRequestPacket());
168 $this->registerPacket(new ItemStackResponsePacket());
169 $this->registerPacket(new PlayerArmorDamagePacket());
170 $this->registerPacket(new CodeBuilderPacket());
171 $this->registerPacket(new UpdatePlayerGameTypePacket());
172 $this->registerPacket(new EmoteListPacket());
173 $this->registerPacket(new PositionTrackingDBServerBroadcastPacket());
174 $this->registerPacket(new PositionTrackingDBClientRequestPacket());
175 $this->registerPacket(new DebugInfoPacket());
176 $this->registerPacket(new PacketViolationWarningPacket());
177 $this->registerPacket(new MotionPredictionHintsPacket());
178 $this->registerPacket(new AnimateEntityPacket());
179 $this->registerPacket(new CameraShakePacket());
180 $this->registerPacket(new PlayerFogPacket());
181 $this->registerPacket(new CorrectPlayerMovePredictionPacket());
182 $this->registerPacket(new ItemRegistryPacket());
183 $this->registerPacket(new ClientboundDebugRendererPacket());
184 $this->registerPacket(new SyncActorPropertyPacket());
185 $this->registerPacket(new AddVolumeEntityPacket());
186 $this->registerPacket(new RemoveVolumeEntityPacket());
187 $this->registerPacket(new SimulationTypePacket());
188 $this->registerPacket(new NpcDialoguePacket());
189 $this->registerPacket(new EduUriResourcePacket());
190 $this->registerPacket(new CreatePhotoPacket());
191 $this->registerPacket(new UpdateSubChunkBlocksPacket());
192 $this->registerPacket(new SubChunkPacket());
193 $this->registerPacket(new SubChunkRequestPacket());
194 $this->registerPacket(new PlayerStartItemCooldownPacket());
195 $this->registerPacket(new ScriptMessagePacket());
196 $this->registerPacket(new CodeBuilderSourcePacket());
197 $this->registerPacket(new TickingAreasLoadStatusPacket());
198 $this->registerPacket(new DimensionDataPacket());
199 $this->registerPacket(new AgentActionEventPacket());
200 $this->registerPacket(new ChangeMobPropertyPacket());
201 $this->registerPacket(new LessonProgressPacket());
202 $this->registerPacket(new RequestAbilityPacket());
203 $this->registerPacket(new RequestPermissionsPacket());
204 $this->registerPacket(new ToastRequestPacket());
205 $this->registerPacket(new UpdateAbilitiesPacket());
206 $this->registerPacket(new UpdateAdventureSettingsPacket());
207 $this->registerPacket(new DeathInfoPacket());
208 $this->registerPacket(new EditorNetworkPacket());
209 $this->registerPacket(new FeatureRegistryPacket());
210 $this->registerPacket(new ServerStatsPacket());
211 $this->registerPacket(new RequestNetworkSettingsPacket());
212 $this->registerPacket(new GameTestRequestPacket());
213 $this->registerPacket(new GameTestResultsPacket());
214 $this->registerPacket(new UpdateClientInputLocksPacket());
215 $this->registerPacket(new CameraPresetsPacket());
216 $this->registerPacket(new UnlockedRecipesPacket());
217 $this->registerPacket(new CameraInstructionPacket());
218 $this->registerPacket(new TrimDataPacket());
219 $this->registerPacket(new OpenSignPacket());
220 $this->registerPacket(new AgentAnimationPacket());
221 $this->registerPacket(new RefreshEntitlementsPacket());
222 $this->registerPacket(new PlayerToggleCrafterSlotRequestPacket());
223 $this->registerPacket(new SetPlayerInventoryOptionsPacket());
224 $this->registerPacket(new SetHudPacket());
225 $this->registerPacket(new AwardAchievementPacket());
226 $this->registerPacket(new ClientboundCloseFormPacket());
227 $this->registerPacket(new ServerboundLoadingScreenPacket());
228 $this->registerPacket(new JigsawStructureDataPacket());
229 $this->registerPacket(new CurrentStructureFeaturePacket());
230 $this->registerPacket(new ServerboundDiagnosticsPacket());
231 $this->registerPacket(new CameraAimAssistPacket());
232 $this->registerPacket(new ContainerRegistryCleanupPacket());
233 $this->registerPacket(new MovementEffectPacket());
234 $this->registerPacket(new SetMovementAuthorityPacket());
235 $this->registerPacket(new CameraAimAssistPresetsPacket());
236 $this->registerPacket(new ClientCameraAimAssistPacket());
237 $this->registerPacket(new ClientMovementPredictionSyncPacket());
238 $this->registerPacket(new UpdateClientOptionsPacket());
239 $this->registerPacket(new PlayerVideoCapturePacket());
240 $this->registerPacket(new PlayerUpdateEntityOverridesPacket());
241 $this->registerPacket(new PlayerLocationPacket());
242 $this->registerPacket(new ClientboundControlSchemeSetPacket());
243 }
244
245 public function registerPacket(Packet $packet) : void{
246 $this->pool[$packet->pid()] = clone $packet;
247 }
248
249 public function getPacketById(int $pid) : ?Packet{
250 return isset($this->pool[$pid]) ? clone $this->pool[$pid] : null;
251 }
252
256 public function getPacket(string $buffer) : ?Packet{
257 $offset = 0;
258 return $this->getPacketById(Binary::readUnsignedVarInt($buffer, $offset) & DataPacket::PID_MASK);
259 }
260}