]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_user/cmd_mode.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_mode.cpp
index 99b9ab20d56f05dc0fcdd3e93ac5cee0c0b96d9e..b1790bb89eb77d133b5cce795bf1c233fbcdfa5d 100644 (file)
@@ -43,9 +43,9 @@ CmdResult CommandMode::Handle(const std::vector<std::string>& parameters, User*
                        targetuser = ServerInstance->FindNick(target);
        }
 
-       if ((!targetchannel) && ((!targetuser) || (IS_SERVER(targetuser))))
+       if ((!targetchannel) && (!targetuser))
        {
-               user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", target.c_str());
+               user->WriteNumeric(Numerics::NoSuchNick(target));
                return CMD_FAILURE;
        }
        if (parameters.size() == 1)
@@ -70,7 +70,7 @@ CmdResult CommandMode::Handle(const std::vector<std::string>& parameters, User*
                        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");
+                               user->WriteNumeric(ERR_USERSDONTMATCH, "Can't change mode for other users");
                                return CMD_FAILURE;
                        }
 
@@ -84,7 +84,10 @@ CmdResult CommandMode::Handle(const std::vector<std::string>& parameters, User*
        else
                flags |= ModeParser::MODE_LOCALONLY;
 
-       ServerInstance->Modes->ProcessSingle(user, targetchannel, targetuser, changelist, flags);
+       if (IS_LOCAL(user))
+               ServerInstance->Modes->ProcessSingle(user, targetchannel, targetuser, changelist, flags);
+       else
+               ServerInstance->Modes->Process(user, targetchannel, targetuser, changelist, flags);
 
        if ((ServerInstance->Modes.GetLastParse().empty()) && (targetchannel) && (parameters.size() == 2))
        {
@@ -132,24 +135,29 @@ void CommandMode::DisplayCurrentModes(User* user, User* targetuser, Channel* tar
        if (targetchannel)
        {
                // Display channel's current mode string
-               user->WriteNumeric(RPL_CHANNELMODEIS, "%s +%s", targetchannel->name.c_str(), targetchannel->ChanModes(targetchannel->HasUser(user)));
-               user->WriteNumeric(RPL_CHANNELCREATED, "%s %lu", targetchannel->name.c_str(), (unsigned long)targetchannel->age);
+               user->WriteNumeric(RPL_CHANNELMODEIS, targetchannel->name, (std::string("+") + targetchannel->ChanModes(targetchannel->HasUser(user))));
+               user->WriteNumeric(RPL_CHANNELCREATED, targetchannel->name, (unsigned long)targetchannel->age);
        }
        else
        {
                if (targetuser == user || user->HasPrivPermission("users/auspex"))
                {
                        // Display user's current mode string
-                       user->WriteNumeric(RPL_UMODEIS, ":+%s", targetuser->FormatModes());
+                       // XXX: Use WriteServ() because WriteNumeric() assumes the target (i.e. next word after the number)
+                       // is 'user' and puts his nick there which is not what we want
+                       user->WriteServ("%03d %s :+%s", RPL_UMODEIS, targetuser->nick.c_str(), targetuser->FormatModes());
                        if (targetuser->IsOper())
                        {
                                ModeHandler* snomask = ServerInstance->Modes->FindMode('s', MODETYPE_USER);
-                               user->WriteNumeric(RPL_SNOMASKIS, "%s :Server notice mask", snomask->GetUserParameter(user).c_str());
+                               std::string snomaskstr = snomask->GetUserParameter(user);
+                               // snomaskstr is empty if the snomask mode isn't set, otherwise it begins with a '+'.
+                               // In the former case output a "+", not an empty string.
+                               user->WriteServ("%03d %s %s%s :Server notice mask", RPL_SNOMASKIS, targetuser->nick.c_str(), (snomaskstr.empty() ? "+" : ""), snomaskstr.c_str());
                        }
                }
                else
                {
-                       user->WriteNumeric(ERR_USERSDONTMATCH, ":Can't view modes for other users");
+                       user->WriteNumeric(ERR_USERSDONTMATCH, "Can't view modes for other users");
                }
        }
 }