/* WARNING - MODULE OUT OF DATE - DOES NOT WORK WITH ANOPE VERSIO N => 1.7 */ /* ---------------------------------------------------------------------------- * Name: no name at the moment (projectname: addon.c) * Author: Jens 'DukePyrolator' Voss * * Date: 06/03/2004 * ----------------------------------------------------------------------------- * This powerful module provides a lot of new features: * - ajoin /nickserv help ajoin * - swhois /operserv help swhois * - helpop /operserv help helpop * ----------------------------------------------------------------------------- * Supported IRCd: UnrealIRCd 3.2 * Tested with: UnrealIRCd 3.2.RC1 * ----------------------------------------------------------------------------- * Limitations: * - users are not removed from database if nick * expires or gets dropped. (is on todo list) * - you should not use this module together with the os_swois module ! * ------------------------------------------------------------------------------ * Bugs: no known at the moment * ------------------------------------------------------------------------------ * Change Log: * v0.9.0 06/03/2004 - first release * v0.9.1 10/03/2004 - fixed a crashbug caused by a unchecked parameter * in ns_ajoin() reported by doh * - fixed some compiler warnings * *-------------------------------------------------------------------------------- * 90% of the code are from an old epona modification made * by Denis 'SciFi' Simonet in 2002 * * Credits go to: * - Mush and tOAsD for help associated with coding. * - apt who added some things when i was too lazy to add it myself :) * Special thanks go to Lindt & Sprüngli for the best chocolate ever * *--------------------------------------------------------------------------------- */ #include "module.h" #include #define AUTHOR "Jens 'DukePyrolator' Voss" #define VERSION "0.9.1" /* Language definitions */ /* ajoin */ #define AJOIN_SYNTAX "Syntax: \002AJOIN option parameters\002" #define AJOIN_SYNTAX2 "/msg NickServ HELP AJOIN for more information." #define AJOIN_HELP1 " \002SET\002 Defines your ajoin channels" #define AJOIN_HELP2 " Syntax is: \002AJOIN SET #chan1,#chan2\002" #define AJOIN_HELP3 " Do \002AJOIN SET OFF\002 to clear your list" #define AJOIN_HELP4 " \002LIST\002 Lists your ajoin channels" #define NICK_NOT_AJOIN "Joining your ajoin channels %s" #define NICK_SHOW_AJOIN "Your ajoin channels are: %s" #define NICK_SHOW_AJOIN_NEW "Your ajoin channels are now %s" #define NICK_NOT_NOAJOIN "You have no ajoin channels set" #define NICK_NOT_EMPTY_AJOINLIST "The ajoin list is now empty" #define NICK_NOT_MAX_AJOIN "The chanlist is too long. The max. length of it is 511 chars" /* swhois */ #define OPER_HELP_SWHOIS1 " Syntax: \002SWHOIS ADD nick swhois\002" #define OPER_HELP_SWHOIS2 " Adds a swhois for an user." #define OPER_HELP_SWHOIS3 " \002SWHOIS DEL nick\002" #define OPER_HELP_SWHOIS4 " Removes a swhois" #define OPER_HELP_SWHOIS5 " \002SWHOIS LIST [nick]\002" #define OPER_HELP_SWHOIS6 " Lists all swhoises or shows the" #define OPER_HELP_SWHOIS7 " swhois of an user." #define NICK_NOT_SWHOIS "Setting your swhois..." /* helpop */ #define OPER_HELP_HELPOP1 " Syntax: \002HELPOP ADD nick modes\002" #define OPER_HELP_HELPOP2 " Adds a helpop with the modes" #define OPER_HELP_HELPOP3 " you define. Note that oper" #define OPER_HELP_HELPOP4 " flags (oOAN etc) don't work!" #define OPER_HELP_HELPOP5 " \002HELPOP DEL nick\002" #define OPER_HELP_HELPOP6 " Deletes a nick from the helpop" #define OPER_HELP_HELPOP7 " list." #define OPER_HELP_HELPOP8 " \002HELPOP LIST [nick]\002" #define OPER_HELP_HELPOP9 " Lists all helpops or the modes" #define OPER_HELP_HELPOP10 " of an user." #define NICK_NOT_HELPOP "Setting your helpop..." /* end of language definitions */ char line [513]; int ns_ajoin(User *u); /* handler for nickserv ajoin */ void help_nickserv(User *u); /* adds help to the nickserv help */ void help_operserv(User *u); /* adds help to the operserv help */ int ajoin_syntax(User *u); /* displays help as defined */ int do_set_ajoin(User *u, char *param); /* adds autojoin channels to database */ int ajoin_list(User *u); /* lists the ajoin channels */ int do_ajoin(User *u); /* checks if a user has autojoin channels and joins him */ int do_swhois(User *u); /* handler for operserv swhois */ int set_swhois(User *u); /* sets swhois on user */ int swhois_add(User *u, char *nick, char *swhois); /* adds new swhois to database */ int swhois_del(User *u, char *nick); /* deletes swhois from database */ int swhois_list(User *u, char *nick); /* shows swhois from database */ int swhois_syntax(User *u); /* displays help as defined */ int do_helpop(User *u); int set_helpop(User *u); int helpop_add(User *u, char *nick, char *helpop); int helpop_del(User *u, char *nick); int helpop_list(User *u, char *nick); int helpop_syntax(User *u); int do_on_identify(User *u); int do_update(User *u); /* database functions */ int exists_nick(char *file, char *name, int format); /* checks if a user exists in the database */ int exists(User *u, char *file, char *nick, int type); /* checks if a user exists in the database */ void rem_u_nick(char *file, char *nic, int form); /* removes user from database */ void rem_u(User *u, char *file, char *user, int form); /* removes user from database */ /***************************************************************************************/ /* initialising modul */ int AnopeInit(int argc, char **argv) { Command *c; c = createCommand("AJOIN", ns_ajoin, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_HEAD); moduleAddHelp(c,ajoin_syntax); c = createCommand("SWHOIS", do_swhois, is_services_oper, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c,swhois_syntax); c = createCommand("HELPOP", do_helpop, is_services_admin, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c,helpop_syntax); c = createCommand("IDENTIFY", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("ID", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("UPDATE", do_update, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleSetNickHelp(help_nickserv); moduleSetOperHelp(help_operserv); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); return MOD_CONT; }; /****************************************************************************************/ int ns_ajoin(User *u) { char *option = strtok(NULL, " "); char *par1 = strtok(NULL, ""); if (!option) { notice(s_NickServ, u->nick, AJOIN_SYNTAX); notice(s_NickServ, u->nick, AJOIN_SYNTAX2); return MOD_STOP; } if (stricmp(option, "SET")==0 && par1) { do_set_ajoin(u, par1); } else if (stricmp(option, "LIST")==0) { ajoin_list(u); } else if (stricmp(option, "DO")==0) { do_ajoin(u); } else { notice(s_NickServ, u->nick, AJOIN_SYNTAX); notice(s_NickServ, u->nick, AJOIN_SYNTAX2); } return MOD_STOP; } /******************************************************************************************/ /* help routines */ void help_nickserv(User *u) { notice(s_NickServ, u->nick, " AJOIN Autojoin Chans"); }; void help_operserv(User *u) { notice(s_OperServ, u->nick, " SWHOIS Adminstrate the swhoises"); }; /* ajoin help */ int ajoin_syntax(User *u) { notice(s_NickServ, u->nick, AJOIN_SYNTAX); notice(s_NickServ, u->nick, AJOIN_HELP1); notice(s_NickServ, u->nick, AJOIN_HELP2); notice(s_NickServ, u->nick, AJOIN_HELP3); notice(s_NickServ, u->nick, AJOIN_HELP4); return MOD_CONT; }; /* swhois help */ int swhois_syntax(User *u) { notice(s_OperServ, u->nick, OPER_HELP_SWHOIS1); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS2); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS3); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS4); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS5); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS6); notice(s_OperServ, u->nick, OPER_HELP_SWHOIS7); return MOD_CONT; } int helpop_syntax(User *u) { notice(s_OperServ, u->nick, OPER_HELP_HELPOP1); notice(s_OperServ, u->nick, OPER_HELP_HELPOP2); notice(s_OperServ, u->nick, OPER_HELP_HELPOP3); notice(s_OperServ, u->nick, OPER_HELP_HELPOP4); notice(s_OperServ, u->nick, OPER_HELP_HELPOP5); notice(s_OperServ, u->nick, OPER_HELP_HELPOP6); notice(s_OperServ, u->nick, OPER_HELP_HELPOP7); notice(s_OperServ, u->nick, OPER_HELP_HELPOP8); notice(s_OperServ, u->nick, OPER_HELP_HELPOP9); notice(s_OperServ, u->nick, OPER_HELP_HELPOP10); return MOD_CONT; } /******************************************************************************************/ int do_on_identify(User *u) { if (!nick_identified(u)) { return MOD_STOP; } do_ajoin(u); set_swhois(u); set_helpop(u); return MOD_CONT; } /******************************************************************************************/ int do_update(User *u) { do_ajoin(u); set_swhois(u); set_helpop(u); return MOD_CONT; }; /******************************************************************************************/ int do_set_ajoin(User *u, char *param) { char to_open[10]; FILE *add; to_open[0] = '\0'; line[0] = '\0'; if(strlen(param)>511) { notice(s_NickServ, u->nick, NICK_NOT_MAX_AJOIN); return MOD_CONT; } if(isalpha(u->nick[0])) { strcat(to_open, "ajoin_X.db"); to_open[6] = tolower(u->nick[0]); } else strcat(to_open, "ajoin_0.db"); if(stricmp(param,"off") == 0) { rem_u_nick(to_open, u->nick, 1); notice(s_NickServ, u->nick, NICK_NOT_EMPTY_AJOINLIST); } else { if(exists_nick(to_open, u->nick,1)==1) rem_u_nick(to_open, u->nick, 1); add = fopen(to_open,"a"); if(add != NULL) { fprintf(add, "%s %s\n", u->nick, param); notice(s_NickServ, u->nick, NICK_SHOW_AJOIN_NEW ,param); fclose(add); } } return MOD_CONT; } /******************************************************************************************/ /* lists the ajoin chans */ int ajoin_list(User *u) { char *chans, to_open[10]; FILE *ajoin; line[0] = '\0'; to_open[0] = '\0'; if (!nick_identified(u)) { notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ); return MOD_CONT; } if(isalpha(u->nick[0])) { strcat(to_open, "ajoin_X.db"); to_open[6] = tolower(u->nick[0]); } else strcat(to_open, "ajoin_0.db"); if(exists_nick(to_open, u->nick, 1)==1) { ajoin = fopen(to_open, "r"); while(!feof(ajoin)) { fgets(line, sizeof(line), ajoin); if(feof(ajoin)) break; if(line[strlen(u->nick)] == ' ' && !strnicmp(line,u->nick,strlen(u->nick))) { strtok(line," "); chans = strtok(NULL,"\n"); notice(s_NickServ, u->nick, NICK_SHOW_AJOIN, chans); return MOD_CONT; } } } notice(s_NickServ, u->nick, NICK_NOT_NOAJOIN); return MOD_CONT; } /***********************************************************************/ /* checks if a user has autojoin chans and joins him */ int do_ajoin(User *u) { char to_open[10], *chans, *user; FILE *ajoin; to_open[0] = '\0'; if (!nick_identified(u)) { return MOD_CONT; } if(isalpha(u->nick[0])) { strcat(to_open, "ajoin_X.db"); to_open[6] = tolower(u->nick[0]); } else strcat(to_open, "ajoin_0.db"); ajoin = fopen(to_open,"r"); if(ajoin != NULL) { while(!feof(ajoin)) { if(feof(ajoin)) break; fgets(line,sizeof(line), ajoin); if(line[strlen(u->nick)] == ' ' && !strnicmp(line,u->nick,strlen(u->nick))) { user = strtok(line," "); chans = strtok(NULL,"\n"); send_cmd(s_OperServ, "SVSJOIN %s :%s", user, chans); if (!exists_nick("silence.db",u->nick, 0)) notice(s_NickServ, u->nick, NICK_NOT_AJOIN, chans); fclose(ajoin); return MOD_CONT; } } fclose(ajoin); } return MOD_CONT; } /************************************************************************/ /* sets, views and changes swhois settings */ int do_swhois(User *u) { char *option = strtok(NULL, " "); char *par1 = strtok(NULL, " "); char *par2 = strtok(NULL, ""); if(!option) { swhois_syntax(u); } else if (stricmp(option, "ADD") == 0 && par1 && par2) { swhois_add(u, par1, par2); } else if (stricmp(option, "DEL") == 0 && par1 && !par2) { swhois_del(u, par1); } else if (stricmp(option, "LIST") == 0) { if (!par1) { swhois_list(u, "%"); } else if (par1 && !par2) { swhois_list(u, par1); } else swhois_syntax(u); } else { swhois_syntax(u); } return MOD_CONT; } /*************************************************************************/ /* set a swhois */ int set_swhois(User *u) { if (!nick_identified(u)) { return MOD_CONT; } if(exists_nick("swhois.db",u->nick,1)==1) { send_cmd(s_OperServ, "SWHOIS %s", line); if (!exists_nick("silence.db",u->nick, 0)) notice(s_NickServ, u->nick, NICK_NOT_SWHOIS); } return MOD_CONT; } /***************************************************************************/ /* adds a swhois */ int swhois_add(User *u, char *nick, char *whois) { FILE *swhois; if(strlen(whois)>280) notice(s_NickServ, u->nick, "The swhois is too long. The max. length is 280 chars"); else { if(exists(u, "swhois.db", nick, 1)==1) rem_u(u, "swhois.db", nick, 1); swhois = fopen("swhois.db","a"); if(swhois != NULL) { fprintf(swhois, "%s :%s\n", nick, whois); notice(s_OperServ, u->nick, "%s has been added to the swhois list", nick); fclose(swhois); } else notice(s_OperServ, u->nick, "An error occured while opening swhois.db"); } return MOD_CONT; } /*************************************************************************/ /* deletes a swhois */ int swhois_del(User *u, char *nick) { if(exists(u,"swhois.db", nick, 1)==1) { rem_u(u, "swhois.db", nick, 1); notice(s_OperServ, u->nick, "The user %s has been successfully deleted", nick); } else notice(s_OperServ, u->nick, "The user %s doesn't exist in the swhois db", nick); return MOD_CONT; } /*************************************************************************/ /* lists all swhois entrys or the swhois of one user */ int swhois_list(User *u, char *nick) { char line[300]; int i = 0; FILE *swhois; line[0] = '\0'; if(nick[0] == '%') { swhois = fopen("swhois.db","r"); if(swhois != NULL) { while(!feof(swhois)) { fgets(line, sizeof(line), swhois); if(feof(swhois)) break; if(line[0] != '\n') { notice(s_OperServ, u->nick, "%d: %s", ++i, line); } } if(i == 0) notice(s_OperServ, u->nick, "there are no swhois entries"); } else notice(s_OperServ, u->nick, "An error occured while opening the swhois db"); } else { if(exists(u, "swhois.db", nick, 1)==1) { swhois = fopen("swhois.db","r"); if(swhois != NULL) { while(!feof(swhois)) { fgets(line, sizeof(line), swhois); if(feof(swhois)) break; if(line[strlen(nick)] == ' ' && !strnicmp(line,nick,strlen(nick))) { notice(s_OperServ, u->nick, "%s", line); break; } } } } else notice(s_OperServ, u->nick, "The user %s is not in the swhois db", nick); } return MOD_CONT; } /*************************************************************************/ /* sets, views and changes helpop settings */ int do_helpop(User *u) { char *option = strtok(NULL, " "); char *par1 = strtok(NULL," "); char *par2 = strtok(NULL," "); if(!option) { helpop_syntax(u); } else if (stricmp(option, "ADD") == 0 && par1 && par2) { helpop_add(u, par1, par2); } else if (stricmp(option, "DEL") == 0 && par1 && !par2) { helpop_del(u, par1); } else if (stricmp(option, "LIST") == 0) { if (!par1) { helpop_list(u, "%"); } else if (par1 && !par2) { helpop_list(u, par1); } else helpop_syntax(u); } else { helpop_syntax(u); } return MOD_CONT; } /************************************************************************/ /* adds a helpop */ int helpop_add(User *u, char *nick, char *helpop) { FILE *hop; if(exists(u, "hop.db", nick, 1)==1) rem_u(u, "hop.db", nick, 1); hop = fopen("hop.db","a"); if(hop != NULL) { fprintf(hop, "%s :%s\n", nick, helpop); notice(s_OperServ, u->nick, "%s has been added to the helpop list, modes %s", nick, helpop); fclose(hop); } else notice(s_OperServ, u->nick, "An error occured while opening hop.db"); return MOD_CONT; } /************************************************************************/ /* deletes a helpop */ int helpop_del(User *u, char *nick) { if(exists(u,"hop.db", nick, 1)==1) { rem_u(u, "hop.db", nick, 1); notice(s_OperServ, u->nick, "The user %s has been successfully deleted", nick); } else notice(s_OperServ, u->nick, "The user %s doesn't exist in the helpop db", nick); return MOD_CONT; } /************************************************************************/ /* lists all helpop entrys or the helpop modes of one user */ int helpop_list(User *u, char *nick) { char line[300]; int i = 0; FILE *hop; line[0] = '\0'; if(nick[0] == '%') { hop = fopen("hop.db","r"); if(hop != NULL) { while(!feof(hop)) { fgets(line, sizeof(line), hop); if(feof(hop)) break; if(line[0] != '\n') { notice(s_OperServ, u->nick, "%d: %s", ++i, line); } } if(i == 0) notice(s_OperServ, u->nick, "there are no helpop entries"); } else notice(s_OperServ, u->nick, "An error occured while opening the helpop db"); } else { if(exists(u, "hop.db", nick, 1)==1) { hop = fopen("hop.db","r"); if(hop != NULL) { while(!feof(hop)) { fgets(line, sizeof(line), hop); if(feof(hop)) break; if(line[strlen(nick)] == ' ' && !strnicmp(line,nick,strlen(nick))) { notice(s_OperServ, u->nick, "%s", line); break; } } } } else notice(s_OperServ, u->nick, "The user %s is not in the helpop db", nick); } return MOD_CONT; } /************************************************************************************/ int set_helpop(User *u) { if (!nick_identified(u)) { return MOD_CONT; } if(exists_nick("hop.db",u->nick, 1)==1) { send_cmd(s_OperServ,"SVS2MODE %s", line); if (!exists_nick("silence.db",u->nick, 0)) notice(s_NickServ, u->nick, NICK_NOT_HELPOP); } return MOD_CONT; } /***************************************************************************************/ /***************************************************************************************/ /* checks if a nick exists in a file */ int exists_nick(char *file, char *name, int format) { FILE *op; line[0] = '\0'; if((op = fopen(file, "r"))==NULL) return 0; while(!feof(op)) { fgets(line,sizeof(line),op); if(feof(op)) break; if(format==1) { if(line[strlen(name)] == ' ' && !strnicmp(line,name,strlen(name))) { fclose(op); return 1; } } else { if(line[strlen(name)] == '\n' && !strnicmp(line,name,strlen(name))) { fclose(op); return 1; } } } fclose(op); return 0; } /**********************************************************************************************/ /* removes a user from database */ void rem_u_nick(char *file, char *nic, int form) { FILE *edit, *dummy; line[0] = '\0'; edit = fopen(file, "r"); dummy = fopen("dummy.db","w"); if(edit != NULL && dummy != NULL) { while(!feof(edit)) { fgets(line, sizeof(line), edit); if(feof(edit)) break; if(form == 1) { if((line[strlen(nic)] == ' ' && !strnicmp(line,nic,strlen(nic))) || line[0] == '\n') { continue; } else { fputs(line,dummy); } } else { if(!strnicmp(line,nic,strlen(nic)) || line[0] == '\n') { continue; } else { fputs(line,dummy); } } } fclose(edit); fclose(dummy); rename("dummy.db",file); } } /*************************************************************************/ /* checks if a user exists in a file */ int exists(User *u, char *file, char *nick, int format) { int i; char line[1000]; FILE *op; line[0] = '\0'; for(i=0; inick); i++) u->nick[i] = tolower(u->nick[i]); edit = fopen(file, "r"); dummy = fopen("dummy.db","w"); if(edit != NULL && dummy != NULL) { while(!feof(edit)) { fgets(line, sizeof(line), edit); if(feof(edit)) break; if(form == 1) { if((line[strlen(user)] == ' ' && !strnicmp(line,user,strlen(user))) || line[0] == '\n') { continue; } else { fputs(line,dummy); } } else { if(!strnicmp(line,user,strlen(user)) || line[0] == '\n') { continue; } else { fputs(line,dummy); } } } fclose(edit); fclose(dummy); rename("dummy.db",file); } } /*************************************************************************/ /* END of module */