6 #include "helpmod_entries.h"
7 #include "helpmod_alias.h"
11 #include "hcommands.h"
26 int HELPMOD_ACCOUNT_EXPIRATION
[] =
28 14 * HDEF_d
, /* H_LAMER */
29 7 * HDEF_d
, /* H_PEON */
30 1 * HDEF_M
, /* H_FRIEND */
31 2 * HDEF_M
, /* H_TRIAL */
32 6 * HDEF_M
, /* H_STAFF */
33 1 * HDEF_y
, /* H_OPER */
34 2 * HDEF_y
/* H_ADMIN */
42 hlc_profile
*hlc_profiles
;
46 helpmod_editor
*helpmod_editors
;
48 modechanges hmodechanges
;
49 time_t helpmod_startup_time
;
51 helpmod_entry helpmod_base
;
54 char helpmod_db
[128] = "helpmod/default";
58 time_t hstat_last_cycle
;
66 void hcommit_modes(void)
68 if (hmodechanges
.cp
== NULL
)
70 if (hchannel_get_by_channel(hmodechanges
.cp
)->flags
& H_PASSIVE
)
72 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
75 localsetmodeflush(&hmodechanges
, 1);
76 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
79 void helpmod_reply(huser
*target
, channel
* returntype
, const char *message
, ... )
85 if (helpmodnick
==NULL
) {
90 vsnprintf(buf
,512,message
,va
);
93 if (buf
[0] == '\0' || buf
[0] == '\n')
96 if (returntype
) /* channel */
97 reply_type
= H_REPLY_NOTICE
;
99 reply_type
= H_REPLY_PRIVMSG
;
101 if (target
->account
!= NULL
)
103 if (target
->account
->flags
& H_ALL_PRIVMSG
)
104 reply_type
= H_REPLY_PRIVMSG
;
105 if (target
->account
->flags
& H_ALL_NOTICE
)
106 reply_type
= H_REPLY_NOTICE
;
109 if (reply_type
== H_REPLY_PRIVMSG
)
110 sendmessagetouser(helpmodnick
,target
->real_user
, "%s", buf
);
112 sendnoticetouser(helpmodnick
,target
->real_user
, "%s", buf
);
115 void helpmod_message_channel(hchannel
*hchan
, const char *message
, ...)
120 if (helpmodnick
==NULL
|| hchan
== NULL
) {
124 va_start(va
,message
);
125 vsnprintf(buf
,512,message
,va
);
128 if (hchan
->flags
& H_PASSIVE
)
131 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", buf
);
134 void helpmod_message_channel_long(hchannel
*hchan
, const char *message
, ...)
136 char buf
[2048], *bp
= buf
;
140 if (helpmodnick
==NULL
|| hchan
== NULL
) {
144 va_start(va
,message
);
145 vsnprintf(buf
,2048,message
,va
);
148 if (hchan
->flags
& H_PASSIVE
)
151 while (strlen(bp
) > 450)
154 if (isspace(bp
[390 + i
]))
161 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
165 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
168 void helpmod_kick(hchannel
*hchan
, huser
*target
, const char *reason
, ...)
173 if (hchan
->flags
& H_PASSIVE
)
177 vsnprintf(buf
,512,reason
,va
);
180 localkickuser(helpmodnick
, hchan
->real_channel
, target
->real_user
, buf
);
183 void helpmod_invite(hchannel
*hchan
, huser
*husr
)
185 if (hchan
->flags
& H_PASSIVE
)
188 localinvite(helpmodnick
, hchan
->real_channel
, husr
->real_user
);
191 static void hmode_set_channel(hchannel
*hchan
)
193 if (hmodechanges
.cp
&& hmodechanges
.cp
!= hchan
->real_channel
)
195 hmodechanges
.cp
= hchan
->real_channel
;
198 void helpmod_channick_modes(huser
*target
, hchannel
*hchan
, short mode
, int now
)
200 void *args
[] = { hchan
->real_channel
, helpmodnick
, target
->real_user
};
201 hmode_set_channel(hchan
);
202 localdosetmode_nick(&hmodechanges
, target
->real_user
, mode
);
204 if (huser_on_channel(target
, hchan
) == NULL
)
206 Error("helpmod", ERR_WARNING
, "Channick mode for user %s not on channel %s", huser_get_nick(target
), hchannel_get_name(hchan
));
210 if (hchan
->flags
& H_PASSIVE
)
216 triggerhook(HOOK_CHANNEL_OPPED
, args
);
219 triggerhook(HOOK_CHANNEL_DEOPPED
, args
);
222 triggerhook(HOOK_CHANNEL_VOICED
, args
);
225 triggerhook(HOOK_CHANNEL_DEVOICED
, args
);
233 void helpmod_setban(hchannel
*hchan
, const char *banstr
, time_t expiration
, int type
, int now
)
235 hmode_set_channel(hchan
);
237 if (hchan
->flags
& H_PASSIVE
)
240 localdosetmode_ban(&hmodechanges
, banstr
, type
);
242 if ((type
== MCB_ADD
) && (expiration
> time(NULL
)))
243 scheduleoneshot(expiration
, (ScheduleCallback
)&hchanban_schedule_entry
, hchanban_add(hchan
, banstr
, expiration
));
249 void helpmod_simple_modes(hchannel
*hchan
, int add
, int remove
, int now
)
251 hmode_set_channel(hchan
);
253 if (hchan
->flags
& H_PASSIVE
)
256 localdosetmode_simple(&hmodechanges
, add
, remove
);
262 void helpmod_set_topic(hchannel
*hchan
, const char* topic
)
264 if (hchan
->flags
& H_PASSIVE
)
267 localsettopic(helpmodnick
, hchan
->real_channel
, (char*)topic
);
270 void helpmod_privmsg(void **args
)
272 void *sender
= args
[0];
273 void *message
= args
[1];
278 sender_nick
= getnickbynick((char*)sender
);
280 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
281 sender_huser
= huser_add(sender_nick
);
283 huser_activity(sender_huser
, NULL
);
285 helpmod_command(sender_huser
, NULL
, (char*)message
);
288 void helpmod_chan_privmsg(void **args
)
290 void *sender
= args
[0];
291 channel
*chan
= (channel
*)args
[1];
292 void *message
= args
[2];
297 hchannel
*hchan
= hchannel_get_by_channel(chan
);
299 sender_nick
= getnickbynick((char*)sender
);
301 if ((hchan
== NULL
|| hchan
->flags
& H_PASSIVE
))
304 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
305 sender_huser
= huser_add(sender_nick
);
307 if (hchan
->flags
& H_DO_STATS
)
309 if (sender_huser
->account
!= NULL
)
310 hstat_calculate_account(hchan
, sender_huser
, message
);
311 hstat_calculate_channel(hchan
, sender_huser
, message
);
313 huser_activity(sender_huser
, hchan
);
315 if (huser_get_level(sender_huser
) < H_TRIAL
) /* staff and staff trials are not subject to any control */
317 if ((hchan
->flags
& H_CENSOR
) && (tmp
= hcensor_check(hchan
->censor
, (char*)message
)))
319 if (hcensor_match(hchan
, sender_huser
, tmp
))
322 if ((hchan
->flags
& H_LAMER_CONTROL
) && (hlc_check(hchan
, sender_huser
, (char*)message
)))
324 if ((hchan
->flags
& H_DISALLOW_LAME_TEXT
) && helpmod_is_lame_line(message
))
326 helpmod_kick(hchan
, sender_huser
, "Please only use normal text on %s", hchannel_get_name(hchan
));
329 if ((hchan
->flags
& H_HIGHLIGHT_PREVENTION
) && hchannel_highlight_detection(hchan
, (char*)message
))
331 helpmod_kick(hchan
, sender_huser
, "Please do not abuse the highlight feature of IRC clients");
336 if (hcommand_is_command((char*)message
) && (hchan
->flags
& H_CHANNEL_COMMANDS
))
337 helpmod_command(sender_huser
, chan
, (char*)message
);
340 void helpmod_kicked(void **args
)
342 /* just rejoin the channel, if an oper wants H gone he can use delchan */
343 channel
*cp
= findchannel(args
[1]);
345 localcreatechannel(helpmodnick
, args
[1]);
348 localjoinchannel(helpmodnick
, cp
);
349 localgetops(helpmodnick
, cp
);
353 void helpmodmessagehandler(nick
*sender
, int messagetype
, void **args
)
358 helpmod_privmsg(args
);
361 helpmod_chan_privmsg(args
);
364 helpmod_kicked(args
);
371 void helpconnect(void) {
373 helpmodnick
=registerlocaluser(HELPMOD_NICK
,
376 "NewServ HelpMod 2, /msg "HELPMOD_NICK
" help",
378 UMODE_OPER
|UMODE_ACCOUNT
|UMODE_SERVICE
,&helpmodmessagehandler
);
380 helpmod_registerhooks();
382 /* continue with the database */
383 if (helpmod_config_read(HELPMOD_DEFAULT_DB
))
385 Error("helpmod", ERR_WARNING
, "Error reading the default database '%s'", HELPMOD_DEFAULT_DB
);
386 if (helpmod_config_read(HELPMOD_FALLBACK_DB
))
387 Error("helpmod", ERR_ERROR
, "Error reading the fallback database '%s'", HELPMOD_FALLBACK_DB
);
390 Error("helpmod", ERR_ERROR
, "Read 0 accounts from database (something is broken)");
393 helpmod_init_entry(&helpmod_base
);
394 helpmod_load_entries(HELPMOD_HELP_DEFAULT_DB
);
412 helpmod_startup_time
= time(NULL
);
413 /* add the supported commands, needs to be done like this since 3 arrays would just become a mess */
414 /* first the legacy old-H commands */
420 /* init hmodechanges */
421 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
423 schedulerecurring(time(NULL
)+1,0,HDEF_h
,(ScheduleCallback
)&huser_clear_inactives
,NULL
);
424 schedulerecurring(time(NULL
)+1,0,HDEF_d
,(ScheduleCallback
)&haccount_clear_inactives
,NULL
);
425 schedulerecurring(time(NULL
)+1,0,HDEF_m
,(ScheduleCallback
)&hban_remove_expired
,NULL
);
426 schedulerecurring(time(NULL
)+1,0,30 * HDEF_s
, (ScheduleCallback
)&hchannel_remove_inactive_users
, NULL
);
427 schedulerecurring(time(NULL
)+1,0,60 * HDEF_m
,(ScheduleCallback
)&hchannel_report
, NULL
);
428 schedulerecurring(time(NULL
) + HDEF_h
, 0, 6 * HDEF_h
, (ScheduleCallback
)&helpmod_config_scheduled_events
, NULL
);
429 schedulerecurring(time(NULL
)+1,0,10 * HDEF_m
, (ScheduleCallback
)&hticket_remove_expired
, NULL
);
430 schedulerecurring(hstat_get_schedule_time() - 5 * HDEF_m
, 0, HDEF_d
, (ScheduleCallback
)&hstat_scheduler
, NULL
);
437 helpmod_deregisterhooks();
438 /* write the database so that we don't lose anything
439 existance of atleast one account is required (sanity check)
442 helpmod_config_write(HELPMOD_DEFAULT_DB
);
444 /* delete schedule stuff */
445 deleteallschedules((ScheduleCallback
)&helpconnect
);
446 deleteallschedules((ScheduleCallback
)&huser_clear_inactives
);
447 deleteallschedules((ScheduleCallback
)&haccount_clear_inactives
);
448 deleteallschedules((ScheduleCallback
)&hban_remove_expired
);
449 deleteallschedules((ScheduleCallback
)&hchannel_remove_inactive_users
);
450 deleteallschedules((ScheduleCallback
)&hchannel_report
);
451 deleteallschedules((ScheduleCallback
)&helpmod_config_scheduled_events
);
452 deleteallschedules((ScheduleCallback
)&hstat_scheduler
);
453 deleteallschedules((ScheduleCallback
)&hchannel_deactivate_join_flood
);
454 deleteallschedules((ScheduleCallback
)&hchanban_schedule_entry
);
455 deleteallschedules((ScheduleCallback
)&hticket_remove_expired
);
464 helpmod_clear_aliases(&aliases
);
465 helpmod_clear_all_entries();
467 deregisterlocaluser(helpmodnick
, "Module unloaded");