os_clearmodes.c

Go to the documentation of this file.
00001 /* OperServ 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: os_clearmodes.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_clearmodes(User * u);
00019 void myOperServHelp(User * u);
00020 
00027 int AnopeInit(int argc, char **argv)
00028 {
00029     Command *c;
00030 
00031     moduleAddAuthor("Anope");
00032     moduleAddVersion
00033         ("$Id: os_clearmodes.c 1265 2007-08-26 15:33:06Z geniusdex $");
00034     moduleSetType(CORE);
00035 
00036     c = createCommand("CLEARMODES", do_clearmodes, is_services_oper,
00037                       OPER_HELP_CLEARMODES, -1, -1, -1, -1);
00038     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00039 
00040     moduleSetOperHelp(myOperServHelp);
00041 
00042     return MOD_CONT;
00043 }
00044 
00048 void AnopeFini(void)
00049 {
00050 
00051 }
00052 
00053 
00058 void myOperServHelp(User * u)
00059 {
00060     if (is_services_oper(u)) {
00061         notice_lang(s_OperServ, u, OPER_HELP_CMD_CLEARMODES);
00062     }
00063 }
00064 
00070 int do_clearmodes(User * u)
00071 {
00072     char *s;
00073     int i;
00074     char *argv[2];
00075     char *chan = strtok(NULL, " ");
00076     Channel *c;
00077     int all = 0;
00078     int count;                  /* For saving ban info */
00079     char **bans;                /* For saving ban info */
00080     int exceptcount;            /* For saving except info */
00081     char **excepts;             /* For saving except info */
00082     int invitecount;            /* For saving invite info */
00083     char **invites;             /* For saving invite info */
00084     struct c_userlist *cu, *next;
00085 
00086     if (!chan) {
00087         syntax_error(s_OperServ, u, "CLEARMODES", OPER_CLEARMODES_SYNTAX);
00088         return MOD_CONT;
00089     } else if (!(c = findchan(chan))) {
00090         notice_lang(s_OperServ, u, CHAN_X_NOT_IN_USE, chan);
00091         return MOD_CONT;
00092     } else if (c->bouncy_modes) {
00093         notice_lang(s_OperServ, u, OPER_BOUNCY_MODES_U_LINE);
00094         return MOD_CONT;
00095     } else {
00096         s = strtok(NULL, " ");
00097         if (s) {
00098             if (stricmp(s, "ALL") == 0) {
00099                 all = 1;
00100             } else {
00101                 syntax_error(s_OperServ, u, "CLEARMODES",
00102                              OPER_CLEARMODES_SYNTAX);
00103                 return MOD_CONT;
00104             }
00105         }
00106 
00107         if (WallOSClearmodes) {
00108             anope_cmd_global(s_OperServ, "%s used CLEARMODES%s on %s",
00109                              u->nick, all ? " ALL" : "", chan);
00110         }
00111         if (all) {
00112             /* Clear mode +o */
00113             if (ircd->svsmode_ucmode) {
00114                 anope_cmd_svsmode_chan(c->name, "-o", NULL);
00115                 for (cu = c->users; cu; cu = next) {
00116                     next = cu->next;
00117                     if (!chan_has_user_status(c, cu->user, CUS_OP)) {
00118                         continue;
00119                     }
00120                     argv[0] = sstrdup("-o");
00121                     argv[1] = cu->user->nick;
00122                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00123                     free(argv[0]);
00124                 }
00125             } else {
00126                 for (cu = c->users; cu; cu = next) {
00127                     next = cu->next;
00128                     if (!chan_has_user_status(c, cu->user, CUS_OP))
00129                         continue;
00130                     argv[0] = sstrdup("-o");
00131                     argv[1] = cu->user->nick;
00132                     anope_cmd_mode(s_OperServ, c->name, "-o %s",
00133                                    cu->user->nick);
00134                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00135                     free(argv[0]);
00136                 }
00137             }
00138 
00139             if (ircd->svsmode_ucmode) {
00140                 anope_cmd_svsmode_chan(c->name, "-v", NULL);
00141                 for (cu = c->users; cu; cu = next) {
00142                     next = cu->next;
00143                     if (!chan_has_user_status(c, cu->user, CUS_VOICE)) {
00144                         continue;
00145                     }
00146                     argv[0] = sstrdup("-v");
00147                     argv[1] = cu->user->nick;
00148                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00149                     free(argv[0]);
00150                 }
00151             } else {
00152                 /* Clear mode +v */
00153                 for (cu = c->users; cu; cu = next) {
00154                     next = cu->next;
00155                     if (!chan_has_user_status(c, cu->user, CUS_VOICE))
00156                         continue;
00157                     argv[0] = sstrdup("-v");
00158                     argv[1] = sstrdup(cu->user->nick);
00159                     anope_cmd_mode(s_OperServ, c->name, "-v %s",
00160                                    cu->user->nick);
00161                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00162                     free(argv[0]);
00163                 }
00164             }
00165 
00166             /* Clear mode +h */
00167             if (ircd->svsmode_ucmode && ircd->halfop) {
00168                 anope_cmd_svsmode_chan(c->name, "-h", NULL);
00169                 for (cu = c->users; cu; cu = next) {
00170                     next = cu->next;
00171                     if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
00172                         continue;
00173                     }
00174                     argv[0] = sstrdup("-h");
00175                     argv[1] = cu->user->nick;
00176                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00177                     free(argv[0]);
00178                 }
00179             } else {
00180                 for (cu = c->users; cu; cu = next) {
00181                     next = cu->next;
00182                     if (!chan_has_user_status(c, cu->user, CUS_HALFOP))
00183                         continue;
00184                     argv[0] = sstrdup("-h");
00185                     argv[1] = sstrdup(cu->user->nick);
00186                     anope_cmd_mode(s_OperServ, c->name, "-h %s",
00187                                    cu->user->nick);
00188                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00189                     free(argv[0]);
00190                 }
00191             }
00192             /* Clear mode Owners */
00193             if (ircd->svsmode_ucmode && ircd->owner) {
00194                 anope_cmd_svsmode_chan(c->name, ircd->ownerunset, NULL);
00195                 for (cu = c->users; cu; cu = next) {
00196                     next = cu->next;
00197                     if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
00198                         continue;
00199                     }
00200                     argv[0] = sstrdup(ircd->ownerunset);
00201                     argv[1] = cu->user->nick;
00202                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00203                     free(argv[0]);
00204                 }
00205             } else {
00206                 for (cu = c->users; cu; cu = next) {
00207                     next = cu->next;
00208                     if (!chan_has_user_status(c, cu->user, CUS_OWNER))
00209                         continue;
00210                     argv[0] = sstrdup(ircd->ownerunset);
00211                     argv[1] = sstrdup(cu->user->nick);
00212                     anope_cmd_mode(s_OperServ, c->name, "%s %s",
00213                                    ircd->ownerunset, cu->user->nick);
00214                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00215                     free(argv[0]);
00216                 }
00217             }
00218             /* Clear mode protected or admins */
00219             if (ircd->svsmode_ucmode && (ircd->protect || ircd->admin)) {
00220 
00221                 anope_cmd_svsmode_chan(c->name, ircd->adminunset, NULL);
00222                 for (cu = c->users; cu; cu = next) {
00223                     next = cu->next;
00224                     if (!chan_has_user_status(c, cu->user, CUS_HALFOP)) {
00225                         continue;
00226                     }
00227                     argv[0] = sstrdup(ircd->adminunset);
00228                     argv[1] = cu->user->nick;
00229                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00230                     free(argv[0]);
00231                 }
00232             } else {
00233                 for (cu = c->users; cu; cu = next) {
00234                     next = cu->next;
00235                     if (!chan_has_user_status(c, cu->user, CUS_PROTECT))
00236                         continue;
00237                     argv[0] = sstrdup(ircd->adminunset);
00238                     argv[1] = sstrdup(cu->user->nick);
00239                     anope_cmd_mode(s_OperServ, c->name, "%s %s",
00240                                    ircd->adminunset, cu->user->nick);
00241                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00242                     free(argv[0]);
00243                 }
00244             }
00245 
00246 
00247         }
00248 
00249         if (c->mode) {
00250             /* Clear modes the bulk of the modes */
00251             anope_cmd_mode(s_OperServ, c->name, "%s", ircd->modestoremove);
00252             argv[0] = sstrdup(ircd->modestoremove);
00253             chan_set_modes(s_OperServ, c, 1, argv, 0);
00254             free(argv[0]);
00255 
00256             /* to prevent the internals from complaining send -k, -L, -f by themselves if we need
00257                to send them - TSL */
00258             if (c->key) {
00259                 anope_cmd_mode(s_OperServ, c->name, "-k %s", c->key);
00260                 argv[0] = sstrdup("-k");
00261                 argv[1] = c->key;
00262                 chan_set_modes(s_OperServ, c, 2, argv, 0);
00263                 free(argv[0]);
00264             }
00265             if (ircd->Lmode && c->redirect) {
00266                 anope_cmd_mode(s_OperServ, c->name, "-L %s", c->redirect);
00267                 argv[0] = sstrdup("-L");
00268                 argv[1] = c->redirect;
00269                 chan_set_modes(s_OperServ, c, 2, argv, 0);
00270                 free(argv[0]);
00271             }
00272             if (ircd->fmode && c->flood) {
00273                 if (flood_mode_char_remove) {
00274                     anope_cmd_mode(s_OperServ, c->name, "%s %s",
00275                                    flood_mode_char_remove, c->flood);
00276                     argv[0] = sstrdup(flood_mode_char_remove);
00277                     argv[1] = c->flood;
00278                     chan_set_modes(s_OperServ, c, 2, argv, 0);
00279                     free(argv[0]);
00280                 } else {
00281                     if (debug) {
00282                         alog("debug: flood_mode_char_remove was not set unable to remove flood/throttle modes");
00283                     }
00284                 }
00285             }
00286         }
00287 
00288         /* Clear bans */
00289         count = c->bancount;
00290         bans = scalloc(sizeof(char *) * count, 1);
00291 
00292         for (i = 0; i < count; i++)
00293             bans[i] = sstrdup(c->bans[i]);
00294 
00295         for (i = 0; i < count; i++) {
00296             argv[0] = sstrdup("-b");
00297             argv[1] = bans[i];
00298             anope_cmd_mode(s_OperServ, c->name, "-b %s", argv[1]);
00299             chan_set_modes(s_OperServ, c, 2, argv, 0);
00300             free(argv[1]);
00301             free(argv[0]);
00302         }
00303 
00304         free(bans);
00305 
00306         excepts = NULL;
00307 
00308         if (ircd->except) {
00309             /* Clear excepts */
00310             exceptcount = c->exceptcount;
00311             excepts = scalloc(sizeof(char *) * exceptcount, 1);
00312 
00313             for (i = 0; i < exceptcount; i++)
00314                 excepts[i] = sstrdup(c->excepts[i]);
00315 
00316             for (i = 0; i < exceptcount; i++) {
00317                 argv[0] = sstrdup("-e");
00318                 argv[1] = excepts[i];
00319                 anope_cmd_mode(s_OperServ, c->name, "-e %s", argv[1]);
00320                 chan_set_modes(s_OperServ, c, 2, argv, 0);
00321                 free(argv[1]);
00322                 free(argv[0]);
00323             }
00324 
00325             if (excepts) {
00326                 free(excepts);
00327             }
00328         }
00329 
00330         if (ircd->invitemode) {
00331             /* Clear invites */
00332             invitecount = c->invitecount;
00333             invites = scalloc(sizeof(char *) * invitecount, 1);
00334 
00335             for (i = 0; i < invitecount; i++)
00336                 invites[i] = sstrdup(c->invite[i]);
00337 
00338             for (i = 0; i < invitecount; i++) {
00339                 argv[0] = sstrdup("-I");
00340                 argv[1] = invites[i];
00341                 anope_cmd_mode(s_OperServ, c->name, "-I %s", argv[1]);
00342                 chan_set_modes(s_OperServ, c, 2, argv, 0);
00343                 free(argv[1]);
00344                 free(argv[0]);
00345             }
00346 
00347             free(invites);
00348         }
00349 
00350     }
00351 
00352     if (all) {
00353         notice_lang(s_OperServ, u, OPER_CLEARMODES_ALL_DONE, chan);
00354     } else {
00355         notice_lang(s_OperServ, u, OPER_CLEARMODES_DONE, chan);
00356     }
00357     return MOD_CONT;
00358 }

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