From 5fb748b111d7ba6a47675c106a0abd886cd151ec Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 6 Apr 2024 16:58:02 +0200 Subject: [PATCH] REFAC(server): Refactor WhisperTarget struct Switch to using an unsigned integer as channel ID and rename member variables to no longer include their type as part of the name (and make names more meaningful in general). Additionally, some Qt containers were replaced with std ones. (cherry picked from commit b7a46b20ab6fe3048a7715a3b06a928936b85215) --- src/murmur/Messages.cpp | 26 +++++++++++++++----------- src/murmur/Server.cpp | 18 +++++++++--------- src/murmur/ServerUser.h | 15 +++++++++------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/murmur/Messages.cpp b/src/murmur/Messages.cpp index 50fbbc3f2df..d02fd572c66 100644 --- a/src/murmur/Messages.cpp +++ b/src/murmur/Messages.cpp @@ -2192,26 +2192,30 @@ void Server::msgVoiceTarget(ServerUser *uSource, MumbleProto::VoiceTarget &msg) const MumbleProto::VoiceTarget_Target &t = msg.targets(i); for (int j = 0; j < t.session_size(); ++j) { unsigned int s = t.session(j); - if (qhUsers.contains(s)) - wt.qlSessions << s; + if (qhUsers.contains(s)) { + wt.sessions.push_back(s); + } } if (t.has_channel_id()) { unsigned int id = t.channel_id(); if (qhChannels.contains(id)) { WhisperTarget::Channel wtc; - wtc.iId = static_cast< int >(id); - wtc.bChildren = t.children(); - wtc.bLinks = t.links(); - if (t.has_group()) - wtc.qsGroup = u8(t.group()); - wt.qlChannels << wtc; + wtc.id = id; + wtc.includeChildren = t.children(); + wtc.includeLinks = t.links(); + if (t.has_group()) { + wtc.targetGroup = u8(t.group()); + } + + wt.channels.push_back(wtc); } } } - if (wt.qlSessions.isEmpty() && wt.qlChannels.isEmpty()) + if (wt.sessions.empty() && wt.channels.empty()) { uSource->qmTargets.remove(target); - else - uSource->qmTargets.insert(target, wt); + } else { + uSource->qmTargets.insert(target, std::move(wt)); + } } } diff --git a/src/murmur/Server.cpp b/src/murmur/Server.cpp index 204b283ba18..224897ea0bb 100644 --- a/src/murmur/Server.cpp +++ b/src/murmur/Server.cpp @@ -2360,14 +2360,14 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons WhisperTargetCache cache; - if (!target.qlChannels.isEmpty()) { - for (const WhisperTarget::Channel ¤tTarget : target.qlChannels) { - Channel *targetChannel = qhChannels.value(static_cast< unsigned int >(currentTarget.iId)); + if (!target.channels.empty()) { + for (const WhisperTarget::Channel ¤tTarget : target.channels) { + Channel *targetChannel = qhChannels.value(currentTarget.id); if (targetChannel) { - bool includeLinks = currentTarget.bLinks && !targetChannel->qhLinks.isEmpty(); - bool includeChildren = currentTarget.bChildren && !targetChannel->qlChannels.isEmpty(); - bool restrictToGroup = !currentTarget.qsGroup.isEmpty(); + bool includeLinks = currentTarget.includeLinks && !targetChannel->qhLinks.isEmpty(); + bool includeChildren = currentTarget.includeChildren && !targetChannel->qlChannels.isEmpty(); + bool restrictToGroup = !currentTarget.targetGroup.isEmpty(); if (!includeLinks && !includeChildren && !restrictToGroup) { // Common case @@ -2404,8 +2404,8 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons // The target group might be changed by a redirect set up via RPC (Ice/gRPC). In that // case the shout is sent to the redirection target instead the originally specified group - const QString &redirect = speaker.qmWhisperRedirect.value(currentTarget.qsGroup); - const QString &targetGroup = redirect.isEmpty() ? currentTarget.qsGroup : redirect; + const QString &redirect = speaker.qmWhisperRedirect.value(currentTarget.targetGroup); + const QString &targetGroup = redirect.isEmpty() ? currentTarget.targetGroup : redirect; for (Channel *subTargetChan : channels) { if (ChanACL::hasPermission(&speaker, subTargetChan, ChanACL::Whisper, &acCache)) { @@ -2437,7 +2437,7 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons } } - for (unsigned int id : target.qlSessions) { + for (unsigned int id : target.sessions) { ServerUser *pDst = qhUsers.value(id); if (pDst && ChanACL::hasPermission(&speaker, pDst->cChannel, ChanACL::Whisper, &acCache) && !cache.channelTargets.contains(pDst)) diff --git a/src/murmur/ServerUser.h b/src/murmur/ServerUser.h index dccf491c9a4..e91f4c879f3 100644 --- a/src/murmur/ServerUser.h +++ b/src/murmur/ServerUser.h @@ -27,6 +27,8 @@ # include #endif +#include + // Unfortunately, this needs to be "large enough" to hold // enough frames to account for both short-term and // long-term "maladjustments". @@ -52,13 +54,14 @@ struct BandwidthRecord { struct WhisperTarget { struct Channel { - int iId; - bool bChildren; - bool bLinks; - QString qsGroup; + unsigned int id; + bool includeChildren; + bool includeLinks; + QString targetGroup; }; - QList< unsigned int > qlSessions; - QList< WhisperTarget::Channel > qlChannels; + + std::vector< unsigned int > sessions; + std::vector< WhisperTarget::Channel > channels; }; class ServerUser;