1 /*
2  * Copyright (c) 2007 William Pitcock
3  * Rights to this code are as documented in doc/LICENSE.
4  *
5  * mlocktweaker.c: A module which tweaks mlock on registration.
6  *
7  */
8 
9 #include "atheme-compat.h"
10 
11 /* Changed to allow for dynamic configuration, to configure this, set
12  * chanserv::mlocktweak to the mode string you want set on channels as
13  * they are registered. Keep in mind that +nt will be applied as well,
14  * so if you do not want +n or +t, negate them in the configuration.
15  * - Quora
16  */
17 char * mlocktweak;
18 
19 DECLARE_MODULE_V1
20 (
21 	"contrib/mlocktweaker", false, _modinit, _moddeinit,
22 	PACKAGE_STRING,
23 	"William Pitcock <nenolod@atheme.org>"
24 );
25 
26 static void handle_channel_register(hook_channel_req_t *hdata);
27 
_modinit(module_t * m)28 void _modinit(module_t *m)
29 {
30 	add_dupstr_conf_item("MLOCKTWEAK", &chansvs.me->conf_table, 0, &mlocktweak, "-t+c");
31 	hook_add_event("channel_register");
32 	hook_add_first_channel_register(handle_channel_register);
33 }
34 
_moddeinit(module_unload_intent_t intent)35 void _moddeinit(module_unload_intent_t intent)
36 {
37 	del_conf_item("MLOCKTWEAK", &chansvs.me->conf_table);
38 	hook_del_channel_register(handle_channel_register);
39 }
40 
handle_channel_register(hook_channel_req_t * hdata)41 static void handle_channel_register(hook_channel_req_t *hdata)
42 {
43 	mychan_t *mc = hdata->mc;
44 	unsigned int *target;
45 	char *it = mlocktweak;
46 
47 	if (mc == NULL)
48 		return;
49 
50 	target = &mc->mlock_on;
51 
52 	while (*it != '\0')
53 	{
54 		switch (*it)
55 		{
56 			case '+':
57 				target = &mc->mlock_on;
58 				break;
59 			case '-':
60 				target = &mc->mlock_off;
61 				break;
62 			default:
63 				*target |= mode_to_flag(*it);
64 				break;
65 		}
66 		++it;
67 	}
68 
69 	mc->mlock_off &= ~mc->mlock_on;
70 }
71