summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/channels.h49
-rw-r--r--include/extern.h2
-rw-r--r--include/services.h23
-rw-r--r--include/users.h14
-rw-r--r--src/actions.c11
-rw-r--r--src/bots.cpp6
-rw-r--r--src/botserv.c47
-rw-r--r--src/channels.c237
-rw-r--r--src/chanserv.c4
-rw-r--r--src/core/bs_act.c2
-rw-r--r--src/core/bs_say.c2
-rw-r--r--src/core/cs_akick.c12
-rw-r--r--src/core/cs_clear.c121
-rw-r--r--src/core/cs_forbid.c10
-rw-r--r--src/core/cs_set.c4
-rw-r--r--src/core/cs_suspend.c10
-rw-r--r--src/core/os_chankill.c13
-rw-r--r--src/core/os_chanlist.c12
-rw-r--r--src/core/os_clearmodes.c46
-rw-r--r--src/core/os_userlist.c11
-rw-r--r--src/memoserv.c10
-rw-r--r--src/modes.cpp2
-rw-r--r--src/modules/cs_enforce.c46
-rw-r--r--src/nickserv.c7
-rw-r--r--src/protocol/bahamut.c16
-rw-r--r--src/protocol/inspircd11.c16
-rw-r--r--src/protocol/inspircd12.cpp16
-rw-r--r--src/protocol/ratbox.c16
-rw-r--r--src/protocol/unreal32.c16
-rw-r--r--src/regchannel.cpp2
-rw-r--r--src/users.c20
31 files changed, 388 insertions, 415 deletions
diff --git a/include/channels.h b/include/channels.h
index 0cd1829e2..3baae9f1b 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -9,6 +9,39 @@
*
*/
+struct UserData
+{
+ UserData()
+ {
+ lastline = NULL;
+ last_use = time(NULL);
+ }
+
+ virtual ~UserData() { delete [] lastline; }
+
+ /* Data validity */
+ time_t last_use;
+
+ /* for flood kicker */
+ int16 lines;
+ time_t last_start;
+
+ /* for repeat kicker */
+ char *lastline;
+ int16 times;
+};
+
+struct UserContainer
+{
+ User *user;
+ UserData *ud;
+
+ UserContainer(User *u) : user(u) { ud = new UserData; }
+ virtual ~UserContainer() { delete ud; }
+};
+
+typedef std::list<UserContainer *> CUserList;
+
enum ChannelFlags
{
/* Channel still exists when emptied */
@@ -24,6 +57,9 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
*/
std::map<ChannelModeName, std::string> Params;
+ /* Modes set on the channel */
+ std::bitset<128> modes;
+
public:
/** Default constructor
* @param name The channel name
@@ -42,14 +78,13 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
char *topic;
std::string topic_setter;
time_t topic_time; /* When topic was set */
- std::bitset<128> modes;
EList *bans;
EList *excepts;
EList *invites;
- struct c_userlist *users;
- uint16 usercount;
+ /* List of users in the channel */
+ CUserList users;
BanData *bd;
@@ -74,8 +109,12 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
*/
void DeleteUser(User *u);
- /**
- * See if a channel has a mode
+ /** See if the channel has any modes at all
+ * @return true or false
+ */
+ inline const bool HasModes() const { return modes.count(); }
+
+ /** See if a channel has a mode
* @param Name The mode name
* @return true or false
*/
diff --git a/include/extern.h b/include/extern.h
index a46894fa2..37fc40144 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -111,7 +111,7 @@ E Entry *elist_find_mask(EList *list, const char *mask);
E long get_memuse(EList *list);
-#define whosends(ci) ((!(ci) || !((ci)->botflags.HasFlag(BS_SYMBIOSIS)) || !(ci)->bi || !(ci)->c || (ci)->c->usercount < Config.BSMinUsers) ? findbot(Config.s_ChanServ) : (ci)->bi)
+#define whosends(ci) ((!(ci) || !((ci)->botflags.HasFlag(BS_SYMBIOSIS)) || !(ci)->bi || !(ci)->c || (ci)->c->users.size() < Config.BSMinUsers) ? findbot(Config.s_ChanServ) : (ci)->bi)
/**** chanserv.c ****/
diff --git a/include/services.h b/include/services.h
index 7483e591e..6a2c748c4 100644
--- a/include/services.h
+++ b/include/services.h
@@ -360,7 +360,6 @@ class Channel;
struct EList;
typedef struct bandata_ BanData;
-typedef struct userdata_ UserData;
typedef struct mailinfo_ MailInfo;
typedef struct akill_ Akill;
typedef struct sxline_ SXLine;
@@ -804,28 +803,6 @@ struct bandata_ {
int16 ttb[TTB_SIZE];
};
-/* This structure stocks information on every user that will be used by
- * BotServ. */
-
-struct userdata_ {
- /* Data validity */
- time_t last_use;
-
- /* for flood kicker */
- int16 lines;
- time_t last_start;
-
- /* for repeat kicker */
- char *lastline;
- int16 times;
-};
-
-struct c_userlist {
- struct c_userlist *next, *prev;
- User *user;
- UserData *ud;
-};
-
#include "channels.h"
/** Channelban type flags
diff --git a/include/users.h b/include/users.h
index 80bf33114..03dad2e55 100644
--- a/include/users.h
+++ b/include/users.h
@@ -9,12 +9,17 @@
*
*/
-struct u_chanlist {
- struct u_chanlist *next, *prev;
+struct ChannelContainer
+{
Channel *chan;
- int16 status; /* Associated flags; see CSTATUS_* below. */
+ int16 status;
+
+ ChannelContainer(Channel *c) : chan(c) { status = 0; }
+ virtual ~ChannelContainer() { }
};
+typedef std::list<ChannelContainer *> UChannelList;
+
/* Online user and channel data. */
class CoreExport User : public Extensible
{
@@ -44,7 +49,8 @@ class CoreExport User : public Extensible
int isSuperAdmin; /* is SuperAdmin on or off? */
- struct u_chanlist *chans; /* Channels user has joined */
+ /* Channels the user is in */
+ UChannelList chans;
unsigned short invalid_pw_count; /* # of invalid password attempts */
time_t invalid_pw_time; /* Time of last invalid password */
diff --git a/src/actions.c b/src/actions.c
index 142f2ae61..39c646cce 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -75,7 +75,6 @@ void sqline(const std::string &mask, const std::string &reason)
{
int i;
Channel *c, *next;
- struct c_userlist *cu, *cunext;
if (ircd->chansqline)
{
@@ -91,12 +90,14 @@ void sqline(const std::string &mask, const std::string &reason)
if (!Anope::Match(c->name, mask, false))
continue;
- for (cu = c->users; cu; cu = cunext)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- cunext = cu->next;
- if (is_oper(cu->user))
+ UserContainer *uc = *it;
+ ++it;
+
+ if (is_oper(uc->user))
continue;
- c->Kick(NULL, cu->user, "%s", reason.c_str());
+ c->Kick(NULL, uc->user, "%s", reason.c_str());
}
}
}
diff --git a/src/bots.cpp b/src/bots.cpp
index 58206963c..d19386abc 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -92,7 +92,7 @@ void BotInfo::RejoinAll()
for (i = 0; i < 256; ++i)
for (ci = chanlists[i]; ci; ci = ci->next)
- if (ci->bi == this && ci->c && (ci->c->usercount >= Config.BSMinUsers))
+ if (ci->bi == this && ci->c && (ci->c->users.size() >= Config.BSMinUsers))
bot_join(ci);
}
@@ -108,7 +108,7 @@ void BotInfo::Assign(User *u, ChannelInfo *ci)
ci->bi = this;
++this->chancount;
- if (ci->c && ci->c->usercount >= Config.BSMinUsers)
+ if (ci->c && ci->c->users.size() >= Config.BSMinUsers)
bot_join(ci);
}
@@ -119,7 +119,7 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci)
if (MOD_RESULT == EVENT_STOP)
return;
- if (ci->c && ci->c->usercount >= Config.BSMinUsers)
+ if (ci->c && ci->c->users.size() >= Config.BSMinUsers)
{
if (u)
ircdproto->SendPart(ci->bi, ci->c, "UNASSIGN from %s", u->nick.c_str());
diff --git a/src/botserv.c b/src/botserv.c
index 855797ef1..25bebaed3 100644
--- a/src/botserv.c
+++ b/src/botserv.c
@@ -572,38 +572,31 @@ static BanData *get_ban_data(Channel * c, User * u)
* Allocates it if necessary.
*/
-static UserData *get_user_data(Channel * c, User * u)
+static UserData *get_user_data(Channel *c, User *u)
{
- struct c_userlist *user;
-
if (!c || !u)
return NULL;
- for (user = c->users; user; user = user->next) {
- if (user->user == u) {
- if (user->ud) {
- time_t now = time(NULL);
-
- /* Checks whether data is obsolete */
- if (now - user->ud->last_use > Config.BSKeepData) {
- if (user->ud->lastline)
- delete [] user->ud->lastline;
- /* We should not free and realloc, but reset to 0
- instead. */
- memset(user->ud, 0, sizeof(UserData));
- user->ud->last_use = now;
- }
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
+ {
+ UserContainer *uc = *it;
- return user->ud;
- } else {
- user->ud = new UserData;
- user->ud->last_use = time(NULL);
- user->ud->lines = 0;
- user->ud->last_start = 0;
- user->ud->lastline = NULL;
- user->ud->times = 0;
- return user->ud;
+ if (uc->user == u)
+ {
+ time_t now = time(NULL);
+
+ /* Checks whether data is obsolete */
+ if (now - uc->ud->last_use > Config.BSKeepData)
+ {
+ if (uc->ud->lastline)
+ delete [] uc->ud->lastline;
+ /* We should not free and realloc, but reset to 0
+ instead. */
+ memset(uc->ud, 0, sizeof(UserData));
+ uc->ud->last_use = now;
}
+
+ return uc->ud;
}
}
@@ -646,7 +639,7 @@ void bot_join(ChannelInfo * ci)
/* Should we be invited? */
if (ci->c->HasMode(CMODE_INVITE)
- || (limit && ci->c->usercount >= limit))
+ || (limit && ci->c->users.size() >= limit))
ircdproto->SendNoticeChanops(ci->bi, ci->c,
"%s invited %s into the channel.",
ci->bi->nick.c_str(), ci->bi->nick.c_str());
diff --git a/src/channels.c b/src/channels.c
index 5f18ad4bb..f0c6e704e 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -44,8 +44,6 @@ Channel::Channel(const std::string &name, time_t ts)
this->creation_time = ts;
this->topic = NULL;
this->bans = this->excepts = this->invites = NULL;
- this->users = NULL;
- this->usercount = 0;
this->bd = NULL;
this->server_modetime = this->chanserv_modetime = 0;
this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_sync = 0;
@@ -128,31 +126,14 @@ void Channel::Sync()
void Channel::JoinUser(User *user)
{
- struct u_chanlist *c;
-
if (debug)
alog("debug: %s joins %s", user->nick.c_str(), this->name.c_str());
- c = new u_chanlist;
- c->prev = NULL;
- c->next = user->chans;
- if (user->chans)
- user->chans->prev = c;
- user->chans = c;
- c->chan = this;
- c->status = 0;
-
- struct c_userlist *u;
-
- u = new c_userlist;
- u->prev = NULL;
- u->next = this->users;
- if (this->users)
- this->users->prev = u;
- this->users = u;
- u->user = user;
- u->ud = NULL;
- this->usercount++;
+ ChannelContainer *cc = new ChannelContainer(this);
+ user->chans.push_back(cc);
+
+ UserContainer *uc = new UserContainer(user);
+ this->users.push_back(uc);
if (get_ignore(user->nick.c_str()) == NULL)
{
@@ -178,12 +159,12 @@ void Channel::JoinUser(User *user)
**/
if (Config.s_BotServ && this->ci && this->ci->bi && !this->ci->HasFlag(CI_PERSIST))
{
- if (this->usercount == Config.BSMinUsers)
+ if (this->users.size() == Config.BSMinUsers)
bot_join(this->ci);
}
if (Config.s_BotServ && this->ci && this->ci->bi)
{
- if (this->usercount >= Config.BSMinUsers && (this->ci->botflags.HasFlag(BS_GREET))
+ if (this->users.size() >= Config.BSMinUsers && (this->ci->botflags.HasFlag(BS_GREET))
&& user->nc && user->nc->greet && check_access(user, this->ci, CA_GREET))
{
/* Only display the greet if the main uplink we're connected
@@ -207,26 +188,17 @@ void Channel::DeleteUser(User *user)
if (this->ci)
update_cs_lastseen(user, this->ci);
- struct c_userlist *u;
- for (u = this->users; u && u->user != user; u = u->next);
- if (!u)
- return;
-
- if (u->ud)
+ CUserList::iterator it;
+ for (it = this->users.begin(); (*it)->user != user && it != this->users.end(); ++it);
+ if (it == this->users.end())
{
- if (u->ud->lastline)
- delete [] u->ud->lastline;
- delete u->ud;
+ if (debug)
+ alog("debug: Channel::DelUser() tried to delete nonexistnat user %s from channel %s", user->nick.c_str(), this->name.c_str());
+ return;
}
- if (u->next)
- u->next->prev = u->prev;
- if (u->prev)
- u->prev->next = u->next;
- else
- this->users = u->next;
- delete u;
- this->usercount--;
+ delete *it;
+ this->users.erase(it);
/* Channel is persistant, it shouldn't be deleted and the service bot should stay */
if (this->HasFlag(CH_PERSIST) || (this->ci && this->ci->HasFlag(CI_PERSIST)))
@@ -242,10 +214,10 @@ void Channel::DeleteUser(User *user)
if (this->ci && this->ci->HasFlag(CI_INHABIT))
return;
- if (Config.s_BotServ && this->ci && this->ci->bi && this->usercount <= Config.BSMinUsers - 1)
+ if (Config.s_BotServ && this->ci && this->ci->bi && this->users.size() <= Config.BSMinUsers - 1)
ircdproto->SendPart(this->ci->bi, this, NULL);
- if (!this->users)
+ if (this->users.empty())
delete this;
}
@@ -463,13 +435,13 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
if (ci)
{
ci->UnsetFlag(CI_PERSIST);
- if (Config.s_BotServ && ci->bi && usercount == Config.BSMinUsers - 1)
+ if (Config.s_BotServ && ci->bi && users.size() == Config.BSMinUsers - 1)
ircdproto->SendPart(ci->bi, this, NULL);
}
}
/* We set -P in an empty channel, delete the channel */
- if (cm->Name == CMODE_PERM && !users)
+ if (cm->Name == CMODE_PERM && users.empty())
{
delete this;
return;
@@ -900,19 +872,16 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c
if (debug)
alog("debug: Channel::KickInternal kicking %s from %s", user->nick.c_str(), this->name.c_str());
- struct u_chanlist *c;
- for (c = user->chans; c && this != c->chan; c = c->next);
- if (c)
+ UChannelList::iterator it;
+ for (it = user->chans.begin(); (*it)->chan != this && it != user->chans.end(); ++it);
+ if (it != user->chans.end())
{
- FOREACH_MOD(I_OnUserKicked, OnUserKicked(c->chan, user, source, reason));
- c->chan->DeleteUser(user);
- if (c->next)
- c->next->prev = c->prev;
- if (c->prev)
- c->prev->next = c->next;
- else
- user->chans = c->next;
- delete c;
+ ChannelContainer *cc = *it;
+
+ FOREACH_MOD(I_OnUserKicked, OnUserKicked(cc->chan, user, source, reason));
+ cc->chan->DeleteUser(user);
+ delete cc;
+ user->chans.erase(it);
}
else if (debug)
alog("debug: Channel::KickInternal got kick for user %s who isn't on channel %s ?", user->nick.c_str(), this->name.c_str());
@@ -959,7 +928,7 @@ char *chan_get_modes(Channel * chan, int complete, int plus)
ChannelModeParam *cmp;
std::map<char, ChannelMode *>::iterator it;
- if (!chan->modes.count())
+ if (chan->HasModes())
{
for (it = ModeManager::ChannelModesByChar.begin(); it != ModeManager::ChannelModesByChar.end(); ++it)
{
@@ -1009,11 +978,9 @@ char *chan_get_modes(Channel * chan, int complete, int plus)
int chan_get_user_status(Channel * chan, User * user)
{
- struct u_chanlist *uc;
-
- for (uc = user->chans; uc; uc = uc->next)
- if (uc->chan == chan)
- return uc->status;
+ for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end(); ++it)
+ if ((*it)->chan == chan)
+ return (*it)->status;
return 0;
}
@@ -1024,14 +991,15 @@ int chan_get_user_status(Channel * chan, User * user)
int chan_has_user_status(Channel * chan, User * user, int16 status)
{
- struct u_chanlist *uc;
+ for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end(); ++it)
+ {
+ ChannelContainer *cc = *it;
- for (uc = user->chans; uc; uc = uc->next) {
- if (uc->chan == chan) {
- if (debug) {
- alog("debug: chan_has_user_status wanted %d the user is %d", status, uc->status);
- }
- return (uc->status & status);
+ if (cc->chan == chan)
+ {
+ if (debug)
+ alog("debug: chan_has_user_status wanted %d the user is %d", status, cc->status);
+ return (cc->status & status);
}
}
return 0;
@@ -1043,15 +1011,17 @@ int chan_has_user_status(Channel * chan, User * user, int16 status)
void chan_remove_user_status(Channel * chan, User * user, int16 status)
{
- struct u_chanlist *uc;
-
if (debug >= 2)
alog("debug: removing user status (%d) from %s for %s", status,
user->nick.c_str(), chan->name.c_str());
- for (uc = user->chans; uc; uc = uc->next) {
- if (uc->chan == chan) {
- uc->status &= ~status;
+ for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end(); ++it)
+ {
+ ChannelContainer *cc = *it;
+
+ if (cc->chan == chan)
+ {
+ cc->status &= ~status;
break;
}
}
@@ -1063,7 +1033,6 @@ void chan_remove_user_status(Channel * chan, User * user, int16 status)
void chan_set_user_status(Channel * chan, User * user, int16 status)
{
- struct u_chanlist *uc;
UserMode *um;
if (debug >= 2)
@@ -1081,9 +1050,13 @@ void chan_set_user_status(Channel * chan, User * user, int16 status)
user->SetMode(NULL, um);
}
- for (uc = user->chans; uc; uc = uc->next) {
- if (uc->chan == chan) {
- uc->status |= status;
+ for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end(); ++it)
+ {
+ ChannelContainer *cc = *it;
+
+ if (cc->chan == chan)
+ {
+ cc->status |= status;
break;
}
}
@@ -1164,7 +1137,6 @@ void get_channel_stats(long *nrec, long *memuse)
{
long count = 0, mem = 0;
Channel *chan;
- struct c_userlist *cu;
BanData *bd;
int i;
std::string buf;
@@ -1186,13 +1158,12 @@ void get_channel_stats(long *nrec, long *memuse)
mem += get_memuse(chan->excepts);
if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE))
mem += get_memuse(chan->invites);
- for (cu = chan->users; cu; cu = cu->next) {
- mem += sizeof(*cu);
- if (cu->ud) {
- mem += sizeof(*cu->ud);
- if (cu->ud->lastline)
- mem += strlen(cu->ud->lastline) + 1;
- }
+ for (CUserList::iterator it = chan->users.begin(); it != chan->users.end(); ++it)
+ {
+ mem += sizeof(*it);
+ mem += sizeof((*it)->ud);
+ if ((*it)->ud->lastline)
+ mem += strlen((*it)->ud->lastline) + 1;
}
for (bd = chan->bd; bd; bd = bd->next) {
if (bd->mask)
@@ -1211,10 +1182,8 @@ void get_channel_stats(long *nrec, long *memuse)
int is_on_chan(Channel * c, User * u)
{
- struct u_chanlist *uc;
-
- for (uc = u->chans; uc; uc = uc->next)
- if (uc->chan == c)
+ for (UChannelList::iterator it = u->chans.begin(); it != u->chans.end(); ++it)
+ if ((*it)->chan == c)
return 1;
return 0;
@@ -1227,14 +1196,15 @@ int is_on_chan(Channel * c, User * u)
User *nc_on_chan(Channel * c, NickCore * nc)
{
- struct c_userlist *u;
-
if (!c || !nc)
return NULL;
- for (u = c->users; u; u = u->next) {
- if (u->user->nc == nc)
- return u->user;
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
+ {
+ UserContainer *uc = *it;
+
+ if (uc->user->nc == nc)
+ return uc->user;
}
return NULL;
}
@@ -1251,17 +1221,9 @@ void do_join(const char *source, int ac, const char **av)
{
User *user;
Channel *chan;
- struct u_chanlist *c, *nextc;
- char *channame;
time_t ctime = time(NULL);
- if (ircd->ts6) {
- user = find_byuid(source);
- if (!user)
- user = finduser(source);
- } else {
- user = finduser(source);
- }
+ user = finduser(source);
if (!user) {
if (debug) {
alog("debug: JOIN from nonexistent user %s: %s", source,
@@ -1275,18 +1237,18 @@ void do_join(const char *source, int ac, const char **av)
while (sep.GetToken(buf))
{
if (buf[0] == '0') {
- c = user->chans;
- while (c) {
- nextc = c->next;
- channame = sstrdup(c->chan->name.c_str());
- FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, c->chan));
- c->chan->DeleteUser(user);
- FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(channame), channame, ""));
- delete [] channame;
- delete c;
- c = nextc;
+ for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end();)
+ {
+ ChannelContainer *cc = *it++;
+
+ std::string channame = cc->chan->name;
+ FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, cc->chan));
+ cc->chan->DeleteUser(user);
+ FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(channame.c_str()), channame, ""));
+ delete cc;
+ user->chans.erase(it);
}
- user->chans = NULL;
+ user->chans.clear();
continue;
}
@@ -1377,15 +1339,8 @@ void do_kick(const std::string &source, int ac, const char **av)
void do_part(const char *source, int ac, const char **av)
{
User *user;
- struct u_chanlist *c;
- if (ircd->ts6) {
- user = find_byuid(source);
- if (!user)
- user = finduser(source);
- } else {
- user = finduser(source);
- }
+ user = finduser(source);
if (!user) {
if (debug) {
alog("debug: PART from nonexistent user %s: %s", source,
@@ -1400,29 +1355,21 @@ void do_part(const char *source, int ac, const char **av)
{
if (debug)
alog("debug: %s leaves %s", source, buf.c_str());
- for (c = user->chans; c && buf != c->chan->name; c = c->next);
- if (c)
+ UChannelList::iterator it;
+ for (it = user->chans.begin(); buf != (*it)->chan->name && it != user->chans.end(); ++it);
+ if (it != user->chans.end())
{
- if (!c->chan)
- {
- alog("user: BUG parting %s: channel entry found but c->chan NULL", buf.c_str());
- return;
- }
+ ChannelContainer *cc = *it;
- FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, c->chan));
- std::string ChannelName = c->chan->name;
+ FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, cc->chan));
+ std::string ChannelName = cc->chan->name;
- c->chan->DeleteUser(user);
+ cc->chan->DeleteUser(user);
- FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName.c_str()), ChannelName, av[1] ? av[1] : ""));
+ delete *it;
+ user->chans.erase(it);
- if (c->next)
- c->next->prev = c->prev;
- if (c->prev)
- c->prev->next = c->next;
- else
- user->chans = c->next;
- delete c;
+ FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName.c_str()), ChannelName, av[1] ? av[1] : ""));
}
}
}
@@ -1636,7 +1583,7 @@ void chan_set_correct_modes(User * user, Channel * c, int give_modes)
* Unless the channel has just been created. -heinz
* Or the user matches CA_AUTODEOP... -GD
*/
- if (((ci->HasFlag(CI_SECUREOPS)) || (c->usercount == 1)
+ if (((ci->HasFlag(CI_SECUREOPS)) || (c->users.size() == 1)
|| check_access(user, ci, CA_AUTODEOP))
&& !is_ulined(user->server->name)) {
if (owner && (status & CUS_OWNER) && !IsFounder(user, ci))
diff --git a/src/chanserv.c b/src/chanserv.c
index af458e42b..56a94839c 100644
--- a/src/chanserv.c
+++ b/src/chanserv.c
@@ -142,7 +142,7 @@ class ChanServTimer : public Timer
c->ci->UnsetFlag(CI_INHABIT);
/* If the channel has users again, don't part it and halt */
- if (c->usercount)
+ if (!c->users.empty())
return;
if (c->ci->bi)
@@ -697,7 +697,7 @@ bool ChannelInfo::CheckKick(User *user)
/* If the channel doesnt have any users and if a bot isn't already in the channel, join it
* NOTE: we use usercount == 1 here as there is one user, but they are about to be destroyed
*/
- if (this->c->usercount == 1 && !this->HasFlag(CI_INHABIT))
+ if (this->c->users.size() == 1 && !this->HasFlag(CI_INHABIT))
{
/* If channel was forbidden, etc, set it +si to prevent rejoin */
if (set_modes)
diff --git a/src/core/bs_act.c b/src/core/bs_act.c
index 8c54f9479..7849f322b 100644
--- a/src/core/bs_act.c
+++ b/src/core/bs_act.c
@@ -39,7 +39,7 @@ class CommandBSAct : public Command
return MOD_CONT;
}
- if (!ci->c || ci->c->usercount < Config.BSMinUsers)
+ if (!ci->c || ci->c->users.size() < Config.BSMinUsers)
{
notice_lang(Config.s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name.c_str());
return MOD_CONT;
diff --git a/src/core/bs_say.c b/src/core/bs_say.c
index 6aa2bb552..65fd93922 100644
--- a/src/core/bs_say.c
+++ b/src/core/bs_say.c
@@ -43,7 +43,7 @@ class CommandBSSay : public Command
return MOD_CONT;
}
- if (!ci->c || ci->c->usercount < Config.BSMinUsers)
+ if (!ci->c || ci->c->users.size() < Config.BSMinUsers)
{
notice_lang(Config.s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name.c_str());
return MOD_CONT;
diff --git a/src/core/cs_akick.c b/src/core/cs_akick.c
index 983dba89f..2a45cd83c 100644
--- a/src/core/cs_akick.c
+++ b/src/core/cs_akick.c
@@ -480,7 +480,6 @@ class CommandCSAKick : public Command
void DoEnforce(User *u, ChannelInfo *ci, const std::vector<ci::string> &params)
{
Channel *c = ci->c;
- c_userlist *cu, *unext;
int count = 0;
if (!c)
@@ -489,17 +488,14 @@ class CommandCSAKick : public Command
return;
}
- cu = c->users;
-
- while (cu)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- unext = cu->next;
- if (ci->CheckKick(cu->user))
+ UserContainer *uc = *it++;
+
+ if (ci->CheckKick(uc->user))
{
- c->Kick(NULL, cu->user, "%s", Config.CSAutokickReason);
count++;
}
- cu = unext;
}
notice_lang(Config.s_ChanServ, u, CHAN_AKICK_ENFORCE_DONE, ci->name.c_str(), count);
diff --git a/src/core/cs_clear.c b/src/core/cs_clear.c
index 0cbb192e3..5f95e0cdc 100644
--- a/src/core/cs_clear.c
+++ b/src/core/cs_clear.c
@@ -38,127 +38,144 @@ class CommandCSClear : public Command
if (c)
ci = c->ci;
- if (!c) {
+ if (!c)
notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
- } else if (!u || !check_access(u, ci, CA_CLEAR)) {
+ else if (!u || !check_access(u, ci, CA_CLEAR))
notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
- } else if (what == "bans") {
+ else if (what == "bans")
+ {
c->ClearBans();
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_BANS, chan);
- } else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && what == "excepts") {
+ }
+ else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && what == "excepts")
+ {
c->ClearExcepts();
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan);
- } else if (ModeManager::FindChannelModeByName(CMODE_INVITE) && what == "invites") {
+ }
+ else if (ModeManager::FindChannelModeByName(CMODE_INVITE) && what == "invites")
+ {
c->ClearInvites();
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_INVITES, chan);
- } else if (what == "modes") {
+ }
+ else if (what == "modes")
+ {
c->ClearModes();
check_modes(c);
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_MODES, chan);
- } else if (what == "ops") {
- const char *av[6]; /* The max we have to hold: chan, ts, modes(max3), nick, nick, nick */
+ }
+ else if (what == "ops")
+ {
int isop, isadmin, isown;
- struct c_userlist *cu, *bnext;
- if (ircd->svsmode_ucmode) {
- av[0] = chan;
+ if (ircd->svsmode_ucmode)
+ {
ircdproto->SendSVSModeChan(c, "-o", NULL);
- if (owner) {
+ if (owner)
+ {
modebuf = '-';
modebuf += owner->ModeChar;
ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL);
}
- if (admin) {
+ if (admin)
+ {
modebuf = '-';
modebuf += admin->ModeChar;
ircdproto->SendSVSModeChan(c, modebuf.c_str(), NULL);
}
- for (cu = c->users; cu; cu = bnext)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- bnext = cu->next;
- isop = chan_has_user_status(c, cu->user, CUS_OP);
- isadmin = chan_has_user_status(c, cu->user, CUS_PROTECT);
- isown = chan_has_user_status(c, cu->user, CUS_OWNER);
+ UserContainer *uc = *it;
+
+ isop = chan_has_user_status(c, uc->user, CUS_OP);
+ isadmin = chan_has_user_status(c, uc->user, CUS_PROTECT);
+ isown = chan_has_user_status(c, uc->user, CUS_OWNER);
if (!isop && !isadmin && !isown)
continue;
if (isown)
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
if (admin)
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
if (isop)
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
}
- } else {
- av[0] = chan;
- for (cu = c->users; cu; cu = bnext)
+ }
+ else
+ {
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- bnext = cu->next;
- isop = chan_has_user_status(c, cu->user, CUS_OP);
- isadmin = chan_has_user_status(c, cu->user, CUS_PROTECT);
- isown = chan_has_user_status(c, cu->user, CUS_OWNER);
+ UserContainer *uc = *it;
+
+ isop = chan_has_user_status(c, uc->user, CUS_OP);
+ isadmin = chan_has_user_status(c, uc->user, CUS_PROTECT);
+ isown = chan_has_user_status(c, uc->user, CUS_OWNER);
if (!isop && !isadmin && !isown)
continue;
if (isown)
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
if (isadmin)
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
if (isop)
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
}
}
- notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_OPS, chan);
- } else if (ModeManager::FindChannelModeByName(CMODE_HALFOP) && what == "hops") {
- struct c_userlist *cu, *bnext;
- for (cu = c->users; cu; cu = bnext)
+ notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_OPS, chan);
+ }
+ else if (ModeManager::FindChannelModeByName(CMODE_HALFOP) && what == "hops")
+ {
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- bnext = cu->next;
+ UserContainer *uc = *it;
- if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
+ if (!chan_has_user_status(c, uc->user, CUS_HALFOP))
continue;
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
}
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_HOPS, chan);
- } else if (what == "voices") {
- struct c_userlist *cu, *bnext;
-
- for (cu = c->users; cu; cu = bnext)
+ }
+ else if (what == "voices")
+ {
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- bnext = cu->next;
+ UserContainer *uc = *it;
- if (!chan_has_user_status(c, cu->user, CUS_VOICE))
+ if (!chan_has_user_status(c, uc->user, CUS_VOICE))
continue;
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_VOICES, chan);
- } else if (what == "users") {
- struct c_userlist *cu, *bnext;
+ }
+ else if (what == "users") {
std::string buf = "CLEAR USERS command from " + u->nick;
- for (cu = c->users; cu; cu = bnext) {
- bnext = cu->next;
- c->Kick(NULL, cu->user, buf.c_str());
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
+ {
+ UserContainer *uc = *it++;
+
+ c->Kick(NULL, uc->user, buf.c_str());
}
+
notice_lang(Config.s_ChanServ, u, CHAN_CLEARED_USERS, chan);
- } else {
- syntax_error(Config.s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
}
+ else
+ syntax_error(Config.s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
+
return MOD_CONT;
}
diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c
index 718cd41a1..57a0b552b 100644
--- a/src/core/cs_forbid.c
+++ b/src/core/cs_forbid.c
@@ -67,21 +67,19 @@ class CommandCSForbid : public Command
if ((c = findchan(ci->name.c_str())))
{
- struct c_userlist *cu, *nextu;
-
/* Before banning everyone, it might be prudent to clear +e and +I lists..
* to prevent ppl from rejoining.. ~ Viper */
c->ClearExcepts();
c->ClearInvites();
- for (cu = c->users; cu; cu = nextu)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- nextu = cu->next;
+ UserContainer *uc = *it++;
- if (is_oper(cu->user))
+ if (is_oper(uc->user))
continue;
- c->Kick(findbot(Config.s_ChanServ), cu->user, "%s", reason ? reason : getstring(cu->user->nc, CHAN_FORBID_REASON));
+ c->Kick(findbot(Config.s_ChanServ), uc->user, "%s", reason ? reason : getstring(uc->user->nc, CHAN_FORBID_REASON));
}
}
diff --git a/src/core/cs_set.c b/src/core/cs_set.c
index 277649cfb..158987acd 100644
--- a/src/core/cs_set.c
+++ b/src/core/cs_set.c
@@ -583,7 +583,7 @@ class CommandCSSet : public Command
/* Unset perm mode */
if (cm && ci->c && ci->c->HasMode(CMODE_PERM))
ci->c->RemoveMode(NULL, cm);
- if (Config.s_BotServ && ci->bi && ci->c->usercount == Config.BSMinUsers - 1)
+ if (Config.s_BotServ && ci->bi && ci->c->users.size() == Config.BSMinUsers - 1)
ircdproto->SendPart(ci->bi, ci->c, NULL);
/* No channel mode, no BotServ, but using ChanServ as the botserv bot
@@ -595,7 +595,7 @@ class CommandCSSet : public Command
findbot(Config.s_ChanServ)->UnAssign(NULL, ci);
}
- if (ci->c && !ci->c->users)
+ if (ci->c && ci->c->users.empty())
delete ci->c;
}
diff --git a/src/core/cs_suspend.c b/src/core/cs_suspend.c
index e4386b021..03a058629 100644
--- a/src/core/cs_suspend.c
+++ b/src/core/cs_suspend.c
@@ -62,16 +62,14 @@ class CommandCSSuspend : public Command
if ((c = findchan(ci->name.c_str())))
{
- struct c_userlist *cu, *nextu;
-
- for (cu = c->users; cu; cu = nextu)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- nextu = cu->next;
+ UserContainer *uc = *it++;
- if (is_oper(cu->user))
+ if (is_oper(uc->user))
continue;
- c->Kick(NULL, cu->user, "%s", reason ? reason : getstring(cu->user->nc, CHAN_SUSPEND_REASON));
+ c->Kick(NULL, uc->user, "%s", reason ? reason : getstring(uc->user->nc, CHAN_SUSPEND_REASON));
}
}
diff --git a/src/core/os_chankill.c b/src/core/os_chankill.c
index ee3038a07..bdb3ecc69 100644
--- a/src/core/os_chankill.c
+++ b/src/core/os_chankill.c
@@ -28,7 +28,6 @@ class CommandOSChanKill : public Command
char reason[BUFSIZE];
time_t expires;
char mask[USERMAX + HOSTMAX + 2];
- struct c_userlist *cu, *cunext;
unsigned last_param = 1;
Channel *c;
@@ -70,15 +69,17 @@ class CommandOSChanKill : public Command
if ((c = findchan(channel)))
{
- for (cu = c->users; cu; cu = cunext)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- cunext = cu->next;
- if (is_oper(cu->user))
+ UserContainer *uc = *it++;
+
+ if (is_oper(uc->user))
continue;
+
strlcpy(mask, "*@", sizeof(mask)); /* Use *@" for the akill's, */
- strlcat(mask, cu->user->host, sizeof(mask));
+ strlcat(mask, uc->user->host, sizeof(mask));
add_akill(NULL, mask, Config.s_OperServ, expires, realreason.c_str());
- check_akill(cu->user->nick.c_str(), cu->user->GetIdent().c_str(), cu->user->host, NULL, NULL);
+ check_akill(uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->host, NULL, NULL);
}
if (Config.WallOSAkill)
ircdproto->SendGlobops(findbot(Config.s_OperServ), "%s used CHANKILL on %s (%s)", u->nick.c_str(), channel, realreason.c_str());
diff --git a/src/core/os_chanlist.c b/src/core/os_chanlist.c
index e5aa27159..e8faa10f7 100644
--- a/src/core/os_chanlist.c
+++ b/src/core/os_chanlist.c
@@ -37,22 +37,22 @@ class CommandOSChanList : public Command
if (pattern && (u2 = finduser(pattern)))
{
- struct u_chanlist *uc;
-
notice_lang(Config.s_OperServ, u, OPER_CHANLIST_HEADER_USER, u2->nick.c_str());
- for (uc = u2->chans; uc; uc = uc->next)
+ for (UChannelList::iterator it = u2->chans.begin(); it != u2->chans.end(); ++it)
{
+ ChannelContainer *cc = *it;
+
if (!Modes.empty())
{
for (std::list<ChannelModeName>::iterator it = Modes.begin(); it != Modes.end(); ++it)
{
- if (!uc->chan->HasMode(*it))
+ if (!cc->chan->HasMode(*it))
continue;
}
}
- notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, uc->chan->name.c_str(), uc->chan->usercount, chan_get_modes(uc->chan, 1, 1), uc->chan->topic ? uc->chan->topic : "");
+ notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), chan_get_modes(cc->chan, 1, 1), cc->chan->topic ? cc->chan->topic : "");
}
}
else
@@ -76,7 +76,7 @@ class CommandOSChanList : public Command
continue;
}
}
- notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, c->name.c_str(), c->usercount, chan_get_modes(c, 1, 1), c->topic ? c->topic : "");
+ notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), chan_get_modes(c, 1, 1), c->topic ? c->topic : "");
}
}
}
diff --git a/src/core/os_clearmodes.c b/src/core/os_clearmodes.c
index 8046abd8f..d0bc4c44b 100644
--- a/src/core/os_clearmodes.c
+++ b/src/core/os_clearmodes.c
@@ -27,7 +27,6 @@ class CommandOSClearModes : public Command
const char *chan = params[0].c_str();
Channel *c;
int all = 0;
- struct c_userlist *cu, *next;
ChannelMode *cm;
std::string buf;
@@ -62,13 +61,14 @@ class CommandOSClearModes : public Command
ircdproto->SendSVSModeChan(c, "-o", NULL);
else
{
- for (cu = c->users; cu; cu = next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = cu->next;
- if (!chan_has_user_status(c, cu->user, CUS_OP))
+ UserContainer *uc = *it;
+
+ if (!chan_has_user_status(c, uc->user, CUS_OP))
continue;
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
}
}
@@ -77,13 +77,14 @@ class CommandOSClearModes : public Command
ircdproto->SendSVSModeChan(c, "-v", NULL);
else
{
- for (cu = c->users; cu; cu = next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = cu->next;
- if (!chan_has_user_status(c, cu->user, CUS_VOICE))
+ UserContainer *uc = *it;
+
+ if (!chan_has_user_status(c, uc->user, CUS_VOICE))
continue;
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
}
@@ -94,13 +95,14 @@ class CommandOSClearModes : public Command
ircdproto->SendSVSModeChan(c, "-h", NULL);
else
{
- for (cu = c->users; cu; cu = next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = cu->next;
- if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
+ UserContainer *uc = *it;
+
+ if (!chan_has_user_status(c, uc->user, CUS_HALFOP))
continue;
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
}
}
}
@@ -115,13 +117,14 @@ class CommandOSClearModes : public Command
ircdproto->SendSVSModeChan(c, buf.c_str(), NULL);
else
{
- for (cu = c->users; cu; cu = next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = cu->next;
- if (!chan_has_user_status(c, cu->user, CUS_OWNER))
+ UserContainer *uc = *it;
+
+ if (!chan_has_user_status(c, uc->user, CUS_OWNER))
continue;
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
}
}
}
@@ -136,13 +139,14 @@ class CommandOSClearModes : public Command
ircdproto->SendSVSModeChan(c, buf.c_str(), NULL);
else
{
- for (cu = c->users; cu; cu = next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = cu->next;
- if (!chan_has_user_status(c, cu->user, CUS_PROTECT))
+ UserContainer *uc = *it;
+
+ if (!chan_has_user_status(c, uc->user, CUS_PROTECT))
continue;
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
}
}
}
diff --git a/src/core/os_userlist.c b/src/core/os_userlist.c
index 9c4f6ed6a..331818bec 100644
--- a/src/core/os_userlist.c
+++ b/src/core/os_userlist.c
@@ -36,21 +36,22 @@ class CommandOSUserList : public Command
if (pattern && (c = findchan(pattern)))
{
- struct c_userlist *cu;
-
notice_lang(Config.s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern);
- for (cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator cuit = c->users.begin(); cuit != c->users.end(); ++cuit)
{
+ UserContainer *uc = *cuit;
+
if (!Modes.empty())
{
for (std::list<UserModeName>::iterator it = Modes.begin(); it != Modes.end(); ++it)
{
- if (!cu->user->HasMode(*it))
+ if (!uc->user->HasMode(*it))
continue;
}
}
- notice_lang(Config.s_OperServ, u, OPER_USERLIST_RECORD, cu->user->nick.c_str(), cu->user->GetIdent().c_str(), cu->user->GetDisplayedHost().c_str());
+
+ notice_lang(Config.s_OperServ, u, OPER_USERLIST_RECORD, uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->GetDisplayedHost().c_str());
}
}
else
diff --git a/src/memoserv.c b/src/memoserv.c
index 922d79bc6..81448becd 100644
--- a/src/memoserv.c
+++ b/src/memoserv.c
@@ -299,12 +299,14 @@ void memo_send(User * u, const char *name, const char *text, int z)
if (nc->HasFlag(NI_MEMO_MAIL))
new_memo_mail(nc, m);
} else {
- struct c_userlist *cu, *next;
Channel *c;
- if (Config.MSNotifyAll && (c = findchan(name))) {
- for (cu = c->users; cu; cu = next) {
- next = cu->next;
+ if (Config.MSNotifyAll && (c = findchan(name)))
+ {
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
+ {
+ UserContainer *cu = *it;
+
if (check_access(cu->user, c->ci, CA_MEMO)) {
if (cu->user->nc
&& (cu->user->nc->HasFlag(NI_MEMO_RECEIVE))
diff --git a/src/modes.cpp b/src/modes.cpp
index 9f886cc3e..c634f7f53 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -237,7 +237,7 @@ void ChannelModeBan::AddMask(Channel *chan, const char *mask)
/* Check whether it matches a botserv bot after adding internally
* and parsing it through cidr support. ~ Viper */
if (Config.s_BotServ && Config.BSSmartJoin && chan->ci && chan->ci->bi
- && chan->usercount >= Config.BSMinUsers)
+ && chan->users.size() >= Config.BSMinUsers)
{
BotInfo *bi = chan->ci->bi;
diff --git a/src/modules/cs_enforce.c b/src/modules/cs_enforce.c
index 6c5bc275f..39d936bca 100644
--- a/src/modules/cs_enforce.c
+++ b/src/modules/cs_enforce.c
@@ -53,8 +53,6 @@ class CommandCSEnforce : public Command
void DoSecureOps(Channel *c)
{
- struct c_userlist *user;
- struct c_userlist *next;
ChannelInfo *ci;
bool hadsecureops = false;
@@ -75,13 +73,12 @@ class CommandCSEnforce : public Command
hadsecureops = true;
}
- user = c->users;
- do
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- next = user->next;
- chan_set_correct_modes(user->user, c, 0);
- user = next;
- } while (user);
+ UserContainer *uc = *it;
+
+ chan_set_correct_modes(uc->user, c, 0);
+ }
if (hadsecureops)
{
@@ -92,13 +89,10 @@ class CommandCSEnforce : public Command
void DoRestricted(Channel *c)
{
- struct c_userlist *user;
- struct c_userlist *next;
ChannelInfo *ci;
int16 old_nojoin_level;
char mask[BUFSIZE];
const char *reason;
- const char *av[3];
User *u;
if (!(ci = c->ci))
@@ -111,28 +105,24 @@ class CommandCSEnforce : public Command
if (ci->levels[CA_NOJOIN] < 0)
ci->levels[CA_NOJOIN] = 0;
- user = c->users;
- do
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- next = user->next;
- u = user->user;
- if (check_access(u, c->ci, CA_NOJOIN))
+ UserContainer *uc = *it++;
+
+ if (check_access(uc->user, ci, CA_NOJOIN))
{
get_idealban(ci, u, mask, sizeof(mask));
reason = getstring(u, CHAN_NOT_ALLOWED_TO_JOIN);
c->SetMode(NULL, CMODE_BAN, mask);
c->Kick(NULL, u, "%s", reason);
}
- user = next;
- } while (user);
+ }
ci->levels[CA_NOJOIN] = old_nojoin_level;
}
void DoCModeR(Channel *c)
{
- struct c_userlist *user;
- struct c_userlist *next;
ChannelInfo *ci;
char mask[BUFSIZE];
const char *reason;
@@ -144,23 +134,21 @@ class CommandCSEnforce : public Command
if (debug)
alog("debug: cs_enforce: Enforcing mode +R on %s", c->name.c_str());
- user = c->users;
- do
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end();)
{
- next = user->next;
- u = user->user;
- if (!nick_identified(u))
+ UserContainer *uc = *it++;
+
+ if (!nick_identified(uc->user))
{
- get_idealban(ci, u, mask, sizeof(mask));
- reason = getstring(u, CHAN_NOT_ALLOWED_TO_JOIN);
+ get_idealban(ci, uc->user, mask, sizeof(mask));
+ reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN);
if (!c->HasMode(CMODE_REGISTERED))
{
c->SetMode(NULL, CMODE_BAN, mask);
}
c->Kick(NULL, u, "%s", reason);
}
- user = next;
- } while (user);
+ }
}
public:
CommandCSEnforce() : Command("ENFORCE", 1, 2)
diff --git a/src/nickserv.c b/src/nickserv.c
index 472fb814a..4ab8fc4b8 100644
--- a/src/nickserv.c
+++ b/src/nickserv.c
@@ -932,13 +932,14 @@ int should_mode_change(int16 status, int16 mode)
int do_setmodes(User * u)
{
- struct u_chanlist *uc;
Channel *c;
/* Walk users current channels */
- for (uc = u->chans; uc; uc = uc->next)
+ for (UChannelList::iterator it = u->chans.begin(); it != u->chans.end(); ++it)
{
- if ((c = uc->chan))
+ ChannelContainer *cc = *it;
+
+ if ((c = cc->chan))
chan_set_correct_modes(u, c, 1);
}
return MOD_CONT;
diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c
index ac0647d41..e57604b8b 100644
--- a/src/protocol/bahamut.c
+++ b/src/protocol/bahamut.c
@@ -363,13 +363,15 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->creation_time = ts;
/* Remove status from all of our users */
- for (struct c_userlist *cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ UserContainer *uc = *it;
+
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
if (c->ci)
{
@@ -497,7 +499,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->UnsetFlag(CH_SYNCING);
/* If there are users in the channel they are allowed to be, set topic mlock etc. */
- if (c->usercount)
+ if (!c->users.empty())
c->Sync();
/* If there are no users in the channel, there is a ChanServ timer set to part the service bot
* and destroy the channel soon
diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c
index 91b400e9b..a4f4fc55d 100644
--- a/src/protocol/inspircd11.c
+++ b/src/protocol/inspircd11.c
@@ -473,13 +473,15 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
c->creation_time = ts;
/* Remove status from all of our users */
- for (struct c_userlist *cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ UserContainer *uc = *it;
+
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
if (c->ci)
{
@@ -566,7 +568,7 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
c->UnsetFlag(CH_SYNCING);
/* If there are users in the channel they are allowed to be, set topic mlock etc. */
- if (c->usercount)
+ if (!c->users.empty())
c->Sync();
/* If there are no users in the channel, there is a ChanServ timer set to part the service bot
* and destroy the channel soon
diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp
index 78d3a88fc..f07d5896e 100644
--- a/src/protocol/inspircd12.cpp
+++ b/src/protocol/inspircd12.cpp
@@ -531,13 +531,15 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
c->creation_time = ts;
/* Remove status from all of our users */
- for (struct c_userlist *cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ UserContainer *uc = *it;
+
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
if (c->ci)
{
@@ -630,7 +632,7 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
c->UnsetFlag(CH_SYNCING);
/* If there are users in the channel they are allowed to be, set topic mlock etc */
- if (c->usercount)
+ if (!c->users.empty())
c->Sync();
/* If there are no users in the channel, there is a ChanServ timer set to part the service bot
* and destroy the channel soon
diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c
index 40ed33634..11141b6a5 100644
--- a/src/protocol/ratbox.c
+++ b/src/protocol/ratbox.c
@@ -358,13 +358,15 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->creation_time = ts;
/* Remove status from all of our users */
- for (struct c_userlist *cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ UserContainer *uc = *it;
+
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
if (c->ci)
{
@@ -457,7 +459,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->UnsetFlag(CH_SYNCING);
/* If there are users in the channel they are allowed to be, set topic mlock etc. */
- if (c->usercount)
+ if (!c->users.empty())
c->Sync();
/* If there are no users in the channel, there is a ChanServ timer set to part the service bot
* and destroy the channel soon
diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c
index 7b924ff52..76411ed51 100644
--- a/src/protocol/unreal32.c
+++ b/src/protocol/unreal32.c
@@ -983,13 +983,15 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->creation_time = ts;
/* Remove status from all of our users */
- for (struct c_userlist *cu = c->users; cu; cu = cu->next)
+ for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it)
{
- c->RemoveMode(NULL, CMODE_OWNER, cu->user->nick);
- c->RemoveMode(NULL, CMODE_PROTECT, cu->user->nick);
- c->RemoveMode(NULL, CMODE_OP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_HALFOP, cu->user->nick);
- c->RemoveMode(NULL, CMODE_VOICE, cu->user->nick);
+ UserContainer *uc = *it;
+
+ c->RemoveMode(NULL, CMODE_OWNER, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_PROTECT, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_OP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_HALFOP, uc->user->nick);
+ c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick);
}
if (c->ci)
{
@@ -1111,7 +1113,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
c->UnsetFlag(CH_SYNCING);
/* If there are users in the channel they are allowed to be, set topic mlock etc. */
- if (c->usercount)
+ if (!c->users.empty())
c->Sync();
/* If there are no users in the channel, there is a ChanServ timer set to part the service bot
* and destroy the channel soon
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 802cf15af..5f9437513 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -87,7 +87,7 @@ ChannelInfo::~ChannelInfo()
if (this->c)
{
- if (this->bi && this->c->usercount >= Config.BSMinUsers)
+ if (this->bi && this->c->users.size() >= Config.BSMinUsers)
ircdproto->SendPart(this->bi, this->c, NULL);
this->c->ci = NULL;
}
diff --git a/src/users.c b/src/users.c
index c98a99133..a1f9fb05c 100644
--- a/src/users.c
+++ b/src/users.c
@@ -42,7 +42,6 @@ User::User(const std::string &snick, const std::string &suid)
host = hostip = vhost = realname = NULL;
server = NULL;
nc = NULL;
- chans = NULL;
invalid_pw_count = timestamp = my_signon = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0;
OnAccess = false;
@@ -223,7 +222,6 @@ void User::SetRealname(const std::string &srealname)
User::~User()
{
- struct u_chanlist *c, *c2;
char *srealname;
if (Config.LogUsers)
@@ -272,16 +270,14 @@ User::~User()
if (debug >= 2)
alog("debug: User::~User(): remove from channels");
- c = this->chans;
-
- while (c)
+ while (!this->chans.empty())
{
- c2 = c->next;
- c->chan->DeleteUser(this);
- delete c;
- c = c2;
+ ChannelContainer *cc = this->chans.front();
+ cc->chan->DeleteUser(this);
+ delete cc;
+ this->chans.pop_front();
}
-
+
/* Cancel pending nickname enforcers, etc */
cancel_user(this);
@@ -413,7 +409,6 @@ void get_user_stats(long *nusers, long *memuse)
long count = 0, mem = 0;
int i;
User *user;
- struct u_chanlist *uc;
for (i = 0; i < 1024; i++) {
for (user = userlist[i]; user; user = user->next) {
@@ -429,8 +424,7 @@ void get_user_stats(long *nusers, long *memuse)
mem += strlen(user->realname) + 1;
if (user->server->name)
mem += strlen(user->server->name) + 1;
- for (uc = user->chans; uc; uc = uc->next)
- mem += sizeof(*uc);
+ mem += (sizeof(ChannelContainer) * user->chans.size());
}
}
*nusers = count;