Debian Codegraph @

modules/contrib/src/ns_waitreg.c

raw
1 /*
2 * Copyright (c) 2010 William Pitcock <[email protected]>
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for delaying user registration
6 */
7
8 #include "atheme-compat.h"
9
10 #if (CURRENT_ABI_REVISION < 730000)
11 # include "conf.h"
12 #endif
13
14 #include <limits.h>
15
16 unsigned int waitreg_time = 0;
17
18 static void
19 waitreg_hook(hook_user_register_check_t *hdata)
20 {
21 return_if_fail(hdata != NULL);
22 return_if_fail(hdata->si != NULL);
23 return_if_fail(hdata->password != NULL);
24
25 if (hdata->si->su == NULL)
26 return;
27
28 if (hdata->si->su->ts >= CURRTIME - waitreg_time)
29 {
30 command_fail(hdata->si, fault_badparams, _("You can not register your nick so soon after connecting. Please wait a while and try again."));
31 hdata->approved++;
32 }
33 }
34
35 static void
36 info_hook(sourceinfo_t *si)
37 {
38 return_if_fail(si != NULL);
39
40 command_success_nodata(si, "Time (in seconds) before users may register an account: %u", waitreg_time);
41 }
42
43 static void
44 mod_init(module_t *m)
45 {
46 MODULE_CONFLICT(m, "nickserv/waitreg");
47
48 hook_add_event("user_can_register");
49 hook_add_user_can_register(waitreg_hook);
50
51 hook_add_event("operserv_info");
52 hook_add_operserv_info(info_hook);
53
54 add_uint_conf_item("WAITREG_TIME", &nicksvs.me->conf_table, 0, &waitreg_time, 0, INT_MAX, 0);
55 }
56
57 static void
58 mod_deinit(module_unload_intent_t intent)
59 {
60 hook_del_user_can_register(waitreg_hook);
61 hook_del_operserv_info(info_hook);
62
63 del_conf_item("WAITREG_TIME", &nicksvs.me->conf_table);
64 }
65
66 SIMPLE_DECLARE_MODULE_V1("contrib/ns_waitreg", MODULE_UNLOAD_CAPABILITY_OK)