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