#include "module.h" #define AUTHOR "SGR" #define VERSION "1.10" /* ----------------------------------------------------------- * Name: cs_forbidunregistered * Author: SGR * Date: 21/10/2003 * ----------------------------------------------------------- * Functions: m_cs_forbidunreg, do_autoassign * Limitations: does not yet "FORBID" the chan, anope-dev r50 * and later only * Tested: Ultimate(2.8.x), Unreal(3.2), Viagra. * ----------------------------------------------------------- * This modules has 6 configurable options. * * This module will prevent normal users making any channels * that are not registered with ChanServ. [Join, remove * exempts then kick+ban all non-opers from any non ChanServ * registered channel as they join] * * Thanks to dengel, Rob and Certus for all there support. * ----------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ /* START OF CONFIGURATION BLOCK - please read the comments :) */ /* ---------------------------------------------------------------------- */ /* * !!! ONLY CHANGE WHAT IS INSIDE THE "SPEACH MARKS" !!!! */ #define ForbidUnregisteredMsg1 "You cannot create new channels on this network, without" #define ForbidUnregisteredMsg2 "being IDENTIFIED to %s. Please identify or join", s_NickServ #define ForbidUnregisteredMsg3 "a channel that is already registered with %s", s_ChanServ //#define ForbidUnregisteredMsg4 " " //#define ForbidUnregisteredMsg5 "Mooo" #define ForbidUnregKICKREASON "You may not create new channels." /* set this to a reasonable time, between 3 and 30 seconds */ #define Mod_TIME_TO_INHABIT "5s" /* ---------------------------------------------------------------------- */ /* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ /* ---------------------------------------------------------------------- */ int m_cs_forbidunreg(char *source, int ac, char **av); int m_cs_set_forbidunreg(User *u); void SGR_Module_Help_CHANSERV_FORBIDUNREG(User *u); int SGR_Module_Help_CHANSERV_FORBIDUNREG_FULL(User *u); int forbid_unreg_on=1; int LOGForbidUnreg =2; int m_cs_forbidleavechan(int argc, char **argv); #if !defined(IRC_BAHAMUT) && !defined(IRC_HYBRID) && !defined(IRC_PTLINK) int m_cs_forbidunreg_modesilence(char *source, int ac, char **av); char *LASTBANCHAN; #else static char csmodes[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #if defined(IRC_HYBRID) 'a', /* (33) ! Channel Admins */ #else 0, #endif 0, 0, 0, 0, 0, 0, 0, 0, 0, 'v', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'o' , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; #endif int AnopeInit(int argc, char **argv) { Command *c; Message *msg = NULL; alog("Loading module cs_forbidunreg.so"); c = createCommand("FORBIDUNREG",m_cs_set_forbidunreg,is_services_admin,-1,-1,-1,-1,-1); moduleAddCommand(CHANSERV, c, MOD_HEAD); moduleAddHelp(c,SGR_Module_Help_CHANSERV_FORBIDUNREG_FULL); moduleSetChanHelp(SGR_Module_Help_CHANSERV_FORBIDUNREG); msg = createMessage("JOIN", m_cs_forbidunreg); moduleAddMessage(msg, MOD_TAIL); msg = createMessage("SJOIN", m_cs_forbidunreg); moduleAddMessage(msg, MOD_TAIL); #if !defined(IRC_BAHAMUT) && !defined(IRC_HYBRID) && !defined(IRC_PTLINK) msg = createMessage("MODE", m_cs_forbidunreg_modesilence); moduleAddMessage(msg, MOD_HEAD); #endif forbid_unreg_on = 1; alog("[cs_forbidunreg] For more info see /msg %s HELP FORBIDUNREG", s_ChanServ); alog("[cs_forbidunreg] Yayness!(tm) - MODULE LOADED AND ACTIVE"); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); return MOD_CONT; } void AnopeFini(void) { alog("Unloading module cs_forbidunreg.so"); #if !defined(IRC_BAHAMUT) && !defined(IRC_HYBRID) && !defined(IRC_PTLINK) if (LASTBANCHAN != NULL) { free(LASTBANCHAN); } #endif } void SGR_Module_Help_CHANSERV_FORBIDUNREG(User *u) { if (is_services_admin(u)) { notice(s_ChanServ,u->nick, " FORBIDUNREG Forbid unregistered users making channels."); } return; } int SGR_Module_Help_CHANSERV_FORBIDUNREG_FULL(User *u) { if (is_services_admin(u)) { notice(s_ChanServ,u->nick, " "); notice(s_ChanServ,u->nick, "Syntax: FORBIDUNREG [ON|OFF|REGONLY]"); notice(s_ChanServ,u->nick, " "); notice(s_ChanServ,u->nick, "Use this command without any parameters to setting to see the"); notice(s_ChanServ,u->nick, "current setting. When set to ON, %s will forbid a user joining", s_ChanServ); notice(s_ChanServ,u->nick, "any channels that are not registered. When set to REGONLY, only"); notice(s_ChanServ,u->nick, "users not identifed to a %s registered nick will be prevented", s_NickServ); notice(s_ChanServ,u->nick, "from making new channels. Opers and above are not affected."); notice(s_ChanServ,u->nick, " "); } return MOD_CONT; } int m_cs_set_forbidunreg(User *u) { char *seton = strtok(NULL, " "); if (!seton) { if (forbid_unreg_on) { notice(s_ChanServ,u->nick, "The current FORBIDUNREG setting is ON"); } else { notice(s_ChanServ,u->nick, "The current FORBIDUNREG setting is OFF"); } return MOD_CONT; } if (stricmp(seton,"ON") == 0 ) { notice(s_ChanServ,u->nick, "The current FORBIDUNREG setting is ON"); wallops(s_ChanServ, "%s set FORBIDUNREG on.", u->nick); forbid_unreg_on = 1; return MOD_CONT; } if (stricmp(seton,"OFF") == 0 ) { notice(s_ChanServ,u->nick, "The current FORBIDUNREG setting is OFF"); wallops(s_ChanServ, "%s set FORBIDUNREG off.", u->nick); forbid_unreg_on = 0; return MOD_CONT; } else { notice(s_ChanServ, u->nick, "SYNTAX: FORBIDUNREG [on|off]"); return MOD_CONT; } return MOD_CONT; } int m_cs_forbidunreg(char *source, int ac, char **av) { ChannelInfo *ci; Channel *c; User *u = NULL; char *argv[1]; if (!forbid_unreg_on) { return MOD_CONT; } if ((!source) || (ac < 1) || (!av[1]) #if defined(IRC_BAHAMUT) || defined(IRC_HYBRID) || defined(IRC_PTLINK) || (!av[3]) #endif ) { return MOD_CONT; } if (!stristr(av[1],"#")) { return MOD_CONT; } #if defined(IRC_BAHAMUT) || defined(IRC_HYBRID) || defined(IRC_PTLINK) if (ac >= 4 && ac <= 6) { char *s, *end, cubuf[CHAN_MAX_SYMBOLS + 2], *end2, *cumodes[CHAN_MAX_SYMBOLS + 1]; cubuf[0] = '+'; cumodes[0] = cubuf; s = av[ac - 1]; while (*s) { end = strchr(s, ' '); if (end) { *end = 0; } end2 = cubuf + 1; while (csmodes[(int) *s] != 0) { *end2++ = csmodes[(int) *s++]; } *end2 = 0; *s++; u = finduser(s); if (!end) { break; } s = end + 1; } if (!(u = finduser(s))) { return MOD_CONT; } } #else if (!(u = finduser(source))) { return MOD_CONT; } #endif if ((ci = cs_findchan(av[1]))) { return MOD_CONT; } c = findchan(av[1]); if (!c) { return MOD_CONT; } if ((is_oper(u) || nick_identified(u)) || (c->usercount > 1)) { return MOD_CONT; } else { char fcounter[CHANMAX+7], *am[3]; struct c_userlist *cu, *next; #if defined(IRC_ULTIMATE) || defined(IRC_UNREAL) || defined(IRC_ULTIMATE3) || defined(IRC_HYBRID) int i = 0; int count = c->exceptcount; char **excepts = scalloc(sizeof(char *) * count, 1); char *an[3]; #endif #if !defined(IRC_BAHAMUT) && !defined(IRC_HYBRID) && !defined(IRC_PTLINK) LASTBANCHAN = av[0]; #elif defined(IRC_BAHAMUT) && defined(IRC_HYBRID) && defined(IRC_PTLINK) send_cmd(NULL, "SJOIN %ld %s + :@%s", (c ? c->creation_time : time(NULL)), av[1], s_ChanServ); #else send_cmd(s_ChanServ, "JOIN %s", av[0]); #endif send_cmd(whosends(ci), "MODE %s +o %s %lu", av[0], s_ChanServ, time(NULL)); send_cmd(whosends(ci), "MODE %s +b *!*@* %lu", av[0], time(NULL)); #if defined(IRC_ULTIMATE) || defined(IRC_UNREAL) || defined(IRC_ULTIMATE3) || defined(IRC_HYBRID) for (i = 0; i < count; i++) { excepts[i] = sstrdup(c->excepts[i]); } for (i = 0; i < count; i++) { an[0] = sstrdup(av[0]); an[1] = sstrdup("-e"); an[2] = excepts[i]; send_cmd(whosends(ci), "MODE %s %s :%s", an[0], an[1], an[2]); do_cmode(s_ChanServ, 3, an); free(an[2]); free(an[1]); free(an[0]); } free(excepts); #endif for (cu = c->users; cu; cu = next) { next = cu->next; if (is_oper(cu->user)) { continue; } am[0] = c->name; am[1] = cu->user->nick; #ifdef ForbidUnregKICKREASON am[2] = ForbidUnregKICKREASON; #else am[2] = "Only registered channels may be used."; #endif send_cmd(s_ChanServ, "KICK %s %s :%s", am[0], am[1], am[2]); do_kick(s_ChanServ, 3, am); #ifdef ForbidUnregisteredMsg1 notice(s_ChanServ, cu->user->nick, ForbidUnregisteredMsg1); #endif #ifdef ForbidUnregisteredMsg2 notice(s_ChanServ, cu->user->nick ,ForbidUnregisteredMsg2); #endif #ifdef ForbidUnregisteredMsg3 notice(s_ChanServ, cu->user->nick, ForbidUnregisteredMsg3); #endif #ifdef ForbidUnregisteredMsg4 notice(s_ChanServ, cu->user->nick, ForbidUnregisteredMsg4); #endif #ifdef ForbidUnregisteredMsg5 notice(s_ChanServ, cu->user->nick, ForbidUnregisteredMsg5); #endif } argv[0] = sstrdup(av[0]); snprintf(fcounter,CHANMAX+7,"%s-forbid",av[0]); if (moduleAddCallback(fcounter, time(NULL)+dotime(Mod_TIME_TO_INHABIT), m_cs_forbidleavechan,1,argv) != MOD_ERR_OK) { send_cmd(s_ChanServ, "PART %s", av[0]); } if (argv[0] != NULL) { free(argv[0]); } return MOD_CONT; } return MOD_CONT; } int m_cs_forbidleavechan(int argc, char **argv) { char *chan = argv[0]; send_cmd(s_ChanServ, "PART %s", chan); return MOD_CONT; } #if !defined(IRC_BAHAMUT) && !defined(IRC_HYBRID) && !defined(IRC_PTLINK) int m_cs_forbidunreg_modesilence(char *source, int ac, char **av) { if (*av[0] == '#' || *av[0] == '&') { if (ac < 2) { return MOD_CONT; } if (av[0] ==LASTBANCHAN) { LASTBANCHAN = "non"; return MOD_STOP; } } else { return MOD_CONT; } return MOD_CONT; } #endif