cs_clear.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_clear.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_clear(User * u);
00019 void myChanServHelp(User * u);
00020 
00027 int AnopeInit(int argc, char **argv)
00028 {
00029     Command *c;
00030 
00031     moduleAddAuthor("Anope");
00032     moduleAddVersion("$Id: cs_clear.c 1265 2007-08-26 15:33:06Z geniusdex $");
00033     moduleSetType(CORE);
00034 
00035     c = createCommand("CLEAR", do_clear, NULL, CHAN_HELP_CLEAR, -1, -1, -1,
00036                       -1);
00037     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00038 
00039     moduleSetChanHelp(myChanServHelp);
00040 
00041     return MOD_CONT;
00042 }
00043 
00047 void AnopeFini(void)
00048 {
00049 
00050 }
00051 
00052 
00053 
00058 void myChanServHelp(User * u)
00059 {
00060     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_CLEAR);
00061 }
00062 
00068 int do_clear(User * u)
00069 {
00070     char *chan = strtok(NULL, " ");
00071     char *what = strtok(NULL, " ");
00072     char tmp[BUFSIZE];
00073     Channel *c;
00074     ChannelInfo *ci;
00075 
00076     if (!what) {
00077         syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
00078     } else if (!(c = findchan(chan))) {
00079         notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
00080     } else if (!(ci = c->ci)) {
00081         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
00082     } else if (ci->flags & CI_VERBOTEN) {
00083         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
00084     } else if (!u || !check_access(u, ci, CA_CLEAR)) {
00085         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00086     } else if (stricmp(what, "bans") == 0) {
00087         char *av[2];
00088         int i;
00089 
00090         /* Save original ban info */
00091         int count = c->bancount;
00092         char **bans = scalloc(sizeof(char *) * count, 1);
00093         for (i = 0; i < count; i++)
00094             bans[i] = sstrdup(c->bans[i]);
00095 
00096         for (i = 0; i < count; i++) {
00097             av[0] = sstrdup("-b");
00098             av[1] = bans[i];
00099             anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
00100             chan_set_modes(whosends(ci), c, 2, av, 0);
00101             free(av[1]);
00102             free(av[0]);
00103         }
00104         notice_lang(s_ChanServ, u, CHAN_CLEARED_BANS, chan);
00105         free(bans);
00106     } else if (ircd->except && stricmp(what, "excepts") == 0) {
00107         char *av[2];
00108         int i;
00109 
00110         /* Save original except info */
00111         int count = c->exceptcount;
00112         char **excepts = scalloc(sizeof(char *) * count, 1);
00113         for (i = 0; i < count; i++)
00114             excepts[i] = sstrdup(c->excepts[i]);
00115 
00116         for (i = 0; i < count; i++) {
00117             av[0] = sstrdup("-e");
00118             av[1] = excepts[i];
00119             anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
00120             chan_set_modes(whosends(ci), c, 2, av, 0);
00121             free(av[1]);
00122             free(av[0]);
00123         }
00124         notice_lang(s_ChanServ, u, CHAN_CLEARED_EXCEPTS, chan);
00125         free(excepts);
00126 
00127     } else if (ircd->invitemode && stricmp(what, "invites") == 0) {
00128         char *av[2];
00129         int i;
00130 
00131         /* Save original except info */
00132         int count = c->invitecount;
00133         char **invites = scalloc(sizeof(char *) * count, 1);
00134         for (i = 0; i < count; i++)
00135             invites[i] = sstrdup(c->invite[i]);
00136 
00137         for (i = 0; i < count; i++) {
00138             av[0] = sstrdup("-I");
00139             av[1] = invites[i];
00140             anope_cmd_mode(whosends(ci), chan, "%s %s", av[0], av[1]);
00141             chan_set_modes(whosends(ci), c, 2, av, 0);
00142             free(av[1]);
00143             free(av[0]);
00144         }
00145         notice_lang(s_ChanServ, u, CHAN_CLEARED_INVITES, chan);
00146         free(invites);
00147 
00148     } else if (stricmp(what, "modes") == 0) {
00149         char buf[BUFSIZE], *end = buf;
00150         char *argv[2];
00151 
00152         if (c->mode) {
00153             /* Clear modes the bulk of the modes */
00154             anope_cmd_mode(whosends(ci), c->name, "%s",
00155                            ircd->modestoremove);
00156             argv[0] = sstrdup(ircd->modestoremove);
00157             chan_set_modes(whosends(ci), c, 1, argv, 0);
00158             free(argv[0]);
00159 
00160             /* to prevent the internals from complaining send -k, -L, -f by themselves if we need
00161                to send them - TSL */
00162             if (c->key) {
00163                 anope_cmd_mode(whosends(ci), c->name, "-k %s", c->key);
00164                 argv[0] = sstrdup("-k");
00165                 argv[1] = c->key;
00166                 chan_set_modes(whosends(ci), c, 2, argv, 0);
00167                 free(argv[0]);
00168             }
00169             if (ircd->Lmode && c->redirect) {
00170                 anope_cmd_mode(whosends(ci), c->name, "-L %s",
00171                                c->redirect);
00172                 argv[0] = sstrdup("-L");
00173                 argv[1] = c->redirect;
00174                 chan_set_modes(whosends(ci), c, 2, argv, 0);
00175                 free(argv[0]);
00176             }
00177             if (ircd->fmode && c->flood) {
00178                 if (flood_mode_char_remove) {
00179                     anope_cmd_mode(whosends(ci), c->name, "%s %s",
00180                                    flood_mode_char_remove, c->flood);
00181                     argv[0] = sstrdup(flood_mode_char_remove);
00182                     argv[1] = c->flood;
00183                     chan_set_modes(whosends(ci), c, 2, argv, 0);
00184                     free(argv[0]);
00185                 } else {
00186                     if (debug) {
00187                         alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
00188                     }
00189                 }
00190             }
00191             check_modes(c);
00192         }
00193 
00194 
00195 
00196         /* TODO: decide if the above implementation is better than this one. */
00197 
00198         if (0) {
00199             CBModeInfo *cbmi = cbmodeinfos;
00200             CBMode *cbm;
00201 
00202             do {
00203                 if (c->mode & cbmi->flag)
00204                     *end++ = cbmi->mode;
00205             } while ((++cbmi)->flag != 0);
00206 
00207             cbmi = cbmodeinfos;
00208 
00209             do {
00210                 if (cbmi->getvalue && (c->mode & cbmi->flag)
00211                     && !(cbmi->flags & CBM_MINUS_NO_ARG)) {
00212                     char *value = cbmi->getvalue(c);
00213 
00214                     if (value) {
00215                         *end++ = ' ';
00216                         while (*value)
00217                             *end++ = *value++;
00218 
00219                         /* Free the value */
00220                         cbm = &cbmodes[(int) cbmi->mode];
00221                         cbm->setvalue(c, NULL);
00222                     }
00223                 }
00224             } while ((++cbmi)->flag != 0);
00225 
00226             *end = 0;
00227 
00228             anope_cmd_mode(whosends(ci), c->name, "-%s", buf);
00229             c->mode = 0;
00230             check_modes(c);
00231         }
00232         notice_lang(s_ChanServ, u, CHAN_CLEARED_MODES, chan);
00233     } else if (stricmp(what, "ops") == 0) {
00234         char *av[3];
00235         struct c_userlist *cu, *next;
00236 
00237         if (ircd->svsmode_ucmode) {
00238             av[0] = sstrdup(chan);
00239             anope_cmd_svsmode_chan(av[0], "-o", NULL);
00240             if (ircd->owner) {
00241                 anope_cmd_svsmode_chan(av[0], ircd->ownerunset, NULL);
00242             }
00243             if (ircd->protect || ircd->admin) {
00244                 anope_cmd_svsmode_chan(av[0], ircd->adminunset, NULL);
00245             }
00246             for (cu = c->users; cu; cu = next) {
00247                 next = cu->next;
00248                 av[0] = sstrdup(chan);
00249                 if (!chan_has_user_status(c, cu->user, CUS_OP)) {
00250                     if (!chan_has_user_status(c, cu->user, CUS_PROTECT)) {
00251                         if (!chan_has_user_status(c, cu->user, CUS_OWNER)) {
00252                             continue;
00253                         } else {
00254                             snprintf(tmp, BUFSIZE, "%so",
00255                                      ircd->ownerunset);
00256                             av[1] = sstrdup(tmp);
00257 
00258                         }
00259                     } else {
00260                         snprintf(tmp, BUFSIZE, "%so", ircd->adminunset);
00261                         av[1] = sstrdup(tmp);
00262                     }
00263                 } else {
00264                     av[1] = sstrdup("-o");
00265                 }
00266                 av[2] = sstrdup(cu->user->nick);
00267                 do_cmode(s_ChanServ, 3, av);
00268                 free(av[2]);
00269                 free(av[1]);
00270                 free(av[0]);
00271             }
00272         } else {
00273             for (cu = c->users; cu; cu = next) {
00274                 next = cu->next;
00275                 av[0] = sstrdup(chan);
00276                 if (!chan_has_user_status(c, cu->user, CUS_OP)) {
00277                     if (!chan_has_user_status(c, cu->user, CUS_PROTECT)) {
00278                         if (!chan_has_user_status(c, cu->user, CUS_OWNER)) {
00279                             continue;
00280                         } else {
00281                             snprintf(tmp, BUFSIZE, "%so",
00282                                      ircd->ownerunset);
00283                             av[1] = sstrdup(tmp);
00284                         }
00285                     } else {
00286                         snprintf(tmp, BUFSIZE, "%so", ircd->adminunset);
00287                         av[1] = sstrdup(tmp);
00288                     }
00289                 } else {
00290                     av[1] = sstrdup("-o");
00291                 }
00292                 av[2] = sstrdup(cu->user->nick);
00293                 anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
00294                                av[2]);
00295                 do_cmode(s_ChanServ, 3, av);
00296                 free(av[2]);
00297                 free(av[1]);
00298                 free(av[0]);
00299             }
00300         }
00301         notice_lang(s_ChanServ, u, CHAN_CLEARED_OPS, chan);
00302     } else if (ircd->halfop && stricmp(what, "hops") == 0) {
00303         char *av[3];
00304         struct c_userlist *cu, *next;
00305 
00306         for (cu = c->users; cu; cu = next) {
00307             next = cu->next;
00308             if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
00309                 continue;
00310             av[0] = sstrdup(chan);
00311             av[1] = sstrdup("-h");
00312             av[2] = sstrdup(cu->user->nick);
00313             if (ircd->svsmode_ucmode) {
00314                 anope_cmd_svsmode_chan(av[0], av[1], NULL);
00315                 do_cmode(s_ChanServ, 3, av);
00316                 break;
00317             } else {
00318                 anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
00319                                av[2]);
00320             }
00321             do_cmode(s_ChanServ, 3, av);
00322             free(av[2]);
00323             free(av[1]);
00324             free(av[0]);
00325         }
00326         notice_lang(s_ChanServ, u, CHAN_CLEARED_HOPS, chan);
00327     } else if (stricmp(what, "voices") == 0) {
00328         char *av[3];
00329         struct c_userlist *cu, *next;
00330 
00331         for (cu = c->users; cu; cu = next) {
00332             next = cu->next;
00333             if (!chan_has_user_status(c, cu->user, CUS_VOICE))
00334                 continue;
00335             av[0] = sstrdup(chan);
00336             av[1] = sstrdup("-v");
00337             av[2] = sstrdup(cu->user->nick);
00338             if (ircd->svsmode_ucmode) {
00339                 anope_cmd_svsmode_chan(av[0], av[1], NULL);
00340                 do_cmode(s_ChanServ, 3, av);
00341                 break;
00342             } else {
00343                 anope_cmd_mode(whosends(ci), av[0], "%s :%s", av[1],
00344                                av[2]);
00345             }
00346             do_cmode(s_ChanServ, 3, av);
00347             free(av[2]);
00348             free(av[1]);
00349             free(av[0]);
00350         }
00351         notice_lang(s_ChanServ, u, CHAN_CLEARED_VOICES, chan);
00352     } else if (stricmp(what, "users") == 0) {
00353         char *av[3];
00354         struct c_userlist *cu, *next;
00355         char buf[256];
00356 
00357         snprintf(buf, sizeof(buf), "CLEAR USERS command from %s", u->nick);
00358 
00359         for (cu = c->users; cu; cu = next) {
00360             next = cu->next;
00361             av[0] = sstrdup(chan);
00362             av[1] = sstrdup(cu->user->nick);
00363             av[2] = sstrdup(buf);
00364             anope_cmd_kick(whosends(ci), av[0], av[1], av[2]);
00365             do_kick(s_ChanServ, 3, av);
00366             free(av[2]);
00367             free(av[1]);
00368             free(av[0]);
00369         }
00370         notice_lang(s_ChanServ, u, CHAN_CLEARED_USERS, chan);
00371     } else {
00372         syntax_error(s_ChanServ, u, "CLEAR", CHAN_CLEAR_SYNTAX);
00373     }
00374     return MOD_CONT;
00375 }

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