hs_setall.c

Go to the documentation of this file.
00001 /* HostServ core functions
00002  *
00003  * (C) 2003-2008 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: hs_setall.c 1403 2008-07-20 20:59:17Z drstein $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_setall(User * u);
00019 void myHostServHelp(User * u);
00020 extern int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask,
00021                       char *creator, time_t time);
00022 
00029 int AnopeInit(int argc, char **argv)
00030 {
00031     Command *c;
00032 
00033     moduleAddAuthor("Anope");
00034     moduleAddVersion("$Id: hs_setall.c 1403 2008-07-20 20:59:17Z drstein $");
00035     moduleSetType(CORE);
00036 
00037     c = createCommand("SETALL", do_setall, is_host_setter,
00038                       HOST_HELP_SETALL, -1, -1, -1, -1);
00039     moduleAddCommand(HOSTSERV, c, MOD_UNIQUE);
00040     moduleSetHostHelp(myHostServHelp);
00041 
00042     return MOD_CONT;
00043 }
00044 
00048 void AnopeFini(void)
00049 {
00050 
00051 }
00052 
00053 
00054 
00059 void myHostServHelp(User * u)
00060 {
00061     if (is_host_setter(u)) {
00062         notice_lang(s_HostServ, u, HOST_HELP_CMD_SETALL);
00063     }
00064 }
00065 
00071 int do_setall(User * u)
00072 {
00073 
00074     char *nick = strtok(NULL, " ");
00075     char *rawhostmask = strtok(NULL, " ");
00076     char *hostmask = smalloc(HOSTMAX);
00077 
00078     NickAlias *na;
00079     int32 tmp_time;
00080     char *s;
00081 
00082     char *vIdent = NULL;
00083 
00084     if (!nick || !rawhostmask) {
00085         notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ);
00086         free(hostmask);
00087         return MOD_CONT;
00088     }
00089 
00090     vIdent = myStrGetOnlyToken(rawhostmask, '@', 0);    /* Get the first substring, @ as delimiter */
00091     if (vIdent) {
00092         rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1);      /* get the remaining string */
00093         if (!rawhostmask) {
00094             notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ);
00095             free(vIdent);
00096             free(hostmask);
00097             return MOD_CONT;
00098         }
00099         if (strlen(vIdent) > USERMAX - 1) {
00100             notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
00101             free(vIdent);
00102             free(rawhostmask);
00103             free(hostmask);
00104             return MOD_CONT;
00105         } else {
00106             for (s = vIdent; *s; s++) {
00107                 if (!isvalidchar(*s)) {
00108                     notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
00109                     free(vIdent);
00110                     free(rawhostmask);
00111                     free(hostmask);
00112                     return MOD_CONT;
00113                 }
00114             }
00115         }
00116         if (!ircd->vident) {
00117             notice_lang(s_HostServ, u, HOST_NO_VIDENT);
00118             free(vIdent);
00119             free(rawhostmask);
00120             free(hostmask);
00121             return MOD_CONT;
00122         }
00123     }
00124 
00125     if (strlen(rawhostmask) < HOSTMAX - 1)
00126         snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask);
00127     else {
00128         notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
00129         if (vIdent) {
00130             free(vIdent);
00131             free(rawhostmask);
00132         }
00133         free(hostmask);
00134         return MOD_CONT;
00135     }
00136 
00137     if (!isValidHost(hostmask, 3)) {
00138         notice_lang(s_HostServ, u, HOST_SET_ERROR);
00139         if (vIdent) {
00140             free(vIdent);
00141             free(rawhostmask);
00142         }
00143         free(hostmask);
00144         return MOD_CONT;
00145     }
00146 
00147     tmp_time = time(NULL);
00148 
00149     if ((na = findnick(nick))) {
00150         if (na->status & NS_VERBOTEN) {
00151             notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
00152             if (vIdent) {
00153                 free(vIdent);
00154                 free(rawhostmask);
00155             }
00156             free(hostmask);
00157             return MOD_CONT;
00158         }
00159         if (vIdent && ircd->vident) {
00160             alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
00161         } else {
00162             alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
00163         }
00164         do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time);
00165         if (vIdent) {
00166             notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent,
00167                         hostmask);
00168         } else {
00169             notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask);
00170         }
00171     } else {
00172         notice_lang(s_HostServ, u, HOST_NOREG, nick);
00173     }
00174     if (vIdent) {
00175         free(vIdent);
00176         free(rawhostmask);
00177     }
00178     free(hostmask);
00179     return MOD_CONT;
00180 }

Generated on Sun Oct 5 09:06:55 2008 for Anope by  doxygen 1.5.7.1