| 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 channel 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(hook_channel_req_t *hdata) |
| 18 |
{ |
| 19 |
mowgli_node_t *n; |
| 20 |
sourceinfo_t *si = hdata->si; |
| 21 |
mychan_t *mc = hdata->mc; |
| 22 |
|
| 23 |
if (si == NULL || mc == NULL) |
| 24 |
return; |
| 25 |
|
| 26 |
MOWGLI_ITER_FOREACH(n, regnotices.head) |
| 27 |
{ |
| 28 |
char *line = n->data; |
| 29 |
|
| 30 |
command_success_nodata(si, "%s", line); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
static int |
| 35 |
regnotice_config_handler(mowgli_config_file_entry_t *ce) |
| 36 |
{ |
| 37 |
mowgli_config_file_entry_t *cce; |
| 38 |
|
| 39 |
MOWGLI_ITER_FOREACH(cce, ce->entries) |
| 40 |
{ |
| 41 |
char *line = sstrdup(cce->varname); |
| 42 |
mowgli_node_add(line, mowgli_node_create(), ®notices); |
| 43 |
} |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
static void |
| 49 |
regnotice_config_purge(void *unused) |
| 50 |
{ |
| 51 |
mowgli_node_t *n, *tn; |
| 52 |
|
| 53 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, regnotices.head) |
| 54 |
{ |
| 55 |
char *line = n->data; |
| 56 |
|
| 57 |
sfree(line); |
| 58 |
mowgli_node_delete(n, ®notices); |
| 59 |
mowgli_node_free(n); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
static void |
| 64 |
mod_init(module_t *m) |
| 65 |
{ |
| 66 |
hook_add_event("config_purge"); |
| 67 |
hook_add_config_purge(regnotice_config_purge); |
| 68 |
|
| 69 |
hook_add_event("channel_register"); |
| 70 |
hook_add_channel_register(regnotice_hook); |
| 71 |
|
| 72 |
add_conf_item("REGNOTICE", &chansvs.me->conf_table, regnotice_config_handler); |
| 73 |
} |
| 74 |
|
| 75 |
static void |
| 76 |
mod_deinit(module_unload_intent_t intent) |
| 77 |
{ |
| 78 |
hook_del_channel_register(regnotice_hook); |
| 79 |
hook_del_config_purge(regnotice_config_purge); |
| 80 |
|
| 81 |
del_conf_item("REGNOTICE", &chansvs.me->conf_table); |
| 82 |
} |
| 83 |
|
| 84 |
SIMPLE_DECLARE_MODULE_V1("contrib/cs_regnotice", MODULE_UNLOAD_CAPABILITY_OK) |