Skip to content

Commit 2ba981a

Browse files
committed
Acknowledge native conn state changes in JS
Fixed a bug with Velocity where ACK_FINISH_CONFIG was sent prior to KNOWN_PACKS, causing the backend to interpret it as a chat message.
1 parent ab1e5e4 commit 2ba981a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

android/app/src/main/java/com/enderchat/modules/connection/ConnectionModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ class ConnectionModule(reactContext: ReactApplicationContext)
262262
compressionEnabled = threshold >= 0
263263
} else if (packet.id.value == ids.loginSuccess && state == ConnectionState.LOGIN) {
264264
state = if (protocolVersion >= PROTOCOL_VERSION_1202) {
265-
directlyWritePacket(ids.loginAcknowledged, ByteArray(0))
265+
// directlyWritePacket(ids.loginAcknowledged, ByteArray(0))
266266
ConnectionState.CONFIGURATION
267267
} else ConnectionState.PLAY
268268
} else if (packet.id.value == ids.finishConfigurationClientBound &&
269269
state == ConnectionState.CONFIGURATION) {
270270
state = ConnectionState.PLAY
271-
directlyWritePacket(ids.finishConfigurationServerBound, ByteArray(0))
271+
// directlyWritePacket(ids.finishConfigurationServerBound, ByteArray(0))
272272
} else if (packet.id.value == ids.startConfigurationClientBound &&
273273
state == ConnectionState.PLAY) {
274274
state = ConnectionState.CONFIGURATION
275-
directlyWritePacket(ids.acknowledgeConfigurationServerBound, ByteArray(0))
275+
// directlyWritePacket(ids.acknowledgeConfigurationServerBound, ByteArray(0))
276276
}
277277

278278
// Forward the packet to JavaScript.

src/minecraft/connection/native.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,29 @@ export class NativeServerConnection extends events.EventEmitter implements Serve
103103
this.state === ConnectionState.LOGIN
104104
) {
105105
this.state =
106-
version >= protocolMap['1.20.2']
107-
? ConnectionState.CONFIGURATION // Ack sent by native code
108-
: ConnectionState.PLAY
106+
version >= protocolMap['1.20.2'] ? ConnectionState.CONFIGURATION : ConnectionState.PLAY
107+
this.writePacket(
108+
packetIds.SERVERBOUND_LOGIN_ACKNOWLEDGED(version) ?? 0,
109+
Buffer.alloc(0),
110+
).catch((err: unknown) => this.emit('error', err))
109111
} else if (
110112
packet.id === packetIds.CLIENTBOUND_FINISH_CONFIGURATION(version) &&
111113
this.state === ConnectionState.CONFIGURATION
112114
) {
113-
this.state = ConnectionState.PLAY // Ack sent by native code
115+
this.state = ConnectionState.PLAY
116+
this.writePacket(
117+
packetIds.SERVERBOUND_ACK_FINISH_CONFIGURATION(version) ?? 0,
118+
Buffer.alloc(0),
119+
).catch((err: unknown) => this.emit('error', err))
114120
} else if (
115121
packet.id === packetIds.CLIENTBOUND_START_CONFIGURATION(version) &&
116122
this.state === ConnectionState.PLAY
117123
) {
118-
this.state = ConnectionState.CONFIGURATION // Ack sent by native code
124+
this.state = ConnectionState.CONFIGURATION
125+
this.writePacket(
126+
packetIds.SERVERBOUND_ACKNOWLEDGE_CONFIGURATION(version) ?? 0,
127+
Buffer.alloc(0),
128+
).catch((err: unknown) => this.emit('error', err))
119129
} else if (
120130
(packet.id === packetIds.CLIENTBOUND_DISCONNECT_LOGIN(version) &&
121131
this.state === ConnectionState.LOGIN) ||

0 commit comments

Comments
 (0)