From 916e34280f0907b3f18bd049ab3735c31b114673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Thu, 2 Mar 2023 00:11:06 +0100 Subject: [PATCH] Fix udp discovery not using 74 byte layout --- discord/gateway.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/gateway.py b/discord/gateway.py index 2dd6facbf..faca4b920 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -1047,23 +1047,23 @@ class DiscordVoiceWebSocket: state.voice_port = data['port'] state.endpoint_ip = data['ip'] - packet = bytearray(70) + packet = bytearray(74) struct.pack_into('>H', packet, 0, 1) # 1 = Send struct.pack_into('>H', packet, 2, 70) # 70 = Length struct.pack_into('>I', packet, 4, state.ssrc) state.socket.sendto(packet, (state.endpoint_ip, state.voice_port)) - recv = await self.loop.sock_recv(state.socket, 70) + recv = await self.loop.sock_recv(state.socket, 74) _log.debug('Received packet in initial_connection: %s.', recv) - # the ip is ascii starting at the 4th byte and ending at the first null - ip_start = 4 + # The IP is ASCII starting at the 8th byte and ending at the first null + ip_start = 8 ip_end = recv.index(0, ip_start) state.ip = recv[ip_start:ip_end].decode('ascii') state.port = struct.unpack_from('>H', recv, len(recv) - 2)[0] _log.debug('Detected ip: %s, port: %s.', state.ip, state.port) - # there *should* always be at least one supported mode (xsalsa20_poly1305) + # There *should* always be at least one supported mode (xsalsa20_poly1305) modes = [mode for mode in data['modes'] if mode in self._connection.supported_modes] _log.debug('Received supported encryption modes: %s.', ", ".join(modes))