diff options
author | Adam <Adam@drink-coca-cola.info> | 2010-05-15 00:56:52 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-06-18 21:01:55 -0400 |
commit | ee57f5719301c3883afcffe5970746f378960917 (patch) | |
tree | 994ac1f0dbc675e9950050a2332bb17da79d5f02 /src | |
parent | c966d7ec17690037a597e1d8908782de376f3052 (diff) |
Store modes in users and channels using the Flags class, cleaner
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/channels.c | 8 | ||||
-rw-r--r-- | src/modes.cpp | 16 | ||||
-rw-r--r-- | src/regchannel.cpp | 28 | ||||
-rw-r--r-- | src/users.c | 14 |
5 files changed, 32 insertions, 36 deletions
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 ¶m, 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 ¶m, 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); |