@@ -41,8 +41,7 @@ import {
41
41
ClickEvent ,
42
42
ColorMap
43
43
} from '../../minecraft/chatToJsx'
44
- import { protocolMap , writeVarInt } from '../../minecraft/utils'
45
- import { concatPacketData , PacketDataTypes } from '../../minecraft/packet'
44
+ import { makeChatMessagePacket } from '../../minecraft/packets/chat'
46
45
import TextField from '../../components/TextField'
47
46
import Text from '../../components/Text'
48
47
@@ -254,38 +253,10 @@ const ChatScreen = ({ navigation, route }: Props) => {
254
253
if ( msg . startsWith ( '/' ) && saveHistory ) {
255
254
setCommandHistory ( ch => ch . concat ( [ msg ] ) )
256
255
}
257
- const is119 =
258
- connection . connection . options . protocolVersion >= protocolMap [ 1.19 ]
259
- const is1191 =
260
- connection . connection . options . protocolVersion >= protocolMap [ '1.19.1' ]
261
- if ( ! is119 ) {
262
- connection . connection
263
- . writePacket ( 0x03 , concatPacketData ( [ msg ] ) )
264
- . catch ( handleError ( addMessage , sendMessageError ) )
265
- } else {
266
- const id = msg . startsWith ( '/' )
267
- ? is1191
268
- ? 0x04
269
- : 0x03
270
- : is1191
271
- ? 0x05
272
- : 0x04
273
- const timestamp = Buffer . alloc ( 8 )
274
- timestamp . writeIntBE ( Date . now ( ) , 2 , 6 ) // writeBigInt64BE(BigInt(Date.now()))
275
- const salt = connection . connection . msgSalt ?? Buffer . alloc ( 8 )
276
- // TODO-1.19: Send signature(s), preview chat, last seen messages and last received message if possible.
277
- const data : PacketDataTypes [ ] = [
278
- msg . startsWith ( '/' ) ? msg . substring ( 1 ) : msg ,
279
- timestamp ,
280
- salt ,
281
- writeVarInt ( 0 ) ,
282
- false
283
- ]
284
- if ( is1191 ) data . push ( writeVarInt ( 0 ) , writeVarInt ( 0 ) )
285
- connection . connection
286
- . writePacket ( id , concatPacketData ( data ) )
287
- . catch ( handleError ( addMessage , sendMessageError ) )
288
- }
256
+ const protocolVersion = connection . connection . options . protocolVersion
257
+ connection . connection
258
+ . writePacket ( ...makeChatMessagePacket ( msg , protocolVersion ) )
259
+ . catch ( handleError ( addMessage , sendMessageError ) )
289
260
}
290
261
291
262
const handleClickEvent = useCallback (
0 commit comments