aboutsummaryrefslogtreecommitdiffstats
path: root/modules/chanfix/main.c
blob: 10cb6f63d13a799c26fb003420175554d434bcad (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* chanfix - channel fixing service
 * Copyright (c) 2010 Atheme Development Group
 */

#include "atheme.h"
#include "chanfix.h"

DECLARE_MODULE_V1
(
	"chanfix/main", false, _modinit, _moddeinit,
	PACKAGE_STRING,
	VENDOR_STRING
);

service_t *chanfix;
mowgli_eventloop_timer_t *chanfix_autofix_timer = NULL;

void _modinit(module_t *m)
{
	chanfix_persist_record_t *rec = mowgli_global_storage_get("atheme.chanfix.main.persist");

	chanfix_gather_init(rec);

	if (rec != NULL)
	{
		free(rec);
		return;
	}

	chanfix = service_add("chanfix", NULL);
	service_bind_command(chanfix, &cmd_chanfix);
	service_bind_command(chanfix, &cmd_scores);
	service_bind_command(chanfix, &cmd_info);
	service_bind_command(chanfix, &cmd_help);
	service_bind_command(chanfix, &cmd_mark);

	hook_add_event("channel_can_register");
	hook_add_channel_can_register(chanfix_can_register);

	add_bool_conf_item("AUTOFIX", &chanfix->conf_table, 0, &chanfix_do_autofix, false);

	chanfix_autofix_timer = mowgli_timer_add(base_eventloop, "chanfix_autofix", chanfix_autofix_ev, NULL, 60);
}

void _moddeinit(module_unload_intent_t intent)
{
	chanfix_persist_record_t *rec = NULL;

	hook_del_channel_can_register(chanfix_can_register);

	mowgli_timer_destroy(base_eventloop, chanfix_autofix_timer);

	if (chanfix)
		service_delete(chanfix);

	switch (intent)
	{
		case MODULE_UNLOAD_INTENT_RELOAD:
		{
			rec = smalloc(sizeof(chanfix_persist_record_t));
			rec->version = 1;

			mowgli_global_storage_put("atheme.chanfix.main.persist", rec);
			break;
		}

		case MODULE_UNLOAD_INTENT_PERM:
		default:
			break;
	}

	chanfix_gather_deinit(intent, rec);
}