diff options
| author | 2021-03-30 17:52:02 +0100 | |
|---|---|---|
| committer | 2021-03-30 18:25:55 +0100 | |
| commit | 49702c621eed54caee6a45c0518d68a33bca8f92 (patch) | |
| tree | 94623f04b8635fbff3f1a90117c32d44fce11075 /src/modules | |
| parent | Remove multi-line FJOIN and FMODE logic. (diff) | |
Convert various mode methods to take Mode::Change.
- AccessCheck
- AfterMode
- BeforeMode
- OnModeChange
- OnRawMode
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/m_autoop.cpp | 20 | ||||
| -rw-r--r-- | src/modules/m_banredirect.cpp | 36 | ||||
| -rw-r--r-- | src/modules/m_cloaking.cpp | 10 | ||||
| -rw-r--r-- | src/modules/m_deaf.cpp | 16 | ||||
| -rw-r--r-- | src/modules/m_delayjoin.cpp | 22 | ||||
| -rw-r--r-- | src/modules/m_disable.cpp | 18 | ||||
| -rw-r--r-- | src/modules/m_exemptchanops.cpp | 8 | ||||
| -rw-r--r-- | src/modules/m_hidelist.cpp | 4 | ||||
| -rw-r--r-- | src/modules/m_hideoper.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_mlock.cpp | 4 | ||||
| -rw-r--r-- | src/modules/m_ojoin.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_operprefix.cpp | 6 | ||||
| -rw-r--r-- | src/modules/m_permchannels.cpp | 18 | ||||
| -rw-r--r-- | src/modules/m_services_account.cpp | 12 | ||||
| -rw-r--r-- | src/modules/m_servprotect.cpp | 10 | ||||
| -rw-r--r-- | src/modules/m_spanningtree/uid.cpp | 11 | ||||
| -rw-r--r-- | src/modules/m_sslmodes.cpp | 8 | ||||
| -rw-r--r-- | src/modules/m_timedbans.cpp | 6 |
18 files changed, 114 insertions, 107 deletions
diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index 63f51cc76..d69933df9 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -51,16 +51,17 @@ class AutoOpList : public ListModeBase return mh ? mh->IsPrefixMode() : NULL; } - ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding) override + ModResult AccessCheck(User* source, Channel* channel, Modes::Change& change) override { - std::string::size_type pos = parameter.find(':'); + std::string::size_type pos = change.param.find(':'); if (pos == 0 || pos == std::string::npos) - return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU; + return change.adding ? MOD_RES_DENY : MOD_RES_PASSTHRU; + unsigned int mylevel = channel->GetPrefixValue(source); - std::string mid(parameter, 0, pos); + std::string mid(change.param, 0, pos); PrefixMode* mh = FindMode(mid); - if (adding && !mh) + if (change.adding && !mh) { source->WriteNumeric(ERR_UNKNOWNMODE, mid, InspIRCd::Format("Cannot find prefix mode '%s' for autoop", mid.c_str())); return MOD_RES_DENY; @@ -68,13 +69,14 @@ class AutoOpList : public ListModeBase else if (!mh) return MOD_RES_PASSTHRU; - std::string dummy; - if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY) + Modes::Change modechange(mh, true, ""); + if (mh->AccessCheck(source, channel, change) == MOD_RES_DENY) return MOD_RES_DENY; - if (mh->GetLevelRequired(adding) > mylevel) + + if (mh->GetLevelRequired(change.adding) > mylevel) { source->WriteNumeric(ERR_CHANOPRIVSNEEDED, channel->name, InspIRCd::Format("You must be able to %s mode %c (%s) to %s an autoop containing it", - adding ? "set" : "unset", mh->GetModeChar(), mh->name.c_str(), adding ? "add" : "remove")); + change.adding ? "set" : "unset", mh->GetModeChar(), mh->name.c_str(), change.adding ? "add" : "remove")); return MOD_RES_DENY; } return MOD_RES_PASSTHRU; diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 0e0efb6a7..9f6056363 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -61,7 +61,7 @@ class BanRedirect : public ModeWatcher { } - bool BeforeMode(User* source, User* dest, Channel* channel, std::string& param, bool adding) override + bool BeforeMode(User* source, User* dest, Channel* channel, Modes::Change& change) override { /* nick!ident@host -> nick!ident@host * nick!ident@host#chan -> nick!ident@host#chan @@ -70,30 +70,30 @@ class BanRedirect : public ModeWatcher * nick#chan -> nick!*@*#chan */ - if ((channel) && !param.empty()) + if ((channel) && !change.param.empty()) { BanRedirectList* redirects; std::string mask[4]; enum { NICK, IDENT, HOST, CHAN } current = NICK; - std::string::iterator start_pos = param.begin(); + std::string::iterator start_pos = change.param.begin(); - if (param.length() >= 2 && param[1] == ':') + if (change.param.length() >= 2 && change.param[1] == ':') return true; - if (param.find('#') == std::string::npos) + if (change.param.find('#') == std::string::npos) return true; ListModeBase* banlm = static_cast<ListModeBase*>(*ban); unsigned int maxbans = banlm->GetLimit(channel); ListModeBase::ModeList* list = banlm->GetList(channel); - if ((list) && (adding) && (maxbans <= list->size())) + if (list && change.adding && maxbans <= list->size()) { source->WriteNumeric(ERR_BANLISTFULL, channel->name, banlm->GetModeChar(), InspIRCd::Format("Channel ban list for %s is full (maximum entries for this channel is %u)", channel->name.c_str(), maxbans)); return false; } - for(std::string::iterator curr = start_pos; curr != param.end(); curr++) + for(std::string::iterator curr = start_pos; curr != change.param.end(); curr++) { switch(*curr) { @@ -123,7 +123,7 @@ class BanRedirect : public ModeWatcher if(mask[current].empty()) { - mask[current].assign(start_pos, param.end()); + mask[current].assign(start_pos, change.param.end()); } /* nick@host wants to be changed to *!nick@host rather than nick!*@host... */ @@ -149,11 +149,11 @@ class BanRedirect : public ModeWatcher } } - param.assign(mask[NICK]).append(1, '!').append(mask[IDENT]).append(1, '@').append(mask[HOST]); + change.param.assign(mask[NICK]).append(1, '!').append(mask[IDENT]).append(1, '@').append(mask[HOST]); if(mask[CHAN].length()) { - if (adding && IS_LOCAL(source)) + if (change.adding && IS_LOCAL(source)) { if (!ServerInstance->IsChannel(mask[CHAN])) { @@ -167,7 +167,7 @@ class BanRedirect : public ModeWatcher source->WriteNumeric(690, InspIRCd::Format("Target channel %s must exist to be set as a redirect.", mask[CHAN].c_str())); return false; } - else if (adding && c->GetPrefixValue(source) < OP_VALUE) + else if (change.adding && c->GetPrefixValue(source) < OP_VALUE) { source->WriteNumeric(690, InspIRCd::Format("You must be opped on %s to set it as a redirect.", mask[CHAN].c_str())); return false; @@ -180,7 +180,7 @@ class BanRedirect : public ModeWatcher } } - if(adding) + if (change.adding) { /* It's a properly valid redirecting ban, and we're adding it */ redirects = extItem.Get(channel); @@ -194,10 +194,10 @@ class BanRedirect : public ModeWatcher for (BanRedirectList::iterator redir = redirects->begin(); redir != redirects->end(); ++redir) { // Mimic the functionality used when removing the mode - if (irc::equals(redir->targetchan, mask[CHAN]) && irc::equals(redir->banmask, param)) + if (irc::equals(redir->targetchan, mask[CHAN]) && irc::equals(redir->banmask, change.param)) { // Make sure the +b handler will still set the right ban - param.append(mask[CHAN]); + change.param.append(mask[CHAN]); // Silently ignore the duplicate and don't set metadata // This still allows channel ops to set/unset a redirect ban to clear "ghost" redirects return true; @@ -206,10 +206,10 @@ class BanRedirect : public ModeWatcher } /* Here 'param' doesn't have the channel on it yet */ - redirects->push_back(BanRedirectEntry(mask[CHAN], param)); + redirects->push_back(BanRedirectEntry(mask[CHAN], change.param)); /* Now it does */ - param.append(mask[CHAN]); + change.param.append(mask[CHAN]); } else { @@ -221,7 +221,7 @@ class BanRedirect : public ModeWatcher for(BanRedirectList::iterator redir = redirects->begin(); redir != redirects->end(); redir++) { - if ((irc::equals(redir->targetchan, mask[CHAN])) && (irc::equals(redir->banmask, param))) + if ((irc::equals(redir->targetchan, mask[CHAN])) && (irc::equals(redir->banmask, change.param))) { redirects->erase(redir); @@ -236,7 +236,7 @@ class BanRedirect : public ModeWatcher } /* Append the channel so the default +b handler can remove the entry too */ - param.append(mask[CHAN]); + change.param.append(mask[CHAN]); } } } diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index d06814fb0..cf4c4ddb1 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -110,7 +110,7 @@ class CloakUser : public ModeHandler { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { LocalUser* user = IS_LOCAL(dest); @@ -121,8 +121,8 @@ class CloakUser : public ModeHandler if (!user) { // Remote setters broadcast mode before host while local setters do the opposite, so this takes that into account - active = IS_LOCAL(source) ? adding : !adding; - dest->SetMode(this, adding); + active = IS_LOCAL(source) ? change.adding : !change.adding; + dest->SetMode(this, change.adding); return MODEACTION_ALLOW; } @@ -139,14 +139,14 @@ class CloakUser : public ModeHandler debounce_ts = ServerInstance->Time(); } - if (adding == user->IsModeSet(this)) + if (change.adding == user->IsModeSet(this)) return MODEACTION_DENY; /* don't allow this user to spam modechanges */ if (source == dest) user->CommandFloodPenalty += 5000; - if (adding) + if (change.adding) { // assume this is more correct if (user->registered != REG_ALL && user->GetRealHost() != user->GetDisplayedHost()) diff --git a/src/modules/m_deaf.cpp b/src/modules/m_deaf.cpp index 5d3a0a4a4..c08c77b18 100644 --- a/src/modules/m_deaf.cpp +++ b/src/modules/m_deaf.cpp @@ -34,15 +34,15 @@ class DeafMode : public ModeHandler public: DeafMode(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { - if (adding == dest->IsModeSet(this)) + if (change.adding == dest->IsModeSet(this)) return MODEACTION_DENY; - if (adding) + if (change.adding) dest->WriteNotice("*** You have enabled user mode +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); + dest->SetMode(this, change.adding); return MODEACTION_ALLOW; } }; @@ -55,15 +55,15 @@ class PrivDeafMode : public ModeHandler { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { - if (adding == dest->IsModeSet(this)) + if (change.adding == dest->IsModeSet(this)) return MODEACTION_DENY; - if (adding) + if (change.adding) dest->WriteNotice("*** You have enabled user mode +D, private deaf mode. This mode means you WILL NOT receive any messages and notices from any nicks. If you did NOT mean to do this, use /mode " + dest->nick + " -D."); - dest->SetMode(this, adding); + dest->SetMode(this, change.adding); return MODEACTION_ALLOW; } }; diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index 84bc576be..dc1b47bb7 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -41,7 +41,7 @@ class DelayJoinMode : public ModeHandler ranktoset = ranktounset = OP_VALUE; } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override; + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override; void RevealUser(User* user, Channel* chan); }; @@ -107,16 +107,16 @@ class ModuleDelayJoin void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) override; void OnUserMessage(User* user, const MessageTarget& target, const MessageDetails& details) override; void OnUserTagMessage(User* user, const MessageTarget& target, const CTCTags::TagMessageDetails& details) override; - ModResult OnRawMode(User* user, Channel* channel, ModeHandler* mh, const std::string& param, bool adding) override; + ModResult OnRawMode(User* user, Channel* channel, const Modes::Change& change) override; }; -ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) +ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) { /* no change */ - if (channel->IsModeSet(this) == adding) + if (channel->IsModeSet(this) == change.adding) return MODEACTION_DENY; - if (!adding) + if (!change.adding) { /* * Make all users visible, as +D is being removed. If we don't do this, @@ -126,7 +126,7 @@ ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channe for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n) RevealUser(n->first, channel); } - channel->SetMode(this, adding); + channel->SetMode(this, change.adding); return MODEACTION_ALLOW; } @@ -225,20 +225,20 @@ void DelayJoinMode::RevealUser(User* user, Channel* chan) } /* make the user visible if they receive any mode change */ -ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, ModeHandler* mh, const std::string& param, bool adding) +ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, const Modes::Change& change) { - if (!channel || param.empty()) + if (!channel || change.param.empty()) return MOD_RES_PASSTHRU; // If not a prefix mode then we got nothing to do here - if (!mh->IsPrefixMode()) + if (!change.mh->IsPrefixMode()) return MOD_RES_PASSTHRU; User* dest; if (IS_LOCAL(user)) - dest = ServerInstance->Users.FindNick(param); + dest = ServerInstance->Users.FindNick(change.param); else - dest = ServerInstance->Users.Find(param); + dest = ServerInstance->Users.Find(change.param); if (!dest) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_disable.cpp b/src/modules/m_disable.cpp index 531b99925..72e0a9145 100644 --- a/src/modules/m_disable.cpp +++ b/src/modules/m_disable.cpp @@ -155,35 +155,35 @@ class ModuleDisable : public Module return MOD_RES_DENY; } - ModResult OnRawMode(User* user, Channel* chan, ModeHandler* mh, const std::string& param, bool adding) override + ModResult OnRawMode(User* user, Channel* chan, const Modes::Change& change) override { // If a mode change is remote or the source is not registered we do nothing. if (!IS_LOCAL(user) || user->registered != REG_ALL) return MOD_RES_PASSTHRU; // If the mode is not disabled or the user has the servers/use-disabled-modes priv we do nothing. - const std::bitset<64>& disabled = (mh->GetModeType() == MODETYPE_CHANNEL) ? chanmodes : usermodes; - if (!disabled.test(mh->GetModeChar() - 'A') || user->HasPrivPermission("servers/use-disabled-modes")) + const std::bitset<64>& disabled = (change.mh->GetModeType() == MODETYPE_CHANNEL) ? chanmodes : usermodes; + if (!disabled.test(change.mh->GetModeChar() - 'A') || user->HasPrivPermission("servers/use-disabled-modes")) return MOD_RES_PASSTHRU; // The user has tried to change a disabled mode! - const char* what = mh->GetModeType() == MODETYPE_CHANNEL ? "channel" : "user"; + const char* what = change.mh->GetModeType() == MODETYPE_CHANNEL ? "channel" : "user"; WriteLog("%s was blocked from %ssetting the disabled %s mode %c (%s)", - user->GetFullRealHost().c_str(), adding ? "" : "un", - what, mh->GetModeChar(), mh->name.c_str()); + user->GetFullRealHost().c_str(), change.adding ? "" : "un", + what, change.mh->GetModeChar(), change.mh->name.c_str()); if (fakenonexistent) { // The server administrator has specified that disabled modes should be // treated as if they do not exist. - user->WriteNumeric(mh->GetModeType() == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK, - mh->GetModeChar(), "is an unknown mode character"); + user->WriteNumeric(change.mh->GetModeType() == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK, + change.mh->GetModeChar(), "is an unknown mode character"); return MOD_RES_DENY; } // Inform the user that the mode they changed has been disabled. user->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - %s mode %c (%s) is disabled", - what, mh->GetModeChar(), mh->name.c_str())); + what, change.mh->GetModeChar(), change.mh->name.c_str())); return MOD_RES_DENY; } }; diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index c5744c525..37146e03c 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -61,22 +61,22 @@ class ExemptChanOps : public ListModeBase return true; } - ModResult AccessCheck(User* source, Channel* channel, std::string& parameter, bool adding) override + ModResult AccessCheck(User* source, Channel* channel, Modes::Change& change) override { std::string restriction; std::string prefix; - if (!ParseEntry(parameter, restriction, prefix)) + if (!ParseEntry(change.param, restriction, prefix)) return MOD_RES_PASSTHRU; PrefixMode* pm = FindMode(prefix); if (!pm) return MOD_RES_PASSTHRU; - if (channel->GetPrefixValue(source) >= pm->GetLevelRequired(adding)) + if (channel->GetPrefixValue(source) >= pm->GetLevelRequired(change.adding)) return MOD_RES_PASSTHRU; source->WriteNumeric(ERR_CHANOPRIVSNEEDED, channel->name, InspIRCd::Format("You must be able to %s mode %c (%s) to %s a restriction containing it", - adding ? "set" : "unset", pm->GetModeChar(), pm->name.c_str(), adding ? "add" : "remove")); + change.adding ? "set" : "unset", pm->GetModeChar(), pm->name.c_str(), change.adding ? "add" : "remove")); return MOD_RES_DENY; } diff --git a/src/modules/m_hidelist.cpp b/src/modules/m_hidelist.cpp index 556171abe..fe41b14d5 100644 --- a/src/modules/m_hidelist.cpp +++ b/src/modules/m_hidelist.cpp @@ -33,10 +33,10 @@ class ListWatcher : public ModeWatcher { } - bool BeforeMode(User* user, User* destuser, Channel* chan, std::string& param, bool adding) override + bool BeforeMode(User* user, User* destuser, Channel* chan, Modes::Change& change) override { // Only handle listmode list requests - if (!param.empty()) + if (!change.param.empty()) return true; // If the user requesting the list is a member of the channel see if they have the diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp index 72f25ef80..74749ec5d 100644 --- a/src/modules/m_hideoper.cpp +++ b/src/modules/m_hideoper.cpp @@ -44,12 +44,12 @@ class HideOper : public SimpleUserModeHandler oper = true; } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { - if (SimpleUserModeHandler::OnModeChange(source, dest, channel, parameter, adding) == MODEACTION_DENY) + if (SimpleUserModeHandler::OnModeChange(source, dest, channel, change) == MODEACTION_DENY) return MODEACTION_DENY; - if (adding) + if (change.adding) opercount++; else opercount--; diff --git a/src/modules/m_mlock.cpp b/src/modules/m_mlock.cpp index adc37b686..490ba79f1 100644 --- a/src/modules/m_mlock.cpp +++ b/src/modules/m_mlock.cpp @@ -39,7 +39,7 @@ class ModuleMLock : public Module { } - ModResult OnRawMode(User* source, Channel* channel, ModeHandler* mh, const std::string& parameter, bool adding) override + ModResult OnRawMode(User* source, Channel* channel, const Modes::Change& change) override { if (!channel) return MOD_RES_PASSTHRU; @@ -51,7 +51,7 @@ class ModuleMLock : public Module if (!mlock_str) return MOD_RES_PASSTHRU; - const char mode = mh->GetModeChar(); + const char mode = change.mh->GetModeChar(); std::string::size_type p = mlock_str->find(mode); if (p != std::string::npos) { diff --git a/src/modules/m_ojoin.cpp b/src/modules/m_ojoin.cpp index b31d0f12e..775ae708f 100644 --- a/src/modules/m_ojoin.cpp +++ b/src/modules/m_ojoin.cpp @@ -94,11 +94,11 @@ class NetworkPrefix : public PrefixMode ranktoset = ranktounset = UINT_MAX; } - ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding) override + ModResult AccessCheck(User* source, Channel* channel, Modes::Change& change) override { - User* theuser = ServerInstance->Users.Find(parameter); + User* theuser = ServerInstance->Users.Find(change.param); // remove own privs? - if (source == theuser && !adding) + if (source == theuser && !change.adding) return MOD_RES_ALLOW; return MOD_RES_PASSTHRU; diff --git a/src/modules/m_operprefix.cpp b/src/modules/m_operprefix.cpp index b5c6eb77d..9cc9cdc7c 100644 --- a/src/modules/m_operprefix.cpp +++ b/src/modules/m_operprefix.cpp @@ -49,7 +49,7 @@ class HideOperWatcher : public ModeWatcher public: HideOperWatcher(ModuleOperPrefixMode* parent); - void AfterMode(User* source, User* dest, Channel* channel, const std::string ¶meter, bool adding) override; + void AfterMode(User* source, User* dest, Channel* channel, const Modes::Change& change) override; }; class ModuleOperPrefixMode : public Module @@ -121,11 +121,11 @@ HideOperWatcher::HideOperWatcher(ModuleOperPrefixMode* parent) { } -void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding) +void HideOperWatcher::AfterMode(User* source, User* dest, Channel* channel, const Modes::Change& change) { // If hideoper is being unset because the user is deopering, don't set +y if (IS_LOCAL(dest) && dest->IsOper()) - parentmod->SetOperPrefix(dest, !adding); + parentmod->SetOperPrefix(dest, !change.adding); } MODULE_INIT(ModuleOperPrefixMode) diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 6d5180bb8..f91ed43c3 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -41,13 +41,13 @@ class PermChannel : public ModeHandler oper = true; } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { - if (adding == channel->IsModeSet(this)) + if (change.adding == channel->IsModeSet(this)) return MODEACTION_DENY; - channel->SetMode(this, adding); - if (!adding) + channel->SetMode(this, change.adding); + if (!change.adding) channel->CheckDestroy(); return MODEACTION_ALLOW; @@ -253,20 +253,22 @@ public: else par.clear(); - mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, par, true); + Modes::Change modechange(mode, true, par); + mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, modechange); } } // We always apply the permchannels mode to permanent channels. par.clear(); - p.OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, par, true); + Modes::Change modechange(&p, true, par); + p.OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, c, modechange); } } } - ModResult OnRawMode(User* user, Channel* chan, ModeHandler* mh, const std::string& param, bool adding) override + ModResult OnRawMode(User* user, Channel* chan, const Modes::Change& change) override { - if (chan && (chan->IsModeSet(p) || mh == &p)) + if (chan && (chan->IsModeSet(p) || change.mh == &p)) dirty = true; return MOD_RES_PASSTHRU; diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 64fcd5070..db15f8c26 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -57,15 +57,15 @@ class Channel_r : public ModeHandler public: Channel_r(Module* Creator) : ModeHandler(Creator, "c_registered", 'r', PARAM_NONE, MODETYPE_CHANNEL) { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { // Only a U-lined server may add or remove the +r mode. if (!IS_LOCAL(source)) { // Only change the mode if it's not redundant - if ((adding != channel->IsModeSet(this))) + if (change.adding != channel->IsModeSet(this)) { - channel->SetMode(this, adding); + channel->SetMode(this, change.adding); return MODEACTION_ALLOW; } } @@ -85,13 +85,13 @@ class User_r : public ModeHandler public: User_r(Module* Creator) : ModeHandler(Creator, "u_registered", 'r', PARAM_NONE, MODETYPE_USER) { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { if (!IS_LOCAL(source)) { - if ((adding != dest->IsModeSet(this))) + if (change.adding != dest->IsModeSet(this)) { - dest->SetMode(this, adding); + dest->SetMode(this, change.adding); return MODEACTION_ALLOW; } } diff --git a/src/modules/m_servprotect.cpp b/src/modules/m_servprotect.cpp index 3b0f7cba2..247a81da7 100644 --- a/src/modules/m_servprotect.cpp +++ b/src/modules/m_servprotect.cpp @@ -41,7 +41,7 @@ class ServProtectMode : public ModeHandler public: ServProtectMode(Module* Creator) : ModeHandler(Creator, "servprotect", 'k', PARAM_NONE, MODETYPE_USER) { oper = true; } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { /* Because this returns MODEACTION_DENY all the time, there is only ONE * way to add this mode and that is at client introduction in the UID command, @@ -80,20 +80,20 @@ class ModuleServProtectMode } } - ModResult OnRawMode(User* user, Channel* chan, ModeHandler* mh, const std::string& param, bool adding) override + ModResult OnRawMode(User* user, Channel* chan, const Modes::Change& change) override { /* Check that the mode is not a server mode, it is being removed, the user making the change is local, there is a parameter, * and the user making the change is not a service. */ - if (!adding && chan && IS_LOCAL(user) && !param.empty()) + if (!change.adding && chan && IS_LOCAL(user) && !change.param.empty()) { - const PrefixMode* const pm = mh->IsPrefixMode(); + const PrefixMode* const pm = change.mh->IsPrefixMode(); if (!pm) return MOD_RES_PASSTHRU; /* Check if the parameter is a valid nick/uuid */ - User *u = ServerInstance->Users.Find(param); + User *u = ServerInstance->Users.Find(change.param); if (u) { Membership* memb = chan->GetUser(u); diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 1a53b8bc4..f4bf2d913 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -38,7 +38,6 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, CommandBase::Params */ time_t age_t = ServerCommand::ExtractTS(params[1]); time_t signon = ServerCommand::ExtractTS(params[7]); - std::string empty; const std::string& modestr = params[8]; // Check if the length of the uuid is correct and confirm the sid portion of the uuid matches the sid of the server introducing the user @@ -102,7 +101,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, CommandBase::Params { if (paramptr >= params.size() - 1) throw ProtocolException("Out of parameters while processing modes"); - std::string mp = params[paramptr++]; + /* IMPORTANT NOTE: * All modes are assumed to succeed here as they are being set by a remote server. * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important @@ -112,10 +111,14 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, CommandBase::Params * will not change in future versions if you want to make use of this protective behaviour * yourself. */ - mh->OnModeChange(_new, _new, NULL, mp, true); + Modes::Change modechange(mh, true, params[paramptr++]); + mh->OnModeChange(_new, _new, NULL, modechange); } else - mh->OnModeChange(_new, _new, NULL, empty, true); + { + Modes::Change modechange(mh, true, ""); + mh->OnModeChange(_new, _new, NULL, modechange); + } _new->SetMode(mh, true); } diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp index 28dc65b9d..9bf7c75cf 100644 --- a/src/modules/m_sslmodes.cpp +++ b/src/modules/m_sslmodes.cpp @@ -72,9 +72,9 @@ class SSLMode : public ModeHandler { } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* source, User* dest, Channel* channel, Modes::Change& change) override { - if (adding) + if (change.adding) { if (!channel->IsModeSet(this)) { @@ -137,9 +137,9 @@ class SSLModeUser : public ModeHandler { } - ModeAction OnModeChange(User* user, User* dest, Channel* channel, std::string& parameter, bool adding) override + ModeAction OnModeChange(User* user, User* dest, Channel* channel, Modes::Change& change) override { - if (adding) + if (change.adding) { if (!dest->IsModeSet(this)) { diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index d7f97c97c..1bf08e01c 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -163,9 +163,9 @@ class BanWatcher : public ModeWatcher { } - void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding) override + void AfterMode(User* source, User* dest, Channel* chan, const Modes::Change& change) override { - if (adding) + if (change.adding) return; for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); ++i) @@ -174,7 +174,7 @@ class BanWatcher : public ModeWatcher continue; const std::string& target = i->mask; - if (irc::equals(banmask, target)) + if (irc::equals(change.param, target)) { TimedBanList.erase(i); break; |
