| 1 |
/* |
| 2 |
* Copyright (c) 2010 William Pitcock <[email protected]> |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* Sends a customized welcome message on nickname registration. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "atheme-compat.h" |
| 9 |
|
| 10 |
#if (CURRENT_ABI_REVISION < 730000) |
| 11 |
# include "conf.h" |
| 12 |
#endif |
| 13 |
|
| 14 |
static mowgli_list_t regnotices = { NULL, NULL, 0 }; |
| 15 |
|
| 16 |
static void |
| 17 |
regnotice_hook(myuser_t *mu) |
| 18 |
{ |
| 19 |
mowgli_node_t *n; |
| 20 |
|
| 21 |
return_if_fail(mu != NULL); |
| 22 |
|
| 23 |
MOWGLI_ITER_FOREACH(n, regnotices.head) |
| 24 |
{ |
| 25 |
char *line = n->data; |
| 26 |
|
| 27 |
myuser_notice(nicksvs.nick, mu, "%s", line); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
static int |
| 32 |
regnotice_config_handler(mowgli_config_file_entry_t *ce) |
| 33 |
{ |
| 34 |
mowgli_config_file_entry_t *cce; |
| 35 |
|
| 36 |
MOWGLI_ITER_FOREACH(cce, ce->entries) |
| 37 |
{ |
| 38 |
char *line = sstrdup(cce->varname); |
| 39 |
mowgli_node_add(line, mowgli_node_create(), ®notices); |
| 40 |
} |
| 41 |
|
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
regnotice_config_purge(void *unused) |
| 47 |
{ |
| 48 |
mowgli_node_t *n, *tn; |
| 49 |
|
| 50 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, regnotices.head) |
| 51 |
{ |
| 52 |
char *line = n->data; |
| 53 |
|
| 54 |
sfree(line); |
| 55 |
mowgli_node_delete(n, ®notices); |
| 56 |
mowgli_node_free(n); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
static void |
| 61 |
mod_init(module_t *m) |
| 62 |
{ |
| 63 |
hook_add_event("config_purge"); |
| 64 |
hook_add_config_purge(regnotice_config_purge); |
| 65 |
|
| 66 |
hook_add_event("user_register"); |
| 67 |
hook_add_user_register(regnotice_hook); |
| 68 |
|
| 69 |
add_conf_item("REGNOTICE", &nicksvs.me->conf_table, regnotice_config_handler); |
| 70 |
} |
| 71 |
|
| 72 |
static void |
| 73 |
mod_deinit(module_unload_intent_t intent) |
| 74 |
{ |
| 75 |
hook_del_user_register(regnotice_hook); |
| 76 |
hook_del_config_purge(regnotice_config_purge); |
| 77 |
|
| 78 |
del_conf_item("REGNOTICE", &nicksvs.me->conf_table); |
| 79 |
} |
| 80 |
|
| 81 |
SIMPLE_DECLARE_MODULE_V1("contrib/ns_regnotice", MODULE_UNLOAD_CAPABILITY_OK) |