diff options
38 files changed, 139 insertions, 148 deletions
diff --git a/include/channels.h b/include/channels.h index b4977eef1..4fb3e48dc 100644 --- a/include/channels.h +++ b/include/channels.h @@ -110,7 +110,6 @@ class CoreExport Channel : public Extensible, public InviteBase * @param value True if you want to set the mode or false if you want to remove it */ void SetMode(ModeHandler* mode, bool value); - void SetMode(char mode,bool mode_on); /** Sets or unsets a custom mode in the channels info * @param mode The mode character to set or unset @@ -126,7 +125,7 @@ class CoreExport Channel : public Extensible, public InviteBase */ inline bool IsModeSet(char mode) { return modes[mode-'A']; } inline bool IsModeSet(ModeHandler* mode) { return modes[mode->GetModeChar()-'A']; } - + bool IsModeSet(ModeHandler& mode) { return IsModeSet(&mode); } /** Returns the parameter for a custom mode on a channel. * @param mode The mode character you wish to query diff --git a/include/users.h b/include/users.h index 218ec4ae0..73ecba0ab 100644 --- a/include/users.h +++ b/include/users.h @@ -447,12 +447,16 @@ class CoreExport User : public Extensible * @return True if the mode is set */ bool IsModeSet(unsigned char m); + bool IsModeSet(ModeHandler* mh); + bool IsModeSet(ModeHandler& mh) { return IsModeSet(&mh); } /** Set a specific usermode to on or off * @param m The user mode * @param value On or off setting of the mode */ void SetMode(unsigned char m, bool value); + void SetMode(ModeHandler* mh, bool value); + void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); } /** Returns true or false for if a user can execute a privilaged oper command. * This is done by looking up their oper type from User::oper, then referencing @@ -901,3 +905,14 @@ inline FakeUser* IS_SERVER(User* u) return u->usertype == USERTYPE_SERVER ? static_cast<FakeUser*>(u) : NULL; } +inline bool User::IsModeSet(ModeHandler* mh) +{ + char m = mh->GetModeChar(); + return (modes[m-65]); +} + +inline void User::SetMode(ModeHandler* mh, bool value) +{ + char m = mh->GetModeChar(); + modes[m-65] = value; +} diff --git a/src/channels.cpp b/src/channels.cpp index 8a4ed3f49..8c59e6893 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -44,11 +44,6 @@ Channel::Channel(const std::string &cname, time_t ts) modes.reset(); } -void Channel::SetMode(char mode,bool mode_on) -{ - modes[mode-65] = mode_on; -} - void Channel::SetMode(ModeHandler* mh, bool on) { modes[mh->GetModeChar() - 65] = on; diff --git a/src/mode.cpp b/src/mode.cpp index a096c9c6a..303d292d9 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -94,7 +94,7 @@ ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel { /* We're either trying to add a mode we already have or remove a mode we don't have, deny. */ - if (dest->IsModeSet(this->GetModeChar()) == adding) + if (dest->IsModeSet(this) == adding) return MODEACTION_DENY; /* adding will be either true or false, depending on if we @@ -103,7 +103,7 @@ ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel aren't removing a mode we don't have, we don't have to do any other checks here to see if it's true or false, just add or remove the mode */ - dest->SetMode(this->GetModeChar(), adding); + dest->SetMode(this, adding); return MODEACTION_ALLOW; } @@ -113,7 +113,7 @@ ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Chan { /* We're either trying to add a mode we already have or remove a mode we don't have, deny. */ - if (channel->IsModeSet(this->GetModeChar()) == adding) + if (channel->IsModeSet(this) == adding) return MODEACTION_DENY; /* adding will be either true or false, depending on if we @@ -122,7 +122,7 @@ ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Chan aren't removing a mode we don't have, we don't have to do any other checks here to see if it's true or false, just add or remove the mode */ - channel->SetMode(this->GetModeChar(), adding); + channel->SetMode(this, adding); return MODEACTION_ALLOW; } @@ -410,9 +410,9 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User* user, /* Make sure the user isn't trying to slip in an invalid parameter */ if ((parameter.find(':') == 0) || (parameter.rfind(' ') != std::string::npos)) continue; - if ((flags & MODE_MERGE) && targetchannel && targetchannel->IsModeSet(modechar) && !mh->IsListMode()) + if ((flags & MODE_MERGE) && targetchannel && targetchannel->IsModeSet(mh) && !mh->IsListMode()) { - std::string ours = targetchannel->GetModeParameter(modechar); + std::string ours = targetchannel->GetModeParameter(mh); if (!mh->ResolveModeConflict(parameter, ours, targetchannel)) /* we won the mode merge, don't apply this mode */ continue; @@ -828,11 +828,11 @@ void ModeHandler::RemoveMode(Channel* channel, irc::modestacker& stack) { RemovePrefixMode(channel, stack); } - else if (channel->IsModeSet(this->GetModeChar())) + else if (channel->IsModeSet(this)) { if (this->GetNumParams(false)) // Removing this mode requires a parameter - stack.Push(this->GetModeChar(), channel->GetModeParameter(this->GetModeChar())); + stack.Push(this->GetModeChar(), channel->GetModeParameter(this)); else stack.Push(this->GetModeChar()); } diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp index f07d47172..e56b26ff1 100644 --- a/src/modes/cmode_k.cpp +++ b/src/modes/cmode_k.cpp @@ -32,18 +32,18 @@ ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, M ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) { - bool exists = channel->IsModeSet('k'); + bool exists = channel->IsModeSet(this); if (IS_LOCAL(source)) { if (exists == adding) return MODEACTION_DENY; - if (exists && (parameter != channel->GetModeParameter('k'))) + if (exists && (parameter != channel->GetModeParameter(this))) { /* Key is currently set and the correct key wasnt given */ return MODEACTION_DENY; } } else { - if (exists && adding && parameter == channel->GetModeParameter('k')) + if (exists && adding && parameter == channel->GetModeParameter(this)) { /* no-op, don't show */ return MODEACTION_DENY; diff --git a/src/modes/umode_s.cpp b/src/modes/umode_s.cpp index 9473d760e..f5631c695 100644 --- a/src/modes/umode_s.cpp +++ b/src/modes/umode_s.cpp @@ -36,18 +36,18 @@ ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Chan if (adding) { /* Fix for bug #310 reported by Smartys */ - if (!dest->modes[UM_SNOMASK]) + if (!dest->IsModeSet(this)) dest->snomasks.reset(); - dest->modes[UM_SNOMASK] = true; + dest->SetMode(this, true); parameter = dest->ProcessNoticeMasks(parameter.c_str()); return MODEACTION_ALLOW; } else { - if (dest->modes[UM_SNOMASK] != false) + if (dest->IsModeSet(this)) { - dest->modes[UM_SNOMASK] = false; + dest->SetMode(this, false); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_allowinvite.cpp b/src/modules/m_allowinvite.cpp index dc6d6da89..eb0eea760 100644 --- a/src/modules/m_allowinvite.cpp +++ b/src/modules/m_allowinvite.cpp @@ -59,7 +59,7 @@ class ModuleAllowInvite : public Module user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You are banned from using INVITE", user->nick.c_str(), channel->name.c_str()); return res; } - if (channel->IsModeSet('A') || res == MOD_RES_ALLOW) + if (channel->IsModeSet(ni) || res == MOD_RES_ALLOW) { // Explicitly allow /invite return MOD_RES_ALLOW; diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp index c13549db8..a23d87a12 100644 --- a/src/modules/m_blockcaps.cpp +++ b/src/modules/m_blockcaps.cpp @@ -76,7 +76,7 @@ public: if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; - if (!c->GetExtBanStatus(user, 'B').check(!c->IsModeSet('B'))) + if (!c->GetExtBanStatus(user, 'B').check(!c->IsModeSet(bc))) { int caps = 0; const char* actstr = "\1ACTION "; diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp index 2c7207698..6d1111a1d 100644 --- a/src/modules/m_blockcolor.cpp +++ b/src/modules/m_blockcolor.cpp @@ -64,7 +64,7 @@ class ModuleBlockColor : public Module if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; - if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet('c'))) + if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet(bc))) { for (std::string::iterator i = text.begin(); i != text.end(); i++) { diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp index ca1a9d5c8..7afb7a999 100644 --- a/src/modules/m_botmode.cpp +++ b/src/modules/m_botmode.cpp @@ -54,7 +54,7 @@ class ModuleBotMode : public Module void OnWhois(User* src, User* dst) CXX11_OVERRIDE { - if (dst->IsModeSet('B')) + if (dst->IsModeSet(bm)) { ServerInstance->SendWhoisLine(src, dst, 335, src->nick+" "+dst->nick+" :is a bot on "+ServerInstance->Config->Network); } diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 1f9766883..533e70eac 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -387,7 +387,7 @@ public: ModResult PreText(User* user, User* dest, std::string& text) { - if (!dest->IsModeSet('g') || (user == dest)) + if (!dest->IsModeSet(myumode) || (user == dest)) return MOD_RES_PASSTHRU; if (operoverride && user->IsOper()) diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 03b99c77c..4148c59b4 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -75,11 +75,11 @@ class ModuleCensor : public Module bool active = false; if (target_type == TYPE_USER) - active = ((User*)dest)->IsModeSet('G'); + active = ((User*)dest)->IsModeSet(cu); else if (target_type == TYPE_CHANNEL) { - active = ((Channel*)dest)->IsModeSet('G'); Channel* c = (Channel*)dest; + active = c->IsModeSet(cc); ModResult res = ServerInstance->OnCheckExemption(user,c,"censor"); if (res == MOD_RES_ALLOW) diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index 9c4f644d7..ad10a2524 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -97,7 +97,7 @@ class HistoryMode : public ModeHandler } else { - if (!channel->IsModeSet('H')) + if (!channel->IsModeSet(this)) return MODEACTION_DENY; ext.unset(channel); } diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index ccc98e557..5613a137f 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -65,7 +65,7 @@ class CloakUser : public ModeHandler */ if (!user) { - dest->SetMode('x',adding); + dest->SetMode(this, adding); return MODEACTION_ALLOW; } @@ -82,7 +82,7 @@ class CloakUser : public ModeHandler debounce_ts = ServerInstance->Time(); } - if (adding == user->IsModeSet('x')) + if (adding == user->IsModeSet(this)) return MODEACTION_DENY; /* don't allow this user to spam modechanges */ @@ -102,7 +102,7 @@ class CloakUser : public ModeHandler if (cloak) { user->ChangeDisplayedHost(cloak->c_str()); - user->SetMode('x',true); + user->SetMode(this, true); return MODEACTION_ALLOW; } else @@ -113,7 +113,7 @@ class CloakUser : public ModeHandler /* User is removing the mode, so restore their real host * and make it match the displayed one. */ - user->SetMode('x',false); + user->SetMode(this, false); user->ChangeDisplayedHost(user->host.c_str()); return MODEACTION_ALLOW; } @@ -312,10 +312,10 @@ class ModuleCloaking : public Module // mode change, we will call SetMode back to true AFTER the host change is done. void OnChangeHost(User* u, const std::string& host) CXX11_OVERRIDE { - if(u->IsModeSet('x')) + if (u->IsModeSet(cu)) { - u->SetMode('x', false); - u->WriteServ("MODE %s -x", u->nick.c_str()); + u->SetMode(cu, false); + u->WriteServ("MODE %s -%c", u->nick.c_str(), cu.GetModeChar()); } } diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index d9ab03053..9401bcd5c 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -53,7 +53,7 @@ class ModulePrivacyMode : public Module if (target_type == TYPE_USER) { User* t = (User*)dest; - if (!user->IsOper() && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t)) + if (!user->IsOper() && (t->IsModeSet(pm)) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t)) { user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user (+c set)", user->nick.c_str(), t->nick.c_str()); return MOD_RES_DENY; diff --git a/src/modules/m_deaf.cpp b/src/modules/m_deaf.cpp index 65591f070..a76f96b61 100644 --- a/src/modules/m_deaf.cpp +++ b/src/modules/m_deaf.cpp @@ -32,24 +32,14 @@ class User_d : public ModeHandler ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { + if (adding == dest->IsModeSet(this)) + return MODEACTION_DENY; + if (adding) - { - if (!dest->IsModeSet('d')) - { - dest->WriteNotice("*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode " + dest->nick + " -d."); - dest->SetMode('d',true); - return MODEACTION_ALLOW; - } - } - else - { - if (dest->IsModeSet('d')) - { - dest->SetMode('d',false); - return MODEACTION_ALLOW; - } - } - return MODEACTION_DENY; + dest->WriteNotice("*** You have enabled usermode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode " + dest->nick + " -d."); + + dest->SetMode(this, adding); + return MODEACTION_ALLOW; } }; @@ -124,7 +114,7 @@ class ModuleDeaf : public Module for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++) { /* not +d ? */ - if (!i->first->IsModeSet('d')) + if (!i->first->IsModeSet(m1)) continue; /* deliver message */ /* matched both U-line only and regular bypasses */ if (is_bypasschar && is_bypasschar_uline) diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index 1216922ba..a1a1479f3 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -67,7 +67,7 @@ class ModuleDelayJoin : public Module ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { /* no change */ - if (channel->IsModeSet('D') == adding) + if (channel->IsModeSet(this) == adding) return MODEACTION_DENY; if (!adding) @@ -80,7 +80,7 @@ ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channe for (UserMembCIter n = names->begin(); n != names->end(); ++n) creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty); } - channel->SetMode('D', adding); + channel->SetMode(this, adding); return MODEACTION_ALLOW; } @@ -113,7 +113,7 @@ static void populate(CUList& except, Membership* memb) void ModuleDelayJoin::OnUserJoin(Membership* memb, bool sync, bool created, CUList& except) { - if (memb->chan->IsModeSet('D')) + if (memb->chan->IsModeSet(djm)) { unjoined.set(memb, 1); populate(except, memb); diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index aeb4e4932..15e997301 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -63,7 +63,7 @@ ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel { if (adding) { - if ((channel->IsModeSet('d')) && (channel->GetModeParameter('d') == parameter)) + if ((channel->IsModeSet(this)) && (channel->GetModeParameter(this) == parameter)) return MODEACTION_DENY; /* Setting a new limit, sanity check */ @@ -77,7 +77,7 @@ ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel } else { - if (!channel->IsModeSet('d')) + if (!channel->IsModeSet(this)) return MODEACTION_DENY; /* @@ -97,7 +97,7 @@ Version ModuleDelayMsg::GetVersion() void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&) { - if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet('d'))) + if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm))) { djm.jointime.set(memb, ServerInstance->Time()); } @@ -123,7 +123,7 @@ ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_ty if (ts == 0) return MOD_RES_PASSTHRU; - std::string len = channel->GetModeParameter('d'); + std::string len = channel->GetModeParameter(&djm); if (ts + atoi(len.c_str()) > ServerInstance->Time()) { diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index 1733d0455..ba0bc62fb 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -157,7 +157,7 @@ class ModuleHelpop : public Module void OnWhois(User* src, User* dst) CXX11_OVERRIDE { - if (dst->IsModeSet('h')) + if (dst->IsModeSet(ho)) { ServerInstance->SendWhoisLine(src, dst, 310, src->nick+" "+dst->nick+" :is available for help."); } diff --git a/src/modules/m_hidechans.cpp b/src/modules/m_hidechans.cpp index 3e2b27181..a53543f07 100644 --- a/src/modules/m_hidechans.cpp +++ b/src/modules/m_hidechans.cpp @@ -68,7 +68,7 @@ class ModuleHideChans : public Module return MOD_RES_PASSTHRU; /* don't touch if -I */ - if (!dest->IsModeSet('I')) + if (!dest->IsModeSet(hm)) return MOD_RES_PASSTHRU; /* if it affects opers, we don't care if they are opered */ diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp index 8c0757fe8..832e5613a 100644 --- a/src/modules/m_hideoper.cpp +++ b/src/modules/m_hideoper.cpp @@ -63,7 +63,7 @@ class ModuleHideOper : public Module if (numeric != 313) return MOD_RES_PASSTHRU; - if (!dest->IsModeSet('H')) + if (!dest->IsModeSet(hm)) return MOD_RES_PASSTHRU; if (!user->HasPrivPermission("users/auspex")) @@ -74,7 +74,7 @@ class ModuleHideOper : public Module void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line) CXX11_OVERRIDE { - if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex")) + if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex")) { // hide the "*" that marks the user as an oper from the /WHO line std::string::size_type pos = line.find("*"); diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 2e91cdf06..a898fd5d1 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -106,7 +106,7 @@ class MsgFlood : public ModeHandler } else { - if (!channel->IsModeSet('f')) + if (!channel->IsModeSet(this)) return MODEACTION_DENY; ext.unset(channel); @@ -135,7 +135,7 @@ class ModuleMsgFlood : public Module ModResult ProcessMessages(User* user,Channel* dest, const std::string &text) { - if ((!IS_LOCAL(user)) || !dest->IsModeSet('f')) + if ((!IS_LOCAL(user)) || !dest->IsModeSet(mf)) return MOD_RES_PASSTHRU; if (ServerInstance->OnCheckExemption(user,dest,"flood") == MOD_RES_ALLOW) diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp index 26b6339a3..9d92b8a44 100644 --- a/src/modules/m_namedmodes.cpp +++ b/src/modules/m_namedmodes.cpp @@ -29,11 +29,11 @@ static void DisplayList(User* user, Channel* channel) ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); if (!mh || mh->IsListMode()) continue; - if (!channel->IsModeSet(letter)) + if (!channel->IsModeSet(mh)) continue; items << " +" << mh->name; if (mh->GetNumParams(true)) - items << " " << channel->GetModeParameter(letter); + items << " " << channel->GetModeParameter(mh); } const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name; user->SendText(line, items); diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 61347ded0..6de6b235c 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -119,7 +119,7 @@ class NickFlood : public ModeHandler } else { - if (!channel->IsModeSet('F')) + if (!channel->IsModeSet(this)) return MODEACTION_DENY; ext.unset(channel); diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp index 29b548e1c..e769ba420 100644 --- a/src/modules/m_noctcp.cpp +++ b/src/modules/m_noctcp.cpp @@ -63,7 +63,7 @@ class ModuleNoCTCP : public Module if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; - if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet('C'))) + if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet(nc))) { user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str()); return MOD_RES_DENY; diff --git a/src/modules/m_nokicks.cpp b/src/modules/m_nokicks.cpp index 2b301f6c5..bb78b60d1 100644 --- a/src/modules/m_nokicks.cpp +++ b/src/modules/m_nokicks.cpp @@ -54,7 +54,7 @@ class ModuleNoKicks : public Module ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE { - if (!memb->chan->GetExtBanStatus(source, 'Q').check(!memb->chan->IsModeSet('Q'))) + if (!memb->chan->GetExtBanStatus(source, 'Q').check(!memb->chan->IsModeSet(nk))) { // Can't kick with Q in place, not even opers with override, and founders source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Can't kick user %s from channel (+Q set)",source->nick.c_str(), memb->chan->name.c_str(), memb->user->nick.c_str()); diff --git a/src/modules/m_nonicks.cpp b/src/modules/m_nonicks.cpp index 8981097be..c9a9116e2 100644 --- a/src/modules/m_nonicks.cpp +++ b/src/modules/m_nonicks.cpp @@ -73,7 +73,7 @@ class ModuleNoNickChange : public Module if (override && user->IsOper()) continue; - if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N'))) + if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet(nn))) { user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)", user->nick.c_str(), curr->name.c_str()); diff --git a/src/modules/m_nonotice.cpp b/src/modules/m_nonotice.cpp index 206362845..c75372953 100644 --- a/src/modules/m_nonotice.cpp +++ b/src/modules/m_nonotice.cpp @@ -57,7 +57,7 @@ class ModuleNoNotice : public Module if ((msgtype == MSG_NOTICE) && (target_type == TYPE_CHANNEL) && (IS_LOCAL(user))) { Channel* c = (Channel*)dest; - if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet('T'))) + if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet(nt))) { res = ServerInstance->OnCheckExemption(user,c,"nonotice"); if (res == MOD_RES_ALLOW) diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp index b3fc91e90..8e46f923f 100644 --- a/src/modules/m_operchans.cpp +++ b/src/modules/m_operchans.cpp @@ -51,7 +51,7 @@ class ModuleOperChans : public Module ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE { - if (chan && chan->IsModeSet('O') && !user->IsOper()) + if (chan && chan->IsModeSet(oc) && !user->IsOper()) { user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join %s (+O is set)", user->nick.c_str(), chan->name.c_str(), chan->name.c_str()); diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 0b4d96c0f..cfb4fef27 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -23,9 +23,34 @@ /* $ModDesc: Provides support for channel mode +P to provide permanent channels */ + +/** Handles the +P channel mode + */ +class PermChannel : public ModeHandler +{ + public: + PermChannel(Module* Creator) + : ModeHandler(Creator, "permanent", 'P', PARAM_NONE, MODETYPE_CHANNEL) + { + oper = true; + } + + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) + { + if (adding == channel->IsModeSet(this)) + return MODEACTION_DENY; + + channel->SetMode(this, adding); + if (!adding) + channel->CheckDestroy(); + + return MODEACTION_ALLOW; + } +}; + // Not in a class due to circular dependancy hell. static std::string permchannelsconf; -static bool WriteDatabase() +static bool WriteDatabase(PermChannel& permchanmode) { /* * We need to perform an atomic write so as not to fuck things up. @@ -52,7 +77,7 @@ static bool WriteDatabase() for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++) { Channel* chan = i->second; - if (!chan->IsModeSet('P')) + if (!chan->IsModeSet(permchanmode)) continue; stream << "<permchannels channel=\"" << ServerConfig::Escape(chan->name) @@ -88,38 +113,6 @@ static bool WriteDatabase() return true; } - -/** Handles the +P channel mode - */ -class PermChannel : public ModeHandler -{ - public: - PermChannel(Module* Creator) : ModeHandler(Creator, "permanent", 'P', PARAM_NONE, MODETYPE_CHANNEL) { oper = true; } - - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) - { - if (adding) - { - if (!channel->IsModeSet('P')) - { - channel->SetMode('P',true); - return MODEACTION_ALLOW; - } - } - else - { - if (channel->IsModeSet('P')) - { - channel->SetMode(this,false); - channel->CheckDestroy(); - return MODEACTION_ALLOW; - } - } - - return MODEACTION_DENY; - } -}; - class ModulePermanentChannels : public Module { PermChannel p; @@ -238,7 +231,7 @@ public: ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt) CXX11_OVERRIDE { - if (chan && (chan->IsModeSet('P') || mode == 'P')) + if (chan && (chan->IsModeSet(p) || mode == p.GetModeChar())) dirty = true; return MOD_RES_PASSTHRU; @@ -246,14 +239,14 @@ public: void OnPostTopicChange(User*, Channel *c, const std::string&) CXX11_OVERRIDE { - if (c->IsModeSet('P')) + if (c->IsModeSet(p)) dirty = true; } void OnBackgroundTimer(time_t) CXX11_OVERRIDE { if (dirty) - WriteDatabase(); + WriteDatabase(p); dirty = false; } @@ -296,7 +289,7 @@ public: ModResult OnChannelPreDelete(Channel *c) CXX11_OVERRIDE { - if (c->IsModeSet('P')) + if (c->IsModeSet(p)) return MOD_RES_DENY; return MOD_RES_PASSTHRU; diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index e40339fa6..5e78ccef2 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -64,7 +64,7 @@ class Redirect : public ModeHandler } } - if (channel->GetModeParameter('L') == parameter) + if (channel->GetModeParameter(this) == parameter) return MODEACTION_DENY; /* * We used to do some checking for circular +L here, but there is no real need for this any more especially as we @@ -74,7 +74,7 @@ class Redirect : public ModeHandler } else { - if (channel->IsModeSet('L')) + if (channel->IsModeSet(this)) { return MODEACTION_ALLOW; } @@ -95,15 +95,14 @@ class AntiRedirect : public SimpleUserModeHandler class ModuleRedirect : public Module { - Redirect re; AntiRedirect re_u; bool UseUsermode; public: - ModuleRedirect() - : re(this), re_u(this) + : re(this) + , re_u(this) { } @@ -133,22 +132,22 @@ class ModuleRedirect : public Module { if (chan) { - if (chan->IsModeSet('L') && chan->IsModeSet('l')) + if (chan->IsModeSet(re) && chan->IsModeSet('l')) { if (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter('l'))) { - std::string channel = chan->GetModeParameter('L'); + std::string channel = chan->GetModeParameter(&re); /* sometimes broken ulines can make circular or chained +L, avoid this */ Channel* destchan = ServerInstance->FindChan(channel); - if (destchan && destchan->IsModeSet('L')) + if (destchan && destchan->IsModeSet(re)) { user->WriteNumeric(470, "%s %s * :You may not join this channel. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname.c_str()); return MOD_RES_DENY; } /* We check the bool value here to make sure we have it enabled, if we don't then usermode +L might be assigned to something else. */ - if (UseUsermode && user->IsModeSet('L')) + if (UseUsermode && user->IsModeSet(re_u)) { user->WriteNumeric(470, "%s %s %s :Force redirection stopped.", user->nick.c_str(), cname.c_str(), channel.c_str()); return MOD_RES_DENY; diff --git a/src/modules/m_rmode.cpp b/src/modules/m_rmode.cpp index f5e6433bf..e4345535e 100644 --- a/src/modules/m_rmode.cpp +++ b/src/modules/m_rmode.cpp @@ -67,7 +67,7 @@ class CommandRMode : public Command if (!mh->IsListMode()) { - if (chan->IsModeSet(modeletter)) + if (chan->IsModeSet(mh)) modestack.Push(modeletter); } else if (((prefixrank = mh->GetPrefixRank()) && (prefixchar = mh->GetPrefix()))) diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 123132ca9..cbd9e536c 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -40,9 +40,9 @@ class Channel_r : public ModeHandler if (!IS_LOCAL(source)) { // Only change the mode if it's not redundant - if ((adding != channel->IsModeSet('r'))) + if ((adding != channel->IsModeSet(this))) { - channel->SetMode('r',adding); + channel->SetMode(this, adding); return MODEACTION_ALLOW; } } @@ -66,9 +66,9 @@ class User_r : public ModeHandler { if (!IS_LOCAL(source)) { - if ((adding != dest->IsModeSet('r'))) + if ((adding != dest->IsModeSet(this))) { - dest->SetMode('r',adding); + dest->SetMode(this, adding); return MODEACTION_ALLOW; } } @@ -144,7 +144,7 @@ class ModuleServicesAccount : public Module ServerInstance->SendWhoisLine(source, dest, 330, "%s %s %s :is logged in as", source->nick.c_str(), dest->nick.c_str(), account->c_str()); } - if (dest->IsModeSet('r')) + if (dest->IsModeSet(m5)) { /* user is registered */ ServerInstance->SendWhoisLine(source, dest, 307, "%s %s :is a registered nick", source->nick.c_str(), dest->nick.c_str()); @@ -154,7 +154,7 @@ class ModuleServicesAccount : public Module void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE { /* On nickchange, if they have +r, remove it */ - if (user->IsModeSet('r') && assign(user->nick) != oldnick) + if (user->IsModeSet(m5) && assign(user->nick) != oldnick) { std::vector<std::string> modechange; modechange.push_back(user->nick); @@ -176,7 +176,7 @@ class ModuleServicesAccount : public Module Channel* c = (Channel*)dest; ModResult res = ServerInstance->OnCheckExemption(user,c,"regmoderated"); - if (c->IsModeSet('M') && !is_registered && res != MOD_RES_ALLOW) + if (c->IsModeSet(m2) && !is_registered && res != MOD_RES_ALLOW) { // user messaging a +M channel and is not registered user->WriteNumeric(477, user->nick+" "+c->name+" :You need to be identified to a registered account to message this channel"); @@ -187,7 +187,7 @@ class ModuleServicesAccount : public Module { User* u = (User*)dest; - if (u->IsModeSet('R') && !is_registered) + if (u->IsModeSet(m3) && !is_registered) { // user messaging a +R user and is not registered user->WriteNumeric(477, ""+ user->nick +" "+ u->nick +" :You need to be identified to a registered account to message this user"); @@ -241,7 +241,7 @@ class ModuleServicesAccount : public Module if (chan) { - if (chan->IsModeSet('R')) + if (chan->IsModeSet(m1)) { if (!is_registered) { diff --git a/src/modules/m_servprotect.cpp b/src/modules/m_servprotect.cpp index 82ad0920b..32dcc21c0 100644 --- a/src/modules/m_servprotect.cpp +++ b/src/modules/m_servprotect.cpp @@ -67,7 +67,7 @@ class ModuleServProtectMode : public Module void OnWhois(User* user, User* dest) CXX11_OVERRIDE { - if (dest->IsModeSet('k')) + if (dest->IsModeSet(bm)) { ServerInstance->SendWhoisLine(user, dest, 310, user->nick+" "+dest->nick+" :is a Network Service on "+ServerInstance->Config->Network); } @@ -90,7 +90,7 @@ class ModuleServProtectMode : public Module * This includes any prefix permission mode, even those registered in other modules, e.g. +qaohv. Using ::ModeString() * here means that the number of modes is restricted to only modes the user has, limiting it to as short a loop as possible. */ - if (u->IsModeSet('k') && memb && memb->modes.find(mode) != std::string::npos) + if (u->IsModeSet(bm) && memb && memb->modes.find(mode) != std::string::npos) { /* BZZZT, Denied! */ user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network.c_str()); @@ -107,7 +107,7 @@ class ModuleServProtectMode : public Module if (src == NULL) return MOD_RES_PASSTHRU; - if (dst->IsModeSet('k')) + if (dst->IsModeSet(bm)) { src->WriteNumeric(485, "%s :You are not permitted to kill %s services!", src->nick.c_str(), ServerInstance->Config->Network.c_str()); ServerInstance->SNO->WriteGlobalSno('a', src->nick+" tried to kill service "+dst->nick+" ("+reason+")"); @@ -118,7 +118,7 @@ class ModuleServProtectMode : public Module ModResult OnUserPreKick(User *src, Membership* memb, const std::string &reason) CXX11_OVERRIDE { - if (memb->user->IsModeSet('k')) + if (memb->user->IsModeSet(bm)) { src->WriteNumeric(484, "%s %s :You are not permitted to kick services", src->nick.c_str(), memb->chan->name.c_str()); @@ -130,7 +130,7 @@ class ModuleServProtectMode : public Module ModResult OnWhoisLine(User* src, User* dst, int &numeric, std::string &text) CXX11_OVERRIDE { - return ((src != dst) && (numeric == 319) && dst->IsModeSet('k')) ? MOD_RES_DENY : MOD_RES_PASSTHRU; + return ((src != dst) && (numeric == 319) && dst->IsModeSet(bm)) ? MOD_RES_DENY : MOD_RES_PASSTHRU; } }; diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index 57d496f1f..29de4ee1c 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -105,7 +105,7 @@ class ModuleShowwhois : public Module void OnWhois(User* source, User* dest) CXX11_OVERRIDE { - if (!dest->IsModeSet('W') || source == dest) + if (!dest->IsModeSet(*sw) || source == dest) return; if (!ShowWhoisFromOpers && source->IsOper()) diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 4bcc2d9b2..2eb7f90e4 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -132,7 +132,7 @@ CmdResult CommandUID::Handle(const parameterlist ¶ms, User* serversrc) } else mh->OnModeChange(_new, _new, NULL, empty, true); - _new->SetMode(*v, true); + _new->SetMode(mh, true); } _new->SetClientIP(params[6].c_str()); diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp index 65933cc14..40398b3ac 100644 --- a/src/modules/m_sslmodes.cpp +++ b/src/modules/m_sslmodes.cpp @@ -43,7 +43,7 @@ class SSLMode : public ModeHandler { if (adding) { - if (!channel->IsModeSet('z')) + if (!channel->IsModeSet(this)) { if (IS_LOCAL(source)) { @@ -61,7 +61,7 @@ class SSLMode : public ModeHandler } } } - channel->SetMode('z',true); + channel->SetMode(this, true); return MODEACTION_ALLOW; } else @@ -71,9 +71,9 @@ class SSLMode : public ModeHandler } else { - if (channel->IsModeSet('z')) + if (channel->IsModeSet(this)) { - channel->SetMode('z',false); + channel->SetMode(this, false); return MODEACTION_ALLOW; } @@ -102,7 +102,7 @@ class ModuleSSLModes : public Module ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE { - if(chan && chan->IsModeSet('z')) + if(chan && chan->IsModeSet(sslm)) { if (!sslm.API) return MOD_RES_DENY; diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp index b7e26afd5..d216d73b2 100644 --- a/src/modules/m_stripcolor.cpp +++ b/src/modules/m_stripcolor.cpp @@ -72,7 +72,7 @@ class ModuleStripColor : public Module if (target_type == TYPE_USER) { User* t = (User*)dest; - active = t->IsModeSet('S'); + active = t->IsModeSet(usc); } else if (target_type == TYPE_CHANNEL) { @@ -82,7 +82,7 @@ class ModuleStripColor : public Module if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; - active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet('S')); + active = !t->GetExtBanStatus(user, 'S').check(!t->IsModeSet(csc)); } if (active) |