cs_clearusers.cpp

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2012 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 CommandCSClearUsers : public Command
00017 {
00018  public:
00019         CommandCSClearUsers(Module *creator) : Command(creator, "chanserv/clearusers", 1, 1)
00020         {
00021                 this->SetDesc(_("Kicks all users on a channel"));
00022                 this->SetSyntax(_("\037channel\037"));
00023         }
00024 
00025         void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
00026         {
00027                 const Anope::string &chan = params[0];
00028 
00029                 Channel *c = Channel::Find(chan);
00030                 Anope::string modebuf;
00031 
00032                 if (!c)
00033                 {
00034                         source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
00035                         return;
00036                 }
00037                 else if (!c->ci)
00038                 {
00039                         source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str());
00040                         return;
00041                 }
00042                 else if (!source.AccessFor(c->ci).HasPriv("FOUNDER") && !source.HasCommand("chanserv/clearusers"))
00043                 {
00044                         source.Reply(ACCESS_DENIED);
00045                         return;
00046                 }
00047                 
00048                 Anope::string buf = "CLEARUSERS command from " + source.GetNick() + " (" + source.nc->display + ")";
00049 
00050                 std::vector<User *> users;
00051                 for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
00052                 {
00053                         User *user = (*it)->user;
00054                         if (!user->HasMode(UMODE_OPER) && user->server != Me)
00055                                 users.push_back(user);
00056                 }
00057 
00058                 for (unsigned i = 0; i < users.size(); ++i)
00059                         c->Kick(NULL, users[i], "%s", buf.c_str());
00060 
00061                 bool override = !source.AccessFor(c->ci).HasPriv("FOUNDER");
00062                 Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, c->ci);
00063 
00064                 source.Reply(_("All users have been kicked from \002%s\002."), chan.c_str());
00065 
00066                 return;
00067         }
00068 
00069         bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00070         {
00071                 this->SendSyntax(source);
00072                 source.Reply(" ");
00073                 source.Reply(_("Tells %s to clear (kick) all users on a channel."
00074                                 " \n"
00075                                 "By default, limited to those with founder access on the\n"
00076                                 "channel."), source.service->nick.c_str());
00077                 return true;
00078         }
00079 };
00080 
00081 class CSClearUsers : public Module
00082 {
00083         CommandCSClearUsers commandcsclearusers;
00084 
00085  public:
00086         CSClearUsers(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00087                 commandcsclearusers(this)
00088         {
00089                 this->SetAuthor("Anope");
00090 
00091         }
00092 };
00093 
00094 MODULE_INIT(CSClearUsers)