2 * modules/um_regonlymsg.c
3 * Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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.
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.
41 #include "privilege.h"
42 #include "s_newconf.h"
46 um_regonlymsg_modinit(void)
48 user_modes
['R'] = find_umode_slot();
53 ierror("um_regonlymsg: unable to allocate usermode slot for +R, unloading module");
61 um_regonlymsg_moddeinit(void)
67 #define IsSetRegOnlyMsg(c) ((c->umodes & user_modes['R']) == user_modes['R'])
69 static const char um_regonlymsg_desc
[] =
70 "Provides usermode +R which restricts messages from unregistered users.";
73 allow_message(struct Client
*source_p
, struct Client
*target_p
)
75 if (!MyClient(target_p
))
78 if (!IsSetRegOnlyMsg(target_p
))
81 if (IsServer(source_p
))
84 /* XXX: controversial? allow opers to send through +R */
88 if (accept_message(source_p
, target_p
))
91 if (source_p
->user
->suser
[0])
98 h_hdl_invite(void *vdata
)
100 hook_data_channel_approval
*data
= vdata
;
101 struct Client
*source_p
= data
->client
;
102 struct Client
*target_p
= data
->target
;
103 static char errorbuf
[BUFSIZE
];
108 if (allow_message(source_p
, target_p
))
111 snprintf(errorbuf
, sizeof errorbuf
, form_str(ERR_NONONREG
),
114 data
->approved
= ERR_NONONREG
;
115 data
->error
= errorbuf
;
119 h_hdl_privmsg_user(void *vdata
)
121 hook_data_privmsg_user
*data
= vdata
;
122 struct Client
*source_p
= data
->source_p
;
123 struct Client
*target_p
= data
->target_p
;
128 if (allow_message(source_p
, target_p
))
131 if (data
->msgtype
== MESSAGE_TYPE_NOTICE
)
134 sendto_one_numeric(source_p
, ERR_NONONREG
, form_str(ERR_NONONREG
),
137 data
->approved
= ERR_NONONREG
;
140 static mapi_hfn_list_av1 um_regonlymsg_hfnlist
[] = {
141 { "invite", h_hdl_invite
},
142 { "privmsg_user", h_hdl_privmsg_user
},
146 DECLARE_MODULE_AV2(um_regonlymsg
, um_regonlymsg_modinit
, um_regonlymsg_moddeinit
,
147 NULL
, NULL
, um_regonlymsg_hfnlist
, NULL
, NULL
, um_regonlymsg_desc
);