-void ModeParser::Process(const std::vector<std::string>& parameters, User* user, ModeProcessFlag flags)
-{
- const std::string& target = parameters[0];
- Channel* targetchannel = ServerInstance->FindChan(target);
- User* targetuser = NULL;
- if (!targetchannel)
- {
- if (IS_LOCAL(user))
- targetuser = ServerInstance->FindNickOnly(target);
- else
- targetuser = ServerInstance->FindNick(target);
- }
- ModeType type = targetchannel ? MODETYPE_CHANNEL : MODETYPE_USER;
-
- LastParse.clear();
- LastChangeList.clear();
-
- if ((!targetchannel) && ((!targetuser) || (IS_SERVER(targetuser))))
- {
- user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", target.c_str());
- return;
- }
- if (parameters.size() == 1)
- {
- this->DisplayCurrentModes(user, targetuser, targetchannel, target.c_str());
- return;
- }
-
- // Populate a temporary Modes::ChangeList with the parameters
- Modes::ChangeList changelist;
- ModeParamsToChangeList(user, type, parameters, changelist);
-
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(OnPreMode, MOD_RESULT, (user, targetuser, targetchannel, parameters));
-
- if (IS_LOCAL(user))
- {
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((targetuser) && (user != targetuser))
- {
- // Local users may only change the modes of other users if a module explicitly allows it
- user->WriteNumeric(ERR_USERSDONTMATCH, ":Can't change mode for other users");
- return;
- }
-
- // This is a mode change by a local user and modules didn't explicitly allow/deny.
- // Ensure access checks will happen for each mode being changed.
- flags |= MODE_CHECKACCESS;
- }
- else if (MOD_RESULT == MOD_RES_DENY)
- return; // Entire mode change denied by a module
- }
-
- ProcessSingle(user, targetchannel, targetuser, changelist, flags);
-
- if ((LastParse.empty()) && (targetchannel) && (parameters.size() == 2))
- {
- /* Special case for displaying the list for listmodes,
- * e.g. MODE #chan b, or MODE #chan +b without a parameter
- */
- this->DisplayListModes(user, targetchannel, parameters[1]);
- }
-}
-