2 # ProcessExtra.pl: Extensions to Process.pl
4 # Version: v0.5 (20010124)
8 if (&IsParam("useStrict")) { use strict; }
10 use POSIX qw(strftime);
14 &VERB("Starting schedulers...",2);
19 # 1 for run straight away, 2 for on next-run.
26 &netsplitCheck(1); # mandatory
27 &floodLoop(1); # mandatory
29 &leakCheck(2); # mandatory
30 &ignoreCheck(1); # mandatory
32 # &ircCheck(2); # mandatory
33 &ircCheck(1); # mandatory
34 &miscCheck(1); # mandatory
35 &miscCheck2(2); # mandatory
36 &shmFlush(1); # mandatory
44 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
46 foreach (keys %sched) {
47 # next unless (exists $sched{$_}{TIME});
48 my $time = $sched{$_}{TIME};
49 next unless (defined $time and $time > time());
54 &status("Schedulers: $count will be running.");
59 my ($interval, $codename, @args) = @_;
60 my $waittime = &getRandomInt($interval);
62 if (!defined $waittime) {
63 &WARN("interval == waittime == UNDEF for $codename.");
67 my $time = $sched{$codename}{TIME};
68 if (defined $time and $time > time()) {
69 &WARN("Sched for $codename already exists.");
73 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
75 my $retval = $conn->schedule($waittime, \&$codename, @args);
76 $sched{$codename}{LABEL} = $retval;
77 $sched{$codename}{TIME} = time()+$waittime;
78 $sched{$codename}{LOOP} = 1;
82 #### LET THE FUN BEGIN.
86 my $interval = &getChanConfDefault("randomQuoteInterval", 60);
88 &ScheduleThis($interval, "randomQuote");
89 return if ($_[0] eq "2"); # defer.
92 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.randtext");
94 &ERROR("random Quote: weird error?");
98 foreach ( &ChanConfList("randomQuote") ) {
99 next unless (&validChan($_));
101 &status("sending random Quote to $_.");
102 &action($_, "Ponders: ".$line);
104 ### TODO: if there were no channels, don't reschedule until channel
105 ### configuration is modified.
112 my $interval = &getChanConfDefault("randomFactoidInterval", 60);
114 &ScheduleThis($interval, "randomFactoid");
115 return if ($_[0] eq "2"); # defer.
119 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
120 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
121 last if (defined $val and $val !~ /^</);
125 &ERROR("rF: tried 5 times but failed.");
130 foreach ( &ChanConfList("randomFactoid") ) {
131 next unless (&validChan($_));
133 &status("sending random Factoid to $_.");
134 &action($_, "Thinks: \037$key\037 is $val");
135 ### FIXME: Use &getReply() on above to format factoid properly?
140 sub randomFreshmeat {
141 my $interval = &getChanConfDefault("randomFresheatInterval", 60);
144 &ScheduleThis($interval, "randomFreshmeat");
145 return if ($_[0] eq "2"); # defer.
148 my @chans = &ChanConfList("randomFreshmeat");
149 return unless (scalar @chans);
151 &Forker("freshmeat", sub {
152 my $retval = &Freshmeat::randPackage();
155 next unless (&validChan($_));
157 &status("sending random Freshmeat to $_.");
165 &ScheduleThis(60, "logLoop");
166 return if ($_[0] eq "2"); # defer.
169 return unless (defined fileno LOG);
170 return unless (&IsParam("logfile"));
171 return unless (&IsParam("maxLogSize"));
173 ### check if current size is too large.
174 if ( -s $file{log} > $param{'maxLogSize'}) {
175 my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]);
176 $file{log} = $param{'logfile'} ."-". $date;
177 &status("cycling log file.");
179 if ( -e $file{log}) {
183 $newlog = $file{log}."-".$i;
184 last if (! -e $newlog);
187 $file{log} = $newlog;
191 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
192 &compress($file{log});
194 &status("cycling log file.");
197 ### check if all the logs exceed size.
198 my $logdir = "$bot_base_dir/log/";
199 if (opendir(LOGS, $logdir)) {
203 while (defined($_ = readdir LOGS)) {
204 my $logfile = "$logdir/$_";
206 next unless ( -f $logfile);
207 my $size = -s $logfile;
208 my $age = (stat $logfile)[9];
210 $age{$age} = $logfile;
211 $size{$logfile} = $size;
218 while ($tsize > $param{'maxLogSize'}) {
219 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
220 my $oldest = (sort {$a <=> $b} keys %age)[0];
221 &status("LOG: unlinking $age{$oldest}.");
222 unlink $age{$oldest};
227 ### TODO: add how many b,kb,mb removed?
228 &status("LOG: removed $delete logs.") if ($delete);
230 &WARN("could not open dir $logdir");
237 &ScheduleThis(1440, "seenFlushOld");
238 return if ($_[0] eq "2"); # defer.
241 # is this global-only?
242 return unless (&IsChanConf("seen") > 0);
243 return unless (&IsChanConf("seenFlushInterval") > 0);
245 # global setting. does not make sense for per-channel.
246 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
249 if ($param{'DBType'} =~ /^pg|postgres|mysql/i) {
250 my $query = "SELECT nick,time FROM seen GROUP BY nick HAVING UNIX_TIMESTAMP() - time > $max_time";
251 my $sth = $dbh->prepare($query);
254 while (my @row = $sth->fetchrow_array) {
255 my ($nick,$time) = @row;
257 &dbDel("seen","nick",$nick);
261 } elsif ($param{'DBType'} =~ /^dbm/i) {
264 foreach (keys %seen) {
265 my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
266 next unless ($delta_time > $max_time);
268 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
273 &FIXME("seenFlushOld: for PG/NO-DB.");
275 &VERB("SEEN deleted $delete seen entries.",2);
281 &ScheduleThis(60, "newsFlush");
282 return if ($_[0] eq "2"); # defer.
285 if (!&ChanConfList("news")) {
286 &DEBUG("newsFlush: news disabled? (chan => $chan)");
293 foreach $chan (keys %::news) {
295 my $total = scalar(keys %{ $::news{$chan} });
298 delete $::news{$chan};
302 foreach $item (keys %{ $::news{$chan} }) {
303 my $t = $::news{$chan}{$item}{Expire};
305 my $tadd = $::news{$chan}{$item}{Time};
306 $oldest = $tadd if ($oldest > $tadd);
308 next if ($t == 0 or $t == -1);
310 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
311 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
315 my $delta = $t - time();
317 next unless (time() > $t);
319 # todo: show how old it was.
320 delete $::news{$chan}{$item};
321 &status("NEWS: (newsflush) deleted '$item'");
326 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
327 $none{$chan} = 1 if ($total == $i);
330 # todo: flush users aswell.
332 foreach $chan (keys %::newsuser) {
333 next if (exists $none{$chan});
335 foreach (keys %{ $::newsuser{$chan} }) {
336 my $t = $::newsuser{$chan}{$_};
337 if (!defined $t or ($t > 2 and $t < 1000)) {
338 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
342 next unless ($oldest > $t);
344 delete $::newsuser{$chan}{$_};
348 my $i = scalar(keys %{ $::newsuser{$chan} });
349 delete $::newsuser{$chan} unless ($i);
352 if ($delete or $duser) {
354 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
359 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
362 &ScheduleThis($interval, "chanlimitCheck");
363 return if ($_[0] eq "2");
366 my $str = join(' ', &ChanConfList("chanlimitcheck") );
367 &DEBUG("chanlimitCheck: str => $str");
369 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
370 next unless (&validChan($chan));
372 if ($chan eq "_default") {
373 &WARN("chanlimit: we're doing $chan!! HELP ME!");
377 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
378 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
379 my $limit = $channels{$chan}{'l'};
381 if (scalar keys %netsplitservers) {
382 if (defined $limit) {
383 &status("chanlimit: netsplit; removing it for $chan.");
384 &rawout("MODE $chan -l");
385 $cache{chanlimitChange}{$chan} = time();
391 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
392 &FIXME("LIMIT: set too low!!! FIXME");
393 ### run NAMES again and flush it.
396 if (defined $limit and $limit == $newlimit) {
397 $cache{chanlimitChange}{$chan} = time();
401 if (!exists $channels{$chan}{'o'}{$ident}) {
402 &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
403 $cache{warn}{chanlimit}{$chan} = 1;
404 &chanServCheck($chan);
407 delete $cache{warn}{chanlimit}{$chan};
409 if (!defined $limit) {
410 &status("chanLimit: setting for first time or from netsplit, for $chan");
413 if (exists $cache{chanlimitChange}{$chan}) {
414 my $delta = time() - $cache{chanlimitChange}{$chan};
415 if ($delta < $interval*60) {
416 &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
421 &rawout("MODE $chan +l $newlimit");
422 $cache{chanlimitChange}{$chan} = time();
430 &ScheduleThis(15, "netsplitCheck");
431 return if ($_[0] eq "2");
434 $cache{'netsplitCache'}++;
435 &DEBUG("running netsplitCheck... $cache{netsplitCache}");
437 if (!scalar %netsplit and scalar %netsplitservers) {
438 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
439 undef %netsplitservers;
443 # well... this shouldn't happen since %netsplit code does it anyway.
444 foreach $s1 (keys %netsplitservers) {
446 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
447 my $delta = time() - $netsplitservers{$s1}{$s2};
449 if ($delta > 60*30) {
450 &status("netsplit between $s1 and $s2 appears to be stale.");
451 delete $netsplitservers{$s1}{$s2};
456 my $i = scalar(keys %{ $netsplitservers{$s1} });
457 delete $netsplitservers{$s1} unless ($i);
460 # %netsplit hash checker.
461 my $count = scalar keys %netsplit;
463 foreach (keys %netsplit) {
464 if (&IsNickInAnyChan($_)) { # why would this happen?
465 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
466 delete $netsplit{$_};
471 next unless (time() - $netsplit{$_} > 60*15);
474 delete $netsplit{$_};
478 foreach (keys %channels) {
479 my $i = $cache{maxpeeps}{$chan} || 0;
480 my $j = scalar(keys %{ $channels{$chan} });
481 next unless ($i > 10 and 0.25*$i > $j);
483 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
487 my $j = scalar(keys %netsplit);
488 &DEBUG("nsC: removed from netsplit list: (before: $count; after: $j)");
491 if (!scalar %netsplit and scalar %netsplitservers) {
492 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
493 undef %netsplitservers;
496 if ($count and !scalar keys %netsplit) {
497 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
507 &ScheduleThis(60, "floodLoop"); # minutes.
508 return if ($_[0] eq "2");
512 my $interval = &getChanConfDefault("floodCycle",60);
514 foreach $who (keys %flood) {
515 foreach (keys %{ $flood{$who} }) {
516 if (!exists $flood{$who}{$_}) {
517 &WARN("flood{$who}{$_} undefined?");
521 if ($time - $flood{$who}{$_} > $interval) {
522 delete $flood{$who}{$_};
527 &VERB("floodLoop: deleted $delete items.",2);
532 my $interval = &getChanConfDefault("seenFlushInterval", 60);
533 &ScheduleThis($interval, "seenFlush");
534 return if ($_[0] eq "2");
540 $stats{'count_old'} = &countKeys("seen") || 0;
544 if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
545 foreach $nick (keys %seencache) {
546 my $retval = &dbReplace("seen", (
547 "nick" => $seencache{$nick}{'nick'},
548 "time" => $seencache{$nick}{'time'},
549 "host" => $seencache{$nick}{'host'},
550 "channel" => $seencache{$nick}{'chan'},
551 "message" => $seencache{$nick}{'msg'},
553 delete $seencache{$nick};
562 my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
564 if (defined $exists and $exists) {
565 &dbUpdate("seen", "nick", $nick, (
566 "time" => $seencache{$nick}{'time'},
567 "host" => $seencache{$nick}{'host'},
568 "channel" => $seencache{$nick}{'chan'},
569 "message" => $seencache{$nick}{'msg'},
573 my $retval = &dbInsert("seen", $nick, (
574 "nick" => $seencache{$nick}{'nick'},
575 "time" => $seencache{$nick}{'time'},
576 "host" => $seencache{$nick}{'host'},
577 "channel" => $seencache{$nick}{'chan'},
578 "message" => $seencache{$nick}{'msg'},
582 ### TODO: put bad nick into a list and don't do it again!
583 &FIXME("Should never happen! (nick => $nick)") if !$retval;
586 delete $seencache{$nick};
590 } elsif ($param{'DBType'} =~ /^dbm/i) {
592 foreach $nick (keys %seencache) {
593 my $retval = &dbInsert("seen", $nick, (
594 "nick" => $seencache{$nick}{'nick'},
595 "time" => $seencache{$nick}{'time'},
596 "host" => $seencache{$nick}{'host'},
597 "channel" => $seencache{$nick}{'chan'},
598 "message" => $seencache{$nick}{'msg'},
601 ### TODO: put bad nick into a list and don't do it again!
602 &FIXME("Should never happen! (nick => $nick)") if !$retval;
604 delete $seencache{$nick};
608 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
611 &status("Seen: Flushed $flushed entries.") if ($flushed);
612 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
613 $stats{'new'}*100/($stats{'count_old'} || 1),
614 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
615 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
616 $stats{'old'}*100 / ( &countKeys("seen") || 1),
617 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
619 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
627 &ScheduleThis(240, "leakCheck");
628 return if ($_[0] eq "2");
631 # flood. this is dealt with in floodLoop()
632 foreach $blah1 (keys %flood) {
633 foreach $blah2 (keys %{ $flood{$blah1} }) {
634 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
637 &DEBUG("leak: hash flood has $count total keys.",2);
641 foreach $blah1 (keys %floodjoin) {
642 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
643 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
646 &DEBUG("leak: hash floodjoin has $count total keys.",2);
649 $count = scalar(keys %floodwarn);
650 &DEBUG("leak: hash floodwarn has $count total keys.",2);
653 foreach $chan (grep /[A-Z]/, keys %channels) {
654 &DEBUG("leak: chan => '$chan'.");
656 foreach $i (keys %{ $channels{$chan} }) {
657 foreach (keys %{ $channels{$chan}{$i} }) {
658 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
664 $count = scalar(keys %chanstats);
665 &DEBUG("leak: hash chanstats has $count total keys.",2);
669 foreach (keys %nuh) {
670 next if (&IsNickInAnyChan($_));
671 next if (exists $dcc{CHAT}{$_});
677 &status("leak: $delete nuh{} items deleted; now have ".
678 scalar(keys %nuh) ) if ($delete);
683 &ScheduleThis(60, "ignoreCheck");
684 return if ($_[0] eq "2"); # defer.
690 foreach (keys %ignore) {
693 foreach (keys %{ $ignore{$chan} }) {
694 my @array = @{ $ignore{$chan}{$_} };
696 next unless ($array[0] and $time > $array[0]);
698 delete $ignore{$chan}{$_};
699 &status("ignore: $_/$chan has expired.");
703 &VERB("ignore: $count items deleted.",2);
708 &ScheduleThis(15, "ircCheck");
709 return if ($_[0] eq "2"); # defer.
712 my @x = &getJoinChans();
713 my $iconf = scalar( @x );
714 my $inow = scalar( keys %channels );
715 if ($iconf > 2 and $inow * 2 <= $iconf) {
716 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
721 if (!$conn->connected or time() - $msgtime > 3600) {
722 # todo: shouldn't we use cache{connect} somewhere?
723 if (exists $cache{connect}) {
724 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
725 $msgtime = time(); # just in case.
727 delete $cache{connect};
729 &status("IRCTEST: possible lost in space; checking. ".
731 &msg($ident, "TEST");
732 $cache{connect} = time();
736 if ($ident !~ /^\Q$param{ircNick}\E$/) {
737 # this does not work unfortunately.
738 &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
740 # this check is misleading... perhaps we should do a notify.
741 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
742 &DEBUG("$param{ircNick} not in use... changing!");
743 &nick( $param{ircNick} );
745 &WARN("$param{ircNick} is still in use...");
749 if (grep /^\s*$/, keys %channels) {
750 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
751 if (exists $channels{''}) {
752 &DEBUG("ircCheck: ok it existed!");
754 &DEBUG("ircCheck: this hsould never happen!");
757 delete $channels{''};
761 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
763 $wtime_userfile = time();
766 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
768 $wtime_chanfile = time();
774 &ScheduleThis(240, "miscCheck");
775 return if ($_[0] eq "2"); # defer.
780 if ( -x "/usr/bin/ipcs") {
781 @ipcs = `/usr/bin/ipcs`;
783 &WARN("ircCheck: no 'ipcs' binary.");
787 # shmid stale remove.
791 # key, shmid, owner, perms, bytes, nattch
792 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
794 my ($shmid, $size) = ($2,$5);
795 next unless ($shmid != $shm and $size == 2000);
796 my $z = &shmRead($shmid);
797 if ($z =~ /^(\d+): /) {
799 next if (time() - $time < 60*60);
802 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
806 &status("SHM: nuking shmid $shmid");
807 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
810 # make backup of important files.
811 &mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*3);
812 &mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*3);
813 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
815 # flush cache{lobotomy}
816 foreach (keys %{ $cache{lobotomy} }) {
817 next unless (time() - $cache{lobotomy}{$_} > 60*60);
818 delete $cache{lobotomy}{$_};
821 ### check modules if they've been modified. might be evil.
827 &ScheduleThis(240, "miscCheck2");
828 return if ($_[0] eq "2"); # defer.
832 opendir(DEBIAN, "$bot_base_dir/debian");
833 foreach ( grep /gz$/, readdir(DEBIAN) ) {
834 my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
837 &status("debian: unlinking file => $_");
838 unlink "$bot_base_dir/debian/$_";
842 # compress logs that should have been compressed.
843 # todo: use strftime?
844 my ($day,$month,$year) = (localtime(time()))[3,4,5];
845 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
847 opendir(DIR,"$bot_base_dir/log");
848 while (my $f = readdir(DIR)) {
849 next unless ( -f "$bot_base_dir/log/$f");
850 next if ($f =~ /gz|bz2/);
851 next unless ($f =~ /(\d{8})/);
852 next if ($date eq $1);
854 &compress("$bot_base_dir/log/$f");
860 return if ($$ != $::bot_pid); # fork protection.
863 &ScheduleThis(5, "shmFlush");
864 return if ($_[0] eq "2");
868 my $shmmsg = &shmRead($shm);
869 $shmmsg =~ s/\0//g; # remove padded \0's.
870 if ($shmmsg =~ s/^(\d+): //) {
874 foreach (split '\|\|', $shmmsg) {
876 &VERB("shm: Processing '$_'.",2);
878 if (/^DCC SEND (\S+) (\S+)$/) {
879 my ($nick,$file) = ($1,$2);
880 if (exists $dcc{'SEND'}{$who}) {
881 &msg($nick, "DCC already active.");
883 &DEBUG("shm: dcc sending $2 to $1.");
884 $conn->new_send($1,$2);
885 $dcc{'SEND'}{$who} = time();
887 } elsif (/^SET FORKPID (\S+) (\S+)/) {
888 $forked{$1}{PID} = $2;
889 } elsif (/^DELETE FORK (\S+)$/) {
891 } elsif (/^EVAL (.*)$/) {
892 &DEBUG("evaling '$1'.");
895 &DEBUG("shm: unknown msg. ($_)");
899 &shmWrite($shm,"") if ($shmmsg ne "");
902 ### this is semi-scheduled
904 if ($ident eq $param{'ircNick'}) {
905 &status("okay, got my nick back.");
910 &ScheduleThis(30, "getNickInUse");
911 return if ($_[0] eq "2"); # defer.
914 &nick( $param{'ircNick'} );
918 return unless &IsChanConf("uptime");
921 &ScheduleThis(60, "uptimeLoop");
922 return if ($_[0] eq "2"); # defer.
931 &ScheduleThis(60, "slashdotLoop");
932 return if ($_[0] eq "2");
935 my @chans = &ChanConfList("slashdotAnnounce");
936 return unless (scalar @chans);
938 &Forker("slashdot", sub {
939 my $line = &Slashdot::slashdotAnnounce();
940 return unless (defined $line);
943 next unless (&::validChan($_));
945 &::status("sending slashdot update to $_.");
946 ¬ice($_, "Slashdot: $line");
953 &ScheduleThis(60, "freshmeatLoop");
954 return if ($_[0] eq "2");
957 my @chans = &ChanConfList("freshmeatAnnounce");
958 return unless (scalar @chans);
960 &Forker("freshmeat", sub {
961 my $data = &Freshmeat::freshmeatAnnounce();
964 next unless (&::validChan($_));
966 &::status("sending freshmeat update to $_.");
974 &ScheduleThis(240, "kernelLoop");
975 return if ($_[0] eq "2");
978 my @chans = &ChanConfList("kernelAnnounce");
979 return unless (scalar @chans);
981 &Forker("kernel", sub {
982 my @data = &Kernel::kernelAnnounce();
985 next unless (&::validChan($_));
987 &::status("sending kernel update to $_.");
990 ¬ice($c, "Kernel: $_");
997 return unless &IsChanConf("wingate");
999 ### FILE CACHE OF OFFENDING WINGATES.
1000 foreach (grep /^$host$/, @wingateBad) {
1001 &status("Wingate: RUNNING ON $host BY $who");
1002 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
1004 my $reason = &getChanConf("wingateKick");
1006 next unless ($reason);
1007 &kick($who, "", $reason)
1010 ### RUN CACHE OF TRIED WINGATES.
1011 if (grep /^$host$/, @wingateCache) {
1012 push(@wingateNow, $host); # per run.
1013 push(@wingateCache, $host); # cache per run.
1015 &DEBUG("Already scanned $host. good.");
1018 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
1019 return if (defined $forked{'wingate'});
1020 return if (time() - $wingaterun <= $interval);
1021 return unless (scalar(keys %wingateToDo));
1023 $wingaterun = time();
1025 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
1030 sub wingateWriteFile {
1032 &ScheduleThis(60, "wingateWriteFile");
1033 return if ($_[0] eq "2"); # defer.
1036 return unless (scalar @wingateCache);
1038 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1039 if ($bot_pid != $$) {
1040 &DEBUG("wingateWriteFile: Reorganising!");
1045 push(@wingateNow, $_);
1050 my %hash = map { $_ => 1 } @wingateNow;
1051 @wingateNow = sort keys %hash;
1054 &DEBUG("wingateWF: writing...");
1055 open(OUT, ">$file");
1056 foreach (@wingateNow) {
1064 &ScheduleThis(720, "factoidCheck");
1065 return if ($_[0] eq "2"); # defer.
1068 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1069 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1071 # disable it since it's "illegal".
1078 my $age = &getFactInfo($_, "modified_time");
1080 if (!defined $age or $age !~ /^\d+$/) {
1081 if (scalar @list > 50) {
1082 if (!$cache{warnDel}) {
1083 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1084 $cache{warnDel} = 1;
1089 &WARN("del factoid: old cruft (no time): $_");
1094 next unless ($time - $age > $stale);
1097 $fix =~ s/ #DEL#$//g;
1098 my $agestr = &Time2String($time - $age);
1099 &status("safedel: Removing '$_' for good. [$agestr old]");
1106 return unless (scalar keys %{ $dcc{CHAT} });
1109 &ScheduleThis(10, "dccStatus");
1110 return if ($_[0] eq "2"); # defer.
1113 my $time = strftime("%H:%M", localtime(time()) );
1116 foreach (keys %channels) {
1118 my $users = keys %{ $channels{$c}{''} };
1119 my $chops = keys %{ $channels{$c}{o} };
1120 my $bans = keys %{ $channels{$c}{b} };
1122 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1123 foreach (keys %{ $dcc{'CHAT'} }) {
1124 next unless (exists $channels{$c}{''}{lc $_});
1125 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1138 foreach (keys %{ $irc->{_queue} }) {
1142 foreach (keys %sched) {
1143 next unless ($q eq $sched{$_});
1148 my $time = $irc->{_queue}->{$q}->[0] - time();
1150 if (defined $sched) {
1151 &DEBUG(" $sched($q): ".&Time2String($time) );
1153 &DEBUG(" NULL($q): ".&Time2String($time) );
1157 &DEBUG("end of sList.");
1160 sub getChanConfDefault {
1161 my($what, $default, $chan) = @_;
1163 if (exists $param{$what}) {
1164 if (!exists $cache{config}{$what}) {
1165 &status("conf: backward-compat: found param{$what} ($param{$what}) instead.");
1166 $cache{config}{$what} = 1;
1169 return $param{$what};
1172 my $val = &getChanConf($what, $chan);
1177 $param{$what} = $default;
1178 &status("conf: auto-setting param{$what} = $default");
1179 $cache{config}{$what} = 1;
1185 my($file, $time) = @_;
1189 &VERB("mkB: file '$file' does not exist.",2);
1194 if ( -e "$file~" ) {
1195 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1196 my $delta = time() - (stat "$file~")[9];
1197 $age = &Time2String($delta);
1202 return unless ($backup);
1204 ### TODO: do internal copying.
1205 &status("Backup: $file ($age)");
1206 CORE::system("/bin/cp $file $file~");