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