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"
34 int HELPMOD_ACCOUNT_EXPIRATION
[] =
36 14 * HDEF_d
, /* H_LAMER */
37 7 * HDEF_d
, /* H_PEON */
38 2 * HDEF_M
, /* H_TRIAL */
39 6 * HDEF_M
, /* H_STAFF */
40 1 * HDEF_y
, /* H_OPER */
41 2 * HDEF_y
/* H_ADMIN */
49 hlc_profile
*hlc_profiles
;
54 modechanges hmodechanges
;
55 time_t helpmod_startup_time
;
57 helpmod_entry helpmod_base
;
60 char helpmod_db
[128] = "helpmod/default";
64 time_t hstat_last_cycle
;
72 void hcommit_modes(void)
74 if (hmodechanges
.cp
== NULL
)
76 if (hchannel_get_by_channel(hmodechanges
.cp
)->flags
& H_PASSIVE
)
78 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
81 localsetmodeflush(&hmodechanges
, 1);
82 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
85 void helpmod_reply(huser
*target
, channel
* returntype
, const char *message
, ... )
91 if (helpmodnick
==NULL
) {
96 vsnprintf(buf
,512,message
,va
);
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 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, 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 while (strlen(bp
) > 450)
151 if (isspace(bp
[390 + i
]))
158 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, bp
);
162 sendmessagetochannel(helpmodnick
, hchan
->real_channel
, bp
);
165 void helpmod_kick(hchannel
*hchan
, huser
*target
, const char *reason
, ...)
170 if (hchan
->flags
& H_PASSIVE
)
174 vsnprintf(buf
,512,reason
,va
);
177 localkickuser(helpmodnick
, hchan
->real_channel
, target
->real_user
, buf
);
180 void helpmod_invite(hchannel
*hchan
, huser
*husr
)
182 localinvite(helpmodnick
, hchan
->real_channel
, husr
->real_user
);
185 static void hmode_set_channel(hchannel
*hchan
)
187 if (hmodechanges
.cp
&& hmodechanges
.cp
!= hchan
->real_channel
)
189 hmodechanges
.cp
= hchan
->real_channel
;
192 void helpmod_channick_modes(huser
*target
, hchannel
*hchan
, short mode
, int now
)
194 void *args
[] = { hchan
->real_channel
, helpmodnick
, target
->real_user
};
195 hmode_set_channel(hchan
);
196 localdosetmode_nick(&hmodechanges
, target
->real_user
, mode
);
198 if (huser_on_channel(target
, hchan
) == NULL
)
200 Error("helpmod", ERR_WARNING
, "Channick mode for user %s not on channel %s", target
->real_user
->nick
, hchannel_get_name(hchan
));
207 triggerhook(HOOK_CHANNEL_OPPED
, args
);
210 triggerhook(HOOK_CHANNEL_DEOPPED
, args
);
213 triggerhook(HOOK_CHANNEL_VOICED
, args
);
216 triggerhook(HOOK_CHANNEL_DEVOICED
, args
);
224 void helpmod_setban(hchannel
*hchan
, const char *banstr
, time_t expiration
, int type
, int now
)
226 hmode_set_channel(hchan
);
227 localdosetmode_ban(&hmodechanges
, banstr
, type
);
229 if ((type
== MCB_ADD
) && (expiration
> time(NULL
)))
230 scheduleoneshot(expiration
, (ScheduleCallback
)&hchanban_schedule_entry
, hchanban_add(hchan
, banstr
, expiration
));
236 void helpmod_simple_modes(hchannel
*hchan
, int add
, int remove
, int now
)
238 hmode_set_channel(hchan
);
240 localdosetmode_simple(&hmodechanges
, add
, remove
);
246 void helpmod_set_topic(hchannel
*hchan
, const char* topic
)
248 localsettopic(helpmodnick
, hchan
->real_channel
, (char*)topic
);
251 void helpmod_privmsg(void **args
)
253 void *sender
= args
[0];
254 void *message
= args
[1];
259 sender_nick
= getnickbynick((char*)sender
);
261 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
262 sender_huser
= huser_add(sender_nick
);
264 huser_activity(sender_huser
, NULL
);
266 helpmod_command(sender_huser
, NULL
, (char*)message
);
269 void helpmod_chan_privmsg(void **args
)
271 void *sender
= args
[0];
272 channel
*chan
= (channel
*)args
[1];
273 void *message
= args
[2];
278 hchannel
*hchan
= hchannel_get_by_channel(chan
);
280 sender_nick
= getnickbynick((char*)sender
);
282 if ((hchan
== NULL
|| hchan
->flags
& H_PASSIVE
))
285 if ((sender_huser
= huser_get(sender_nick
)) == NULL
)
286 sender_huser
= huser_add(sender_nick
);
288 if (hchan
->flags
& H_DO_STATS
)
289 hstat_calculate_general(hchan
, sender_huser
, message
);
291 huser_activity(sender_huser
, hchan
);
293 if (huser_get_level(sender_huser
) < H_TRIAL
) /* staff and staff trials are not subject to any control */
295 if ((hchan
->flags
& H_CENSOR
) && (tmp
= hcensor_check(hchan
->censor
, (char*)message
)))
297 helpmod_kick(hchan
, sender_huser
, tmp
->reason
?tmp
->reason
->content
:"Improper user");
300 if ((hchan
->flags
& H_LAMER_CONTROL
) && (hlc_check(hchan
, sender_huser
, (char*)message
)))
302 if ((hchan
->flags
& H_DISALLOW_LAME_TEXT
) && helpmod_is_lame_line(message
))
304 helpmod_kick(hchan
, sender_huser
, "Please use only normal text on %s", hchannel_get_name(hchan
));
309 if (hcommand_is_command((char*)message
) && (hchan
->flags
& H_CHANNEL_COMMANDS
))
310 helpmod_command(sender_huser
, chan
, (char*)message
);
313 void helpmod_kicked(void **args
)
315 /* just rejoin the channel, if an oper wants H gone he can use delchan */
316 channel
*cp
= findchannel(args
[1]);
318 localcreatechannel(helpmodnick
, args
[1]);
321 localjoinchannel(helpmodnick
, cp
);
322 localgetops(helpmodnick
, cp
);
326 void helpmodmessagehandler(nick
*sender
, int messagetype
, void **args
)
331 helpmod_privmsg(args
);
334 helpmod_chan_privmsg(args
);
337 helpmod_kicked(args
);
344 void helpconnect(void) {
346 helpmodnick
=registerlocaluser(HELPMOD_NICK
,
349 "NewServ HelpMod 2, /msg H help",
351 UMODE_OPER
|UMODE_ACCOUNT
|UMODE_SERVICE
,&helpmodmessagehandler
);
353 helpmod_registerhooks();
355 /* continue with the database */
356 if (helpmod_config_read(HELPMOD_DEFAULT_DB
))
358 Error("helpmod", ERR_WARNING
, "Error reading the default database '%s'", HELPMOD_DEFAULT_DB
);
359 if (helpmod_config_read(HELPMOD_FALLBACK_DB
))
360 Error("helpmod", ERR_ERROR
, "Error reading the fallback database '%s'", HELPMOD_FALLBACK_DB
);
363 Error("helpmod", ERR_ERROR
, "Read 0 accounts from database (something is broken)");
366 helpmod_init_entry(&helpmod_base
);
367 helpmod_load_entries(HELPMOD_HELP_DEFAULT_DB
);
385 helpmod_startup_time
= time(NULL
);
386 /* add the supported commands, needs to be done like this since 3 arrays would just become a mess */
387 /* first the legacy old-H commands */
393 /* init hmodechanges */
394 localsetmodeinit(&hmodechanges
, NULL
, helpmodnick
);
396 schedulerecurring(time(NULL
)+1,0,HDEF_h
,(ScheduleCallback
)&huser_clear_inactives
,NULL
);
397 schedulerecurring(time(NULL
)+1,0,HDEF_d
,(ScheduleCallback
)&haccount_clear_inactives
,NULL
);
398 schedulerecurring(time(NULL
)+1,0,HDEF_m
,(ScheduleCallback
)&hban_remove_expired
,NULL
);
399 schedulerecurring(time(NULL
)+1,0,30 * HDEF_s
, (ScheduleCallback
)&hchannel_remove_inactive_users
, NULL
);
400 schedulerecurring(time(NULL
)+1,0,5 * HDEF_m
,(ScheduleCallback
)&hchannel_report
, NULL
);
401 schedulerecurring(time(NULL
) + HDEF_h
, 0, 6 * HDEF_h
, (ScheduleCallback
)&helpmod_config_scheduled_events
, NULL
);
402 schedulerecurring(time(NULL
)+1,0,10 * HDEF_m
, (ScheduleCallback
)&hticket_remove_expired
, NULL
);
403 schedulerecurring(hstat_get_schedule_time() - 5 * HDEF_m
, 0, HDEF_d
, (ScheduleCallback
)&hstat_scheduler
, NULL
);
410 helpmod_deregisterhooks();
411 /* write the database so that we don't lose anything
412 existance of atleast one account is required (sanity check)
415 helpmod_config_write(HELPMOD_DEFAULT_DB
);
417 /* delete schedule stuff */
418 deleteallschedules((ScheduleCallback
)&helpconnect
);
419 deleteallschedules((ScheduleCallback
)&huser_clear_inactives
);
420 deleteallschedules((ScheduleCallback
)&haccount_clear_inactives
);
421 deleteallschedules((ScheduleCallback
)&hban_remove_expired
);
422 deleteallschedules((ScheduleCallback
)&hchannel_remove_inactive_users
);
423 deleteallschedules((ScheduleCallback
)&hchannel_report
);
424 deleteallschedules((ScheduleCallback
)&helpmod_config_scheduled_events
);
425 deleteallschedules((ScheduleCallback
)&hstat_scheduler
);
426 deleteallschedules((ScheduleCallback
)&hchannel_deactivate_join_flood
);
427 deleteallschedules((ScheduleCallback
)&hchanban_schedule_entry
);
428 deleteallschedules((ScheduleCallback
)&hticket_remove_expired
);
437 helpmod_clear_aliases(&aliases
);
438 helpmod_clear_all_entries();
440 deregisterlocaluser(helpmodnick
, "Module unloaded");