/* ********************************************************************* * ** *** Released from : C-IRC Modules **** Description : Delays the joining process till the given time is up **** Written by : srcmaster *** Web page : http://www.crypthon.org ** * ** Changes: * ** 1.0 * - Initial release ** 1.1 * - Fixed potential crashes on join and quit * - [REQUEST] Nick changes are not permitted anymore (while users in delay) * * ** Configuration line: set { join-delay 5s; }; * ********************************************************************* */ #include "config.h" #include "struct.h" #include "common.h" #include "sys.h" #include "numeric.h" #include "msg.h" #include "proto.h" #include "channel.h" #include #include #include #include #include #ifdef _WIN32 #include #endif #include #include "h.h" #ifdef STRIPBADWORDS #include "badwords.h" #endif #ifdef _WIN32 #include "version.h" #endif #define J(x) auser[x->slot] typedef struct _JEvent { Event *event; } JEvent; static JEvent *auser[4096]; static Hook *JH, *PCH, *QH = NULL; ModuleInfo joindelay; DLLFUNC int joindelay_ct(ConfigFile *, ConfigEntry *, int, int *); DLLFUNC int joindelay_cr(ConfigFile *, ConfigEntry *, int); DLLFUNC int joindelay_cpt(int *); DLLFUNC int nickreover(); DLLFUNC int nickover(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]); static int ptime = 0; static int pre_connect_h(aClient *); static int quit_h(aClient *, char *); static int join_h(aClient *, aChannel *, char *[]); static void join_stuff(aClient *); ModuleHeader MOD_HEADER(joindelay) = { "joindelay", "$Id: m_joindelay.c,v 1.1 2011/03/17 00:42:25 srcmaster Exp $", "Adds a delay to the join command by srcmaster", "3.2-b8-1", NULL }; ModuleInfo joindelay; DLLFUNC int MOD_TEST(joindelay)(ModuleInfo *module) { bcopy(module, &joindelay, module->size); HookAddEx(joindelay.handle, HOOKTYPE_CONFIGTEST, joindelay_ct); HookAddEx(joindelay.handle, HOOKTYPE_CONFIGPOSTTEST, joindelay_cpt); return MOD_SUCCESS; } DLLFUNC int MOD_INIT(joindelay)(ModuleInfo *module) { ModuleSetOptions(joindelay.handle, MOD_OPT_PERM); JH = HookAddEx(joindelay.handle, HOOKTYPE_PRE_LOCAL_JOIN, join_h); PCH = HookAddEx(joindelay.handle, HOOKTYPE_PRE_LOCAL_CONNECT, pre_connect_h); QH = HookAddEx(joindelay.handle, HOOKTYPE_LOCAL_QUIT, quit_h); HookAddEx(joindelay.handle, HOOKTYPE_CONFIGRUN, joindelay_cr); HookAddEx(joindelay.handle, HOOKTYPE_REHASH_COMPLETE, nickreover); if (!JH || !PCH || !QH) return MOD_FAILED; return MOD_SUCCESS; } DLLFUNC int MOD_LOAD(joindelay)(int module_load) { CmdoverrideAdd(joindelay.handle, "NICK", nickover); return MOD_SUCCESS; } DLLFUNC int MOD_UNLOAD(joindelay)(int module_unload) { HookDel(JH); HookDel(PCH); HookDel(QH); return MOD_SUCCESS; } DLLFUNC int nickreover() { CmdoverrideAdd(joindelay.handle, "NICK", nickover); return 1; } DLLFUNC int joindelay_ct(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { int errors = 0; if (type != CONFIG_SET) return 0; if (!strcmp(ce->ce_varname, "join-delay")) { if (!ce->ce_vardata) { config_error("Make sure you have the join-delay set!"); errors++; } ptime = 1; // i know, i know... *errs = errors; return errors ? -1 : 1; } else return 0; } DLLFUNC int joindelay_cr(ConfigFile *cf, ConfigEntry *ce, int type) { if (type != CONFIG_SET) return 0; if (!strcmp(ce->ce_varname, "join-delay")) { ptime = config_checkval(ce->ce_vardata, CFG_TIME); return 1; } else return 0; } DLLFUNC int joindelay_cpt(int *errs) { int errors = 0; if (!ptime) { config_error("Make sure you have the join-delay set!"); errors++; } *errs = errors; return errors ? -1 : 1; } static int join_h(aClient *cptr, aChannel *chptr, char *parv[]) { if (J(cptr) && !IsAnOper(cptr) && (TStime() - cptr->firsttime) < ptime) return HOOK_DENY; return HOOK_CONTINUE; } static void join_stuff(aClient *cptr) { if (IsAnOper(cptr)) return; if (!BadPtr(AUTO_JOIN_CHANS) && strcmp(AUTO_JOIN_CHANS, "0")) { char *chans[3] = { cptr->name, AUTO_JOIN_CHANS, NULL }; do_cmd(cptr, cptr, "JOIN", 3, chans); } } static int pre_connect_h(aClient *cptr) { if (MyConnect(cptr)) { J(cptr) = MyMallocEx(sizeof(JEvent)); J(cptr)->event = EventAddEx(joindelay.handle, "join-stuff", ptime, 1, join_stuff, cptr); } return HOOK_CONTINUE; } static int quit_h(aClient *cptr, char *comment) { if (MyConnect(cptr)) { if (J(cptr)) { EventDel(J(cptr)->event); memset(J(cptr), 0, sizeof(JEvent)); MyFree(J(cptr)); J(cptr) = NULL; } } return 0; } DLLFUNC int nickover(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]) { if (MyConnect(sptr)) { if (J(cptr) && !IsAnOper(cptr) && (TStime() - cptr->firsttime) < ptime) return 0; } if (ovr->prev) return ovr->prev->func(ovr->prev, cptr, sptr, parc, parv); else return ovr->command->func(cptr, sptr, parc, parv); }