| 1 |
/* chanfix - channel fixing service |
| 2 |
* Copyright (c) 2010 Atheme Development Group |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "atheme.h" |
| 6 |
#include "chanfix.h" |
| 7 |
|
| 8 |
DECLARE_MODULE_V1 |
| 9 |
( |
| 10 |
"chanfix/main", false, _modinit, _moddeinit, |
| 11 |
PACKAGE_STRING, |
| 12 |
VENDOR_STRING |
| 13 |
); |
| 14 |
|
| 15 |
service_t *chanfix; |
| 16 |
mowgli_eventloop_timer_t *chanfix_autofix_timer = NULL; |
| 17 |
|
| 18 |
void _modinit(module_t *m) |
| 19 |
{ |
| 20 |
chanfix_persist_record_t *rec = mowgli_global_storage_get("atheme.chanfix.main.persist"); |
| 21 |
|
| 22 |
chanfix_gather_init(rec); |
| 23 |
|
| 24 |
if (rec != NULL) |
| 25 |
{ |
| 26 |
free(rec); |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
chanfix = service_add("chanfix", NULL); |
| 31 |
service_bind_command(chanfix, &cmd_chanfix); |
| 32 |
service_bind_command(chanfix, &cmd_scores); |
| 33 |
service_bind_command(chanfix, &cmd_info); |
| 34 |
service_bind_command(chanfix, &cmd_help); |
| 35 |
service_bind_command(chanfix, &cmd_mark); |
| 36 |
|
| 37 |
hook_add_event("channel_can_register"); |
| 38 |
hook_add_channel_can_register(chanfix_can_register); |
| 39 |
|
| 40 |
add_bool_conf_item("AUTOFIX", &chanfix->conf_table, 0, &chanfix_do_autofix, false); |
| 41 |
|
| 42 |
chanfix_autofix_timer = mowgli_timer_add(base_eventloop, "chanfix_autofix", chanfix_autofix_ev, NULL, 60); |
| 43 |
} |
| 44 |
|
| 45 |
void _moddeinit(module_unload_intent_t intent) |
| 46 |
{ |
| 47 |
chanfix_persist_record_t *rec = NULL; |
| 48 |
|
| 49 |
hook_del_channel_can_register(chanfix_can_register); |
| 50 |
|
| 51 |
mowgli_timer_destroy(base_eventloop, chanfix_autofix_timer); |
| 52 |
|
| 53 |
if (chanfix) |
| 54 |
service_delete(chanfix); |
| 55 |
|
| 56 |
switch (intent) |
| 57 |
{ |
| 58 |
case MODULE_UNLOAD_INTENT_RELOAD: |
| 59 |
{ |
| 60 |
rec = smalloc(sizeof(chanfix_persist_record_t)); |
| 61 |
rec->version = 1; |
| 62 |
|
| 63 |
mowgli_global_storage_put("atheme.chanfix.main.persist", rec); |
| 64 |
break; |
| 65 |
} |
| 66 |
|
| 67 |
case MODULE_UNLOAD_INTENT_PERM: |
| 68 |
default: |
| 69 |
break; |
| 70 |
} |
| 71 |
|
| 72 |
chanfix_gather_deinit(intent, rec); |
| 73 |
} |