@@ -187,54 +187,7 @@ class ConnectionModule(reactContext: ReactApplicationContext)
187187 return @launch
188188 }
189189
190- // Login state packet IDs
191- val loginSuccessId = 0x02
192- val loginAcknowledgedId = 0x03
193- val setCompressionId = 0x03
194- // Configuration state packet IDs
195- val configurationKeepAliveClientBoundId =
196- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x04
197- else 0x03
198- val configurationKeepAliveServerBoundId =
199- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x04
200- else 0x03
201- val finishConfigurationClientBoundId =
202- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x03
203- else 0x02
204- val finishConfigurationServerBoundId =
205- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x03
206- else 0x02
207- // Play state packet IDs
208- val startConfigurationClientBoundId =
209- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x69
210- else if (protocolVersion >= PROTOCOL_VERSION_1203 ) 0x67
211- else if (protocolVersion >= PROTOCOL_VERSION_1202 ) 0x65
212- else - 1
213- val acknowledgeConfigurationServerBoundId =
214- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x0c
215- else if (protocolVersion >= PROTOCOL_VERSION_1202 ) 0x0b
216- else - 1
217- val playKeepAliveClientBoundId =
218- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x26
219- else if (protocolVersion >= PROTOCOL_VERSION_1202 ) 0x24
220- else if (protocolVersion >= PROTOCOL_VERSION_1194 ) 0x23
221- else if (protocolVersion >= PROTOCOL_VERSION_1193 ) 0x1f
222- else if (protocolVersion >= PROTOCOL_VERSION_1191 ) 0x20
223- else if (protocolVersion >= PROTOCOL_VERSION_119 ) 0x1e
224- else if (protocolVersion >= PROTOCOL_VERSION_117 ) 0x21
225- else if (protocolVersion >= PROTOCOL_VERSION_1164 ) 0x1f
226- else - 1
227- val playKeepAliveServerBoundId =
228- if (protocolVersion >= PROTOCOL_VERSION_1205 ) 0x18
229- else if (protocolVersion >= PROTOCOL_VERSION_1203 ) 0x15
230- else if (protocolVersion >= PROTOCOL_VERSION_1202 ) 0x14
231- else if (protocolVersion >= PROTOCOL_VERSION_1194 ) 0x12
232- else if (protocolVersion >= PROTOCOL_VERSION_1193 ) 0x11
233- else if (protocolVersion >= PROTOCOL_VERSION_1191 ) 0x12
234- else if (protocolVersion >= PROTOCOL_VERSION_119 ) 0x11
235- else if (protocolVersion >= PROTOCOL_VERSION_117 ) 0x0f
236- else if (protocolVersion >= PROTOCOL_VERSION_1164 ) 0x10
237- else - 1
190+ val ids = PacketIds (protocolVersion)
238191
239192 // Re-use the current thread, start reading from the socket.
240193 val buffer = ByteArrayOutputStream ()
@@ -274,28 +227,28 @@ class ConnectionModule(reactContext: ReactApplicationContext)
274227 // and Start/Finish Configuration state changes.
275228 // FIXME: I feel this is incorrect logic and writePacket should also have a write lock?
276229 // No write lock since writePacket isn't called during login/config sequence (usually).
277- if (packet.id.value == playKeepAliveClientBoundId && state == ConnectionState .PLAY ) {
278- directlyWritePacket(playKeepAliveServerBoundId , packet.data)
279- } else if (packet.id.value == configurationKeepAliveClientBoundId &&
230+ if (packet.id.value == ids.playKeepAliveClientBound && state == ConnectionState .PLAY ) {
231+ directlyWritePacket(ids.playKeepAliveServerBound , packet.data)
232+ } else if (packet.id.value == ids.configurationKeepAliveClientBound &&
280233 state == ConnectionState .CONFIGURATION ) {
281- directlyWritePacket(configurationKeepAliveServerBoundId , packet.data)
282- } else if (packet.id.value == setCompressionId && state == ConnectionState .LOGIN ) {
234+ directlyWritePacket(ids.configurationKeepAliveServerBound , packet.data)
235+ } else if (packet.id.value == ids.setCompression && state == ConnectionState .LOGIN ) {
283236 val threshold = VarInt .read(packet.data)?.value ? : 0
284237 compressionThreshold = threshold
285238 compressionEnabled = threshold >= 0
286- } else if (packet.id.value == loginSuccessId && state == ConnectionState .LOGIN ) {
239+ } else if (packet.id.value == ids.loginSuccess && state == ConnectionState .LOGIN ) {
287240 state = if (protocolVersion >= PROTOCOL_VERSION_1202 ) {
288- directlyWritePacket(loginAcknowledgedId , ByteArray (0 ))
241+ directlyWritePacket(ids.loginAcknowledged , ByteArray (0 ))
289242 ConnectionState .CONFIGURATION
290243 } else ConnectionState .PLAY
291- } else if (packet.id.value == finishConfigurationClientBoundId &&
244+ } else if (packet.id.value == ids.finishConfigurationClientBound &&
292245 state == ConnectionState .CONFIGURATION ) {
293246 state = ConnectionState .PLAY
294- directlyWritePacket(finishConfigurationServerBoundId , ByteArray (0 ))
295- } else if (packet.id.value == startConfigurationClientBoundId &&
247+ directlyWritePacket(ids.finishConfigurationServerBound , ByteArray (0 ))
248+ } else if (packet.id.value == ids.startConfigurationClientBound &&
296249 state == ConnectionState .PLAY ) {
297250 state = ConnectionState .CONFIGURATION
298- directlyWritePacket(acknowledgeConfigurationServerBoundId , ByteArray (0 ))
251+ directlyWritePacket(ids.acknowledgeConfigurationServerBound , ByteArray (0 ))
299252 }
300253
301254 // Forward the packet to JavaScript.
0 commit comments