]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/hhooks.c
r646@blue (orig r494): slug | 2006-05-15 23:35:33 +0100
[irc/quakenet/newserv.git] / helpmod2 / hhooks.c
CommitLineData
c86edd1d
Q
1#include <string.h>
2#include <assert.h>
3
4#include "../core/hooks.h"
5#include "../localuser/localuser.h"
6
7#include "helpmod.h"
8#include "hchannel.h"
9#include "haccount.h"
10#include "huser.h"
11#include "hban.h"
12#include "hqueue.h"
13#include "hgen.h"
14#include "hstat.h"
9af95c3d 15/*
c86edd1d
Q
16void helpmod_hook_quit(int unused, void *args)
17{
18 nick *nck = ((nick**)args)[0];
19 huser *husr = huser_get(nck);
9af95c3d 20 / * it was someone we didn't even know * /
c86edd1d
Q
21 if (husr == NULL)
22 return;
23}
9af95c3d 24*/
25
c86edd1d
Q
26/*
27void helpmod_hook_part(int unused, void *args)
28{
29 channel *chan = ((channel**)args)[0];
30 hchannel *hchan = hchannel_get_by_channel(chan);
31 nick *nck = ((nick**)args)[1];
32 huser *husr;
33
c86edd1d
Q
34}
35*/
052247fa 36static void helpmod_hook_join(int unused, void *args)
c86edd1d
Q
37{
38 channel *chan = ((channel**)args)[0];
39 hchannel *hchan = hchannel_get_by_channel(chan);
40 nick *nck = ((nick**)args)[1];
41 huser *husr;
42
6daae5b5 43 /* if we're not on this channel or the target is G, the event is of no interest */
44 if (hchan == NULL || nck == helpmodnick)
c86edd1d
Q
45 return;
46
47 husr = huser_get(nck);
48
49 assert(husr != NULL); /* hook_channel_newnick should fix this */
50
9af95c3d 51 if ((hchan->flags & H_JOINFLOOD_PROTECTION) && !(hchan->flags & H_PASSIVE))
c86edd1d 52 {
e908ecfa 53 if (hchan->jf_control < time(NULL))
54 hchan->jf_control = time(NULL);
55 else
56 hchan->jf_control++;
c86edd1d 57
052247fa 58 if (hchan->jf_control - time(NULL) > 12 && !IsRegOnly(hchan))
e908ecfa 59 {
60 if (hchan->flags & H_REPORT && hchannel_is_valid(hchan->report_to))
9af95c3d 61 helpmod_message_channel(hchan->report_to, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan));
62 hchannel_activate_join_flood(hchan);
63 }
c86edd1d
Q
64 }
65
e908ecfa 66 if (hchan->flags & H_PASSIVE)
67 return;
68
c86edd1d
Q
69 if (hchan->flags & H_DO_STATS)
70 hstat_add_join(hchan);
71
72 if (hchan->flags & H_TROJAN_REMOVAL && huser_is_trojan(husr))
73 {
74 hban_huser(husr, "Trojan client", time(NULL) + 4 * HDEF_d, 1);
75 return;
76 }
77
052247fa 78 if (huser_get_level(husr) >= H_STAFF && (huser_get_account_flags(husr) & H_AUTO_OP) && hchannel_authority(hchan, husr))
c86edd1d
Q
79 helpmod_channick_modes(husr, hchan ,MC_OP,HNOW);
80
052247fa 81 if (huser_get_level(husr) >= H_TRIAL && (huser_get_account_flags(husr) & H_AUTO_VOICE) && hchannel_authority(hchan, husr))
c86edd1d
Q
82 helpmod_channick_modes(husr, hchan, MC_VOICE,HNOW);
83
84 if (hchan->flags & H_WELCOME && *hchan->real_channel->index->name->content)
85 helpmod_reply(husr, chan, "[%s] %s", hchan->real_channel->index->name->content, hchan->welcome);
86
87
88 if (hchan->flags & H_QUEUE && hchan->flags & H_QUEUE_SPAMMY)
89 {
90 if (huser_get_level(husr) < H_STAFF)
91 helpmod_reply(husr, NULL, "Channel %s is using a queue system. This means you will have to wait for support. Your queue position is #%d and currently the average time in queue is %s. Please wait for your turn and do not attempt to contact channel operators directly", hchannel_get_name(hchan), hqueue_get_position(hchan, husr), helpmod_strtime(hqueue_average_time(hchan)));
92 }
93 if (IsModerated(hchan->real_channel) && !(hchan->flags & H_QUEUE) && (hchan->flags & H_ANTI_IDLE))
94 { /* being nice to users */
95 if (huser_get_level(husr) < H_STAFF)
96 helpmod_reply(husr, NULL, "Channel %s is currently moderated and there are anti-idle measures in place. This usually means that there is no one to handle your problem at this time. Please try again later and don't forget to read the FAQ at www.quakenet.org", hchannel_get_name(hchan));
97 }
98}
99
052247fa 100static void helpmod_hook_channel_newnick(int unused, void *args)
c86edd1d
Q
101{
102 channel *chan = ((channel**)args)[0];
103 hchannel *hchan = hchannel_get_by_channel(chan);
104 nick *nck = ((nick**)args)[1];
105 huser *husr;
106
6daae5b5 107 /* if we're not on this channel or the target is G, the event is of no interest */
108 if (hchan == NULL || nck == helpmodnick)
c86edd1d
Q
109 return;
110
111 if ((husr = huser_get(nck)) == NULL)
112 husr = huser_add(nck);
3a839281 113
c86edd1d
Q
114 assert(huser_on_channel(husr, hchan) == NULL);
115 assert(hchannel_on_channel(hchan, husr) == NULL);
116
117 hchannel_add_user(hchan, husr);
118 huser_add_channel(husr, hchan);
119
e908ecfa 120 if (hchan->flags & H_PASSIVE)
121 return;
122
052247fa
CP
123 huser_activity(husr, NULL);
124
125 if (huser_get_level(husr) == H_LAMER || (huser_get_level(husr) <= H_TRIAL && hban_check(nck)))
c86edd1d
Q
126 {
127 hban *hb = hban_check(nck);
c86edd1d 128
ce659137 129 const char *banmask = hban_ban_string(nck, HBAN_HOST);
130 helpmod_setban(hchan, banmask, time(NULL) + 1 * HDEF_d, MCB_ADD, HNOW);
c86edd1d 131
ce659137 132 if (hb)
133 helpmod_kick(hchan, husr,hban_get_reason(hb));
134 else
135 helpmod_kick(hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(hchan));
136
137 return;
c86edd1d
Q
138 }
139 if (hchan->flags & H_QUEUE)
140 hqueue_handle_queue(hchan, NULL);
141}
142
052247fa 143static void helpmod_hook_channel_lostnick(int unused, void *args)
c86edd1d
Q
144{
145 channel *chan = ((channel**)args)[0];
146 hchannel *hchan = hchannel_get_by_channel(chan);
147 huser_channel *huserchan;
148 nick *nck = ((nick**)args)[1];
149 huser *husr;
150
6daae5b5 151 /* In event that G was kicked, nothing is done */
152 if (nck == helpmodnick)
153 return;
154
c86edd1d
Q
155 /* hackery, can't think of a better way to do this */
156 huser *oper = NULL;
157 int handle_queue = 0;
158
159 /* if we're not on this channel, the event is of no interest */
160 if (hchan == NULL)
161 return;
162
163 husr = huser_get(nck);
164
165 assert(husr != NULL);
166
167 huserchan = huser_on_channel(husr, hchan);
3a839281 168
c86edd1d
Q
169 assert(hchannel_on_channel(hchan, husr) != NULL);
170 assert(huserchan != NULL);
171
e908ecfa 172 if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN) && !(hchan->flags & H_PASSIVE)) /* && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))*/
173 if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
c86edd1d
Q
174 /* if it was a netsplit, we do not trigger autoqueue */
175 {
176 oper = huserchan->responsible_oper;
177 handle_queue = !0;
178 }
179
180 hchannel_del_user(hchan, husr);
181 huser_del_channel(husr, hchan);
182
183 if (nck == helpmodnick)
184 { /* if H left the channel, we remove all the users from the channel */
185 while (hchan->channel_users)
186 {
c86edd1d
Q
187 huser_del_channel(hchan->channel_users->husr, hchan);
188 hchannel_del_user(hchan, hchan->channel_users->husr);
189 }
190 }
191
192 else if (handle_queue)
193 hqueue_handle_queue(hchan, oper);
194}
195
052247fa 196static void helpmod_hook_nick_lostnick(int unused, void *args)
c86edd1d 197{
9af95c3d 198 nick *nck = (nick*)args;
c86edd1d
Q
199 huser *husr = huser_get(nck);
200
201 /* it was someone we didn't even know */
202 if (husr == NULL)
e908ecfa 203 return;
c86edd1d
Q
204
205 huser_del(husr);
206}
207
052247fa 208static void helpmod_hook_channel_opped(int unused, void *args)
c86edd1d
Q
209{
210 hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
211 huser_channel *huserchan;
212 huser *husr, *husr2;
213
214 if (hchan == NULL)
215 return;
216
217 husr = huser_get(((nick**)args)[2]);
218 husr2 = huser_get(((nick**)args)[1]);
219
220 assert(husr != NULL);
221
222 huserchan = huser_on_channel(husr, hchan);
223
224 assert(huserchan != NULL);
225
226 huserchan->flags |= HCUMODE_OP;
227
e908ecfa 228 if (hchan->flags & H_PASSIVE)
229 return;
230
c86edd1d 231 /* if the +o was given by a network service, G will not interfere */
3a839281 232 if (husr2 == NULL || strlen(huser_get_nick(husr2)) == 1)
c86edd1d
Q
233 return;
234
235 if (huser_get_level(husr) < H_STAFF)
236 helpmod_channick_modes(husr, hchan, MC_DEOP ,HNOW);
237}
238
052247fa 239static void helpmod_hook_channel_deopped(int unused, void *args)
c86edd1d
Q
240{
241 hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
242 huser_channel *huserchan;
243 huser *husr;
244
245 if (hchan == NULL)
246 return;
247
248 husr = huser_get(((nick**)args)[2]);
249
250 assert(husr != NULL);
251
252 huserchan = huser_on_channel(husr, hchan);
253
254 assert(huserchan != NULL);
255
256 huserchan->flags &= ~HCUMODE_OP;
c86edd1d
Q
257}
258
052247fa 259static void helpmod_hook_channel_voiced(int unused, void *args)
c86edd1d
Q
260{
261 hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
262 huser_channel *huserchan;
263 huser *husr;
264
265 if (hchan == NULL)
266 return;
267 husr = huser_get(((nick**)args)[2]);
268
269 assert(husr != NULL);
270
271 huserchan = huser_on_channel(husr, hchan);
272
273 assert(huserchan != NULL);
274
275 huserchan->flags |= HCUMODE_VOICE;
276
277 if (hchan->flags & H_QUEUE)
278 {
279 huserchan->flags |= HQUEUE_DONE;
280 huserchan->last_activity = time(NULL);
281 }
282}
283
052247fa 284static void helpmod_hook_channel_devoiced(int unused, void *args)
c86edd1d
Q
285{
286 hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
287 huser_channel *huserchan;
288 huser *husr;
289
290 if (hchan == NULL)
291 return;
292
293 husr = huser_get(((nick**)args)[2]);
294
295 assert(husr != NULL);
296
297 huserchan = huser_on_channel(husr, hchan);
298
299 assert(huserchan != NULL);
300
301 huserchan->flags &= ~HCUMODE_VOICE;
302
e908ecfa 303 if (hchan->flags & H_PASSIVE)
304 return;
305
c86edd1d
Q
306 if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN) && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))
307 {
308 if (serverlist[homeserver(husr->real_user->numeric)].linkstate != LS_SQUIT)
309 { /* if it was a netsplit, we do not trigger autoqueue */
310 hqueue_handle_queue(hchan, huserchan->responsible_oper);
c86edd1d
Q
311 }
312 }
313}
314
052247fa 315static void helpmod_hook_channel_topic(int unused, void *args)
c86edd1d
Q
316{
317 hchannel *hchan = hchannel_get_by_channel(((channel**)args)[0]);
318 huser *husr;
319
e908ecfa 320 if (hchan == NULL || hchan->flags & H_PASSIVE)
c86edd1d
Q
321 return;
322
323 husr = huser_get(((nick**)args)[2]);
324
325 if (hchan->flags & H_HANDLE_TOPIC)
326 {
327 if (husr != NULL && huser_get_level(husr) >= H_OPER)
328 {
329 htopic_del_all(&hchan->topic);
330 htopic_add(&hchan->topic, hchan->real_channel->topic->content, 0);
331 }
332 else
333 {
334 hchannel_set_topic(hchan);
335 }
336 }
337}
338
052247fa 339static void helpmod_hook_nick_account(int unused, void *args)
c86edd1d
Q
340{
341 nick *nck = (nick*)args;
342 huser *husr = huser_get(nck);
343 if (husr == NULL)
344 return;
345 else
052247fa
CP
346 husr->account = haccount_get_by_name(nck->authname);
347
348 if (huser_get_level(husr) == H_LAMER)
349 while (husr->hchannels)
350 helpmod_kick(husr->hchannels->hchan, husr, "Your presence on channel %s is not wanted", hchannel_get_name(husr->hchannels->hchan));
c86edd1d
Q
351}
352
052247fa 353static void helpmod_hook_server_newserver(int unused, void *args)
9af95c3d 354{
355 hchannel *hchan;
356 int numeric = (int)args;
357 server srv = serverlist[numeric];
358
359 /* check linkstate to prevent spam */
360 if (srv.linkstate == LS_LINKING)
361 {
362 for (hchan = hchannels;hchan != NULL;hchan = hchan->next)
363 if ((hchan->flags & H_HANDLE_TOPIC) && (hchan->topic != NULL))
364 hchannel_set_topic(hchan);
365 }
366}
367
c86edd1d
Q
368void helpmod_registerhooks(void)
369{
9af95c3d 370/* registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
c86edd1d 371 /*if (registerhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
ce659137 372 registerhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
373 registerhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
374 registerhook(HOOK_CHANNEL_NEWNICK, &helpmod_hook_channel_newnick);
375 registerhook(HOOK_CHANNEL_LOSTNICK, &helpmod_hook_channel_lostnick);
376 registerhook(HOOK_CHANNEL_OPPED, &helpmod_hook_channel_opped);
377 registerhook(HOOK_CHANNEL_DEOPPED, &helpmod_hook_channel_deopped);
378 registerhook(HOOK_CHANNEL_VOICED, &helpmod_hook_channel_voiced);
379 registerhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
380 registerhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
381 registerhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
9af95c3d 382 registerhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
c86edd1d
Q
383}
384
385void helpmod_deregisterhooks(void)
386{
9af95c3d 387/* deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
c86edd1d 388 /*if (deregisterhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
ce659137 389 deregisterhook(HOOK_CHANNEL_JOIN, &helpmod_hook_join);
390 deregisterhook(HOOK_NICK_LOSTNICK, &helpmod_hook_nick_lostnick);
391 deregisterhook(HOOK_CHANNEL_NEWNICK, &helpmod_hook_channel_newnick);
392 deregisterhook(HOOK_CHANNEL_LOSTNICK, &helpmod_hook_channel_lostnick);
393 deregisterhook(HOOK_CHANNEL_OPPED, &helpmod_hook_channel_opped);
394 deregisterhook(HOOK_CHANNEL_DEOPPED, &helpmod_hook_channel_deopped);
395 deregisterhook(HOOK_CHANNEL_VOICED, &helpmod_hook_channel_voiced);
396 deregisterhook(HOOK_CHANNEL_DEVOICED, &helpmod_hook_channel_devoiced);
397 deregisterhook(HOOK_CHANNEL_TOPIC, &helpmod_hook_channel_topic);
398 deregisterhook(HOOK_NICK_ACCOUNT, &helpmod_hook_nick_account);
9af95c3d 399 deregisterhook(HOOK_SERVER_NEWSERVER, &helpmod_hook_server_newserver);
c86edd1d 400}