]> jfr.im git - solanum.git/blob - extensions/umode_hide_idle_time.c
extensions/umode_hide_idle_time: mask times for hidden sources (#373)
[solanum.git] / extensions / umode_hide_idle_time.c
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 "client.h"
23 #include "hook.h"
24 #include "ircd.h"
25 #include "logger.h"
26 #include "send.h"
27 #include "s_conf.h"
28 #include "s_user.h"
29 #include "s_newconf.h"
30
31 static const char hide_desc[] = "Provides user mode +I to hide a user's idle time";
32
33 static void h_huc_doing_idle_time_hook(void *);
34
35 mapi_hfn_list_av1 huc_hfnlist[] = {
36 { "doing_whois_show_idle", h_huc_doing_idle_time_hook },
37 { "doing_trace_show_idle", h_huc_doing_idle_time_hook },
38 { "doing_stats_show_idle", h_huc_doing_idle_time_hook },
39 { "doing_who_show_idle", h_huc_doing_idle_time_hook },
40 { NULL, NULL }
41 };
42
43 static void
44 h_huc_doing_idle_time_hook(void *data_)
45 {
46 hook_data_client_approval *data = data_;
47
48 if (data->approved == 0)
49 return;
50
51 if ((data->client->umodes | data->target->umodes) & user_modes['I'])
52 {
53 if (HasPrivilege(data->client, "auspex:usertimes"))
54 data->approved = WHOIS_IDLE_AUSPEX;
55 else if (data->client != data->target)
56 data->approved = WHOIS_IDLE_HIDE;
57 }
58 }
59
60 static int
61 _modinit(void)
62 {
63 user_modes['I'] = find_umode_slot();
64 construct_umodebuf();
65 if (!user_modes['I'])
66 {
67 ierror("umode_hide_idle_time: unable to allocate usermode slot for +I, unloading extension");
68 return -1;
69 }
70 return 0;
71 }
72
73 static void
74 _moddeinit(void)
75 {
76 user_modes['I'] = 0;
77 construct_umodebuf();
78 }
79
80 DECLARE_MODULE_AV2(hide_idle_time, _modinit, _moddeinit, NULL, NULL, huc_hfnlist, NULL, NULL, hide_desc);