2 * Copyright (C) 2021 David Schultz <me@zpld.me>
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.
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.
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
22 #include <capability.h>
25 #include <s_newconf.h>
29 static char cap_oper_desc
[] = "Provides the solanum.chat/oper capability";
31 static bool cap_oper_oper_visible(struct Client
*);
32 static void cap_oper_outbound_msgbuf(void *);
33 static void cap_oper_umode_changed(void *);
34 static void cap_oper_cap_change(void *);
36 static unsigned CLICAP_OPER
;
37 static unsigned CLICAP_OPER_AUSPEX
;
38 static unsigned CLICAP_OPER_JUSTOPER
;
39 static unsigned CLICAP_OPER_NORMAL
;
41 static struct ClientCapability capdata_oper_oper
= {
42 .visible
= cap_oper_oper_visible
,
45 mapi_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
},
53 mapi_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
},
61 cap_oper_oper_visible(struct Client
*client
)
67 cap_oper_outbound_msgbuf(void *data_
)
69 hook_data
*data
= data_
;
70 struct MsgBuf
*msgbuf
= data
->arg1
;
72 if (data
->client
== NULL
|| !IsPerson(data
->client
))
75 if (IsOper(data
->client
))
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 */
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
);
88 update_clicap_oper(struct Client
*client
)
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
;
95 if (client
->localClient
->caps
& CLICAP_OPER
&& HasPrivilege(client
, "auspex:oper"))
97 /* if the client is an oper with auspex, let them see everything */
98 client
->localClient
->caps
|= CLICAP_OPER_AUSPEX
;
100 else if (client
->localClient
->caps
& CLICAP_OPER
&& IsOper(client
))
102 /* if the client is an oper, let them see other opers */
103 client
->localClient
->caps
|= CLICAP_OPER_JUSTOPER
;
105 else if (client
->localClient
->caps
& CLICAP_OPER
)
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
;
114 cap_oper_umode_changed(void *data_
)
116 hook_data_umode_changed
*data
= data_
;
118 if (!MyClient(data
->client
))
121 update_clicap_oper(data
->client
);
125 cap_oper_cap_change(void *data_
)
127 hook_data_cap_change
*data
= data_
;
129 update_clicap_oper(data
->client
);
137 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
139 struct Client
*client
= ptr
->data
;
141 update_clicap_oper(client
);
147 DECLARE_MODULE_AV2(cap_oper
, modinit
, NULL
, NULL
, NULL
, cap_oper_hfnlist
, cap_oper_caps
, NULL
, cap_oper_desc
);