]>
Commit | Line | Data |
---|---|---|
968dee68 AC |
1 | /* |
2 | * modules/um_regonlymsg.c | |
3 | * Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org> | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are | |
7 | * met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3. The name of the author may not be used to endorse or promote products | |
15 | * derived from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | |
29 | ||
30 | #include "stdinc.h" | |
31 | #include "modules.h" | |
32 | #include "hook.h" | |
33 | #include "client.h" | |
34 | #include "ircd.h" | |
35 | #include "send.h" | |
36 | #include "hash.h" | |
37 | #include "s_conf.h" | |
38 | #include "s_user.h" | |
39 | #include "s_serv.h" | |
40 | #include "numeric.h" | |
41 | #include "privilege.h" | |
42 | #include "s_newconf.h" | |
43 | ||
44 | static int | |
45 | um_regonlymsg_modinit(void) | |
46 | { | |
47 | user_modes['R'] = find_umode_slot(); | |
48 | construct_umodebuf(); | |
49 | ||
50 | return 0; | |
51 | } | |
52 | ||
53 | static void | |
54 | um_regonlymsg_moddeinit(void) | |
55 | { | |
56 | user_modes['R'] = 0; | |
57 | construct_umodebuf(); | |
58 | } | |
59 | ||
60 | #define IsSetRegOnlyMsg(c) ((c->umodes & user_modes['R']) == user_modes['R']) | |
61 | ||
62 | static const char um_regonlymsg_desc[] = | |
63 | "Provides usermode +R which restricts messages from unregistered users."; | |
64 | ||
65 | static bool | |
66 | allow_message(struct Client *source_p, struct Client *target_p) | |
67 | { | |
68 | if (!IsSetRegOnlyMsg(target_p)) | |
69 | return false; | |
70 | ||
71 | if (IsServer(source_p)) | |
72 | return false; | |
73 | ||
74 | /* XXX: controversial? allow opers to send through +R */ | |
75 | if (IsOper(source_p)) | |
76 | return false; | |
77 | ||
78 | if (accept_message(source_p, target_p)) | |
79 | return false; | |
80 | ||
81 | if (source_p->user->suser[0]) | |
82 | return false; | |
83 | ||
84 | return true; | |
85 | } | |
86 | ||
87 | static void | |
88 | h_can_invite(void *vdata) | |
89 | { | |
90 | hook_data_channel_approval *data = vdata; | |
91 | struct Client *source_p = data->client; | |
92 | struct Client *target_p = data->target; | |
93 | ||
94 | if (allow_message(source_p, target_p)) | |
95 | return; | |
96 | ||
97 | sendto_one_numeric(source_p, ERR_NONONREG, form_str(ERR_NONONREG), | |
98 | target_p->name); | |
99 | ||
100 | data->approved = ERR_NONONREG; | |
101 | } | |
102 | ||
103 | static void | |
104 | h_hdl_privmsg_user(void *vdata) | |
105 | { | |
106 | hook_data_privmsg_user *data = vdata; | |
107 | struct Client *source_p = data->source_p; | |
108 | struct Client *target_p = data->target_p; | |
109 | ||
110 | if (allow_message(source_p, target_p)) | |
111 | return; | |
112 | ||
113 | if (data->msgtype == MESSAGE_TYPE_NOTICE) | |
114 | return; | |
115 | ||
116 | sendto_one_numeric(source_p, ERR_NONONREG, form_str(ERR_NONONREG), | |
117 | target_p->name); | |
118 | ||
119 | data->approved = ERR_NONONREG; | |
120 | } | |
121 | ||
122 | static mapi_hfn_list_av1 um_regonlymsg_hfnlist[] = { | |
123 | { "can_invite", h_can_invite }, | |
124 | { "privmsg_user", h_hdl_privmsg_user }, | |
125 | { NULL, NULL } | |
126 | }; | |
127 | ||
128 | DECLARE_MODULE_AV2(um_regonlymsg, um_regonlymsg_modinit, um_regonlymsg_moddeinit, | |
129 | NULL, NULL, um_regonlymsg_hfnlist, NULL, NULL, um_regonlymsg_desc); |