Skip to content

Commit

Permalink
tweak(mumble): swap to completely using TCP ping for checking if UDP …
Browse files Browse the repository at this point in the history
…is available

- The previous implementation would constantly swap between UDP/TCP constantly causing the players mic to stutter
- The old implementation should've been completely removed, this is an oversight in f182bb5
  • Loading branch information
AvarianKnight committed Jan 5, 2025
1 parent 6f5c264 commit 08a5077
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion code/components/voip-mumble/include/MumbleClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ class MumbleClient : public IMumbleClient, public Botan::TLS::Callbacks

bool m_hasUdp = false;

std::chrono::milliseconds m_lastUdp;
bool m_udpTimedOut = false;

// the time in milliseconds since the player joined the mumble server
// This is used to determine if we should allow UDP warnings
std::chrono::milliseconds m_timeSinceJoin;

std::chrono::milliseconds m_nextPing;

Expand Down
25 changes: 14 additions & 11 deletions code/components/voip-mumble/src/MumbleClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void MumbleClient::Initialize()

m_voiceTarget = 0;

m_lastUdp = {};
m_nextPing = {};

m_loop = Instance<net::UvLoopManager>::Get()->GetOrCreate("mumble");
Expand Down Expand Up @@ -116,6 +115,7 @@ void MumbleClient::Initialize()

// don't start idle timer here - it should only start after TLS handshake is done!

m_timeSinceJoin = msec();
m_connectionInfo.isConnected = true;
});

Expand Down Expand Up @@ -166,11 +166,6 @@ void MumbleClient::Initialize()
m_idleTimer = m_loop->Get()->resource<uvw::TimerHandle>();
m_idleTimer->on<uvw::TimerEvent>([this](const uvw::TimerEvent& ev, uvw::TimerHandle& t)
{
if (m_hasUdp && (msec() - m_lastUdp) > kUDPTimeout)
{
m_hasUdp = false;
console::PrintWarning("mumble", "Server isn't responding to UDP packets, swapping to TCP.\n");
}

auto lockedIsActive = [this]()
{
Expand Down Expand Up @@ -428,7 +423,6 @@ concurrency::task<MumbleConnectionInfo*> MumbleClient::ConnectAsync(const net::P

m_tcpPingCount = 0;

m_lastUdp = {};

memset(m_tcpPings, 0, sizeof(m_tcpPings));

Expand Down Expand Up @@ -782,8 +776,6 @@ void MumbleClient::HandleUDP(const uint8_t* buf, size_t size)
return;
}

// update UDP timestamp
m_lastUdp = msec();

// handle voice packet
HandleVoice(outBuf, size - 4);
Expand Down Expand Up @@ -971,10 +963,21 @@ void MumbleClient::HandlePing(const MumbleProto::Ping& ping)
m_crypto.m_remoteLost = ping.lost();
m_crypto.m_remoteResync = ping.resync();

if (m_hasUdp && (m_crypto.m_remoteGood == 0 || m_crypto.m_localGood == 0) && (msec() - m_lastUdp) > 2s)
if (m_hasUdp && (m_crypto.m_remoteGood == 0 || m_crypto.m_localGood == 0) && (msec() - m_timeSinceJoin) > 20s)
{
console::PrintWarning("mumble", "UDP packets can *not* be received. Switching to TCP tunnel mode.\n");
m_hasUdp = false;
if (m_crypto.m_remoteGood == 0 && m_crypto.m_localGood == 0)
{
console::PrintWarning("mumble", "UDP packets cannot be sent or received from the server. Switching to TCP mode.");
}
else if (m_crypto.m_remoteGood == 0)
{
console::PrintWarning("mumble", "UDP packets cannot be received by the server. Switching to TCP mode.");
}
else
{
console::PrintWarning("mumble", "UDP packets cannot be received from the server. Switching to TCP mode.");
}
}
else if (!m_hasUdp && m_crypto.m_remoteGood > 3 && m_crypto.m_localGood > 3)
{
Expand Down

0 comments on commit 08a5077

Please sign in to comment.