Skip to content

Commit

Permalink
Implement support for "Ping (play)" packet.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jun 6, 2023
1 parent 7767ddf commit fcef88f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/minecraft/packets/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ const packetIds = {
[protocolMap['1.19.1'], 0x62],
[protocolMap['1.19'], 0x5f]
]),
CLIENTBOUND_PING: generateIdFunction([
[protocolMap['1.19.4'], 0x32],
[protocolMap['1.19.3'], 0x2e],
[protocolMap['1.19.1'], 0x2f],
[protocolMap['1.19'], 0x2d],
[protocolMap['1.17'], 0x30]
]),

// Serverbound (play)
SERVERBOUND_KEEP_ALIVE: generateIdFunction([
Expand Down Expand Up @@ -126,6 +133,13 @@ const packetIds = {
[protocolMap['1.19.1'], 0x04],
[protocolMap['1.19'], 0x03],
[protocolMap['1.16.4'], null]
]),
SERVERBOUND_PONG: generateIdFunction([
[protocolMap['1.19.4'], 0x20],
[protocolMap['1.19.3'], 0x1f],
[protocolMap['1.19.1'], 0x20],
[protocolMap['1.19'], 0x1f],
[protocolMap['1.17'], 0x1d]
])
}

Expand Down
5 changes: 5 additions & 0 deletions src/screens/chat/packetHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import packetIds from '../../minecraft/packets/ids'

export const enderChatPrefix = '\u00A74[\u00A7cEnderChat\u00A74] \u00A7c'
export const parseMessageError = 'An error occurred when parsing chat.'
export const unknownError = 'An unknown error occurred.'
export const clientSettingsError =
'An error occurred when sending client settings.'
export const inventoryCloseError =
Expand Down Expand Up @@ -216,5 +217,9 @@ export const packetHandler =
addMessage(info)
} // LOW-TODO: Long-term it would be better to have a UI.
healthRef.current = newHealth
} else if (packet.id === packetIds.CLIENTBOUND_PING(version)) {
connection // Pong (play)
.writePacket(packetIds.SERVERBOUND_PONG(version) ?? 0, packet.data)
.catch(handleError(addMessage, unknownError))
}
}

0 comments on commit fcef88f

Please sign in to comment.