cs_ban.c

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@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  * $Id: cs_ban.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_unban(User * u);
00019 int do_ban(User * u);
00020 void myChanServHelp(User * u);
00021 
00028 int AnopeInit(int argc, char **argv)
00029 {
00030     Command *c;
00031 
00032     moduleAddAuthor("Anope");
00033     moduleAddVersion("$Id: cs_ban.c 1265 2007-08-26 15:33:06Z geniusdex $");
00034     moduleSetType(CORE);
00035 
00036     c = createCommand("BAN", do_ban, NULL, CHAN_HELP_BAN, -1, -1, -1, -1);
00037     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00038     c = createCommand("UNBAN", do_unban, NULL, CHAN_HELP_UNBAN, -1, -1, -1,
00039                       -1);
00040     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00041 
00042     moduleSetChanHelp(myChanServHelp);
00043 
00044     return MOD_CONT;
00045 }
00046 
00050 void AnopeFini(void)
00051 {
00052 
00053 }
00054 
00055 
00056 
00061 void myChanServHelp(User * u)
00062 {
00063     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_BAN);
00064     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNBAN);
00065 }
00066 
00072 int do_ban(User * u)
00073 {
00074     char *chan = strtok(NULL, " ");
00075     char *params = strtok(NULL, " ");
00076     char *reason = strtok(NULL, "");
00077 
00078     Channel *c;
00079     ChannelInfo *ci;
00080     User *u2;
00081 
00082     int is_same;
00083 
00084     if (!reason) {
00085         reason = "Requested";
00086     } else {
00087         if (strlen(reason) > 200)
00088             reason[200] = '\0';
00089     }
00090 
00091     if (!chan) {
00092         struct u_chanlist *uc, *next;
00093 
00094         /* Bans the user on every channels he is on. */
00095 
00096         for (uc = u->chans; uc; uc = next) {
00097             next = uc->next;
00098             if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
00099                 && check_access(u, ci, CA_BANME)) {
00100                 char *av[3];
00101                 char mask[BUFSIZE];
00102 
00103                 /*
00104                  * Dont ban/kick the user on channels where he is excepted
00105                  * to prevent services <-> server wars.
00106                  */
00107                 if (ircd->except) {
00108                     if (is_excepted(ci, u))
00109                         notice_lang(s_ChanServ, u, CHAN_EXCEPTED,
00110                                     u->nick, ci->name);
00111                     continue;
00112                 }
00113                 if (is_protected(u)) {
00114                     notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00115                     continue;
00116                 }
00117 
00118                 av[0] = sstrdup("+b");
00119                 get_idealban(ci, u, mask, sizeof(mask));
00120                 av[1] = mask;
00121                 anope_cmd_mode(whosends(ci), uc->chan->name, "+b %s",
00122                                av[1]);
00123                 chan_set_modes(s_ChanServ, uc->chan, 2, av, 1);
00124                 free(av[0]);
00125 
00126                 if ((ci->flags & CI_SIGNKICK)
00127                     || ((ci->flags & CI_SIGNKICK_LEVEL)
00128                         && !check_access(u, ci, CA_SIGNKICK)))
00129                     anope_cmd_kick(whosends(ci), ci->name, u->nick,
00130                                    "%s (%s)", reason, u->nick);
00131                 else
00132                     anope_cmd_kick(whosends(ci), ci->name, u->nick, "%s",
00133                                    reason);
00134                 av[0] = ci->name;
00135                 av[1] = u->nick;
00136                 av[2] = reason;
00137                 do_kick(s_ChanServ, 3, av);
00138             }
00139         }
00140 
00141         return MOD_CONT;
00142     } else if (!params) {
00143         params = u->nick;
00144     }
00145 
00146     is_same = (params == u->nick) ? 1 : (stricmp(params, u->nick) == 0);
00147 
00148     if (!(c = findchan(chan))) {
00149         notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
00150     } else if (!(ci = c->ci)) {
00151         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
00152     } else if (ci->flags & CI_VERBOTEN) {
00153         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
00154     } else if (is_same ? !(u2 = u) : !(u2 = finduser(params))) {
00155         notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, params);
00156     } else if (!is_same ? !check_access(u, ci, CA_BAN) :
00157                !check_access(u, ci, CA_BANME)) {
00158         notice_lang(s_ChanServ, u, ACCESS_DENIED);
00159     } else if (!is_same && (ci->flags & CI_PEACE)
00160                && (get_access(u2, ci) >= get_access(u, ci))) {
00161         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00162         /*
00163          * Dont ban/kick the user on channels where he is excepted
00164          * to prevent services <-> server wars.
00165          */
00166     } else if (ircd->except && is_excepted(ci, u2)) {
00167         notice_lang(s_ChanServ, u, CHAN_EXCEPTED, u2->nick, ci->name);
00168     } else if (ircd->protectedumode && is_protected(u2)) {
00169         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00170     } else {
00171         char *av[3];
00172         char mask[BUFSIZE];
00173 
00174         av[0] = sstrdup("+b");
00175         get_idealban(ci, u2, mask, sizeof(mask));
00176         av[1] = mask;
00177         anope_cmd_mode(whosends(ci), c->name, "+b %s", av[1]);
00178         chan_set_modes(s_ChanServ, c, 2, av, 1);
00179         free(av[0]);
00180 
00181         /* We still allow host banning while not allowing to kick */
00182         if (!is_on_chan(c, u2))
00183             return MOD_CONT;
00184 
00185         if ((ci->flags & CI_SIGNKICK)
00186             || ((ci->flags & CI_SIGNKICK_LEVEL)
00187                 && !check_access(u, ci, CA_SIGNKICK)))
00188             anope_cmd_kick(whosends(ci), ci->name, params, "%s (%s)",
00189                            reason, u->nick);
00190         else
00191             anope_cmd_kick(whosends(ci), ci->name, params, "%s", reason);
00192 
00193         av[0] = ci->name;
00194         av[1] = params;
00195         av[2] = reason;
00196         do_kick(s_ChanServ, 3, av);
00197     }
00198     return MOD_CONT;
00199 }
00200 
00206 int do_unban(User * u)
00207 {
00208     char *chan = strtok(NULL, " ");
00209     Channel *c;
00210     ChannelInfo *ci;
00211 
00212     if (!chan) {
00213         syntax_error(s_ChanServ, u, "UNBAN", CHAN_UNBAN_SYNTAX);
00214     } else if (!(c = findchan(chan))) {
00215         notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
00216     } else if (!(ci = c->ci)) {
00217         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
00218     } else if (ci->flags & CI_VERBOTEN) {
00219         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
00220     } else if (!check_access(u, ci, CA_UNBAN)) {
00221         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00222     } else {
00223         common_unban(ci, u->nick);
00224         notice_lang(s_ChanServ, u, CHAN_UNBANNED, chan);
00225     }
00226     return MOD_CONT;
00227 }

Generated on Sun Dec 30 09:26:46 2007 for Anope by  doxygen 1.5.1-20070107