hs_set.c

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

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