+
+ /* Yerk, invalid! */
+ if ((parameter.find(':') == 0) || (parameter.rfind(' ') != std::string::npos))
+ parameter.clear();
+ }
+ else
+ {
+ /* No parameter, continue to the next mode */
+ continue;
+ }
+
+ FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, parameter, adding, 1, servermode));
+ }
+ else
+ {
+ FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, "", adding, 0, servermode));
+ }
+
+ if (IS_LOCAL(user) && (MOD_RESULT == ACR_DENY))
+ continue;
+
+ if (!SkipAccessChecks && IS_LOCAL(user) && (MOD_RESULT != ACR_ALLOW))
+ {
+ /* Check access to this mode character */
+ if ((type == MODETYPE_CHANNEL) && (modehandlers[handler_id]->GetNeededPrefix()))
+ {
+ char needed = modehandlers[handler_id]->GetNeededPrefix();
+ ModeHandler* prefixmode = FindPrefix(needed);
+
+ /* If the mode defined by the handler is not '\0', but the handler for it
+ * cannot be found, they probably dont have the right module loaded to implement
+ * the prefix they want to compare the mode against, e.g. '&' for m_chanprotect.
+ * Revert to checking against the minimum core prefix, '%'.
+ */
+ if (needed && !prefixmode)
+ prefixmode = FindPrefix('%');
+
+ unsigned int neededrank = prefixmode->GetPrefixRank();
+ /* Compare our rank on the channel against the rank of the required prefix,
+ * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown
+ * in NAMES(X) are not in rank order, we know the most powerful mode is listed
+ * first, so we don't need to iterate, we just look up the first instead.
+ */
+ std::string modestring = targetchannel->GetAllPrefixChars(user);
+ char ml = (modestring.empty() ? '\0' : modestring[0]);
+ ModeHandler* ourmode = FindPrefix(ml);
+ if (!ourmode || ourmode->GetPrefixRank() < neededrank)
+ {
+ /* Bog off */
+ user->WriteNumeric(482, "%s %s :You must have channel privilege %c or above to %sset channel mode %c",
+ user->nick, targetchannel->name, needed, adding ? "" : "un", modechar);
+ continue;
+ }
+ }
+ }
+
+ bool had_parameter = !parameter.empty();
+
+ for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
+ {
+ if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type, servermode) == false)
+ {
+ abort = true;
+ break;
+ }
+ /* A module whacked the parameter completely, and there was one. abort. */
+ if ((had_parameter) && (parameter.empty()))
+ {
+ abort = true;
+ break;
+ }
+ }
+
+ if (abort)
+ continue;
+
+ /* It's an oper only mode, check if theyre an oper. If they arent,
+ * eat any parameter that came with the mode, and continue to next
+ */
+ if (adding && (IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!user->HasModePermission(modehandlers[handler_id]->GetModeChar(), type)))
+ {
+ if (IS_OPER(user))
+ {
+ user->WriteNumeric(481, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c",
+ user->nick,
+ user->oper,
+ type == MODETYPE_CHANNEL ? "channel" : "user",
+ modehandlers[handler_id]->GetModeChar());