[Fix] Receiving voice packets (use system-assigned port) (#2857)
* Voice receive fix (use system-selected port) * Update SocketGuild.cs --------- Co-authored-by: Misha133 <mihagribkov133@gmail.com>
This commit is contained in:
@@ -321,11 +321,9 @@ namespace Discord.Audio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string ip;
|
string ip;
|
||||||
int port;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ip = Encoding.UTF8.GetString(packet, 8, 74 - 10).TrimEnd('\0');
|
ip = Encoding.UTF8.GetString(packet, 8, 74 - 10).TrimEnd('\0');
|
||||||
port = (packet[73] << 8) | packet[72];
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -334,7 +332,7 @@ namespace Discord.Audio
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _audioLogger.DebugAsync("Received Discovery").ConfigureAwait(false);
|
await _audioLogger.DebugAsync("Received Discovery").ConfigureAwait(false);
|
||||||
await ApiClient.SendSelectProtocol(ip, port).ConfigureAwait(false);
|
await ApiClient.SendSelectProtocol(ip).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (_connection.State == ConnectionState.Connected)
|
else if (_connection.State == ConnectionState.Connected)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace Discord.Audio
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task SendSelectProtocol(string externalIp, int externalPort)
|
public Task SendSelectProtocol(string externalIp)
|
||||||
{
|
{
|
||||||
return SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
|
return SendAsync(VoiceOpCode.SelectProtocol, new SelectProtocolParams
|
||||||
{
|
{
|
||||||
@@ -151,7 +151,7 @@ namespace Discord.Audio
|
|||||||
Data = new UdpProtocolInfo
|
Data = new UdpProtocolInfo
|
||||||
{
|
{
|
||||||
Address = externalIp,
|
Address = externalIp,
|
||||||
Port = externalPort,
|
Port = UdpPort,
|
||||||
Mode = Mode
|
Mode = Mode
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1744,11 +1744,9 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
if (external)
|
if (external)
|
||||||
{
|
{
|
||||||
#pragma warning disable IDISP001
|
_ = promise.TrySetResultAsync(null);
|
||||||
var _ = promise.TrySetResultAsync(null);
|
|
||||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false);
|
await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
#pragma warning restore IDISP001
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_audioClient == null)
|
if (_audioClient == null)
|
||||||
@@ -1766,19 +1764,15 @@ namespace Discord.WebSocket
|
|||||||
await promise.TrySetExceptionAsync(ex);
|
await promise.TrySetExceptionAsync(ex);
|
||||||
else
|
else
|
||||||
await promise.TrySetCanceledAsync();
|
await promise.TrySetCanceledAsync();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
audioClient.Connected += () =>
|
audioClient.Connected += () =>
|
||||||
{
|
{
|
||||||
#pragma warning disable IDISP001
|
_ = promise.TrySetResultAsync(_audioClient);
|
||||||
var _ = promise.TrySetResultAsync(_audioClient);
|
|
||||||
#pragma warning restore IDISP001
|
|
||||||
return Task.Delay(0);
|
return Task.Delay(0);
|
||||||
};
|
};
|
||||||
#pragma warning disable IDISP003
|
|
||||||
_audioClient = audioClient;
|
_audioClient = audioClient;
|
||||||
#pragma warning restore IDISP003
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false);
|
await Discord.ApiClient.SendVoiceStateUpdateAsync(_voiceStateUpdateParams).ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user