6 #include "helpmod_entries.h"
7 #include "helpmod_alias.h"
11 #include "hcommands.h"
25 #include "../lib/version.h"
29 int HELPMOD_ACCOUNT_EXPIRATION
[] =
31 14 * HDEF_d
, /* H_LAMER */
32 7 * HDEF_d
, /* H_PEON */
33 1 * HDEF_M
, /* H_FRIEND */
34 2 * HDEF_M
, /* H_TRIAL */
35 6 * HDEF_M
, /* H_STAFF */
36 1 * HDEF_y
, /* H_OPER */
37 2 * HDEF_y
/* H_ADMIN */
45 hlc_profile
*hlc_profiles
;
49 helpmod_editor
*helpmod_editors
;
51 modechanges hmodechanges
;
52 time_t helpmod_startup_time
;
54 helpmod_entry helpmod_base
;
57 char helpmod_db
[128] = "helpmod/default";
61 time_t hstat_last_cycle
;
69 void hcommit_modes(void)
71 if (hmodechanges
.cp
== NULL
)
73 if (hchannel_get_by_channel(hmodechanges
.cp
)->flags
& H_PASSIVE
)
75 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
78 localsetmodeflush(&hmodechanges
, 1);
79 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
82 void helpmod_reply(huser
*target
, channel
* returntype
, const char *message
, ... )
88 if (helpmodnick
==NULL
) {
93 vsnprintf(buf
,512,message
,va
);
96 if (buf
[0] == '\0' || buf
[0] == '\n')
99 if (returntype
) /* channel */
100 reply_type
= H_REPLY_NOTICE
;
102 reply_type
= H_REPLY_PRIVMSG
;
104 if (target
->account
!= NULL
)
106 if (target
->account
->flags
& H_ALL_PRIVMSG
)
107 reply_type
= H_REPLY_PRIVMSG
;
108 if (target
->account
->flags
& H_ALL_NOTICE
)
109 reply_type
= H_REPLY_NOTICE
;
112 if (reply_type
== H_REPLY_PRIVMSG
)
113 sendmessagetouser(helpmodnick
,target
->real_user
, "%s", buf
);
115 sendnoticetouser(helpmodnick
,target
->real_user
, "%s", buf
);
118 void helpmod_message_channel(hchannel
*hchan
, const char *message
, ...)
123 if (helpmodnick
==NULL
|| hchan
== NULL
) {
127 va_start(va
,message
);
128 vsnprintf(buf
,512,message
,va
);
131 if (hchan
->flags
& H_PASSIVE
)
134 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", buf
);
137 void helpmod_message_channel_long(hchannel
*hchan
, const char *message
, ...)
139 char buf
[2048], *bp
= buf
;
143 if (helpmodnick
==NULL
|| hchan
== NULL
) {
147 va_start(va
,message
);
148 vsnprintf(buf
,2048,message
,va
);
151 if (hchan
->flags
& H_PASSIVE
)
154 while (strlen(bp
) > 450)
157 if (isspace(bp
[390 + i
]))
164 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
168 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
171 void helpmod_kick(hchannel
*hchan
, huser
*target
, const char *reason
, ...)
176 if (hchan
->flags
& H_PASSIVE
)
180 vsnprintf(buf
,512,reason
,va
);
183 localkickuser(helpmodnick
, hchan
->real_channel
, target
->real_user
, buf
);
186 void helpmod_invite(hchannel
*hchan
, huser
*husr
)
188 if (hchan
->flags
& H_PASSIVE
)
191 localinvite(helpmodnick
, hchan
->real_channel
->index
, husr
->real_user
);
194 static void hmode_set_channel(hchannel
*hchan
)
196 if (hmodechanges
.cp
&& hmodechanges
.cp
!= hchan
->real_channel
)
198 hmodechanges
.cp
= hchan
->real_channel
;
201 void helpmod_channick_modes(huser
*target
, hchannel
*hchan
, short mode
, int now
)
203 void *args
[] = { hchan
->real_channel
, helpmodnick
, target
->real_user
};
204 hmode_set_channel(hchan
);
205 localdosetmode_nick(&hmodechanges
, target
->real_user
, mode
);
207 if (huser_on_channel(target
, hchan
) == NULL
)
209 Error("helpmod", ERR_WARNING
, "Channick mode for user %s not on channel %s", huser_get_nick(target
), hchannel_get_name(hchan
));
213 if (hchan
->flags
& H_PASSIVE
)
219 triggerhook(HOOK_CHANNEL_OPPED
, args
);
222 triggerhook(HOOK_CHANNEL_DEOPPED
, args
);
225 triggerhook(HOOK_CHANNEL_VOICED
, args
);
228 triggerhook(HOOK_CHANNEL_DEVOICED
, args
);
236 void helpmod_setban(hchannel
*hchan
, const char *banstr
, time_t expiration
, int type
, int now
)
238 hmode_set_channel(hchan
);
240 if (hchan
->flags
& H_PASSIVE
)
243 localdosetmode_ban(&hmodechanges
, banstr
, type
);
245 if ((type
== MCB_ADD
) && (expiration
> time(NULL
)))
246 scheduleoneshot(expiration
, (ScheduleCallback
)&hchanban_schedule_entry
, hchanban_add(hchan
, banstr
, expiration
));
252 void helpmod_simple_modes(hchannel
*hchan
, int add
, int remove
, int now
)
254 hmode_set_channel(hchan
);
256 if (hchan
->flags
& H_PASSIVE
)
259 localdosetmode_simple(&hmodechanges
, add
, remove
);
265 void helpmod_set_topic(hchannel
*hchan
, const char* topic
)
267 if (hchan
->flags
& H_PASSIVE
)
270 localsettopic(helpmodnick
, hchan
->real_channel
, (char*)topic
);
273 void helpmod_privmsg(void **args
)
275 void *sender
= args
[0];
276 void *message
= args
[1];
281 sender_nick
= getnickbynick((char*)sender
);
283 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
284 sender_huser
= huser_add(sender_nick
);
286 huser_activity(sender_huser
, NULL
);
288 helpmod_command(sender_huser
, NULL
, (char*)message
);
291 void helpmod_chan_privmsg(void **args
)
293 void *sender
= args
[0];
294 channel
*chan
= (channel
*)args
[1];
295 void *message
= args
[2];
300 hchannel
*hchan
= hchannel_get_by_channel(chan
);
302 sender_nick
= getnickbynick((char*)sender
);
304 if ((hchan
== NULL
|| hchan
->flags
& H_PASSIVE
))
307 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
308 sender_huser
= huser_add(sender_nick
);
310 if (hchan
->flags
& H_DO_STATS
)
312 if (sender_huser
->account
!= NULL
)
313 hstat_calculate_account(hchan
, sender_huser
, message
);
314 hstat_calculate_channel(hchan
, sender_huser
, message
);
316 huser_activity(sender_huser
, hchan
);
318 if (huser_get_level(sender_huser
) < H_FRIEND
) /* staff, staff trials and friends are not subject to any control */
320 if ((hchan
->flags
& H_CENSOR
) && (tmp
= hcensor_check(hchan
->censor
, (char*)message
)))
322 if (hcensor_match(hchan
, sender_huser
, tmp
))
325 if ((hchan
->flags
& H_LAMER_CONTROL
) && (hlc_check(hchan
, sender_huser
, (char*)message
)))
327 if ((hchan
->flags
& H_DISALLOW_LAME_TEXT
) && helpmod_is_lame_line(message
))
329 helpmod_kick(hchan
, sender_huser
, "Please only use normal text on %s", hchannel_get_name(hchan
));
332 if ((hchan
->flags
& H_HIGHLIGHT_PREVENTION
) && hchannel_highlight_detection(hchan
, (char*)message
))
334 helpmod_kick(hchan
, sender_huser
, "Please do not abuse the highlight feature of IRC clients");
339 if (hcommand_is_command((char*)message
) && (hchan
->flags
& H_CHANNEL_COMMANDS
))
340 helpmod_command(sender_huser
, chan
, (char*)message
);
343 void helpmod_kicked(void **args
)
345 /* just rejoin the channel, if an oper wants H gone he can use delchan */
346 channel
*cp
= findchannel(args
[1]);
348 localcreatechannel(helpmodnick
, args
[1]);
351 localjoinchannel(helpmodnick
, cp
);
352 localgetops(helpmodnick
, cp
);
356 void helpmodmessagehandler(nick
*sender
, int messagetype
, void **args
)
361 helpmod_privmsg(args
);
364 helpmod_chan_privmsg(args
);
367 helpmod_kicked(args
);
374 void helpconnect(void) {
376 helpmodnick
=registerlocaluser(HELPMOD_NICK
,
379 "NewServ HelpMod 2, /msg "HELPMOD_NICK
" help",
381 UMODE_OPER
|UMODE_ACCOUNT
|UMODE_SERVICE
,&helpmodmessagehandler
);
383 helpmod_registerhooks();
385 /* continue with the database */
386 if (helpmod_config_read(HELPMOD_DEFAULT_DB
))
388 Error("helpmod", ERR_WARNING
, "Error reading the default database '%s'", HELPMOD_DEFAULT_DB
);
389 if (helpmod_config_read(HELPMOD_FALLBACK_DB
))
390 Error("helpmod", ERR_ERROR
, "Error reading the fallback database '%s'", HELPMOD_FALLBACK_DB
);
393 Error("helpmod", ERR_ERROR
, "Read 0 accounts from database (something is broken)");
396 helpmod_init_entry(&helpmod_base
);
397 helpmod_load_entries(HELPMOD_HELP_DEFAULT_DB
);
415 helpmod_startup_time
= time(NULL
);
416 /* add the supported commands, needs to be done like this since 3 arrays would just become a mess */
417 /* first the legacy old-H commands */
423 /* init hmodechanges */
424 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
426 schedulerecurring(time(NULL
)+1,0,HDEF_h
,(ScheduleCallback
)&huser_clear_inactives
,NULL
);
427 schedulerecurring(time(NULL
)+1,0,HDEF_d
,(ScheduleCallback
)&haccount_clear_inactives
,NULL
);
428 schedulerecurring(time(NULL
)+1,0,HDEF_m
,(ScheduleCallback
)&hban_remove_expired
,NULL
);
429 schedulerecurring(time(NULL
)+1,0,30 * HDEF_s
, (ScheduleCallback
)&hchannel_remove_inactive_users
, NULL
);
430 schedulerecurring(time(NULL
)+1,0,60 * HDEF_m
,(ScheduleCallback
)&hchannel_report
, NULL
);
431 schedulerecurring(time(NULL
) + HDEF_h
, 0, 6 * HDEF_h
, (ScheduleCallback
)&helpmod_config_scheduled_events
, NULL
);
432 schedulerecurring(time(NULL
)+1,0,10 * HDEF_m
, (ScheduleCallback
)&hticket_remove_expired
, NULL
);
433 schedulerecurring(hstat_get_schedule_time() - 5 * HDEF_m
, 0, HDEF_d
, (ScheduleCallback
)&hstat_scheduler
, NULL
);
440 helpmod_deregisterhooks();
441 /* write the database so that we don't lose anything
442 existance of atleast one account is required (sanity check)
445 helpmod_config_write(HELPMOD_DEFAULT_DB
);
447 /* delete schedule stuff */
448 deleteallschedules((ScheduleCallback
)&helpconnect
);
449 deleteallschedules((ScheduleCallback
)&huser_clear_inactives
);
450 deleteallschedules((ScheduleCallback
)&haccount_clear_inactives
);
451 deleteallschedules((ScheduleCallback
)&hban_remove_expired
);
452 deleteallschedules((ScheduleCallback
)&hchannel_remove_inactive_users
);
453 deleteallschedules((ScheduleCallback
)&hchannel_report
);
454 deleteallschedules((ScheduleCallback
)&helpmod_config_scheduled_events
);
455 deleteallschedules((ScheduleCallback
)&hstat_scheduler
);
456 deleteallschedules((ScheduleCallback
)&hchannel_deactivate_join_flood
);
457 deleteallschedules((ScheduleCallback
)&hchanban_schedule_entry
);
458 deleteallschedules((ScheduleCallback
)&hticket_remove_expired
);
467 helpmod_clear_aliases(&aliases
);
468 helpmod_clear_all_entries();
470 deregisterlocaluser(helpmodnick
, "Module unloaded");