1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 15:44:46 +02:00

Rename ChanUserContainer to Membership.

This commit is contained in:
Sadie Powell
2026-01-14 17:17:37 +00:00
parent 3af9da7c05
commit 792308ed5d
23 changed files with 124 additions and 118 deletions
+12 -8
View File
@@ -23,8 +23,8 @@ typedef Anope::unordered_map<Channel *> channel_map;
extern CoreExport channel_map ChannelList;
/* A user container, there is one of these per user per channel. */
struct ChanUserContainer final
/* A user's membership to a channel, there is one of these per user per channel. */
struct Membership final
: public Extensible
{
User *user;
@@ -32,7 +32,11 @@ struct ChanUserContainer final
/* Status the user has in the channel */
ChannelStatus status;
ChanUserContainer(User *u, Channel *c) : user(u), chan(c) { }
Membership(User *u, Channel *c)
: user(u)
, chan(c)
{
}
};
class CoreExport Channel final
@@ -61,7 +65,7 @@ public:
bool botchannel = false;
/* Users in the channel */
typedef std::map<User *, ChanUserContainer *> ChanUserList;
typedef std::map<User *, Membership *> ChanUserList;
ChanUserList users;
/* Current topic of the channel */
@@ -114,9 +118,9 @@ public:
/** Join a user internally to the channel
* @param u The user
* @param status The status to give the user, if any
* @return The UserContainer for the user
* @return The membership for the user
*/
ChanUserContainer *JoinUser(User *u, const ChannelStatus *status);
Membership *JoinUser(User *u, const ChannelStatus *status);
/** Remove a user internally from the channel
* @param u The user
@@ -125,9 +129,9 @@ public:
/** Check if the user is on the channel
* @param u The user
* @return A user container if found, else NULL
* @return A membership if found, else NULL
*/
ChanUserContainer *FindUser(User *u) const;
Membership *FindUser(User *u) const;
/** Check if a user has a status on a channel
* @param u The user
+1 -1
View File
@@ -22,7 +22,6 @@ class Channel;
class ChannelInfo;
class ChannelStatus;
namespace ChanServ { class AutoKick; class ModeLock; }
struct ChanUserContainer;
class ClientSocket;
class Command;
class CommandSource;
@@ -35,6 +34,7 @@ class InfoFormatter;
class IRCDProto;
class ListenSocket;
class Log;
struct Membership;
class Memo;
struct MemoInfo;
class MessageSource;
+2 -2
View File
@@ -292,10 +292,10 @@ public:
/** Called before a user has been kicked from a channel.
* @param source The kicker
* @param cu The user, channel, and status of the user being kicked
* @param memb The membership for the user who is being kicked
* @param kickmsg The reason for the kick.
*/
virtual void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
virtual void OnPreUserKicked(const MessageSource &source, Membership *memb, const Anope::string &kickmsg) ATTR_NOT_NULL(3) { throw NotImplementedException(); }
/** Called when a user has been kicked from a channel.
* @param source The kicker
+3 -3
View File
@@ -89,7 +89,7 @@ public: // XXX: exposing a tiny bit too much
time_t awaytime = 0;
/* Channels the user is in */
typedef std::map<Channel *, ChanUserContainer *> ChanUserList;
typedef std::map<Channel *, Membership *> ChanUserList;
ChanUserList chans;
/* Last time this user sent a memo command used */
@@ -338,9 +338,9 @@ public:
* This is preferred over using FindUser in Channel, as there are usually more users in a channel
* than channels a user is in
* @param c The channel
* @return The channel container, or NULL
* @return The channel membership, or NULL
*/
ChanUserContainer *FindChannel(Channel *c) const;
Membership *FindChannel(Channel *c) const;
/** Check if the user is protected from kicks and negative mode changes
* @return true or false
+3 -3
View File
@@ -1081,11 +1081,11 @@ class BSKick final
UserData *GetUserData(User *u, Channel *c)
{
ChanUserContainer *uc = c->FindUser(u);
if (uc == NULL)
auto *memb = c->FindUser(u);
if (memb == NULL)
return NULL;
UserData *ud = userdata.Require(uc);
UserData *ud = userdata.Require(memb);
return ud;
}
+2 -2
View File
@@ -462,9 +462,9 @@ public:
{
if (!always_lower && Anope::CurTime == c->created && c->ci && setter.GetUser() && !setter.GetUser()->server->IsULined())
{
ChanUserContainer *cu = c->FindUser(setter.GetUser());
auto *memb = c->FindUser(setter.GetUser());
ChannelMode *cm = ModeManager::FindChannelModeByName("OP");
if (cu && cm && !cu->status.HasMode(cm->mchar))
if (memb && cm && !memb->status.HasMode(cm->mchar))
{
/* Our -o and their mode change crossing, bounce their mode */
c->RemoveMode(c->ci->WhoSends(), mode, data.value);
+2 -2
View File
@@ -203,10 +203,10 @@ class CommandCSAKick final
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
{
ChanUserContainer *uc = it->second;
auto *memb = it->second;
++it;
if (c->CheckKick(uc->user))
if (c->CheckKick(memb->user))
++count;
}
+8 -8
View File
@@ -213,23 +213,23 @@ public:
int matched = 0, kicked = 0;
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;)
{
ChanUserContainer *uc = it->second;
auto *memb = it->second;
++it;
Entry e(mode, mask);
if (e.Matches(uc->user))
if (e.Matches(memb->user))
{
++matched;
AccessGroup u2_access = ci->AccessFor(uc->user);
AccessGroup u2_access = ci->AccessFor(memb->user);
if (matched > 1 && !founder)
continue;
if (u != uc->user && ci->HasExt("PEACE") && u2_access >= u_access)
if (u != memb->user && ci->HasExt("PEACE") && u2_access >= u_access)
continue;
else if (ci->c->MatchesList(uc->user, "EXCEPT"))
else if (ci->c->MatchesList(memb->user, "EXCEPT"))
continue;
else if (uc->user->IsProtected())
else if (memb->user->IsProtected())
continue;
if (block.Get<bool>("kick", "yes"))
@@ -242,10 +242,10 @@ public:
{ "message", reason },
{ "nick", source.GetNick() },
});
c->Kick(ci->WhoSends(), uc->user, signkickformat);
c->Kick(ci->WhoSends(), memb->user, signkickformat);
}
else
c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
c->Kick(ci->WhoSends(), memb->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
}
}
}
+2 -2
View File
@@ -179,8 +179,8 @@ private:
/* The newer users are at the end of the list, so kick users starting from the end */
for (Channel::ChanUserList::reverse_iterator it = ci->c->users.rbegin(), it_end = ci->c->users.rend(); it != it_end; ++it)
{
ChanUserContainer *uc = it->second;
User *user = uc->user;
auto *memb = it->second;
User *user = memb->user;
if (user->IsProtected())
continue;
+7 -7
View File
@@ -92,18 +92,18 @@ public:
int matched = 0, kicked = 0;
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;)
{
ChanUserContainer *uc = it->second;
auto *memb = it->second;
++it;
Entry e("", mask);
if (e.Matches(uc->user))
if (e.Matches(memb->user))
{
++matched;
AccessGroup u2_access = ci->AccessFor(uc->user);
if (u != uc->user && ci->HasExt("PEACE") && u2_access >= u_access)
AccessGroup u2_access = ci->AccessFor(memb->user);
if (u != memb->user && ci->HasExt("PEACE") && u2_access >= u_access)
continue;
else if (uc->user->IsProtected())
else if (memb->user->IsProtected())
continue;
++kicked;
@@ -114,10 +114,10 @@ public:
{ "message", reason },
{ "nick", source.GetNick() },
});
c->Kick(ci->WhoSends(), uc->user, signkickformat);
c->Kick(ci->WhoSends(), memb->user, signkickformat);
}
else
c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
c->Kick(ci->WhoSends(), memb->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
}
}
+8 -8
View File
@@ -603,14 +603,14 @@ class CommandCSMode final
for (Channel::ChanUserList::const_iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end;)
{
ChanUserContainer *uc = it->second;
auto *memb = it->second;
++it;
AccessGroup targ_access = ci->AccessFor(uc->user);
AccessGroup targ_access = ci->AccessFor(memb->user);
if (uc->user->IsProtected())
if (memb->user->IsProtected())
{
source.Reply(_("You do not have the access to change %s's modes."), uc->user->nick.c_str());
source.Reply(_("You do not have the access to change %s's modes."), memb->user->nick.c_str());
continue;
}
@@ -622,17 +622,17 @@ class CommandCSMode final
}
else
{
source.Reply(_("You do not have the access to change %s's modes."), uc->user->nick.c_str());
source.Reply(_("You do not have the access to change %s's modes."), memb->user->nick.c_str());
continue;
}
}
if (Anope::Match(uc->user->GetMask(), param))
if (Anope::Match(memb->user->GetMask(), param))
{
if (adding)
ci->c->SetMode(NULL, cm, uc->user->GetUID());
ci->c->SetMode(NULL, cm, memb->user->GetUID());
else
ci->c->RemoveMode(NULL, cm, uc->user->GetUID());
ci->c->RemoveMode(NULL, cm, memb->user->GetUID());
}
}
}
+2 -2
View File
@@ -420,9 +420,9 @@ public:
UpdateUser(u, PART, u->nick, "", channel, msg);
}
void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &msg) override
void OnPreUserKicked(const MessageSource &source, Membership *memb, const Anope::string &msg) override
{
UpdateUser(cu->user, KICK, cu->user->nick, source.GetSource(), cu->chan->name, msg);
UpdateUser(memb->user, KICK, memb->user->nick, source.GetSource(), memb->chan->name, msg);
}
private:
+6 -4
View File
@@ -140,10 +140,12 @@ class CommandCSDown final
{
static void RemoveAll(User *u, Channel *c)
{
ChanUserContainer *cu = c->FindUser(u);
if (cu != NULL)
for (size_t i = cu->status.Modes().length(); i > 0;)
c->RemoveMode(NULL, ModeManager::FindChannelModeByChar(cu->status.Modes()[--i]), u->GetUID());
auto *memb = c->FindUser(u);
if (memb != NULL)
{
for (size_t i = memb->status.Modes().length(); i > 0;)
c->RemoveMode(NULL, ModeManager::FindChannelModeByChar(memb->status.Modes()[--i]), u->GetUID());
}
}
public:
+5 -5
View File
@@ -571,18 +571,18 @@ private:
}
public:
void OnPreUserKicked(const MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) override
void OnPreUserKicked(const MessageSource &source, Membership *memb, const Anope::string &kickmsg) override
{
if (!cu->chan->ci || !cs_stats.HasExt(cu->chan->ci))
if (!memb->chan->ci || !cs_stats.HasExt(memb->chan->ci))
return;
query = "CALL " + prefix + "chanstats_proc_update(@channel@, @nick@, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0);";
query.SetValue("channel", cu->chan->name);
query.SetValue("nick", GetDisplay(cu->user));
query.SetValue("channel", memb->chan->name);
query.SetValue("nick", GetDisplay(memb->user));
this->RunQuery(query);
query = "CALL " + prefix + "chanstats_proc_update(@channel@, @nick@, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0);";
query.SetValue("channel", cu->chan->name);
query.SetValue("channel", memb->chan->name);
query.SetValue("nick", GetDisplay(source.GetUser()));
this->RunQuery(query);
}
+5 -5
View File
@@ -117,16 +117,16 @@ public:
* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(u);
if (uc)
uc->status.Clear();
auto *memb = c->FindUser(u);
if (memb)
memb->status.Clear();
BotInfo *setter = BotInfo::Find(u->GetUID());
for (auto mode : cs.Modes())
c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), u->GetUID(), false);
if (uc)
uc->status = cs;
if (memb)
memb->status = cs;
}
}
+8 -8
View File
@@ -511,16 +511,16 @@ public:
/* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(user);
if (uc != NULL)
uc->status.Clear();
auto *memb = c->FindUser(user);
if (memb != NULL)
memb->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
for (auto mode : cs.Modes())
c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
if (memb != NULL)
memb->status = cs;
}
}
@@ -817,9 +817,9 @@ namespace InspIRCdExtBan
Channel *c = Channel::Find(channel);
if (c != NULL)
{
ChanUserContainer *uc = c->FindUser(u);
if (uc != NULL)
if (cm == NULL || uc->status.HasMode(cm->mchar))
auto *memb = c->FindUser(u);
if (memb != NULL)
if (cm == NULL || memb->status.HasMode(cm->mchar))
return true;
}
+5 -5
View File
@@ -100,16 +100,16 @@ public:
/* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(user);
if (uc != NULL)
uc->status.Clear();
auto *memb = c->FindUser(user);
if (memb != NULL)
memb->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
for (auto mode : cs.Modes())
c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
if (memb != NULL)
memb->status = cs;
}
}
+5 -5
View File
@@ -72,16 +72,16 @@ public:
/* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(user);
if (uc != NULL)
uc->status.Clear();
auto *memb = c->FindUser(user);
if (memb != NULL)
memb->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
for (auto mode : cs.Modes())
c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
if (memb != NULL)
memb->status = cs;
}
}
+8 -8
View File
@@ -194,16 +194,16 @@ private:
/* If the user is internally on the channel with flags, kill them so that
* the stacker will allow this.
*/
ChanUserContainer *uc = c->FindUser(user);
if (uc != NULL)
uc->status.Clear();
auto *memb = c->FindUser(user);
if (memb != NULL)
memb->status.Clear();
BotInfo *setter = BotInfo::Find(user->GetUID());
for (auto mode : cs.Modes())
c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false);
if (uc != NULL)
uc->status = cs;
if (memb != NULL)
memb->status = cs;
}
}
@@ -543,9 +543,9 @@ namespace UnrealExtBan
Channel *c = Channel::Find(channel);
if (c != NULL)
{
ChanUserContainer *uc = c->FindUser(u);
if (uc != NULL)
if (cm == NULL || uc->status.HasMode(cm->mchar))
auto *memb = c->FindUser(u);
if (memb != NULL)
if (cm == NULL || memb->status.HasMode(cm->mchar))
return true;
}
+23 -23
View File
@@ -135,18 +135,18 @@ bool Channel::CheckDelete()
return MOD_RESULT != EVENT_STOP && this->users.empty();
}
ChanUserContainer *Channel::JoinUser(User *user, const ChannelStatus *status)
Membership *Channel::JoinUser(User *user, const ChannelStatus *status)
{
if (user->server && user->server->IsSynced())
Log(user, this, "join");
auto *cuc = new ChanUserContainer(user, this);
user->chans[this] = cuc;
this->users[user] = cuc;
auto *memb = new Membership(user, this);
user->chans[this] = memb;
this->users[user] = memb;
if (status)
cuc->status = *status;
memb->status = *status;
return cuc;
return memb;
}
void Channel::DeleteUser(User *user)
@@ -156,18 +156,18 @@ void Channel::DeleteUser(User *user)
FOREACH_MOD(OnLeaveChannel, (user, this));
ChanUserContainer *cu = user->FindChannel(this);
auto *memb = user->FindChannel(this);
if (!this->users.erase(user))
Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistent user " << user->nick << " from channel " << this->name;
if (!user->chans.erase(this))
Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistent channel " << this->name << " from " << user->nick << "'s channel list";
delete cu;
delete memb;
QueueForDeletion();
}
ChanUserContainer *Channel::FindUser(User *u) const
Membership *Channel::FindUser(User *u) const
{
ChanUserList::const_iterator it = this->users.find(u);
if (it != this->users.end())
@@ -178,13 +178,13 @@ ChanUserContainer *Channel::FindUser(User *u) const
bool Channel::HasUserStatus(User *u, ChannelModeStatus *cms)
{
/* Usually its more efficient to search the users channels than the channels users */
ChanUserContainer *cc = u->FindChannel(this);
if (cc)
auto *memb = u->FindChannel(this);
if (memb)
{
if (cms)
return cc->status.HasMode(cms->mchar);
return memb->status.HasMode(cms->mchar);
else
return cc->status.Empty();
return memb->status.Empty();
}
return false;
@@ -281,9 +281,9 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *ocm, const Mod
Log(LOG_DEBUG) << "Setting +" << cm->mchar << " on " << this->name << " for " << u->nick;
/* Set the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
if (cc)
cc->status.AddMode(cm->mchar);
auto *memb = u->FindChannel(this);
if (memb)
memb->status.AddMode(cm->mchar);
FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, data));
@@ -352,9 +352,9 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *ocm, const
Log(LOG_DEBUG) << "Setting -" << cm->mchar << " on " << this->name << " for " << u->nick;
/* Remove the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
if (cc)
cc->status.DelMode(cm->mchar);
auto *memb = u->FindChannel(this);
if (memb)
memb->status.DelMode(cm->mchar);
FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param));
@@ -762,16 +762,16 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic
Anope::string chname = this->name;
ChanUserContainer *cu = target->FindChannel(this);
if (cu == NULL)
auto *memb = target->FindChannel(this);
if (memb == NULL)
{
Log(LOG_DEBUG) << "Channel::KickInternal got kick for user " << target->nick << " from " << source.GetSource() << " who isn't on channel " << this->name;
return;
}
ChannelStatus status = cu->status;
ChannelStatus status = memb->status;
FOREACH_MOD(OnPreUserKicked, (source, cu, reason));
FOREACH_MOD(OnPreUserKicked, (source, memb, reason));
this->DeleteUser(target);
FOREACH_MOD(OnUserKicked, (source, target, this->name, status, reason));
}
+3 -3
View File
@@ -382,10 +382,10 @@ Conf::Conf() : Block("")
c->botchannel = true;
/* Remove all existing modes */
ChanUserContainer *cu = c->FindUser(bi);
if (cu != NULL)
auto *memb = c->FindUser(bi);
if (memb != NULL)
{
for (auto mode : cu->status.Modes())
for (auto mode : memb->status.Modes())
c->RemoveMode(bi, ModeManager::FindChannelModeByChar(mode), bi->GetUID());
}
/* Set the new modes */
+3 -3
View File
@@ -92,12 +92,12 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> &params,
{
for (User::ChanUserList::iterator it = user->chans.begin(), it_end = user->chans.end(); it != it_end; )
{
ChanUserContainer *cc = it->second;
Channel *c = cc->chan;
auto *memb = it->second;
Channel *c = memb->chan;
++it;
FOREACH_MOD(OnPrePartChannel, (user, c));
cc->chan->DeleteUser(user);
memb->chan->DeleteUser(user);
FOREACH_MOD(OnPartChannel, (user, c, c->name, ""));
}
continue;
+1 -1
View File
@@ -738,7 +738,7 @@ const User::ModeList &User::GetModeList() const
return modes;
}
ChanUserContainer *User::FindChannel(Channel *c) const
Membership *User::FindChannel(Channel *c) const
{
User::ChanUserList::const_iterator it = this->chans.find(c);
if (it != this->chans.end())