]> jfr.im git - solanum.git/blame - extensions/helpops.c
extensions/helpops: implement DEHELPER command
[solanum.git] / extensions / helpops.c
CommitLineData
4d21f1e8
AC
1/*
2 * Helpops system.
3 * -- kaniini
4 */
5
6#include "stdinc.h"
7#include "modules.h"
8#include "client.h"
9#include "hook.h"
10#include "ircd.h"
11#include "send.h"
12#include "s_conf.h"
13#include "s_user.h"
14#include "s_newconf.h"
15#include "numeric.h"
16
17static rb_dlink_list helper_list = { NULL, NULL, 0 };
18static void h_hdl_stats_request(hook_data_int *hdata);
19static void h_hdl_new_remote_user(struct Client *client_p);
20static void h_hdl_client_exit(hook_data_client_exit *hdata);
21static void h_hdl_umode_changed(hook_data_umode_changed *hdata);
22static void h_hdl_whois(hook_data_client *hdata);
161ac1c8
AC
23static int mo_dehelper(struct Client *, struct Client *, int, const char **);
24static int me_dehelper(struct Client *, struct Client *, int, const char **);
25static int do_dehelper(struct Client *source_p, struct Client *target_p);
4d21f1e8
AC
26
27mapi_hfn_list_av1 helpops_hfnlist[] = {
28 { "doing_stats", (hookfn) h_hdl_stats_request },
29 { "new_remote_user", (hookfn) h_hdl_new_remote_user },
30 { "client_exit", (hookfn) h_hdl_client_exit },
31 { "umode_changed", (hookfn) h_hdl_umode_changed },
32 { "doing_whois", (hookfn) h_hdl_whois },
33 { "doing_whois_global", (hookfn) h_hdl_whois },
34 { NULL, NULL }
35};
36
37static int UMODE_HELPOPS = 0;
38
161ac1c8
AC
39struct Message dehelper_msgtab = {
40 "DEHELPER", 0, 0, 0, MFLG_SLOW,
41 {mg_unreg, mg_not_oper, mg_not_oper, mg_ignore, {me_dehelper, 2}, {mo_dehelper, 2}}
42};
43
44mapi_clist_av1 helpops_clist[] = { &dehelper_msgtab, NULL };
45
46static int mo_dehelper(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
47{
48 struct Client *target_p;
49
50 if (!IsOperAdmin(source_p))
51 {
52 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
53 return 0;
54 }
55
56 if(!(target_p = find_named_person(parv[1])))
57 {
58 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
59 return 0;
60 }
61
62 if(MyClient(target_p))
63 do_dehelper(source_p, target_p);
64 else
65 sendto_one(target_p, ":%s ENCAP %s DEHELPER %s",
66 use_id(source_p), target_p->servptr->name, use_id(target_p));
67
68 return 0;
69}
70
71static int me_dehelper(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
72{
73 struct Client *target_p = find_person(parv[1]);
74 if(!target_p)
75 {
76 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
77 return 0;
78 }
79 if(!MyClient(target_p))
80 return 0;
81
82 do_dehelper(source_p, target_p);
83 return 0;
84}
85
86static int do_dehelper(struct Client *source_p, struct Client *target_p)
87{
88 const char *fakeparv[4];
89
90 if(!(target_p->umodes & UMODE_HELPOPS))
91 return 0;
92
93 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using DEHELPER on %s",
94 source_p->name, target_p->name);
95 sendto_one_notice(target_p, ":*** %s is using DEHELPER on you", source_p->name);
96
97 fakeparv[0] = fakeparv[1] = target_p->name;
98 fakeparv[2] = "-H";
99 fakeparv[3] = NULL;
100 user_mode(target_p, target_p, 3, fakeparv);
101 return 0;
102}
103
4d21f1e8
AC
104static int
105_modinit(void)
106{
107 /* add the usermode to the available slot */
108 user_modes['H'] = UMODE_HELPOPS = find_umode_slot();
109 construct_umodebuf();
110
111 return 0;
112}
113
114static void
115_moddeinit(void)
116{
117 /* disable the umode and remove it from the available list */
118 user_modes['H'] = UMODE_HELPOPS = 0;
119 construct_umodebuf();
120}
121
122static void
123h_hdl_stats_request(hook_data_int *hdata)
124{
125 struct Client *target_p;
126 rb_dlink_node *helper_ptr;
127 unsigned int count = 0;
128
129 if (hdata->arg2 != 'p')
130 return;
131
132 RB_DLINK_FOREACH (helper_ptr, helper_list.head)
133 {
134 target_p = helper_ptr->data;
135
136 if(IsOperInvis(target_p) && !IsOper(hdata->client))
137 continue;
138
139 if(target_p->user->away)
140 continue;
141
142 count++;
143
144 sendto_one_numeric(hdata->client, RPL_STATSDEBUG,
145 "p :%s (%s@%s)",
146 target_p->name, target_p->username,
147 target_p->host);
148 }
149
150 sendto_one_numeric(hdata->client, RPL_STATSDEBUG,
151 "p :%u staff members", count);
152
153 hdata->result = 1;
154}
155
156static void
157h_hdl_new_remote_user(struct Client *client_p)
158{
159 if (client_p->umodes & UMODE_HELPOPS)
160 rb_dlinkAddAlloc(client_p, &helper_list);
161}
162
163static void
164h_hdl_client_exit(hook_data_client_exit *hdata)
165{
166 if (hdata->target->umodes & UMODE_HELPOPS)
167 rb_dlinkFindDestroy(hdata->target, &helper_list);
168}
169
170static void
171h_hdl_umode_changed(hook_data_umode_changed *hdata)
172{
173 struct Client *source_p = hdata->client;
174
175 /* didn't change +H umode, we don't need to do anything */
176 if (!((hdata->oldumodes ^ source_p->umodes) & UMODE_HELPOPS))
177 return;
178
179 if (source_p->umodes & UMODE_HELPOPS)
180 {
181 if (MyClient(source_p) && !HasPrivilege(source_p, "usermode:helpops"))
182 {
183 source_p->umodes &= ~UMODE_HELPOPS;
184 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "usermode:helpops");
185 return;
186 }
187
188 rb_dlinkAddAlloc(source_p, &helper_list);
189 }
190 else if (!(source_p->umodes & UMODE_HELPOPS))
191 rb_dlinkFindDestroy(source_p, &helper_list);
192}
193
194static void
195h_hdl_whois(hook_data_client *hdata)
196{
197 struct Client *source_p = hdata->client;
198 struct Client *target_p = hdata->target;
199
200 if ((target_p->umodes & UMODE_HELPOPS) && EmptyString(target_p->user->away))
201 {
202 sendto_one_numeric(source_p, RPL_WHOISHELPOP, form_str(RPL_WHOISHELPOP), target_p->name);
203 }
204}
205
161ac1c8 206DECLARE_MODULE_AV1(helpops, _modinit, _moddeinit, helpops_clist, NULL, helpops_hfnlist, "");