os_mode.cpp

Go to the documentation of this file.
00001 /* OperServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  */
00011 
00012 /*************************************************************************/
00013 
00014 #include "module.h"
00015 
00016 class CommandOSMode : public Command
00017 {
00018  public:
00019         CommandOSMode(Module *creator) : Command(creator, "operserv/mode", 2, 3)
00020         {
00021                 this->SetDesc(_("Change channel modes"));
00022                 this->SetSyntax(_("\037channel\037 \037modes\037"));
00023                 this->SetSyntax(_("\037channel\037 CLEAR [ALL]"));
00024         }
00025 
00026         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00027         {
00028                 const Anope::string &target = params[0];
00029                 const Anope::string &modes = params[1];
00030 
00031                 Channel *c = Channel::Find(target);
00032                 if (!c)
00033                         source.Reply(CHAN_X_NOT_IN_USE, target.c_str());
00034                 else if (c->bouncy_modes)
00035                         source.Reply(_("Services is unable to change modes. Are your servers' U:lines configured correctly?"));
00036                 else if (modes.equals_ci("CLEAR"))
00037                 {
00038                         bool all = params.size() > 2 && params[2].equals_ci("ALL");
00039 
00040                         const Channel::ModeList chmodes = c->GetModes();
00041                         for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end; ++it)
00042                                 c->RemoveMode(c->ci->WhoSends(), it->first, it->second, false);
00043 
00044                         if (all)
00045                         {
00046                                 for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
00047                                 {
00048                                         ChanUserContainer *uc = *it;
00049 
00050                                         if (uc->user->HasMode("OPER"))
00051                                                 continue;
00052 
00053                                         for (std::set<Anope::string>::iterator it2 = uc->status.modes.begin(), it2_end = uc->status.modes.end(); it2 != it2_end; ++it2)
00054                                                 c->RemoveMode(c->ci->WhoSends(), *it2, uc->user->GetUID(), false);
00055                                 }
00056 
00057                                 source.Reply(_("All modes cleared on %s."), c->name.c_str());
00058                         }
00059                         else
00060                                 source.Reply(_("Non-status modes cleared on %s."), c->name.c_str());
00061                 }
00062                 else
00063                 {
00064                         spacesepstream sep(modes + (params.size() > 2 ? " " + params[2] : ""));
00065                         Anope::string mode;
00066                         int add = 1;
00067                         Anope::string log_modes, log_params;
00068 
00069                         sep.GetToken(mode);
00070                         for (unsigned i = 0; i < mode.length(); ++i)
00071                         {
00072                                 char ch = mode[i];
00073 
00074                                 if (ch == '+')
00075                                 {
00076                                         add = 1;
00077                                         log_modes += "+";
00078                                         continue;
00079                                 }
00080                                 else if (ch == '-')
00081                                 {
00082                                         add = 0;
00083                                         log_modes += "-";
00084                                         continue;
00085                                 }
00086 
00087                                 ChannelMode *cm = ModeManager::FindChannelModeByChar(ch);
00088                                 if (!cm)
00089                                         continue;
00090 
00091                                 Anope::string param, param_log;
00092                                 if (cm->type != MODE_REGULAR)
00093                                 {
00094                                         if (!sep.GetToken(param))
00095                                                 continue;
00096 
00097                                         param_log = param;
00098 
00099                                         if (cm->type == MODE_STATUS)
00100                                         {
00101                                                 User *targ = User::Find(param, true);
00102                                                 if (targ == NULL || c->FindUser(targ) == NULL)
00103                                                         continue;
00104                                                 param = targ->GetUID();
00105                                         }
00106                                 }
00107 
00108                                 log_modes += cm->mchar;
00109                                 if (!param.empty())
00110                                         log_params += " " + param_log;
00111 
00112                                 if (add)
00113                                         c->SetMode(source.service, cm, param, false);
00114                                 else
00115                                         c->RemoveMode(source.service, cm, param, false);
00116                         }
00117 
00118                         if (!log_modes.replace_all_cs("+", "").replace_all_cs("-", "").empty())
00119                                 Log(LOG_ADMIN, source, this) << log_modes << log_params << " on " << c->name;
00120                 }
00121         }
00122 
00123         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00124         {
00125                 this->SendSyntax(source);
00126                 source.Reply(" ");
00127                 source.Reply(_("Allows Services Operators to change modes for any channel.\n"
00128                                 "Parameters are the same as for the standard /MODE command.\n"
00129                                 "Alternatively, CLEAR may be given to clear all modes on the channel.\n"
00130                                 "If CLEAR ALL is given then all modes, including user status, is removed.\n"));
00131                 return true;
00132         }
00133 };
00134 
00135 class CommandOSUMode : public Command
00136 {
00137  public:
00138         CommandOSUMode(Module *creator) : Command(creator, "operserv/umode", 2, 2)
00139         {
00140                 this->SetDesc(_("Change user modes"));
00141                 this->SetSyntax(_("\037user\037 \037modes\037"));
00142         }
00143 
00144         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00145         {
00146                 const Anope::string &target = params[0];
00147                 const Anope::string &modes = params[1];
00148 
00149                 User *u2 = User::Find(target, true);
00150                 if (!u2)
00151                         source.Reply(NICK_X_NOT_IN_USE, target.c_str());
00152                 else
00153                 {
00154                         u2->SetModes(source.service, "%s", modes.c_str());
00155                         source.Reply(_("Changed usermodes of \002%s\002 to %s."), u2->nick.c_str(), modes.c_str());
00156 
00157                         u2->SendMessage(source.service, _("\002%s\002 changed your usermodes to %s."), source.GetNick().c_str(), modes.c_str());
00158 
00159                         Log(LOG_ADMIN, source, this) << modes << " on " << target;
00160                 }
00161         }
00162 
00163         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00164         {
00165                 this->SendSyntax(source);
00166                 source.Reply(" ");
00167                 source.Reply(_("Allows Services Operators to change modes for any user.\n"
00168                                 "Parameters are the same as for the standard /MODE command."));
00169                 return true;
00170         }
00171 };
00172 
00173 class OSMode : public Module
00174 {
00175         CommandOSMode commandosmode;
00176         CommandOSUMode commandosumode;
00177 
00178  public:
00179         OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00180                 commandosmode(this), commandosumode(this)
00181         {
00182                 this->SetAuthor("Anope");
00183 
00184         }
00185 };
00186 
00187 MODULE_INIT(OSMode)