6 #include "../localuser/localuser.h"
7 #include "../localuser/localuserchannel.h"
8 #include "../control/control.h"
9 #include "../channel/channel.h"
10 #include "../nick/nick.h"
11 #include "../core/config.h"
12 #include "../core/schedule.h"
13 #include "../core/hooks.h"
15 #include "helpmod_entries.h"
16 #include "helpmod_alias.h"
20 #include "hcommands.h"
35 int HELPMOD_ACCOUNT_EXPIRATION
[] =
37 14 * HDEF_d
, /* H_LAMER */
38 7 * HDEF_d
, /* H_PEON */
39 1 * HDEF_M
, /* H_FRIEND */
40 2 * HDEF_M
, /* H_TRIAL */
41 6 * HDEF_M
, /* H_STAFF */
42 1 * HDEF_y
, /* H_OPER */
43 2 * HDEF_y
/* H_ADMIN */
51 hlc_profile
*hlc_profiles
;
55 helpmod_editor
*helpmod_editors
;
57 modechanges hmodechanges
;
58 time_t helpmod_startup_time
;
60 helpmod_entry helpmod_base
;
63 char helpmod_db
[128] = "helpmod/default";
67 time_t hstat_last_cycle
;
75 void hcommit_modes(void)
77 if (hmodechanges
.cp
== NULL
)
79 if (hchannel_get_by_channel(hmodechanges
.cp
)->flags
& H_PASSIVE
)
81 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
84 localsetmodeflush(&hmodechanges
, 1);
85 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
88 void helpmod_reply(huser
*target
, channel
* returntype
, const char *message
, ... )
94 if (helpmodnick
==NULL
) {
99 vsnprintf(buf
,512,message
,va
);
102 if (buf
[0] == '\0' || buf
[0] == '\n')
105 if (returntype
) /* channel */
106 reply_type
= H_REPLY_NOTICE
;
108 reply_type
= H_REPLY_PRIVMSG
;
110 if (target
->account
!= NULL
)
112 if (target
->account
->flags
& H_ALL_PRIVMSG
)
113 reply_type
= H_REPLY_PRIVMSG
;
114 if (target
->account
->flags
& H_ALL_NOTICE
)
115 reply_type
= H_REPLY_NOTICE
;
118 if (reply_type
== H_REPLY_PRIVMSG
)
119 sendmessagetouser(helpmodnick
,target
->real_user
, "%s", buf
);
121 sendnoticetouser(helpmodnick
,target
->real_user
, "%s", buf
);
124 void helpmod_message_channel(hchannel
*hchan
, const char *message
, ...)
129 if (helpmodnick
==NULL
|| hchan
== NULL
) {
133 va_start(va
,message
);
134 vsnprintf(buf
,512,message
,va
);
137 if (hchan
->flags
& H_PASSIVE
)
140 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", buf
);
143 void helpmod_message_channel_long(hchannel
*hchan
, const char *message
, ...)
145 char buf
[2048], *bp
= buf
;
149 if (helpmodnick
==NULL
|| hchan
== NULL
) {
153 va_start(va
,message
);
154 vsnprintf(buf
,2048,message
,va
);
157 if (hchan
->flags
& H_PASSIVE
)
160 while (strlen(bp
) > 450)
163 if (isspace(bp
[390 + i
]))
170 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
174 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, "%s", bp
);
177 void helpmod_kick(hchannel
*hchan
, huser
*target
, const char *reason
, ...)
182 if (hchan
->flags
& H_PASSIVE
)
186 vsnprintf(buf
,512,reason
,va
);
189 localkickuser(helpmodnick
, hchan
->real_channel
, target
->real_user
, buf
);
192 void helpmod_invite(hchannel
*hchan
, huser
*husr
)
194 if (hchan
->flags
& H_PASSIVE
)
197 localinvite(helpmodnick
, hchan
->real_channel
, husr
->real_user
);
200 static void hmode_set_channel(hchannel
*hchan
)
202 if (hmodechanges
.cp
&& hmodechanges
.cp
!= hchan
->real_channel
)
204 hmodechanges
.cp
= hchan
->real_channel
;
207 void helpmod_channick_modes(huser
*target
, hchannel
*hchan
, short mode
, int now
)
209 void *args
[] = { hchan
->real_channel
, helpmodnick
, target
->real_user
};
210 hmode_set_channel(hchan
);
211 localdosetmode_nick(&hmodechanges
, target
->real_user
, mode
);
213 if (huser_on_channel(target
, hchan
) == NULL
)
215 Error("helpmod", ERR_WARNING
, "Channick mode for user %s not on channel %s", huser_get_nick(target
), hchannel_get_name(hchan
));
219 if (hchan
->flags
& H_PASSIVE
)
225 triggerhook(HOOK_CHANNEL_OPPED
, args
);
228 triggerhook(HOOK_CHANNEL_DEOPPED
, args
);
231 triggerhook(HOOK_CHANNEL_VOICED
, args
);
234 triggerhook(HOOK_CHANNEL_DEVOICED
, args
);
242 void helpmod_setban(hchannel
*hchan
, const char *banstr
, time_t expiration
, int type
, int now
)
244 hmode_set_channel(hchan
);
246 if (hchan
->flags
& H_PASSIVE
)
249 localdosetmode_ban(&hmodechanges
, banstr
, type
);
251 if ((type
== MCB_ADD
) && (expiration
> time(NULL
)))
252 scheduleoneshot(expiration
, (ScheduleCallback
)&hchanban_schedule_entry
, hchanban_add(hchan
, banstr
, expiration
));
258 void helpmod_simple_modes(hchannel
*hchan
, int add
, int remove
, int now
)
260 hmode_set_channel(hchan
);
262 if (hchan
->flags
& H_PASSIVE
)
265 localdosetmode_simple(&hmodechanges
, add
, remove
);
271 void helpmod_set_topic(hchannel
*hchan
, const char* topic
)
273 if (hchan
->flags
& H_PASSIVE
)
276 localsettopic(helpmodnick
, hchan
->real_channel
, (char*)topic
);
279 void helpmod_privmsg(void **args
)
281 void *sender
= args
[0];
282 void *message
= args
[1];
287 sender_nick
= getnickbynick((char*)sender
);
289 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
290 sender_huser
= huser_add(sender_nick
);
292 huser_activity(sender_huser
, NULL
);
294 helpmod_command(sender_huser
, NULL
, (char*)message
);
297 void helpmod_chan_privmsg(void **args
)
299 void *sender
= args
[0];
300 channel
*chan
= (channel
*)args
[1];
301 void *message
= args
[2];
306 hchannel
*hchan
= hchannel_get_by_channel(chan
);
308 sender_nick
= getnickbynick((char*)sender
);
310 if ((hchan
== NULL
|| hchan
->flags
& H_PASSIVE
))
313 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
314 sender_huser
= huser_add(sender_nick
);
316 if (hchan
->flags
& H_DO_STATS
)
318 if (sender_huser
->account
!= NULL
)
319 hstat_calculate_account(hchan
, sender_huser
, message
);
320 hstat_calculate_channel(hchan
, sender_huser
, message
);
322 huser_activity(sender_huser
, hchan
);
324 if (huser_get_level(sender_huser
) < H_TRIAL
) /* staff and staff trials are not subject to any control */
326 if ((hchan
->flags
& H_CENSOR
) && (tmp
= hcensor_check(hchan
->censor
, (char*)message
)))
328 if (hcensor_match(hchan
, sender_huser
, tmp
))
331 if ((hchan
->flags
& H_LAMER_CONTROL
) && (hlc_check(hchan
, sender_huser
, (char*)message
)))
333 if ((hchan
->flags
& H_DISALLOW_LAME_TEXT
) && helpmod_is_lame_line(message
))
335 helpmod_kick(hchan
, sender_huser
, "Please only use normal text on %s", hchannel_get_name(hchan
));
338 if ((hchan
->flags
& H_HIGHLIGHT_PREVENTION
) && hchannel_highlight_detection(hchan
, (char*)message
))
340 helpmod_kick(hchan
, sender_huser
, "Please do not abuse the highlight feature of IRC clients");
345 if (hcommand_is_command((char*)message
) && (hchan
->flags
& H_CHANNEL_COMMANDS
))
346 helpmod_command(sender_huser
, chan
, (char*)message
);
349 void helpmod_kicked(void **args
)
351 /* just rejoin the channel, if an oper wants H gone he can use delchan */
352 channel
*cp
= findchannel(args
[1]);
354 localcreatechannel(helpmodnick
, args
[1]);
357 localjoinchannel(helpmodnick
, cp
);
358 localgetops(helpmodnick
, cp
);
362 void helpmodmessagehandler(nick
*sender
, int messagetype
, void **args
)
367 helpmod_privmsg(args
);
370 helpmod_chan_privmsg(args
);
373 helpmod_kicked(args
);
380 void helpconnect(void) {
382 helpmodnick
=registerlocaluser(HELPMOD_NICK
,
385 "NewServ HelpMod 2, /msg "HELPMOD_NICK
" help",
387 UMODE_OPER
|UMODE_ACCOUNT
|UMODE_SERVICE
,&helpmodmessagehandler
);
389 helpmod_registerhooks();
391 /* continue with the database */
392 if (helpmod_config_read(HELPMOD_DEFAULT_DB
))
394 Error("helpmod", ERR_WARNING
, "Error reading the default database '%s'", HELPMOD_DEFAULT_DB
);
395 if (helpmod_config_read(HELPMOD_FALLBACK_DB
))
396 Error("helpmod", ERR_ERROR
, "Error reading the fallback database '%s'", HELPMOD_FALLBACK_DB
);
399 Error("helpmod", ERR_ERROR
, "Read 0 accounts from database (something is broken)");
402 helpmod_init_entry(&helpmod_base
);
403 helpmod_load_entries(HELPMOD_HELP_DEFAULT_DB
);
421 helpmod_startup_time
= time(NULL
);
422 /* add the supported commands, needs to be done like this since 3 arrays would just become a mess */
423 /* first the legacy old-H commands */
429 /* init hmodechanges */
430 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
432 schedulerecurring(time(NULL
)+1,0,HDEF_h
,(ScheduleCallback
)&huser_clear_inactives
,NULL
);
433 schedulerecurring(time(NULL
)+1,0,HDEF_d
,(ScheduleCallback
)&haccount_clear_inactives
,NULL
);
434 schedulerecurring(time(NULL
)+1,0,HDEF_m
,(ScheduleCallback
)&hban_remove_expired
,NULL
);
435 schedulerecurring(time(NULL
)+1,0,30 * HDEF_s
, (ScheduleCallback
)&hchannel_remove_inactive_users
, NULL
);
436 schedulerecurring(time(NULL
)+1,0,60 * HDEF_m
,(ScheduleCallback
)&hchannel_report
, NULL
);
437 schedulerecurring(time(NULL
) + HDEF_h
, 0, 6 * HDEF_h
, (ScheduleCallback
)&helpmod_config_scheduled_events
, NULL
);
438 schedulerecurring(time(NULL
)+1,0,10 * HDEF_m
, (ScheduleCallback
)&hticket_remove_expired
, NULL
);
439 schedulerecurring(hstat_get_schedule_time() - 5 * HDEF_m
, 0, HDEF_d
, (ScheduleCallback
)&hstat_scheduler
, NULL
);
446 helpmod_deregisterhooks();
447 /* write the database so that we don't lose anything
448 existance of atleast one account is required (sanity check)
451 helpmod_config_write(HELPMOD_DEFAULT_DB
);
453 /* delete schedule stuff */
454 deleteallschedules((ScheduleCallback
)&helpconnect
);
455 deleteallschedules((ScheduleCallback
)&huser_clear_inactives
);
456 deleteallschedules((ScheduleCallback
)&haccount_clear_inactives
);
457 deleteallschedules((ScheduleCallback
)&hban_remove_expired
);
458 deleteallschedules((ScheduleCallback
)&hchannel_remove_inactive_users
);
459 deleteallschedules((ScheduleCallback
)&hchannel_report
);
460 deleteallschedules((ScheduleCallback
)&helpmod_config_scheduled_events
);
461 deleteallschedules((ScheduleCallback
)&hstat_scheduler
);
462 deleteallschedules((ScheduleCallback
)&hchannel_deactivate_join_flood
);
463 deleteallschedules((ScheduleCallback
)&hchanban_schedule_entry
);
464 deleteallschedules((ScheduleCallback
)&hticket_remove_expired
);
473 helpmod_clear_aliases(&aliases
);
474 helpmod_clear_all_entries();
476 deregisterlocaluser(helpmodnick
, "Module unloaded");