13 void helpmod_hook_quit(int unused, void *args)
15 nick *nck = ((nick**)args)[0];
16 huser *husr = huser_get(nck);
17 / * it was someone we didn't even know * /
24 void helpmod_hook_part(int unused, void *args)
26 channel *chan = ((channel**)args)[0];
27 hchannel *hchan = hchannel_get_by_channel(chan);
28 nick *nck = ((nick**)args)[1];
33 static void helpmod_hook_join(int unused
, void *args
)
35 channel
*chan
= ((channel
**)args
)[0];
36 hchannel
*hchan
= hchannel_get_by_channel(chan
);
37 nick
*nck
= ((nick
**)args
)[1];
40 /* if we're not on this channel or the target is G, the event is of no interest */
41 if (hchan
== NULL
|| nck
== helpmodnick
)
44 husr
= huser_get(nck
);
46 assert(husr
!= NULL
); /* hook_channel_newnick should fix this */
48 if ((hchan
->flags
& H_JOINFLOOD_PROTECTION
) && !(hchan
->flags
& H_PASSIVE
))
50 if (hchan
->jf_control
< time(NULL
))
51 hchan
->jf_control
= time(NULL
);
55 if (hchan
->jf_control
- time(NULL
) > 12 && !IsRegOnly(hchan
))
57 if (hchan
->flags
& H_REPORT
&& hchannel_is_valid(hchan
->report_to
))
58 helpmod_message_channel(hchan
->report_to
, "Warning: Possible join flood on %s, setting +r", hchannel_get_name(hchan
));
59 hchannel_activate_join_flood(hchan
);
63 if (hchan
->flags
& H_PASSIVE
)
66 if (hchan
->flags
& H_DO_STATS
)
67 hstat_add_join(hchan
);
69 if (hchan
->flags
& H_TROJAN_REMOVAL
&& huser_is_trojan(husr
))
71 hban_huser(husr
, "Trojan client", time(NULL
) + 4 * HDEF_d
, 1);
75 if (huser_get_level(husr
) >= H_STAFF
&& (huser_get_account_flags(husr
) & H_AUTO_OP
) && hchannel_authority(hchan
, husr
))
76 helpmod_channick_modes(husr
, hchan
,MC_OP
,HNOW
);
78 if (huser_get_level(husr
) >= H_TRIAL
&& (huser_get_account_flags(husr
) & H_AUTO_VOICE
) && hchannel_authority(hchan
, husr
))
79 helpmod_channick_modes(husr
, hchan
, MC_VOICE
,HNOW
);
81 if (hchan
->flags
& H_WELCOME
&& *hchan
->real_channel
->index
->name
->content
)
82 helpmod_reply(husr
, chan
, "[%s] %s", hchan
->real_channel
->index
->name
->content
, hchan
->welcome
);
85 if (hchan
->flags
& H_QUEUE
&& hchan
->flags
& H_QUEUE_SPAMMY
)
87 if (huser_get_level(husr
) < H_STAFF
)
88 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
)));
90 if (IsModerated(hchan
->real_channel
) && !(hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_ANTI_IDLE
))
91 { /* being nice to users */
92 if (huser_get_level(husr
) < H_STAFF
)
93 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 static void helpmod_hook_channel_newnick(int unused
, void *args
)
99 channel
*chan
= ((channel
**)args
)[0];
100 hchannel
*hchan
= hchannel_get_by_channel(chan
);
101 nick
*nck
= ((nick
**)args
)[1];
104 /* if we're not on this channel or the target is G, the event is of no interest */
105 if (hchan
== NULL
|| nck
== helpmodnick
)
108 if ((husr
= huser_get(nck
)) == NULL
)
109 husr
= huser_add(nck
);
111 assert(huser_on_channel(husr
, hchan
) == NULL
);
112 assert(hchannel_on_channel(hchan
, husr
) == NULL
);
114 hchannel_add_user(hchan
, husr
);
115 huser_add_channel(husr
, hchan
);
117 if (hchan
->flags
& H_PASSIVE
)
120 huser_activity(husr
, NULL
);
122 if (huser_get_level(husr
) == H_LAMER
|| (huser_get_level(husr
) <= H_TRIAL
&& hban_check(nck
)))
124 hban
*hb
= hban_check(nck
);
126 const char *banmask
= hban_ban_string(nck
, HBAN_HOST
);
127 helpmod_setban(hchan
, banmask
, time(NULL
) + 1 * HDEF_d
, MCB_ADD
, HNOW
);
130 helpmod_kick(hchan
, husr
,hban_get_reason(hb
));
132 helpmod_kick(hchan
, husr
, "Your presence on channel %s is not wanted", hchannel_get_name(hchan
));
136 if (hchan
->flags
& H_QUEUE
)
137 hqueue_handle_queue(hchan
, NULL
);
140 static void helpmod_hook_channel_lostnick(int unused
, void *args
)
142 channel
*chan
= ((channel
**)args
)[0];
143 hchannel
*hchan
= hchannel_get_by_channel(chan
);
144 huser_channel
*huserchan
;
145 nick
*nck
= ((nick
**)args
)[1];
148 /* In event that G was kicked, nothing is done */
149 if (nck
== helpmodnick
)
152 /* hackery, can't think of a better way to do this */
154 int handle_queue
= 0;
156 /* if we're not on this channel, the event is of no interest */
160 husr
= huser_get(nck
);
162 assert(husr
!= NULL
);
164 huserchan
= huser_on_channel(husr
, hchan
);
166 assert(hchannel_on_channel(hchan
, husr
) != NULL
);
167 assert(huserchan
!= NULL
);
169 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)))*/
170 if (serverlist
[homeserver(husr
->real_user
->numeric
)].linkstate
!= LS_SQUIT
)
171 /* if it was a netsplit, we do not trigger autoqueue */
173 oper
= huserchan
->responsible_oper
;
177 hchannel_del_user(hchan
, husr
);
178 huser_del_channel(husr
, hchan
);
180 if (nck
== helpmodnick
)
181 { /* if H left the channel, we remove all the users from the channel */
182 while (hchan
->channel_users
)
184 huser_del_channel(hchan
->channel_users
->husr
, hchan
);
185 hchannel_del_user(hchan
, hchan
->channel_users
->husr
);
189 else if (handle_queue
)
190 hqueue_handle_queue(hchan
, oper
);
193 static void helpmod_hook_nick_lostnick(int unused
, void *args
)
195 nick
*nck
= (nick
*)args
;
196 huser
*husr
= huser_get(nck
);
198 /* it was someone we didn't even know */
205 static void helpmod_hook_channel_opped(int unused
, void *args
)
207 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
208 huser_channel
*huserchan
;
214 husr
= huser_get(((nick
**)args
)[2]);
215 husr2
= huser_get(((nick
**)args
)[1]);
217 assert(husr
!= NULL
);
219 huserchan
= huser_on_channel(husr
, hchan
);
221 assert(huserchan
!= NULL
);
223 huserchan
->flags
|= HCUMODE_OP
;
225 if (hchan
->flags
& H_PASSIVE
)
228 /* if the +o was given by a network service, G will not interfere */
229 if (husr2
== NULL
|| strlen(huser_get_nick(husr2
)) == 1)
232 if (huser_get_level(husr
) < H_STAFF
)
233 helpmod_channick_modes(husr
, hchan
, MC_DEOP
,HNOW
);
236 static void helpmod_hook_channel_deopped(int unused
, void *args
)
238 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
239 huser_channel
*huserchan
;
245 husr
= huser_get(((nick
**)args
)[2]);
247 assert(husr
!= NULL
);
249 huserchan
= huser_on_channel(husr
, hchan
);
251 assert(huserchan
!= NULL
);
253 huserchan
->flags
&= ~HCUMODE_OP
;
256 static void helpmod_hook_channel_voiced(int unused
, void *args
)
258 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
259 huser_channel
*huserchan
;
264 husr
= huser_get(((nick
**)args
)[2]);
266 assert(husr
!= NULL
);
268 huserchan
= huser_on_channel(husr
, hchan
);
270 assert(huserchan
!= NULL
);
272 huserchan
->flags
|= HCUMODE_VOICE
;
274 if (hchan
->flags
& H_QUEUE
)
276 huserchan
->flags
|= HQUEUE_DONE
;
277 huserchan
->last_activity
= time(NULL
);
281 static void helpmod_hook_channel_devoiced(int unused
, void *args
)
283 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
284 huser_channel
*huserchan
;
290 husr
= huser_get(((nick
**)args
)[2]);
292 assert(husr
!= NULL
);
294 huserchan
= huser_on_channel(husr
, hchan
);
296 assert(huserchan
!= NULL
);
298 huserchan
->flags
&= ~HCUMODE_VOICE
;
300 if (hchan
->flags
& H_PASSIVE
)
303 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
) && (huser_get_level(husr
) == H_PEON
) && (huserchan
->flags
& HCUMODE_VOICE
) && (hchannel_count_queue(hchan
)))
305 if (serverlist
[homeserver(husr
->real_user
->numeric
)].linkstate
!= LS_SQUIT
)
306 { /* if it was a netsplit, we do not trigger autoqueue */
307 hqueue_handle_queue(hchan
, huserchan
->responsible_oper
);
312 static void helpmod_hook_channel_topic(int unused
, void *args
)
314 hchannel
*hchan
= hchannel_get_by_channel(((channel
**)args
)[0]);
317 if (hchan
== NULL
|| hchan
->flags
& H_PASSIVE
)
320 husr
= huser_get(((nick
**)args
)[2]);
322 if (hchan
->flags
& H_HANDLE_TOPIC
)
324 if (husr
!= NULL
&& huser_get_level(husr
) >= H_OPER
)
326 htopic_del_all(&hchan
->topic
);
327 htopic_add(&hchan
->topic
, hchan
->real_channel
->topic
->content
, 0);
331 hchannel_set_topic(hchan
);
336 static void helpmod_hook_nick_account(int unused
, void *args
)
338 nick
*nck
= (nick
*)args
;
339 huser
*husr
= huser_get(nck
);
340 huser_channel
*huserchan
, *huserchannext
;
344 husr
->account
= haccount_get_by_name(nck
->authname
);
346 if (huser_get_level(husr
) == H_LAMER
) {
347 for (huserchan
= husr
->hchannels
; huserchan
; huserchan
= huserchannext
) {
348 huserchannext
= huserchan
->next
;
349 helpmod_kick(huserchan
->hchan
, husr
, "Your presence on channel %s is not wanted", hchannel_get_name(huserchan
->hchan
));
354 static void helpmod_hook_server_newserver(int unused
, void *args
)
357 long numeric
= (long)args
;
358 server srv
= serverlist
[numeric
];
360 /* check linkstate to prevent spam */
361 if (srv
.linkstate
== LS_LINKING
)
363 for (hchan
= hchannels
;hchan
!= NULL
;hchan
= hchan
->next
)
364 if ((hchan
->flags
& H_HANDLE_TOPIC
) && (hchan
->topic
!= NULL
))
365 hchannel_set_topic(hchan
);
369 void helpmod_registerhooks(void)
371 /* registerhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
372 /*if (registerhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
373 registerhook(HOOK_CHANNEL_JOIN
, &helpmod_hook_join
);
374 registerhook(HOOK_NICK_LOSTNICK
, &helpmod_hook_nick_lostnick
);
375 registerhook(HOOK_CHANNEL_NEWNICK
, &helpmod_hook_channel_newnick
);
376 registerhook(HOOK_CHANNEL_LOSTNICK
, &helpmod_hook_channel_lostnick
);
377 registerhook(HOOK_CHANNEL_OPPED
, &helpmod_hook_channel_opped
);
378 registerhook(HOOK_CHANNEL_DEOPPED
, &helpmod_hook_channel_deopped
);
379 registerhook(HOOK_CHANNEL_VOICED
, &helpmod_hook_channel_voiced
);
380 registerhook(HOOK_CHANNEL_DEVOICED
, &helpmod_hook_channel_devoiced
);
381 registerhook(HOOK_CHANNEL_TOPIC
, &helpmod_hook_channel_topic
);
382 registerhook(HOOK_NICK_ACCOUNT
, &helpmod_hook_nick_account
);
383 registerhook(HOOK_SERVER_NEWSERVER
, &helpmod_hook_server_newserver
);
386 void helpmod_deregisterhooks(void)
388 /* deregisterhook(HOOK_NICK_QUIT, &helpmod_hook_quit); */
389 /*if (deregisterhook(HOOK_CHANNEL_PART, &helpmod_hook_part));*/
390 deregisterhook(HOOK_CHANNEL_JOIN
, &helpmod_hook_join
);
391 deregisterhook(HOOK_NICK_LOSTNICK
, &helpmod_hook_nick_lostnick
);
392 deregisterhook(HOOK_CHANNEL_NEWNICK
, &helpmod_hook_channel_newnick
);
393 deregisterhook(HOOK_CHANNEL_LOSTNICK
, &helpmod_hook_channel_lostnick
);
394 deregisterhook(HOOK_CHANNEL_OPPED
, &helpmod_hook_channel_opped
);
395 deregisterhook(HOOK_CHANNEL_DEOPPED
, &helpmod_hook_channel_deopped
);
396 deregisterhook(HOOK_CHANNEL_VOICED
, &helpmod_hook_channel_voiced
);
397 deregisterhook(HOOK_CHANNEL_DEVOICED
, &helpmod_hook_channel_devoiced
);
398 deregisterhook(HOOK_CHANNEL_TOPIC
, &helpmod_hook_channel_topic
);
399 deregisterhook(HOOK_NICK_ACCOUNT
, &helpmod_hook_nick_account
);
400 deregisterhook(HOOK_SERVER_NEWSERVER
, &helpmod_hook_server_newserver
);