summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-15 00:56:52 -0400
committerAdam <Adam@anope.org>2010-06-18 21:01:55 -0400
commitee57f5719301c3883afcffe5970746f378960917 (patch)
tree994ac1f0dbc675e9950050a2332bb17da79d5f02
parentc966d7ec17690037a597e1d8908782de376f3052 (diff)
Store modes in users and channels using the Flags class, cleaner
-rw-r--r--include/channels.h4
-rw-r--r--include/extern.h4
-rw-r--r--include/regchannel.h6
-rw-r--r--include/users.h6
-rw-r--r--src/Makefile2
-rw-r--r--src/channels.c8
-rw-r--r--src/modes.cpp16
-rw-r--r--src/regchannel.cpp28
-rw-r--r--src/users.c14
9 files changed, 42 insertions, 46 deletions
diff --git a/include/channels.h b/include/channels.h
index 4285a9f21..7814a377a 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -62,7 +62,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
std::map<ChannelModeName, std::string> Params;
/* Modes set on the channel */
- std::bitset<128> modes;
+ Flags<ChannelModeName> modes;
public:
/** Default constructor
@@ -136,7 +136,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
/** See if the channel has any modes at all
* @return true or false
*/
- inline const bool HasModes() const { return modes.count(); }
+ inline const bool HasModes() const { return modes.FlagCount(); }
/** See if a channel has a mode
* @param Name The mode name
diff --git a/include/extern.h b/include/extern.h
index a10585e69..657452fd0 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -350,8 +350,8 @@ E int str_is_cidr(char *str, uint32 * ip, uint32 * mask, char **host);
/**** modes.cpp ****/
/* Number of generic modes we support */
E unsigned GenericChannelModes, GenericUserModes;
-E std::bitset<128> DefMLockOn;
-E std::bitset<128> DefMLockOff;
+E Flags<ChannelModeName> DefMLockOn;
+E Flags<ChannelModeName> DefMLockOff;
E std::map<ChannelModeName, std::string> DefMLockParams;
/* Modes to set on bots when they join the channel */
E std::list<ChannelModeStatus *> BotModes;
diff --git a/include/regchannel.h b/include/regchannel.h
index 4a571182b..474b6f79a 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -67,9 +67,9 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag>
std::map<ChannelModeName, std::string> Params; /* Map of parameters by mode name for mlock */
std::vector<ChanAccess *> access; /* List of authorized users */
std::vector<AutoKick *> akick; /* List of users to kickban */
- std::vector<BadWord *> badwords; /* List of badwords */
- std::bitset<128> mlock_on; /* Modes mlocked on */
- std::bitset<128> mlock_off; /* Modes mlocked off */
+ std::vector<BadWord *> badwords; /* List of badwords */
+ Flags<ChannelModeName> mlock_on; /* Modes mlocked on */
+ Flags<ChannelModeName> mlock_off; /* Modes mlocked off */
public:
/** Default constructor
diff --git a/include/users.h b/include/users.h
index 3937e2ebe..135e115ef 100644
--- a/include/users.h
+++ b/include/users.h
@@ -36,7 +36,7 @@ class CoreExport User : public Extensible
std::string ident;
std::string uid;
bool OnAccess; /* If the user is on the access list of the nick theyre on */
- std::bitset<128> modes; /* Bitset of mode names the user has set on them */
+ Flags<UserModeName> modes; /* Bitset of mode names the user has set on them */
std::map<UserModeName, std::string> Params; /* Map of user modes and the params this user has */
NickCore *nc; /* NickCore account the user is currently loggged in as */
@@ -254,9 +254,9 @@ class CoreExport User : public Extensible
/** Set a string of modes on a user
* @param bi The client setting the mode
- * @param modes The modes
+ * @param umodes The modes
*/
- void SetModes(BotInfo *bi, const char *modes, ...);
+ void SetModes(BotInfo *bi, const char *umodes, ...);
/** Find the channel container for Channel c that the user is on
* This is preferred over using FindUser in Channel, as there are usually more users in a channel
diff --git a/src/Makefile b/src/Makefile
index 1756e6702..c5dec5633 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,7 +6,7 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o command.o comm
INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \
../include/pseudo.h ../include/sysconf.h ../include/config.h \
- ../include/services.h \
+ ../include/services.h ../include/regchannel.h \
../include/timers.h ../include/extern.h \
../include/modules.h ../include/slist.h ../include/hashcomp.h \
../include/threadengine.h ../include/mail.h
diff --git a/src/channels.c b/src/channels.c
index 6250d2342..4cdfb2c42 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -271,7 +271,7 @@ bool Channel::HasUserStatus(User *u, ChannelModeName Name)
*/
bool Channel::HasMode(ChannelModeName Name)
{
- return modes[Name];
+ return modes.HasFlag(Name);
}
/** Set a mode internally on a channel, this is not sent out to the IRCd
@@ -334,7 +334,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, bool En
return;
}
- modes[cm->Name] = true;
+ modes.SetFlag(cm->Name);
if (!param.empty())
{
@@ -476,7 +476,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
return;
}
- modes[cm->Name] = false;
+ modes.UnsetFlag(cm->Name);
if (cm->Type == MODE_PARAM)
{
@@ -719,7 +719,7 @@ void Channel::ClearModes(BotInfo *bi)
}
}
- modes.reset();
+ modes.ClearFlags();
}
/** Clear all the bans from the channel
diff --git a/src/modes.cpp b/src/modes.cpp
index 1e725cf7f..935d1e1b3 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -30,9 +30,9 @@ std::map<ChannelModeName, ChannelMode *> ModeManager::ChannelModesByName;
/* Number of generic modes we support */
unsigned GenericChannelModes = 0, GenericUserModes = 0;
/* Default mlocked modes on */
-std::bitset<128> DefMLockOn;
+Flags<ChannelModeName> DefMLockOn;
/* Default mlocked modes off */
-std::bitset<128> DefMLockOff;
+Flags<ChannelModeName> DefMLockOff;
/* Map for default mlocked mode parameters */
std::map<ChannelModeName, std::string> DefMLockParams;
/* Modes to set on bots when they join the channel */
@@ -42,10 +42,10 @@ std::list<ChannelModeStatus *> BotModes;
*/
void SetDefaultMLock()
{
- DefMLockOn.reset();
- DefMLockOff.reset();
+ DefMLockOn.ClearFlags();
+ DefMLockOff.ClearFlags();
DefMLockParams.clear();
- std::bitset<128> *ptr = NULL;
+ Flags<ChannelModeName> *ptr = NULL;
std::string modes, param;
spacesepstream sep(Config.MLock);
@@ -66,9 +66,9 @@ void SetDefaultMLock()
if (cm && (cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM))
{
- ptr->set(cm->Name);
+ ptr->SetFlag(cm->Name);
- if (*ptr == DefMLockOn && cm->Type == MODE_PARAM)
+ if (ptr == &DefMLockOn && cm->Type == MODE_PARAM)
{
if (sep.GetToken(param))
{
@@ -77,7 +77,7 @@ void SetDefaultMLock()
else
{
Alog() << "Warning: Got default mlock mode " << cm->ModeChar << " with no param?";
- ptr->set(cm->Name, false);
+ ptr->UnsetFlag(cm->Name);
}
}
}
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 1da77d912..8bc5078aa 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -421,9 +421,9 @@ void ChannelInfo::CleanBadWords()
const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status)
{
if (status)
- return mlock_on[Name];
+ return mlock_on.HasFlag(Name);
else
- return mlock_off[Name];
+ return mlock_off.HasFlag(Name);
}
/** Set a mlock
@@ -434,8 +434,6 @@ const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status)
*/
bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string param)
{
- size_t value = Name;
-
if (!status && !param.empty())
throw CoreException("Was told to mlock a mode negatively with a param?");
@@ -445,8 +443,8 @@ bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string
return false;
/* First, remove this everywhere */
- mlock_on[value] = false;
- mlock_off[value] = false;
+ mlock_on.UnsetFlag(Name);
+ mlock_off.UnsetFlag(Name);
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
if (it != Params.end())
@@ -455,9 +453,9 @@ bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string
}
if (status)
- mlock_on[value] = true;
+ mlock_on.SetFlag(Name);
else
- mlock_off[value] = true;
+ mlock_off.SetFlag(Name);
if (status && !param.empty())
{
@@ -473,15 +471,13 @@ bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string
*/
bool ChannelInfo::RemoveMLock(ChannelModeName Name)
{
- size_t value = Name;
-
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnUnMLock, OnUnMLock(Name));
if (MOD_RESULT == EVENT_STOP)
return false;
- mlock_on[value] = false;
- mlock_off[value] = false;
+ mlock_on.UnsetFlag(Name);
+ mlock_off.UnsetFlag(Name);
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
if (it != Params.end())
@@ -496,8 +492,8 @@ bool ChannelInfo::RemoveMLock(ChannelModeName Name)
*/
void ChannelInfo::ClearMLock()
{
- mlock_on.reset();
- mlock_off.reset();
+ mlock_on.ClearFlags();
+ mlock_off.ClearFlags();
}
/** Get the number of mlocked modes for this channel
@@ -507,9 +503,9 @@ void ChannelInfo::ClearMLock()
const size_t ChannelInfo::GetMLockCount(bool status) const
{
if (status)
- return mlock_on.count();
+ return mlock_on.FlagCount();
else
- return mlock_off.count();
+ return mlock_off.FlagCount();
}
/** Get a param from the channel
diff --git a/src/users.c b/src/users.c
index e89d09ad3..4311f8d33 100644
--- a/src/users.c
+++ b/src/users.c
@@ -513,7 +513,7 @@ void User::UpdateHost()
*/
const bool User::HasMode(UserModeName Name) const
{
- return modes[Name];
+ return modes.HasFlag(Name);
}
/** Set a mode internally on the user, the IRCd is not informed
@@ -525,7 +525,7 @@ void User::SetModeInternal(UserMode *um, const std::string &Param)
if (!um)
return;
- modes[um->Name] = true;
+ modes.SetFlag(um->Name);
if (!Param.empty())
{
Params.insert(std::make_pair(um->Name, Param));
@@ -542,7 +542,7 @@ void User::RemoveModeInternal(UserMode *um)
if (!um)
return;
- modes[um->Name] = false;
+ modes.UnsetFlag(um->Name);
std::map<UserModeName, std::string>::iterator it = Params.find(um->Name);
if (it != Params.end())
{
@@ -619,16 +619,16 @@ void User::RemoveMode(BotInfo *bi, char ModeChar)
/** Set a string of modes on a user
* @param bi The client setting the mode
- * @param modes The modes
+ * @param umodes The modes
*/
-void User::SetModes(BotInfo *bi, const char *modes, ...)
+void User::SetModes(BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
std::string modebuf, sbuf;
int add = -1;
- va_start(args, modes);
- vsnprintf(buf, BUFSIZE - 1, modes, args);
+ va_start(args, umodes);
+ vsnprintf(buf, BUFSIZE - 1, umodes, args);
va_end(args);
spacesepstream sep(buf);