]>
Commit | Line | Data |
---|---|---|
0ba1da59 EM |
1 | /* |
2 | * Solanum: a slightly advanced ircd | |
3 | * chm_regmsg: require identification to chat (+R mode). | |
4 | * | |
5 | * Copyright (c) 2020 Eric Mertens <emertens@gmail.com> | |
6 | * | |
7 | * Permission to use, copy, modify, and/or distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice is present in all copies. | |
10 | * | |
11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
13 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
14 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
15 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
16 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
17 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
19 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
20 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
21 | * POSSIBILITY OF SUCH DAMAGE. | |
22 | */ | |
23 | ||
24 | #include "stdinc.h" | |
25 | #include "modules.h" | |
26 | #include "hook.h" | |
27 | #include "client.h" | |
28 | #include "ircd.h" | |
29 | #include "logger.h" | |
30 | #include "send.h" | |
31 | #include "s_conf.h" | |
32 | #include "s_user.h" | |
33 | #include "s_serv.h" | |
34 | #include "numeric.h" | |
35 | #include "chmode.h" | |
36 | #include "inline/stringops.h" | |
37 | ||
38 | static const char chm_regmsg_desc[] = | |
39 | "Adds channel mode +R, which blocks messagess from unregistered users"; | |
40 | ||
41 | static unsigned int mode_regmsg; | |
42 | ||
43 | static void chm_regmsg_process(void *); | |
44 | ||
45 | mapi_hfn_list_av1 chm_regmsg_hfnlist[] = { | |
82436efb | 46 | { "privmsg_channel", chm_regmsg_process }, |
0ba1da59 EM |
47 | { NULL, NULL } |
48 | }; | |
49 | ||
50 | static void | |
51 | chm_regmsg_process(void *data_) | |
52 | { | |
53 | hook_data_privmsg_channel *data = data_; | |
54 | struct membership *msptr; | |
55 | ||
56 | /* message is already blocked, defer */ | |
57 | if (data->approved) | |
58 | return; | |
59 | ||
981a94c3 EM |
60 | /* mode is unset, accept */ |
61 | if (!(data->chptr->mode.mode & mode_regmsg)) | |
62 | return; | |
63 | ||
0ba1da59 EM |
64 | /* user is identified, accept */ |
65 | if (!EmptyString(data->source_p->user->suser)) | |
66 | return; | |
67 | ||
68 | /* voice and op override identification requirement, accept */ | |
69 | msptr = find_channel_membership(data->chptr, data->source_p); | |
70 | if (is_chanop_voiced(msptr)) | |
71 | return; | |
72 | ||
73 | sendto_one_numeric(data->source_p, ERR_MSGNEEDREGGEDNICK, form_str(ERR_MSGNEEDREGGEDNICK), | |
74 | data->source_p->name, data->chptr->chname); | |
75 | data->approved = ERR_MSGNEEDREGGEDNICK; | |
76 | } | |
77 | ||
78 | static int | |
79 | _modinit(void) | |
80 | { | |
81 | mode_regmsg = cflag_add('R', chm_simple); | |
82 | if (mode_regmsg == 0) { | |
83 | ierror("chm_regmsg: unable to allocate cmode slot for +R, unloading module"); | |
84 | return -1; | |
85 | } | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
90 | static void | |
91 | _moddeinit(void) | |
92 | { | |
93 | cflag_orphan('R'); | |
94 | } | |
95 | ||
96 | DECLARE_MODULE_AV2(chm_regmsg, _modinit, _moddeinit, NULL, NULL, chm_regmsg_hfnlist, NULL, NULL, chm_regmsg_desc); |