anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
cs_unban.cpp (3377B)
1 /* ChanServ core functions 2 * 3 * (C) 2003-2022 Anope Team 4 * Contact us at team@anope.org 5 * 6 * Please read COPYING and README for further details. 7 * 8 * Based on the original code of Epona by Lara. 9 * Based on the original code of Services by Andy Church. 10 */ 11 12 #include "module.h" 13 14 class CommandCSUnban : public Command 15 { 16 public: 17 CommandCSUnban(Module *creator) : Command(creator, "chanserv/unban", 0, 2) 18 { 19 this->SetDesc(_("Remove all bans preventing a user from entering a channel")); 20 this->SetSyntax(_("\037channel\037 [\037nick\037]")); 21 } 22 23 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override 24 { 25 ChannelMode *cm = ModeManager::FindChannelModeByName("BAN"); 26 if (!cm) 27 return; 28 29 std::vector<ChannelMode *> modes = cm->listeners; 30 modes.push_back(cm); 31 32 if (params.empty()) 33 { 34 if (!source.GetUser()) 35 return; 36 37 std::deque<ChannelInfo *> queue; 38 source.GetAccount()->GetChannelReferences(queue); 39 40 unsigned count = 0; 41 for (unsigned i = 0; i < queue.size(); ++i) 42 { 43 ChannelInfo *ci = queue[i]; 44 45 if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) 46 continue; 47 48 FOREACH_MOD(OnChannelUnban, (source.GetUser(), ci)); 49 50 for (unsigned j = 0; j < modes.size(); ++j) 51 if (ci->c->Unban(source.GetUser(), modes[j]->name, true)) 52 ++count; 53 } 54 55 Log(LOG_COMMAND, source, this, NULL) << "on all channels"; 56 source.Reply(_("You have been unbanned from %d channels."), count); 57 58 return; 59 } 60 61 ChannelInfo *ci = ChannelInfo::Find(params[0]); 62 if (ci == NULL) 63 { 64 source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); 65 return; 66 } 67 68 if (ci->c == NULL) 69 { 70 source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); 71 return; 72 } 73 74 if (!source.AccessFor(ci).HasPriv("UNBAN") && !source.HasPriv("chanserv/kick")) 75 { 76 source.Reply(ACCESS_DENIED); 77 return; 78 } 79 80 User *u2 = source.GetUser(); 81 if (params.size() > 1) 82 u2 = User::Find(params[1], true); 83 84 if (!u2) 85 { 86 source.Reply(NICK_X_NOT_IN_USE, params[1].c_str()); 87 return; 88 } 89 90 bool override = !source.AccessFor(ci).HasPriv("UNBAN") && source.HasPriv("chanserv/kick"); 91 Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to unban " << u2->nick; 92 93 FOREACH_MOD(OnChannelUnban, (u2, ci)); 94 95 for (unsigned i = 0; i < modes.size(); ++i) 96 ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2); 97 if (u2 == source.GetUser()) 98 source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str()); 99 else 100 source.Reply(_("\002%s\002 has been unbanned from \002%s\002."), u2->nick.c_str(), ci->c->name.c_str()); 101 } 102 103 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override 104 { 105 this->SendSyntax(source); 106 source.Reply(" "); 107 source.Reply(_("Tells %s to remove all bans preventing you or the given\n" 108 "user from entering the given channel. If no channel is\n" 109 "given, all bans affecting you in channels you have access\n" 110 "in are removed.\n" 111 " \n" 112 "By default, limited to AOPs or those with level 5 access and above\n" 113 "on the channel."), source.service->nick.c_str()); 114 return true; 115 } 116 }; 117 118 class CSUnban : public Module 119 { 120 CommandCSUnban commandcsunban; 121 122 public: 123 CSUnban(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), 124 commandcsunban(this) 125 { 126 127 } 128 }; 129 130 MODULE_INIT(CSUnban)