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