Skip to content

Commit

Permalink
Use 74 byte payload for udp discovery (#2413)
Browse files Browse the repository at this point in the history
* Use 74 byte payload for udp discovery
* Bump to 4.4.1
  • Loading branch information
MinnDevelopment committed Mar 1, 2023
1 parent c2d16c8 commit 39ba0c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -29,7 +29,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "5.1.0"
}

val versionObj = Version(major = "4", minor = "4", revision = "0")
val versionObj = Version(major = "4", minor = "4", revision = "1")

project.group = "net.dv8tion"
project.version = "$versionObj"
Expand Down
Expand Up @@ -583,8 +583,8 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc
//Create new UDP socket for communication
audioConnection.udpSocket = new DatagramSocket();

//Create a byte array of length 70 containing our ssrc.
ByteBuffer buffer = ByteBuffer.allocate(70); //70 taken from documentation
//Create a byte array of length 74 containing our ssrc.
ByteBuffer buffer = ByteBuffer.allocate(74); //74 taken from documentation
buffer.putShort((short) 1); // 1 = send (receive will be 2)
buffer.putShort((short) 70); // length = 70 bytes (required)
buffer.putInt(ssrc); // Put the ssrc that we were given into the packet to send back to discord.
Expand All @@ -595,7 +595,7 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc
audioConnection.udpSocket.send(discoveryPacket);

//Discord responds to our packet, returning a packet containing our external ip and the port we connected through.
DatagramPacket receivedPacket = new DatagramPacket(new byte[70], 70); //Give a buffer the same size as the one we sent.
DatagramPacket receivedPacket = new DatagramPacket(new byte[74], 74); //Give a buffer the same size as the one we sent.
audioConnection.udpSocket.setSoTimeout(1000);
audioConnection.udpSocket.receive(receivedPacket);

Expand All @@ -609,7 +609,7 @@ private InetSocketAddress handleUdpDiscovery(InetSocketAddress address, int ssrc

//Take bytes between SSRC and PORT and put them into a string
// null bytes at the beginning are skipped and the rest are appended to the end of the string
String ourIP = new String(received, 4, received.length - 6);
String ourIP = new String(received, 8, received.length - 10);
// Removes the extra nulls attached to the end of the IP string
ourIP = ourIP.trim();

Expand Down

0 comments on commit 39ba0c2

Please sign in to comment.