00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 class CommandModeBase : public Command
00017 {
00018 void do_mode(CommandSource &source, Command *com, ChannelMode *cm, const Anope::string &chan, const Anope::string &nick, bool set, const Anope::string &level, const Anope::string &levelself)
00019 {
00020 User *u = source.GetUser();
00021 User *u2 = User::Find(nick, true);
00022 Channel *c = Channel::Find(chan);
00023
00024 if (!c)
00025 {
00026 source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
00027 return;
00028
00029 }
00030
00031 if (!u2)
00032 {
00033 source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
00034 return;
00035 }
00036
00037 ChannelInfo *ci = c->ci;
00038 if (!ci)
00039 {
00040 source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str());
00041 return;
00042 }
00043
00044 bool is_same = u == u2;
00045 AccessGroup u_access = source.AccessFor(ci), u2_access = ci->AccessFor(u2);
00046
00047 if (is_same ? !source.AccessFor(ci).HasPriv(levelself) : !source.AccessFor(ci).HasPriv(level))
00048 source.Reply(ACCESS_DENIED);
00049 else if (!set && !is_same && ci->HasFlag(CI_PEACE) && u2_access >= u_access)
00050 source.Reply(ACCESS_DENIED);
00051 else if (!set && u2->IsProtected() && !is_same)
00052 source.Reply(ACCESS_DENIED);
00053 else if (!c->FindUser(u2))
00054 source.Reply(NICK_X_NOT_ON_CHAN, u2->nick.c_str(), c->name.c_str());
00055 else
00056 {
00057 if (set)
00058 c->SetMode(NULL, cm, u2->GetUID());
00059 else
00060 c->RemoveMode(NULL, cm, u2->GetUID());
00061
00062 Log(LOG_COMMAND, source, com, ci) << "for " << u2->nick;
00063 }
00064 }
00065
00066 protected:
00077 void do_util(CommandSource &source, Command *com, ChannelMode *cm, const Anope::string &chan, const Anope::string &nick, bool set, const Anope::string &level, const Anope::string &levelself)
00078 {
00079 User *u = source.GetUser();
00080
00081 if (chan.empty() && u)
00082 for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end(); ++it)
00083 do_mode(source, com, cm, (*it)->chan->name, u->nick, set, level, levelself);
00084 else if (!chan.empty())
00085 do_mode(source, com, cm, chan, !nick.empty() ? nick : u->nick, set, level, levelself);
00086 }
00087
00088 public:
00089 CommandModeBase(Module *creator, const Anope::string &cname) : Command(creator, cname, 0, 2)
00090 {
00091 this->SetSyntax(_("[\037channel\037] [\037nick\037]"));
00092 }
00093 };
00094
00095 class CommandCSOp : public CommandModeBase
00096 {
00097 public:
00098 CommandCSOp(Module *creator) : CommandModeBase(creator, "chanserv/op")
00099 {
00100 this->SetDesc(_("Gives Op status to a selected nick on a channel"));
00101 }
00102
00103 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00104 {
00105 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP);
00106
00107 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, "OPDEOP", "OPDEOPME");
00108 }
00109
00110 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00111 {
00112 this->SendSyntax(source);
00113 source.Reply(" ");
00114 source.Reply(_("Ops a selected nick on a channel. If nick is not given,\n"
00115 "it will op you. If channel is not given, it will op you\n"
00116 "on every channel.\n"
00117 " \n"
00118 "By default, limited to AOPs or those with level 5 access\n"
00119 "and above on the channel."));
00120 return true;
00121 }
00122 };
00123
00124 class CommandCSDeOp : public CommandModeBase
00125 {
00126 public:
00127 CommandCSDeOp(Module *creator) : CommandModeBase(creator, "chanserv/deop")
00128 {
00129 this->SetDesc(_("Deops a selected nick on a channel"));
00130 }
00131
00132 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00133 {
00134 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP);
00135
00136 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, "OPDEOP", "OPDEOPME");
00137 }
00138
00139 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00140 {
00141 this->SendSyntax(source);
00142 source.Reply(" ");
00143 source.Reply("Deops a selected nick on a channel. If nick is not given,\n"
00144 "it will deop you. If channel is not given, it will deop\n"
00145 "you on every channel.\n"
00146 " \n"
00147 "By default, limited to AOPs or those with level 5 access\n"
00148 "and above on the channel.");
00149 return true;
00150 }
00151 };
00152
00153 class CommandCSVoice : public CommandModeBase
00154 {
00155 public:
00156 CommandCSVoice(Module *creator) : CommandModeBase(creator, "chanserv/voice")
00157 {
00158 this->SetDesc(_("Voices a selected nick on a channel"));
00159 }
00160
00161 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00162 {
00163 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE);
00164
00165 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, "VOICE", "VOICEME");
00166 }
00167
00168 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00169 {
00170 this->SendSyntax(source);
00171 source.Reply(" ");
00172 source.Reply(_("Voices a selected nick on a channel. If nick is not given,\n"
00173 "it will voice you. If channel is not given, it will voice you\n"
00174 "on every channel.\n"
00175 " \n"
00176 "By default, limited to AOPs or those with level 5 access\n"
00177 "and above on the channel, or to VOPs or those with level 3\n"
00178 "and above for self voicing."));
00179 return true;
00180 }
00181 };
00182
00183 class CommandCSDeVoice : public CommandModeBase
00184 {
00185 public:
00186 CommandCSDeVoice(Module *creator) : CommandModeBase(creator, "chanserv/devoice")
00187 {
00188 this->SetDesc(_("Devoices a selected nick on a channel"));
00189 }
00190
00191 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00192 {
00193 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE);
00194
00195 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, "VOICE", "VOICEME");
00196 }
00197
00198 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00199 {
00200 this->SendSyntax(source);
00201 source.Reply(" ");
00202 source.Reply(_("Devoices a selected nick on a channel. If nick is not given,\n"
00203 "it will devoice you. If channel is not given, it will devoice\n"
00204 "you on every channel.\n"
00205 " \n"
00206 "By default, limited to AOPs or those with level 5 access\n"
00207 "and above on the channel, or to VOPs or those with level 3\n"
00208 "and above for self devoicing."));
00209 return true;
00210 }
00211 };
00212
00213 class CommandCSHalfOp : public CommandModeBase
00214 {
00215 public:
00216 CommandCSHalfOp(Module *creator) : CommandModeBase(creator, "chanserv/halfop")
00217 {
00218 this->SetDesc(_("Halfops a selected nick on a channel"));
00219 }
00220
00221 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00222 {
00223 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP);
00224
00225 if (!cm)
00226 return;
00227
00228 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, "HALFOP", "HALFOPME");
00229 }
00230
00231 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00232 {
00233 this->SendSyntax(source);
00234 source.Reply(" ");
00235 source.Reply(_("Halfops a selected nick on a channel. If nick is not given,\n"
00236 "it will halfop you. If channel is not given, it will halfop\n"
00237 "you on every channel.\n"
00238 " \n"
00239 "By default, limited to AOPs and those with level 5 access\n"
00240 "and above on the channel, or to HOPs or those with level 4\n"
00241 "and above for self halfopping."));
00242 return true;
00243 }
00244 };
00245
00246 class CommandCSDeHalfOp : public CommandModeBase
00247 {
00248 public:
00249 CommandCSDeHalfOp(Module *creator) : CommandModeBase(creator, "chanserv/dehalfop")
00250 {
00251 this->SetDesc(_("Dehalfops a selected nick on a channel"));
00252 }
00253
00254 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00255 {
00256 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP);
00257
00258 if (!cm)
00259 return;
00260
00261 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, "HALFOP", "HALFOPME");
00262 }
00263
00264 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00265 {
00266 this->SendSyntax(source);
00267 source.Reply(" ");
00268 source.Reply(_("Dehalfops a selected nick on a channel. If nick is not given,\n"
00269 "it will dehalfop you. If channel is not given, it will dehalfop\n"
00270 "you on every channel.\n"
00271 " \n"
00272 "By default, limited to AOPs and those with level 5 access\n"
00273 "and above on the channel, or to HOPs or those with level 4\n"
00274 "and above for self dehalfopping."));
00275 return true;
00276 }
00277 };
00278
00279 class CommandCSProtect : public CommandModeBase
00280 {
00281 public:
00282 CommandCSProtect(Module *creator) : CommandModeBase(creator, "chanserv/protect")
00283 {
00284 this->SetDesc(_("Protects a selected nick on a channel"));
00285 }
00286
00287 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00288 {
00289 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT);
00290
00291 if (!cm)
00292 return;
00293
00294 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, "PROTECT", "PROTECTME");
00295 }
00296
00297 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00298 {
00299 this->SendSyntax(source);
00300 source.Reply(" ");
00301 source.Reply(_("Protects a selected nick on a channel. If nick is not given,\n"
00302 "it will protect you. If channel is not given, it will protect\n"
00303 "you on every channel.\n"
00304 " \n"
00305 "By default, limited to the founder, or to SOPs or those with\n"
00306 "level 10 and above on the channel for self protecting."));
00307 return true;
00308 }
00309 };
00310
00311 class CommandCSDeProtect : public CommandModeBase
00312 {
00313 public:
00314 CommandCSDeProtect(Module *creator) : CommandModeBase(creator, "chanserv/deprotect")
00315 {
00316 this->SetDesc(_("Deprotects a selected nick on a channel"));
00317 }
00318
00319 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00320 {
00321 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT);
00322
00323 if (!cm)
00324 return;
00325
00326 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, "PROTECT", "PROTECTME");
00327 }
00328
00329 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00330 {
00331 this->SendSyntax(source);
00332 source.Reply(" ");
00333 source.Reply(_("Deprotects a selected nick on a channel. If nick is not given,\n"
00334 "it will deprotect you. If channel is not given, it will deprotect\n"
00335 "you on every channel.\n"
00336 " \n"
00337 "By default, limited to the founder, or to SOPs or those with\n"
00338 "level 10 and above on the channel for self deprotecting."));
00339 return true;
00340 }
00341 };
00342
00343 class CommandCSOwner : public CommandModeBase
00344 {
00345 public:
00346 CommandCSOwner(Module *creator) : CommandModeBase(module, "chanserv/owner")
00347 {
00348 this->SetDesc(_("Gives you owner status on channel"));
00349 }
00350
00351 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00352 {
00353 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER);
00354
00355 if (!cm)
00356 return;
00357
00358 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", true, "OWNER", "OWNERME");
00359 }
00360
00361 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00362 {
00363 this->SendSyntax(source);
00364 source.Reply(" ");
00365 source.Reply(_("Gives the selected nick owner status on \002channel\002. If nick is not\n"
00366 "given, it will give you owner. If channel is not given, it will\n"
00367 "give you owner on every channel.\n"
00368 " \n"
00369 "Limited to those with founder access on the channel."));
00370 return true;
00371 }
00372 };
00373
00374 class CommandCSDeOwner : public CommandModeBase
00375 {
00376 public:
00377 CommandCSDeOwner(Module *creator) : CommandModeBase(creator, "chanserv/deowner")
00378 {
00379 this->SetDesc(_("Removes your owner status on a channel"));
00380 }
00381
00382 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00383 {
00384 ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER);
00385
00386 if (!cm)
00387 return;
00388
00389 return do_util(source, this, cm, !params.empty() ? params[0] : "", params.size() > 1 ? params[1] : "", false, "OWNER", "OWNERME");
00390 }
00391
00392 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00393 {
00394 this->SendSyntax(source);
00395 source.Reply(" ");
00396 source.Reply(_("Removes owner status from the selected nick on \002channel\002. If nick\n"
00397 "is not given, it will deowner you. If channel is not given, it will\n"
00398 "deowner you on every channel.\n"
00399 " \n"
00400 "Limited to those with founder access on the channel."));
00401 return true;
00402 }
00403 };
00404
00405 class CSModes : public Module
00406 {
00407 CommandCSOwner commandcsowner;
00408 CommandCSDeOwner commandcsdeowner;
00409 CommandCSProtect commandcsprotect;
00410 CommandCSDeProtect commandcsdeprotect;
00411 CommandCSOp commandcsop;
00412 CommandCSDeOp commandcsdeop;
00413 CommandCSHalfOp commandcshalfop;
00414 CommandCSDeHalfOp commandcsdehalfop;
00415 CommandCSVoice commandcsvoice;
00416 CommandCSDeVoice commandcsdevoice;
00417
00418 public:
00419 CSModes(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00420 commandcsowner(this), commandcsdeowner(this), commandcsprotect(this), commandcsdeprotect(this),
00421 commandcsop(this), commandcsdeop(this), commandcshalfop(this), commandcsdehalfop(this),
00422 commandcsvoice(this), commandcsdevoice(this)
00423 {
00424 this->SetAuthor("Anope");
00425
00426
00427 }
00428 };
00429
00430 MODULE_INIT(CSModes)