]> jfr.im git - solanum.git/blame - extensions/cap_oper.c
add help for `chm_regmsg`
[solanum.git] / extensions / cap_oper.c
CommitLineData
ef7a99cd
DS
1/*
2 * Copyright (C) 2021 David Schultz <me@zpld.me>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 * USA
18 */
19
20#include <stdinc.h>
21#include <modules.h>
22#include <capability.h>
23#include <s_conf.h>
24#include <s_serv.h>
25#include <s_newconf.h>
26#include <client.h>
27#include <msgbuf.h>
28
29static char cap_oper_desc[] = "Provides the solanum.chat/oper capability";
30
31static bool cap_oper_oper_visible(struct Client *);
32static void cap_oper_outbound_msgbuf(void *);
33static void cap_oper_umode_changed(void *);
34static void cap_oper_cap_change(void *);
35
36static unsigned CLICAP_OPER;
37static unsigned CLICAP_OPER_AUSPEX;
38static unsigned CLICAP_OPER_JUSTOPER;
39static unsigned CLICAP_OPER_NORMAL;
40
41static struct ClientCapability capdata_oper_oper = {
42 .visible = cap_oper_oper_visible,
43};
44
45mapi_cap_list_av2 cap_oper_caps[] = {
46 { MAPI_CAP_CLIENT, "solanum.chat/oper", NULL, &CLICAP_OPER },
47 { MAPI_CAP_CLIENT, "?oper_auspex", &capdata_oper_oper, &CLICAP_OPER_AUSPEX },
48 { MAPI_CAP_CLIENT, "?oper_justoper", &capdata_oper_oper, &CLICAP_OPER_JUSTOPER },
49 { MAPI_CAP_CLIENT, "?oper_normal", &capdata_oper_oper, &CLICAP_OPER_NORMAL },
50 { 0, NULL, NULL, NULL },
51};
52
53mapi_hfn_list_av1 cap_oper_hfnlist[] = {
54 { "outbound_msgbuf", cap_oper_outbound_msgbuf, HOOK_NORMAL },
55 { "umode_changed", cap_oper_umode_changed, HOOK_MONITOR },
56 { "cap_change", cap_oper_cap_change, HOOK_MONITOR },
57 { NULL, NULL, 0 },
58};
59
60static bool
61cap_oper_oper_visible(struct Client *client)
62{
63 return false;
64}
65
66static void
67cap_oper_outbound_msgbuf(void *data_)
68{
69 hook_data *data = data_;
70 struct MsgBuf *msgbuf = data->arg1;
71
72 if (data->client == NULL || !IsPerson(data->client))
73 return;
74
75 if (IsOper(data->client))
76 {
77 /* send all oper data to auspex */
78 msgbuf_append_tag(msgbuf, "solanum.chat/oper", data->client->user->opername, CLICAP_OPER_AUSPEX);
79 if (HasPrivilege(data->client, "oper:hidden") || ConfigFileEntry.hide_opers)
80 /* these people aren't allowed to see hidden opers */
81 return;
82 msgbuf_append_tag(msgbuf, "solanum.chat/oper", data->client->user->opername, CLICAP_OPER_JUSTOPER);
83 msgbuf_append_tag(msgbuf, "solanum.chat/oper", NULL, CLICAP_OPER_NORMAL);
84 }
85}
86
87static inline void
88update_clicap_oper(struct Client *client)
89{
90 /* clear out old caps */
91 client->localClient->caps &= ~CLICAP_OPER_AUSPEX;
92 client->localClient->caps &= ~CLICAP_OPER_JUSTOPER;
93 client->localClient->caps &= ~CLICAP_OPER_NORMAL;
94
95 if (client->localClient->caps & CLICAP_OPER && HasPrivilege(client, "auspex:oper"))
96 {
97 /* if the client is an oper with auspex, let them see everything */
98 client->localClient->caps |= CLICAP_OPER_AUSPEX;
99 }
100 else if (client->localClient->caps & CLICAP_OPER && IsOper(client))
101 {
102 /* if the client is an oper, let them see other opers */
103 client->localClient->caps |= CLICAP_OPER_JUSTOPER;
104 }
105 else if (client->localClient->caps & CLICAP_OPER)
106 {
107 /* if the client is a normal user, let them see opers
108 provided that server wide oper hiding is not enabled */
109 client->localClient->caps |= CLICAP_OPER_NORMAL;
110 }
111}
112
113static void
114cap_oper_umode_changed(void *data_)
115{
116 hook_data_umode_changed *data = data_;
117
118 if (!MyClient(data->client))
119 return;
120
121 update_clicap_oper(data->client);
122}
123
124static void
125cap_oper_cap_change(void *data_)
126{
127 hook_data_cap_change *data = data_;
128
129 update_clicap_oper(data->client);
130}
131
132static int
133modinit(void)
134{
135 rb_dlink_node *ptr;
136
137 RB_DLINK_FOREACH(ptr, lclient_list.head)
138 {
139 struct Client *client = ptr->data;
140
141 update_clicap_oper(client);
142 }
143
144 return 0;
145}
146
147DECLARE_MODULE_AV2(cap_oper, modinit, NULL, NULL, NULL, cap_oper_hfnlist, cap_oper_caps, NULL, cap_oper_desc);