/Modules/m_delayjoin.c
C | 271 lines | 163 code | 28 blank | 80 comment | 26 complexity | 74203f39f2c90ae8c005cd84ab800902 MD5 | raw file
- /*
- * ==================================================================
- * Module: m_delayjoin.c
- * Author: Stealth <stealth@x-tab.org>
- * Version: 2.0.2
- * License: GNU Afferro General Public Licnese
- * Description: Requires clients to be connected for a certain amount
- * of time before allowing them to join any channels.
- * ==================================================================
- * Copyright (C) 2012 "Stealth" <stealth@x-tab.org>
- *
- * This license grants permission to freely use, modify, and
- * distribute this module with the following conditions:
- * - You must keep this module licensed with the GNU Affero General
- * Public Licnese, either version 3 or newer.
- * - This copyright notice must stay intact.
- * - You must provide the module source (incluing any modifications)
- * upon request to anyone who wishes to see it.
- * Please see the GNU AGPL text for full details (link below).
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * The full version of the GNU AGPL license may be found at
- * http://www.gnu.org/licenses/agpl.html
- */
- /*
- * Configuration:
- *
- * There are 2 directives that need to be set in your unrealircd.conf file:
- *
- * set::delayjoin::time
- * This should be set to the time users will be unable to join channels after
- * connecting to your server. The default is in seconds, unless you specify
- * otherwise. The time value should be formatted the same as a G:Line.
- *
- * set::delayjoin::reason
- * This is what will be displayed to users when they attempt to join a
- * channel. The reason will be prefixed with "Cannot join #Channel:". It would
- * probably be helpful to your users if you put the time you set in this
- * reason.
- *
- *
- * ChangeLog:
- * 1/8/2012 - 2.0.2
- * - Changed license to GNU AGPL
- *
- * 12/31/2011 - 2.0.1
- * - Don't remember when/why I made the module 2.0.1, but I did...
- * - Fix whitespaces in docs/changelog. Everything is now consistent.
- *
- * 12/19/2007 - 2.0.0
- * - Changed module from using Command Override to hooking pre_local_join
- * - Added configuration
- * - Thanks to fez for helping with set::auto-join issues
- *
- * 12/18/2007 - 0.0.1
- * -Initial version (built off of delaylist by w00t <surreal.w00t@gmail.com>)
- *
- *
- *
- * Credits:
- * - w00t <surreal.w00t@gmail.com>
- * Initial version was built off of DelayList.
- *
- * - Syzop <syzop@vulnscan.org>
- * Configuration stuff was borrowed from the antirandom module
- *
- * - DukePyrolator <DukePyrolator@FantasyIRC.net>
- * Guide for hooking pre_local_join in m_onlyopersjoin
- *
- * - fez <wrongway.org>
- * Hours of debugging and putting up with my n00bness :P
- */
- #include "config.h"
- #include "struct.h"
- #include "common.h"
- #include "sys.h"
- #include "numeric.h"
- #include "msg.h"
- #include "channel.h"
- #include <time.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #ifdef _WIN32
- #include <io.h>
- #endif
- #include <fcntl.h>
- #include "h.h"
- #include "proto.h"
- #ifdef STRIPBADWORDS
- #include "badwords.h"
- #endif
- #ifdef _WIN32
- #include "version.h"
- #endif
- struct {
- int reason;
- int time;
- } req;
- struct {
- char *reason;
- long time;
- } cfg;
- static Cmdoverride *delayjoin_override = NULL;
- static ModuleInfo *delayjoin_modinfo = NULL;
- static void free_config(void);
- #define DelHook(x) if (x) HookDel(x); x = NULL
- Hook *HookJoin = NULL;
- DLLFUNC int delayjoin_config_test(ConfigFile *, ConfigEntry *, int, int *);
- DLLFUNC int delayjoin_config_run(ConfigFile *, ConfigEntry *, int);
- DLLFUNC int delayjoin_config_posttest(int *);
- DLLFUNC int m_delayjoin(aClient *sptr, aChannel *chptr, char *parv[]);
- ModuleHeader MOD_HEADER(delayjoin)
- = {
- "delayjoin", /* Name */
- "2.0.2", /* Ver */
- "Deny /join for newly connected users by Stealth <stealth@x-tab.org>", /* Desc. */
- "3.2-b8-1",
- NULL
- };
- DLLFUNC int MOD_TEST(delayjoin)(ModuleInfo *modinfo)
- {
- memset(&req, 0, sizeof(req));
- memset(&cfg, 0, sizeof(cfg));
- HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, delayjoin_config_test);
- HookAddEx(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, delayjoin_config_posttest);
- return MOD_SUCCESS;
- }
- DLLFUNC int MOD_INIT(delayjoin)(ModuleInfo *modinfo)
- {
- delayjoin_modinfo = modinfo;
- HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, delayjoin_config_run);
- HookJoin = HookAddEx(modinfo->handle, HOOKTYPE_PRE_LOCAL_JOIN, m_delayjoin);
- return MOD_SUCCESS;
- }
- DLLFUNC int MOD_LOAD(delayjoin)(int module_load)
- {
- return MOD_SUCCESS;
- }
- DLLFUNC int MOD_UNLOAD(delayjoin)(int module_unload)
- {
- DelHook(HookJoin);
- free_config();
- return MOD_SUCCESS;
- }
- static void free_config(void)
- {
- if (cfg.reason)
- MyFree(cfg.reason);
- memset(&cfg, 0, sizeof(cfg)); /* needed! */
- }
- DLLFUNC int delayjoin_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
- {
- int errors = 0;
- ConfigEntry *cep;
- if (type != CONFIG_SET)
- return 0;
- /* We are only interrested in set::delayjoin... */
- if (!ce || !ce->ce_varname || strcmp(ce->ce_varname, "delayjoin"))
- return 0;
- for (cep = ce->ce_entries; cep; cep = cep->ce_next)
- {
- if (!cep->ce_varname)
- {
- config_error("%s:%i: blank set::delayjoin item",
- cep->ce_fileptr->cf_filename, cep->ce_varlinenum);
- errors++;
- } else
- if (!cep->ce_vardata)
- {
- config_error("%s:%i: set::delayjoin::%s with no value",
- cep->ce_fileptr->cf_filename, cep->ce_varlinenum, cep->ce_varname);
- errors++;
- } else
- if (!strcmp(cep->ce_varname, "reason"))
- {
- req.reason = 1;
- } else
- if (!strcmp(cep->ce_varname, "time"))
- {
- req.time = 1;
- } else
- {
- config_error("%s:%i: unknown directive set::delayjoin::%s",
- cep->ce_fileptr->cf_filename, cep->ce_varlinenum, cep->ce_varname);
- errors++;
- }
- }
- *errs = errors;
- return errors ? -1 : 1;
- }
- DLLFUNC int delayjoin_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
- {
- ConfigEntry *cep, *cep2;
- if (type != CONFIG_SET)
- return 0;
- /* We are only interrested in set::delayjoin... */
- if (!ce || !ce->ce_varname || strcmp(ce->ce_varname, "delayjoin"))
- return 0;
- for (cep = ce->ce_entries; cep; cep = cep->ce_next)
- {
- if (!strcmp(cep->ce_varname, "reason"))
- {
- if (cfg.reason)
- MyFree(cfg.reason);
- cfg.reason = strdup(cep->ce_vardata);
- } else
- if (!strcmp(cep->ce_varname, "time"))
- {
- cfg.time = config_checkval(cep->ce_vardata, CFG_TIME);
- }
- }
- return 1;
- }
- DLLFUNC int delayjoin_config_posttest(int *errs)
- {
- int errors = 0;
- if (!req.time) { config_error("set::delayjoin::time missing"); errors++; }
- if (!req.reason) { config_error("set::delayjoin::reason missing"); errors++; }
- *errs = errors;
- return errors ? -1 : 1;
- }
- DLLFUNC int m_delayjoin(aClient *sptr, aChannel *chptr, char *parv[])
- {
- if (is_autojoin_chan(chptr->chname))
- return HOOK_CONTINUE;
- if (!IsAnOper(sptr))
- {
- if ((TStime() - sptr->firsttime) < cfg.time)
- {
- /* DENIED! */
- sendto_one(sptr, ":%s %s %s :*** Cannot join %s: %s", me.name, IsWebTV(sptr) ? "PRIVMSG" : "NOTICE", sptr->name, chptr->chname, cfg.reason);
- return HOOK_DENY;
- }
- }
- /* aww, no fun. they've been connected a while :( - let it through */
- return HOOK_CONTINUE;
- }