Skip to content

Commit 0846183

Browse files
committed
Initial 1.20.3 work, fix pinging certain servers
1 parent 7420409 commit 0846183

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class ConnectionModule(reactContext: ReactApplicationContext)
197197
val is1193 = protocolVersion >= PROTOCOL_VERSION_1193
198198
val is1194 = protocolVersion >= PROTOCOL_VERSION_1194
199199
val is1202 = protocolVersion >= PROTOCOL_VERSION_1202
200+
val is1203 = protocolVersion >= PROTOCOL_VERSION_1203
200201
// Login state packet IDs
201202
val loginSuccessId = 0x02
202203
val loginAcknowledgedId = 0x03
@@ -208,9 +209,10 @@ class ConnectionModule(reactContext: ReactApplicationContext)
208209
val finishConfigurationServerBoundId = 0x02
209210
// Play state packet IDs
210211
val startConfigurationClientBoundId =
211-
if (is1202) 0x65
212+
if (is1203) 0x67
213+
else if (is1202) 0x65
212214
else -1
213-
val configurationAcknowledgedServerBoundId =
215+
val acknowledgeConfigurationServerBoundId =
214216
if (is1202) 0x0b
215217
else -1
216218
val playKeepAliveClientBoundId =
@@ -223,7 +225,8 @@ class ConnectionModule(reactContext: ReactApplicationContext)
223225
else if (is1164) 0x1f
224226
else -1
225227
val playKeepAliveServerBoundId =
226-
if (is1202) 0x14
228+
if (is1203) 0x15
229+
else if (is1202) 0x14
227230
else if (is1194) 0x12
228231
else if (is1193) 0x11
229232
else if (is1191) 0x12
@@ -291,7 +294,7 @@ class ConnectionModule(reactContext: ReactApplicationContext)
291294
} else if (packet.id.value == startConfigurationClientBoundId &&
292295
state == ConnectionState.PLAY) {
293296
state = ConnectionState.CONFIGURATION
294-
directlyWritePacket(configurationAcknowledgedServerBoundId, ByteArray(0))
297+
directlyWritePacket(acknowledgeConfigurationServerBoundId, ByteArray(0))
295298
}
296299

297300
// Forward the packet to JavaScript.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const val PROTOCOL_VERSION_1191 = 760
1717
const val PROTOCOL_VERSION_1193 = 761
1818
const val PROTOCOL_VERSION_1194 = 762
1919
const val PROTOCOL_VERSION_1202 = 764
20+
const val PROTOCOL_VERSION_1203 = 765
2021

2122
fun compressData(bytes: ByteArray): ByteArray {
2223
ByteArrayOutputStream(bytes.size).use {

src/minecraft/chatToJsx.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface BaseChat {
6363
insertion?: string // LOW-TODO: Support this.
6464
clickEvent?: ClickEvent
6565
hoverEvent?: HoverEvent
66+
type?: 'text' | 'translatable' | 'score' | 'keybind' | 'nbt' // LOW-TODO: Support keybind and score
6667
}
6768

6869
export interface PlainTextChat extends BaseChat {

src/minecraft/connection/javascript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const initiateJavaScriptConnection = async (
171171
conn.state === ConnectionState.PLAY
172172
) {
173173
const ackPacketId =
174-
packetIds.SERVERBOUND_CONFIGURATION_ACKNOWLEDGED(version)
174+
packetIds.SERVERBOUND_ACKNOWLEDGE_CONFIGURATION(version)
175175
conn
176176
.writePacket(ackPacketId ?? 0, Buffer.from([]))
177177
.catch(err => conn.emit('error', err))

src/minecraft/packets/ids.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const packetIds = {
8585
[protocolMap['1.16.4'], 0x24]
8686
]),
8787
CLIENTBOUND_RESPAWN: generateIdFunction([
88+
[protocolMap['1.20.3'], 0x45],
8889
[protocolMap['1.20.2'], 0x43],
8990
[protocolMap['1.19.4'], 0x41],
9091
[protocolMap['1.19.3'], 0x3d],
@@ -95,6 +96,7 @@ const packetIds = {
9596
]),
9697
// AKA Set Health
9798
CLIENTBOUND_UPDATE_HEALTH: generateIdFunction([
99+
[protocolMap['1.20.3'], 0x5b],
98100
[protocolMap['1.20.2'], 0x59],
99101
[protocolMap['1.19.4'], 0x57],
100102
[protocolMap['1.19.3'], 0x53],
@@ -134,6 +136,7 @@ const packetIds = {
134136
[protocolMap['1.19'], 0x30]
135137
]),
136138
CLIENTBOUND_SYSTEM_CHAT_MESSAGE: generateIdFunction([
139+
[protocolMap['1.20.3'], 0x69],
137140
[protocolMap['1.20.2'], 0x67],
138141
[protocolMap['1.19.4'], 0x64],
139142
[protocolMap['1.19.3'], 0x60],
@@ -149,13 +152,15 @@ const packetIds = {
149152
[protocolMap['1.17'], 0x30]
150153
]),
151154
CLIENTBOUND_START_CONFIGURATION: generateIdFunction([
155+
[protocolMap['1.20.3'], 0x67],
152156
[protocolMap['1.20.2'], 0x65]
153157
]),
154158

155159
// ==================
156160
// Serverbound (play)
157161
// ==================
158162
SERVERBOUND_KEEP_ALIVE_PLAY: generateIdFunction([
163+
[protocolMap['1.20.3'], 0x15],
159164
[protocolMap['1.20.2'], 0x14],
160165
[protocolMap['1.19.4'], 0x12],
161166
[protocolMap['1.19.3'], 0x11],
@@ -203,14 +208,15 @@ const packetIds = {
203208
[protocolMap['1.16.4'], null]
204209
]),
205210
SERVERBOUND_PONG_PLAY: generateIdFunction([
211+
[protocolMap['1.20.3'], 0x24],
206212
[protocolMap['1.20.2'], 0x23],
207213
[protocolMap['1.19.4'], 0x20],
208214
[protocolMap['1.19.3'], 0x1f],
209215
[protocolMap['1.19.1'], 0x20],
210216
[protocolMap['1.19'], 0x1f],
211217
[protocolMap['1.17'], 0x1d]
212218
]),
213-
SERVERBOUND_CONFIGURATION_ACKNOWLEDGED: generateIdFunction([
219+
SERVERBOUND_ACKNOWLEDGE_CONFIGURATION: generateIdFunction([
214220
[protocolMap['1.20.2'], 0x0b]
215221
])
216222
}

src/minecraft/pingServer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
padBufferToLength,
77
resolveHostname,
88
readVarInt,
9-
writeVarInt
9+
writeVarInt,
10+
protocolMap
1011
} from './utils'
1112
import {
1213
makeBasePacket,
@@ -116,7 +117,12 @@ export const modernPing = async (opts: {
116117
// Create data to send in Handshake.
117118
const portBuf = Buffer.alloc(2)
118119
portBuf.writeUInt16BE(port)
119-
const handshakeData = [writeVarInt(-1), host, portBuf, writeVarInt(1)]
120+
const handshakeData = [
121+
writeVarInt(protocolMap.latest), // It would be better to use -1, but some servers misbehave
122+
host,
123+
portBuf,
124+
writeVarInt(1)
125+
]
120126

121127
// Initialise Handshake with server.
122128
socket.write(makeBasePacket(0x00, concatPacketData(handshakeData)), () =>
@@ -146,7 +152,7 @@ export const modernPing = async (opts: {
146152
try {
147153
const responsePacket = packets.find(p => p.id === 0x00)
148154
if (!responsePacket) {
149-
return reject(new TypeError('No response packet was sent!'))
155+
return reject(new Error('No response packet was sent!'))
150156
}
151157
const [jsonLength, varIntLength] = readVarInt(responsePacket.data)
152158
const json = responsePacket.data

src/minecraft/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const protocolMap = {
1818
'1.20': 763,
1919
'1.20.1': 763,
2020
'1.20.2': 764,
21+
'1.20.3': 765,
22+
'1.20.4': 765,
2123
latest: 764,
2224
auto: -1
2325
}

0 commit comments

Comments
 (0)