Skip to content

Commit 5fb748b

Browse files
committed
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 b7a46b2)
1 parent 21998b8 commit 5fb748b

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

src/murmur/Messages.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,26 +2192,30 @@ void Server::msgVoiceTarget(ServerUser *uSource, MumbleProto::VoiceTarget &msg)
21922192
const MumbleProto::VoiceTarget_Target &t = msg.targets(i);
21932193
for (int j = 0; j < t.session_size(); ++j) {
21942194
unsigned int s = t.session(j);
2195-
if (qhUsers.contains(s))
2196-
wt.qlSessions << s;
2195+
if (qhUsers.contains(s)) {
2196+
wt.sessions.push_back(s);
2197+
}
21972198
}
21982199
if (t.has_channel_id()) {
21992200
unsigned int id = t.channel_id();
22002201
if (qhChannels.contains(id)) {
22012202
WhisperTarget::Channel wtc;
2202-
wtc.iId = static_cast< int >(id);
2203-
wtc.bChildren = t.children();
2204-
wtc.bLinks = t.links();
2205-
if (t.has_group())
2206-
wtc.qsGroup = u8(t.group());
2207-
wt.qlChannels << wtc;
2203+
wtc.id = id;
2204+
wtc.includeChildren = t.children();
2205+
wtc.includeLinks = t.links();
2206+
if (t.has_group()) {
2207+
wtc.targetGroup = u8(t.group());
2208+
}
2209+
2210+
wt.channels.push_back(wtc);
22082211
}
22092212
}
22102213
}
2211-
if (wt.qlSessions.isEmpty() && wt.qlChannels.isEmpty())
2214+
if (wt.sessions.empty() && wt.channels.empty()) {
22122215
uSource->qmTargets.remove(target);
2213-
else
2214-
uSource->qmTargets.insert(target, wt);
2216+
} else {
2217+
uSource->qmTargets.insert(target, std::move(wt));
2218+
}
22152219
}
22162220
}
22172221

src/murmur/Server.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,14 +2360,14 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons
23602360

23612361
WhisperTargetCache cache;
23622362

2363-
if (!target.qlChannels.isEmpty()) {
2364-
for (const WhisperTarget::Channel &currentTarget : target.qlChannels) {
2365-
Channel *targetChannel = qhChannels.value(static_cast< unsigned int >(currentTarget.iId));
2363+
if (!target.channels.empty()) {
2364+
for (const WhisperTarget::Channel &currentTarget : target.channels) {
2365+
Channel *targetChannel = qhChannels.value(currentTarget.id);
23662366

23672367
if (targetChannel) {
2368-
bool includeLinks = currentTarget.bLinks && !targetChannel->qhLinks.isEmpty();
2369-
bool includeChildren = currentTarget.bChildren && !targetChannel->qlChannels.isEmpty();
2370-
bool restrictToGroup = !currentTarget.qsGroup.isEmpty();
2368+
bool includeLinks = currentTarget.includeLinks && !targetChannel->qhLinks.isEmpty();
2369+
bool includeChildren = currentTarget.includeChildren && !targetChannel->qlChannels.isEmpty();
2370+
bool restrictToGroup = !currentTarget.targetGroup.isEmpty();
23712371

23722372
if (!includeLinks && !includeChildren && !restrictToGroup) {
23732373
// Common case
@@ -2404,8 +2404,8 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons
24042404

24052405
// The target group might be changed by a redirect set up via RPC (Ice/gRPC). In that
24062406
// case the shout is sent to the redirection target instead the originally specified group
2407-
const QString &redirect = speaker.qmWhisperRedirect.value(currentTarget.qsGroup);
2408-
const QString &targetGroup = redirect.isEmpty() ? currentTarget.qsGroup : redirect;
2407+
const QString &redirect = speaker.qmWhisperRedirect.value(currentTarget.targetGroup);
2408+
const QString &targetGroup = redirect.isEmpty() ? currentTarget.targetGroup : redirect;
24092409

24102410
for (Channel *subTargetChan : channels) {
24112411
if (ChanACL::hasPermission(&speaker, subTargetChan, ChanACL::Whisper, &acCache)) {
@@ -2437,7 +2437,7 @@ WhisperTargetCache Server::createWhisperTargetCacheFor(ServerUser &speaker, cons
24372437
}
24382438
}
24392439

2440-
for (unsigned int id : target.qlSessions) {
2440+
for (unsigned int id : target.sessions) {
24412441
ServerUser *pDst = qhUsers.value(id);
24422442
if (pDst && ChanACL::hasPermission(&speaker, pDst->cChannel, ChanACL::Whisper, &acCache)
24432443
&& !cache.channelTargets.contains(pDst))

src/murmur/ServerUser.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# include <sys/socket.h>
2828
#endif
2929

30+
#include <vector>
31+
3032
// Unfortunately, this needs to be "large enough" to hold
3133
// enough frames to account for both short-term and
3234
// long-term "maladjustments".
@@ -52,13 +54,14 @@ struct BandwidthRecord {
5254

5355
struct WhisperTarget {
5456
struct Channel {
55-
int iId;
56-
bool bChildren;
57-
bool bLinks;
58-
QString qsGroup;
57+
unsigned int id;
58+
bool includeChildren;
59+
bool includeLinks;
60+
QString targetGroup;
5961
};
60-
QList< unsigned int > qlSessions;
61-
QList< WhisperTarget::Channel > qlChannels;
62+
63+
std::vector< unsigned int > sessions;
64+
std::vector< WhisperTarget::Channel > channels;
6265
};
6366

6467
class ServerUser;

0 commit comments

Comments
 (0)