-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
pool.go
197 lines (190 loc) · 9.12 KB
/
pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package packet
import (
"reflect"
)
// Register registers a function that returns a packet for a specific ID. Packets with this ID coming in from
// connections will resolve to the packet returned by the function passed.
//noinspection GoUnusedExportedFunction
func Register(id uint32, pk func() Packet) {
registeredPackets[id] = pk
}
// registeredPackets holds packets registered by the user.
var registeredPackets = map[uint32]func() Packet{}
// Pool is a map holding packets indexed by a packet ID.
type Pool map[uint32]Packet
// NewPool returns a new pool with all supported packets sent. Packets may be retrieved from it simply by
// indexing it with the packet ID.
func NewPool() Pool {
p := Pool{
IDLogin: &Login{},
IDPlayStatus: &PlayStatus{},
IDServerToClientHandshake: &ServerToClientHandshake{},
IDClientToServerHandshake: &ClientToServerHandshake{},
IDDisconnect: &Disconnect{},
IDResourcePacksInfo: &ResourcePacksInfo{},
IDResourcePackStack: &ResourcePackStack{},
IDResourcePackClientResponse: &ResourcePackClientResponse{},
IDText: &Text{},
IDSetTime: &SetTime{},
IDStartGame: &StartGame{},
IDAddPlayer: &AddPlayer{},
IDAddActor: &AddActor{},
IDRemoveActor: &RemoveActor{},
IDAddItemActor: &AddItemActor{},
// ---
IDTakeItemActor: &TakeItemActor{},
IDMoveActorAbsolute: &MoveActorAbsolute{},
IDMovePlayer: &MovePlayer{},
IDRiderJump: &RiderJump{},
IDUpdateBlock: &UpdateBlock{},
IDAddPainting: &AddPainting{},
IDTickSync: &TickSync{},
// ---
IDLevelEvent: &LevelEvent{},
IDBlockEvent: &BlockEvent{},
IDActorEvent: &ActorEvent{},
IDMobEffect: &MobEffect{},
IDUpdateAttributes: &UpdateAttributes{},
IDInventoryTransaction: &InventoryTransaction{},
IDMobEquipment: &MobEquipment{},
IDMobArmourEquipment: &MobArmourEquipment{},
IDInteract: &Interact{},
IDBlockPickRequest: &BlockPickRequest{},
IDActorPickRequest: &ActorPickRequest{},
IDPlayerAction: &PlayerAction{},
IDActorFall: &ActorFall{},
IDHurtArmour: &HurtArmour{},
IDSetActorData: &SetActorData{},
IDSetActorMotion: &SetActorMotion{},
IDSetActorLink: &SetActorLink{},
IDSetHealth: &SetHealth{},
IDSetSpawnPosition: &SetSpawnPosition{},
IDAnimate: &Animate{},
IDRespawn: &Respawn{},
IDContainerOpen: &ContainerOpen{},
IDContainerClose: &ContainerClose{},
IDPlayerHotBar: &PlayerHotBar{},
IDInventoryContent: &InventoryContent{},
IDInventorySlot: &InventorySlot{},
IDContainerSetData: &ContainerSetData{},
IDCraftingData: &CraftingData{},
IDCraftingEvent: &CraftingEvent{},
IDGUIDataPickItem: &GUIDataPickItem{},
IDAdventureSettings: &AdventureSettings{},
IDBlockActorData: &BlockActorData{},
IDPlayerInput: &PlayerInput{},
IDLevelChunk: &LevelChunk{},
IDSetCommandsEnabled: &SetCommandsEnabled{},
IDSetDifficulty: &SetDifficulty{},
IDChangeDimension: &ChangeDimension{},
IDSetPlayerGameType: &SetPlayerGameType{},
IDPlayerList: &PlayerList{},
IDSimpleEvent: &SimpleEvent{},
IDEvent: &Event{},
IDSpawnExperienceOrb: &SpawnExperienceOrb{},
IDClientBoundMapItemData: &ClientBoundMapItemData{},
IDMapInfoRequest: &MapInfoRequest{},
IDRequestChunkRadius: &RequestChunkRadius{},
IDChunkRadiusUpdated: &ChunkRadiusUpdated{},
IDItemFrameDropItem: &ItemFrameDropItem{},
IDGameRulesChanged: &GameRulesChanged{},
IDCamera: &Camera{},
IDBossEvent: &BossEvent{},
IDShowCredits: &ShowCredits{},
IDAvailableCommands: &AvailableCommands{},
IDCommandRequest: &CommandRequest{},
IDCommandBlockUpdate: &CommandBlockUpdate{},
IDCommandOutput: &CommandOutput{},
IDUpdateTrade: &UpdateTrade{},
IDUpdateEquip: &UpdateEquip{},
IDResourcePackDataInfo: &ResourcePackDataInfo{},
IDResourcePackChunkData: &ResourcePackChunkData{},
IDResourcePackChunkRequest: &ResourcePackChunkRequest{},
IDTransfer: &Transfer{},
IDPlaySound: &PlaySound{},
IDStopSound: &StopSound{},
IDSetTitle: &SetTitle{},
IDAddBehaviourTree: &AddBehaviourTree{},
IDStructureBlockUpdate: &StructureBlockUpdate{},
IDShowStoreOffer: &ShowStoreOffer{},
IDPurchaseReceipt: &PurchaseReceipt{},
IDPlayerSkin: &PlayerSkin{},
IDSubClientLogin: &SubClientLogin{},
IDAutomationClientConnect: &AutomationClientConnect{},
IDSetLastHurtBy: &SetLastHurtBy{},
IDBookEdit: &BookEdit{},
IDNPCRequest: &NPCRequest{},
IDPhotoTransfer: &PhotoTransfer{},
IDModalFormRequest: &ModalFormRequest{},
IDModalFormResponse: &ModalFormResponse{},
IDServerSettingsRequest: &ServerSettingsRequest{},
IDServerSettingsResponse: &ServerSettingsResponse{},
IDShowProfile: &ShowProfile{},
IDSetDefaultGameType: &SetDefaultGameType{},
IDRemoveObjective: &RemoveObjective{},
IDSetDisplayObjective: &SetDisplayObjective{},
IDSetScore: &SetScore{},
IDLabTable: &LabTable{},
IDUpdateBlockSynced: &UpdateBlockSynced{},
IDMoveActorDelta: &MoveActorDelta{},
IDSetScoreboardIdentity: &SetScoreboardIdentity{},
IDSetLocalPlayerAsInitialised: &SetLocalPlayerAsInitialised{},
IDUpdateSoftEnum: &UpdateSoftEnum{},
IDNetworkStackLatency: &NetworkStackLatency{},
// ---
IDScriptCustomEvent: &ScriptCustomEvent{},
IDSpawnParticleEffect: &SpawnParticleEffect{},
IDAvailableActorIdentifiers: &AvailableActorIdentifiers{},
IDNetworkChunkPublisherUpdate: &NetworkChunkPublisherUpdate{},
IDBiomeDefinitionList: &BiomeDefinitionList{},
IDLevelSoundEvent: &LevelSoundEvent{},
IDLevelEventGeneric: &LevelEventGeneric{},
IDLecternUpdate: &LecternUpdate{},
// ---
IDAddEntity: &AddEntity{},
IDRemoveEntity: &RemoveEntity{},
IDClientCacheStatus: &ClientCacheStatus{},
IDOnScreenTextureAnimation: &OnScreenTextureAnimation{},
IDMapCreateLockedCopy: &MapCreateLockedCopy{},
IDStructureTemplateDataRequest: &StructureTemplateDataExportResponse{},
IDStructureTemplateDataResponse: &StructureTemplateDataExportResponse{},
IDUpdateBlockProperties: &UpdateBlockProperties{},
IDClientCacheBlobStatus: &ClientCacheBlobStatus{},
IDClientCacheMissResponse: &ClientCacheMissResponse{},
IDEducationSettings: &EducationSettings{},
IDEmote: &Emote{},
IDMultiPlayerSettings: &MultiPlayerSettings{},
IDSettingsCommand: &SettingsCommand{},
IDAnvilDamage: &AnvilDamage{},
IDCompletedUsingItem: &CompletedUsingItem{},
IDNetworkSettings: &NetworkSettings{},
IDPlayerAuthInput: &PlayerAuthInput{},
IDCreativeContent: &CreativeContent{},
IDPlayerEnchantOptions: &PlayerEnchantOptions{},
IDItemStackRequest: &ItemStackRequest{},
IDItemStackResponse: &ItemStackResponse{},
IDPlayerArmourDamage: &PlayerArmourDamage{},
IDCodeBuilder: &CodeBuilder{},
IDUpdatePlayerGameType: &UpdatePlayerGameType{},
IDEmoteList: &EmoteList{},
IDPositionTrackingDBServerBroadcast: &PositionTrackingDBServerBroadcast{},
IDPositionTrackingDBClientRequest: &PositionTrackingDBClientRequest{},
IDDebugInfo: &DebugInfo{},
IDPacketViolationWarning: &PacketViolationWarning{},
}
for id, pk := range registeredPackets {
p[id] = pk()
}
return p
}
// PacketsByName is a map holding a function to create a new packet for each packet registered in Pool. These
// functions are indexed using the exact packet name they return.
var PacketsByName = map[string]func() Packet{}
func init() {
for _, packet := range NewPool() {
pk := packet
PacketsByName[reflect.TypeOf(pk).Elem().Name()] = func() Packet {
return reflect.New(reflect.TypeOf(pk).Elem()).Interface().(Packet)
}
}
}