4 #include "../core/hooks.h"
5 #include "../localuser/localuser.h"
16 void helpmod_hook_quit(int unused
, void *args
)
18 nick
*nck
= ((nick
**)args
)[0];
19 huser
*husr
= huser_get(nck
);
20 /* it was someone we didn't even know */
25 void helpmod_hook_part(int unused, void *args)
27 channel *chan = ((channel**)args)[0];
28 hchannel *hchan = hchannel_get_by_channel(chan);
29 nick *nck = ((nick**)args)[1];
35 void helpmod_hook_join(int unused
, void *args
)
37 channel
*chan
= ((channel
**)args
)[0];
38 hchannel
*hchan
= hchannel_get_by_channel(chan
);
39 nick
*nck
= ((nick
**)args
)[1];
42 /* if we're not on this channel, the event is of no interest */
43 if (hchan
== NULL
|| hchan
->flags
& H_PASSIVE
)
46 husr
= huser_get(nck
);
48 assert(husr
!= NULL
); /* hook_channel_newnick should fix this */
50 if (hchan
->flags
& H_JOINFLOOD_PROTECTION
)
52 if (hchan
->jf_control
< time(NULL
))
53 hchan
->jf_control
= time(NULL
);
57 if (hchan
->jf_control
- time(NULL
) > 25 && !IsRegOnly(hchan
))
59 if (hchan
->flags
& H_REPORT
&& hchannel_is_valid(hchan
->report_to
))
60 helpmod_message_channel(hchan
->report_to
, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan
));
61 hchannel_activate_join_flood(hchan
);
65 if (hchan
->flags
& H_DO_STATS
)
66 hstat_add_join(hchan
);
68 if (hchan
->flags
& H_TROJAN_REMOVAL
&& huser_is_trojan(husr
))
70 hban_huser(husr
, "Trojan client", time(NULL
) + 4 * HDEF_d
, 1);
74 if (huser_get_level(husr
) > H_PEON
&& (huser_get_account_flags(husr
) & H_AUTO_OP
) && hchannel_authority(hchan
, husr
))
75 helpmod_channick_modes(husr
, hchan
,MC_OP
,HNOW
);
77 if (huser_get_level(husr
) > H_PEON
&& (huser_get_account_flags(husr
) & H_AUTO_VOICE
) && hchannel_authority(hchan
, husr
))
78 helpmod_channick_modes(husr
, hchan
, MC_VOICE
,HNOW
);
80 if (hchan
->flags
& H_WELCOME
&& *hchan
->real_channel
->index
->name
->content
)
81 helpmod_reply(husr
, chan
, "[%s] %s", hchan
->real_channel
->index
->name
->content
, hchan
->welcome
);
84 if (hchan
->flags
& H_QUEUE
&& hchan
->flags
& H_QUEUE_SPAMMY
)
86 if (huser_get_level(husr
) < H_STAFF
)
87 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
)));
89 if (IsModerated(hchan
->real_channel
) && !(hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_ANTI_IDLE
))
90 { /* being nice to users */
91 if (huser_get_level(husr
) < H_STAFF
)
92 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
));
96 void helpmod_hook_channel_newnick(int unused
, void *args
)
98 channel
*chan
= ((channel
**)args
)[0];
99 hchannel
*hchan
= hchannel_get_by_channel(chan
);
100 nick
*nck
= ((nick
**)args
)[1];
103 /* if we're not on this channel, the event is of no interest */
107 if ((husr
= huser_get(nck
)) == NULL
)
108 husr
= huser_add(nck
);
110 fprintf(hdebug_file, "%d ADD %s to %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
113 assert(huser_on_channel(husr
, hchan
) == NULL
);
114 assert(hchannel_on_channel(hchan
, husr
) == NULL
);
116 hchannel_add_user(hchan
, husr
);
117 huser_add_channel(husr
, hchan
);
119 if (huser_get_level(husr
) == H_LAMER
|| (huser_get_level(husr
) == H_PEON
&& hban_check(nck
)))
121 hban
*hb
= hban_check(nck
);
124 const char *banmask
= hban_ban_string(nck
, HBAN_HOST
);
126 helpmod_setban(hchan
, banmask
, time(NULL
) + 1 * HDEF_d
, MCB_ADD
, HNOW
);
128 helpmod_kick(hchan
, husr
,hban_get_reason(hb
));
132 if (hchan
->flags
& H_QUEUE
)
133 hqueue_handle_queue(hchan
, NULL
);
136 void helpmod_hook_channel_lostnick(int unused
, void *args
)
138 channel
*chan
= ((channel
**)args
)[0];
139 hchannel
*hchan
= hchannel_get_by_channel(chan
);
140 huser_channel
*huserchan
;
141 nick
*nck
= ((nick
**)args
)[1];
144 /* hackery, can't think of a better way to do this */
146 int handle_queue
= 0;
148 /* if we're not on this channel, the event is of no interest */
152 husr
= huser_get(nck
);
154 assert(husr
!= NULL
);
156 huserchan
= huser_on_channel(husr
, hchan
);
158 fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), husr->real_user->nick, hchannel_get_name(hchan));
161 assert(hchannel_on_channel(hchan
, husr
) != NULL
);
162 assert(huserchan
!= NULL
);
164 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
)) /* && (huser_get_level(husr) == H_PEON) && (huserchan->flags & HCUMODE_VOICE) && (hchannel_count_queue(hchan)))*/
165 if (serverlist
[homeserver(husr
->real_user
->numeric
)].linkstate
!= LS_SQUIT
)
166 /* if it was a netsplit, we do not trigger autoqueue */
168 oper
= huserchan
->responsible_oper
;
172 hchannel_del_user(hchan
, husr
);
173 huser_del_channel(husr
, hchan
);
175 if (nck
== helpmodnick
)
176 { /* if H left the channel, we remove all the users from the channel */
177 while (hchan
->channel_users
)
180 fprintf(hdebug_file, "%d DEL %s from %s\n", time(NULL), hchan->channel_users->husr->real_user->nick, hchannel_get_name(hchan));
183 huser_del_channel(hchan
->channel_users
->husr
, hchan
);
184 hchannel_del_user(hchan
, hchan
->channel_users
->husr
);
188 else if (handle_queue
)
189 hqueue_handle_queue(hchan
, oper
);
192 void helpmod_hook_nick_lostnick(int unused
, void *args
)
194 nick
*nck
= ((nick
**)args
)[0];
195 huser
*husr
= huser_get(nck
);
197 /* it was someone we didn't even know */
204 void helpmod_hook_channel_opped(int unused
, void *args
)
206 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
207 huser_channel
*huserchan
;
213 husr
= huser_get(((nick
**)args
)[2]);
214 husr2
= huser_get(((nick
**)args
)[1]);
216 assert(husr
!= NULL
);
218 huserchan
= huser_on_channel(husr
, hchan
);
220 assert(huserchan
!= NULL
);
222 huserchan
->flags
|= HCUMODE_OP
;
224 /* if the +o was given by a network service, G will not interfere */
225 if (husr2
== NULL
|| strlen(husr2
->real_user
->nick
) == 1)
228 if (huser_get_level(husr
) < H_STAFF
)
229 helpmod_channick_modes(husr
, hchan
, MC_DEOP
,HNOW
);
232 void helpmod_hook_channel_deopped(int unused
, void *args
)
234 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
235 huser_channel
*huserchan
;
241 husr
= huser_get(((nick
**)args
)[2]);
243 assert(husr
!= NULL
);
245 huserchan
= huser_on_channel(husr
, hchan
);
247 assert(huserchan
!= NULL
);
249 huserchan
->flags
&= ~HCUMODE_OP
;
253 void helpmod_hook_channel_voiced(int unused
, void *args
)
255 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
256 huser_channel
*huserchan
;
261 husr
= huser_get(((nick
**)args
)[2]);
263 assert(husr
!= NULL
);
265 huserchan
= huser_on_channel(husr
, hchan
);
267 assert(huserchan
!= NULL
);
269 huserchan
->flags
|= HCUMODE_VOICE
;
271 if (hchan
->flags
& H_QUEUE
)
273 huserchan
->flags
|= HQUEUE_DONE
;
274 huserchan
->last_activity
= time(NULL
);
278 void helpmod_hook_channel_devoiced(int unused
, void *args
)
280 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
281 huser_channel
*huserchan
;
287 husr
= huser_get(((nick
**)args
)[2]);
289 assert(husr
!= NULL
);
291 huserchan
= huser_on_channel(husr
, hchan
);
293 assert(huserchan
!= NULL
);
295 huserchan
->flags
&= ~HCUMODE_VOICE
;
297 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
) && (huser_get_level(husr
) == H_PEON
) && (huserchan
->flags
& HCUMODE_VOICE
) && (hchannel_count_queue(hchan
)))
299 if (serverlist
[homeserver(husr
->real_user
->numeric
)].linkstate
!= LS_SQUIT
)
300 { /* if it was a netsplit, we do not trigger autoqueue */
301 hqueue_handle_queue(hchan
, huserchan
->responsible_oper
);
302 /*if (huser_valid(huserchan->responsible_oper) && huser_on_channel(huserchan->responsible_oper, hchan))
303 hqueue_advance(hchan, huserchan->responsible_oper, 1);
305 hqueue_advance(hchan, huserchan->responsible_oper, 1);
311 void helpmod_hook_channel_topic(int unused
, void *args
)
313 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
319 husr
= huser_get(((nick
**)args
)[2]);
321 if (hchan
->flags
& H_HANDLE_TOPIC
)
323 if (husr
!= NULL
&& huser_get_level(husr
) >= H_OPER
)
325 htopic_del_all(&hchan
->topic
);
326 htopic_add(&hchan
->topic
, hchan
->real_channel
->topic
->content
, 0);
330 hchannel_set_topic(hchan
);
335 void helpmod_hook_nick_account(int unused
, void *args
)
337 nick
*nck
= (nick
*)args
;
338 huser
*husr
= huser_get(nck
);
342 husr
->account
= haccount_get_by_name(nck
->authname
);
345 void helpmod_registerhooks(void)
347 if (registerhook(HOOK_NICK_QUIT
, &helpmod_hook_quit
));
348 /*if (registerhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
349 if (registerhook(HOOK_CHANNEL_JOIN
, &helpmod_hook_join
));
350 if (registerhook(HOOK_NICK_LOSTNICK
, &helpmod_hook_nick_lostnick
));
351 if (registerhook(HOOK_CHANNEL_NEWNICK
, &helpmod_hook_channel_newnick
));
352 if (registerhook(HOOK_CHANNEL_LOSTNICK
, &helpmod_hook_channel_lostnick
));
353 if (registerhook(HOOK_CHANNEL_OPPED
, &helpmod_hook_channel_opped
));
354 if (registerhook(HOOK_CHANNEL_DEOPPED
, &helpmod_hook_channel_deopped
));
355 if (registerhook(HOOK_CHANNEL_VOICED
, &helpmod_hook_channel_voiced
));
356 if (registerhook(HOOK_CHANNEL_DEVOICED
, &helpmod_hook_channel_devoiced
));
357 if (registerhook(HOOK_CHANNEL_TOPIC
, &helpmod_hook_channel_topic
));
358 if (registerhook(HOOK_NICK_ACCOUNT
, &helpmod_hook_nick_account
));
361 void helpmod_deregisterhooks(void)
363 if (deregisterhook(HOOK_NICK_QUIT
, &helpmod_hook_quit
));
364 /*if (deregisterhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
365 if (deregisterhook(HOOK_CHANNEL_JOIN
, &helpmod_hook_join
));
366 if (deregisterhook(HOOK_NICK_LOSTNICK
, &helpmod_hook_nick_lostnick
));
367 if (deregisterhook(HOOK_CHANNEL_NEWNICK
, &helpmod_hook_channel_newnick
));
368 if (deregisterhook(HOOK_CHANNEL_LOSTNICK
, &helpmod_hook_channel_lostnick
));
369 if (deregisterhook(HOOK_CHANNEL_OPPED
, &helpmod_hook_channel_opped
));
370 if (deregisterhook(HOOK_CHANNEL_DEOPPED
, &helpmod_hook_channel_deopped
));
371 if (deregisterhook(HOOK_CHANNEL_VOICED
, &helpmod_hook_channel_voiced
));
372 if (deregisterhook(HOOK_CHANNEL_DEVOICED
, &helpmod_hook_channel_devoiced
));
373 if (deregisterhook(HOOK_CHANNEL_TOPIC
, &helpmod_hook_channel_topic
));
374 if (deregisterhook(HOOK_NICK_ACCOUNT
, &helpmod_hook_nick_account
));