]>
Commit | Line | Data |
---|---|---|
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 | ||
eeabf33a EM |
17 | static const char helpops_desc[] = "The helpops system as used by freenode"; |
18 | ||
4d21f1e8 | 19 | static rb_dlink_list helper_list = { NULL, NULL, 0 }; |
82436efb EM |
20 | static void h_hdl_stats_request(void *hdata); |
21 | static void h_hdl_new_remote_user(void *client_p); | |
22 | static void h_hdl_client_exit(void *hdata); | |
23 | static void h_hdl_umode_changed(void *hdata); | |
24 | static void h_hdl_whois(void *hdata); | |
4d3f8ead | 25 | static void recurse_client_exit(struct Client *client_p); |
b1c32af9 AC |
26 | static void helper_add(struct Client *client_p); |
27 | static void helper_delete(struct Client *client_p); | |
3c7d6fcc EM |
28 | static void mo_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
29 | static void me_dehelper(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
30 | static void do_dehelper(struct Client *source_p, struct Client *target_p); | |
4d21f1e8 AC |
31 | |
32 | mapi_hfn_list_av1 helpops_hfnlist[] = { | |
82436efb EM |
33 | { "doing_stats", h_hdl_stats_request }, |
34 | { "new_remote_user", h_hdl_new_remote_user }, | |
35 | { "client_exit", h_hdl_client_exit }, | |
36 | { "umode_changed", h_hdl_umode_changed }, | |
37 | { "doing_whois", h_hdl_whois }, | |
38 | { "doing_whois_global", h_hdl_whois }, | |
4d21f1e8 AC |
39 | { NULL, NULL } |
40 | }; | |
41 | ||
0f8ec938 | 42 | #define UMODECHAR_HELPOPS 'h' |
4d21f1e8 | 43 | |
161ac1c8 | 44 | struct Message dehelper_msgtab = { |
7baa37a9 | 45 | "DEHELPER", 0, 0, 0, 0, |
161ac1c8 AC |
46 | {mg_unreg, mg_not_oper, mg_not_oper, mg_ignore, {me_dehelper, 2}, {mo_dehelper, 2}} |
47 | }; | |
48 | ||
49 | mapi_clist_av1 helpops_clist[] = { &dehelper_msgtab, NULL }; | |
50 | ||
3c7d6fcc EM |
51 | static void |
52 | mo_dehelper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
161ac1c8 AC |
53 | { |
54 | struct Client *target_p; | |
55 | ||
4a4b2095 | 56 | if (!HasPrivilege(source_p, "oper:dehelper")) |
161ac1c8 | 57 | { |
4a4b2095 | 58 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "dehelper"); |
3c7d6fcc | 59 | return; |
161ac1c8 AC |
60 | } |
61 | ||
62 | if(!(target_p = find_named_person(parv[1]))) | |
63 | { | |
64 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]); | |
3c7d6fcc | 65 | return; |
161ac1c8 AC |
66 | } |
67 | ||
68 | if(MyClient(target_p)) | |
69 | do_dehelper(source_p, target_p); | |
70 | else | |
71 | sendto_one(target_p, ":%s ENCAP %s DEHELPER %s", | |
72 | use_id(source_p), target_p->servptr->name, use_id(target_p)); | |
161ac1c8 AC |
73 | } |
74 | ||
3c7d6fcc EM |
75 | static void |
76 | me_dehelper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv) | |
161ac1c8 AC |
77 | { |
78 | struct Client *target_p = find_person(parv[1]); | |
79 | if(!target_p) | |
80 | { | |
81 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]); | |
3c7d6fcc | 82 | return; |
161ac1c8 AC |
83 | } |
84 | if(!MyClient(target_p)) | |
3c7d6fcc | 85 | return; |
161ac1c8 AC |
86 | |
87 | do_dehelper(source_p, target_p); | |
161ac1c8 AC |
88 | } |
89 | ||
3c7d6fcc EM |
90 | static void |
91 | do_dehelper(struct Client *source_p, struct Client *target_p) | |
161ac1c8 AC |
92 | { |
93 | const char *fakeparv[4]; | |
0f8ec938 | 94 | static const char minus_helpops[3] = {'-', UMODECHAR_HELPOPS, '\0'}; |
161ac1c8 | 95 | |
6c639159 | 96 | if(!(target_p->umodes & user_modes[UMODECHAR_HELPOPS])) |
3c7d6fcc | 97 | return; |
161ac1c8 AC |
98 | |
99 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using DEHELPER on %s", | |
100 | source_p->name, target_p->name); | |
101 | sendto_one_notice(target_p, ":*** %s is using DEHELPER on you", source_p->name); | |
102 | ||
103 | fakeparv[0] = fakeparv[1] = target_p->name; | |
0f8ec938 | 104 | fakeparv[2] = minus_helpops; |
161ac1c8 AC |
105 | fakeparv[3] = NULL; |
106 | user_mode(target_p, target_p, 3, fakeparv); | |
161ac1c8 AC |
107 | } |
108 | ||
4d21f1e8 AC |
109 | static int |
110 | _modinit(void) | |
111 | { | |
0c5dd86c EK |
112 | rb_dlink_node *ptr; |
113 | ||
6c639159 | 114 | user_modes[UMODECHAR_HELPOPS] = find_umode_slot(); |
4d21f1e8 AC |
115 | construct_umodebuf(); |
116 | ||
0c5dd86c EK |
117 | RB_DLINK_FOREACH (ptr, global_client_list.head) |
118 | { | |
119 | struct Client *client_p = ptr->data; | |
120 | if (IsPerson(client_p) && (client_p->umodes & user_modes[UMODECHAR_HELPOPS])) | |
121 | helper_add(client_p); | |
122 | } | |
123 | ||
4d21f1e8 AC |
124 | return 0; |
125 | } | |
126 | ||
127 | static void | |
128 | _moddeinit(void) | |
129 | { | |
0c5dd86c EK |
130 | rb_dlink_node *n, *tn; |
131 | ||
6c639159 | 132 | user_modes[UMODECHAR_HELPOPS] = 0; |
4d21f1e8 | 133 | construct_umodebuf(); |
0c5dd86c EK |
134 | |
135 | RB_DLINK_FOREACH_SAFE(n, tn, helper_list.head) | |
136 | rb_dlinkDestroy(n, &helper_list); | |
4d21f1e8 AC |
137 | } |
138 | ||
139 | static void | |
82436efb | 140 | h_hdl_stats_request(void *data) |
4d21f1e8 | 141 | { |
82436efb | 142 | hook_data_int *hdata = data; |
4d21f1e8 AC |
143 | struct Client *target_p; |
144 | rb_dlink_node *helper_ptr; | |
145 | unsigned int count = 0; | |
146 | ||
147 | if (hdata->arg2 != 'p') | |
148 | return; | |
149 | ||
150 | RB_DLINK_FOREACH (helper_ptr, helper_list.head) | |
151 | { | |
152 | target_p = helper_ptr->data; | |
153 | ||
4d21f1e8 AC |
154 | if(target_p->user->away) |
155 | continue; | |
156 | ||
157 | count++; | |
158 | ||
54f05581 EK |
159 | if (IsOper(hdata->client) && SeesOper(target_p, hdata->client) |
160 | && !EmptyString(target_p->user->opername)) | |
161 | sendto_one_numeric(hdata->client, RPL_STATSDEBUG, | |
162 | "p :%s (%s@%s) {%s}", | |
163 | target_p->name, target_p->username, target_p->host, | |
164 | target_p->user->opername); | |
165 | else | |
166 | sendto_one_numeric(hdata->client, RPL_STATSDEBUG, | |
167 | "p :%s (%s@%s)", | |
168 | target_p->name, target_p->username, target_p->host); | |
4d21f1e8 AC |
169 | } |
170 | ||
171 | sendto_one_numeric(hdata->client, RPL_STATSDEBUG, | |
172 | "p :%u staff members", count); | |
173 | ||
174 | hdata->result = 1; | |
175 | } | |
176 | ||
b1c32af9 AC |
177 | static void |
178 | helper_add(struct Client *client_p) | |
179 | { | |
180 | if (rb_dlinkFind(client_p, &helper_list) != NULL) | |
181 | return; | |
182 | ||
183 | rb_dlinkAddAlloc(client_p, &helper_list); | |
184 | } | |
185 | ||
186 | static void | |
187 | helper_delete(struct Client *client_p) | |
188 | { | |
189 | rb_dlinkFindDestroy(client_p, &helper_list); | |
190 | } | |
191 | ||
4d21f1e8 | 192 | static void |
82436efb | 193 | h_hdl_new_remote_user(void *data) |
4d21f1e8 | 194 | { |
82436efb | 195 | struct Client *client_p = data; |
6c639159 | 196 | if (client_p->umodes & user_modes[UMODECHAR_HELPOPS]) |
b1c32af9 | 197 | helper_add(client_p); |
4d21f1e8 AC |
198 | } |
199 | ||
200 | static void | |
4d3f8ead | 201 | recurse_client_exit(struct Client *client_p) |
4d21f1e8 | 202 | { |
4d3f8ead | 203 | if (IsPerson(client_p)) |
8093dc5f | 204 | { |
6c639159 | 205 | if (client_p->umodes & user_modes[UMODECHAR_HELPOPS]) |
b1c32af9 | 206 | helper_delete(client_p); |
8093dc5f | 207 | } |
4d3f8ead | 208 | else if (IsServer(client_p)) |
8093dc5f AC |
209 | { |
210 | rb_dlink_node *nptr; | |
211 | ||
4d3f8ead AC |
212 | RB_DLINK_FOREACH(nptr, client_p->serv->users.head) |
213 | recurse_client_exit(nptr->data); | |
8093dc5f | 214 | |
4d3f8ead AC |
215 | RB_DLINK_FOREACH(nptr, client_p->serv->servers.head) |
216 | recurse_client_exit(nptr->data); | |
8093dc5f | 217 | } |
4d21f1e8 AC |
218 | } |
219 | ||
4d3f8ead | 220 | static void |
82436efb | 221 | h_hdl_client_exit(void *data) |
4d3f8ead | 222 | { |
82436efb | 223 | hook_data_client_exit *hdata = data; |
4d3f8ead AC |
224 | recurse_client_exit(hdata->target); |
225 | } | |
226 | ||
4d21f1e8 | 227 | static void |
82436efb | 228 | h_hdl_umode_changed(void *data) |
4d21f1e8 | 229 | { |
82436efb | 230 | hook_data_umode_changed *hdata = data; |
4d21f1e8 AC |
231 | struct Client *source_p = hdata->client; |
232 | ||
0f8ec938 | 233 | /* didn't change +h umode, we don't need to do anything */ |
53390430 | 234 | bool changed = (hdata->oldumodes ^ source_p->umodes) & user_modes[UMODECHAR_HELPOPS]; |
4d21f1e8 | 235 | |
6c639159 | 236 | if (source_p->umodes & user_modes[UMODECHAR_HELPOPS]) |
4d21f1e8 AC |
237 | { |
238 | if (MyClient(source_p) && !HasPrivilege(source_p, "usermode:helpops")) | |
239 | { | |
6c639159 | 240 | source_p->umodes &= ~user_modes[UMODECHAR_HELPOPS]; |
4d21f1e8 | 241 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "usermode:helpops"); |
0f8ec938 | 242 | /* they didn't ask for +h so we must be removing it */ |
53390430 EK |
243 | if (!changed) |
244 | helper_delete(source_p); | |
4d21f1e8 AC |
245 | return; |
246 | } | |
247 | ||
53390430 EK |
248 | if (changed) |
249 | helper_add(source_p); | |
4d21f1e8 | 250 | } |
53390430 EK |
251 | else if (changed) |
252 | { | |
b1c32af9 | 253 | helper_delete(source_p); |
53390430 | 254 | } |
4d21f1e8 AC |
255 | } |
256 | ||
257 | static void | |
82436efb | 258 | h_hdl_whois(void *data) |
4d21f1e8 | 259 | { |
82436efb | 260 | hook_data_client *hdata = data; |
4d21f1e8 AC |
261 | struct Client *source_p = hdata->client; |
262 | struct Client *target_p = hdata->target; | |
263 | ||
6c639159 | 264 | if ((target_p->umodes & user_modes[UMODECHAR_HELPOPS]) && EmptyString(target_p->user->away)) |
4d21f1e8 AC |
265 | { |
266 | sendto_one_numeric(source_p, RPL_WHOISHELPOP, form_str(RPL_WHOISHELPOP), target_p->name); | |
267 | } | |
268 | } | |
269 | ||
a278a4fc | 270 | DECLARE_MODULE_AV2(helpops, _modinit, _moddeinit, helpops_clist, NULL, helpops_hfnlist, NULL, NULL, helpops_desc); |