Skip to content

Commit

Permalink
REFAC(server): Refactor WhisperTarget struct
Browse files Browse the repository at this point in the history
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 b7a46b2)
  • Loading branch information
Krzmbrzl committed Apr 6, 2024
1 parent 21998b8 commit 5fb748b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
26 changes: 15 additions & 11 deletions src/murmur/Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/murmur/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2360,14 +2360,14 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons

WhisperTargetCache cache;

if (!target.qlChannels.isEmpty()) {
for (const WhisperTarget::Channel &currentTarget : target.qlChannels) {
Channel *targetChannel = qhChannels.value(static_cast< unsigned int >(currentTarget.iId));
if (!target.channels.empty()) {
for (const WhisperTarget::Channel &currentTarget : 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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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))
Expand Down
15 changes: 9 additions & 6 deletions src/murmur/ServerUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# include <sys/socket.h>
#endif

#include <vector>

// Unfortunately, this needs to be "large enough" to hold
// enough frames to account for both short-term and
// long-term "maladjustments".
Expand All @@ -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;
Expand Down

0 comments on commit 5fb748b

Please sign in to comment.