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(1); # mandatory
33 &miscCheck(1); # mandatory
34 &miscCheck2(2); # mandatory
35 &shmFlush(1); # mandatory
40 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
43 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
45 foreach (keys %sched) {
46 # next unless (exists $sched{$_}{TIME});
47 my $time = $sched{$_}{TIME};
48 next unless (defined $time and $time > time());
53 &status("Schedulers: $count will be running.");
58 my ($interval, $codename, @args) = @_;
59 my $waittime = &getRandomInt($interval);
61 if (!defined $waittime) {
62 &WARN("interval == waittime == UNDEF for $codename.");
66 my $time = $sched{$codename}{TIME};
67 if (defined $time and $time > time()) {
68 &WARN("Sched for $codename already exists.");
72 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
74 my $retval = $conn->schedule($waittime, \&$codename, @args);
75 $sched{$codename}{LABEL} = $retval;
76 $sched{$codename}{TIME} = time()+$waittime;
77 $sched{$codename}{LOOP} = 1;
81 #### LET THE FUN BEGIN.
85 my $interval = &getChanConfDefault("randomQuoteInterval", 60);
87 &ScheduleThis($interval, "randomQuote");
88 return if ($_[0] eq "2"); # defer.
91 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
93 &ERROR("random Quote: weird error?");
97 foreach ( &ChanConfList("randomQuote") ) {
98 next unless (&validChan($_));
100 &status("sending random Quote to $_.");
101 &action($_, "Ponders: ".$line);
103 ### TODO: if there were no channels, don't reschedule until channel
104 ### configuration is modified.
111 my $interval = &getChanConfDefault("randomFactoidInterval", 60);
113 &ScheduleThis($interval, "randomFactoid");
114 return if ($_[0] eq "2"); # defer.
118 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
119 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
120 last if (defined $val and $val !~ /^</);
124 &ERROR("rF: tried 5 times but failed.");
129 foreach ( &ChanConfList("randomFactoid") ) {
130 next unless (&validChan($_));
132 &status("sending random Factoid to $_.");
133 &action($_, "Thinks: \037$key\037 is $val");
134 ### FIXME: Use &getReply() on above to format factoid properly?
139 sub randomFreshmeat {
140 my $interval = &getChanConfDefault("randomFresheatInterval", 60);
143 &ScheduleThis($interval, "randomFreshmeat");
144 return if ($_[0] eq "2"); # defer.
147 my @chans = &ChanConfList("randomFreshmeat");
148 return unless (scalar @chans);
150 &Forker("freshmeat", sub {
151 my $retval = &Freshmeat::randPackage();
154 next unless (&validChan($_));
156 &status("sending random Freshmeat to $_.");
164 &ScheduleThis(60, "logLoop");
165 return if ($_[0] eq "2"); # defer.
168 return unless (defined fileno LOG);
169 return unless (&IsParam("logfile"));
170 return unless (&IsParam("maxLogSize"));
172 ### check if current size is too large.
173 if ( -s $file{log} > $param{'maxLogSize'}) {
174 my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]);
175 $file{log} = $param{'logfile'} ."-". $date;
176 &status("cycling log file.");
178 if ( -e $file{log}) {
182 $newlog = $file{log}."-".$i;
183 last if (! -e $newlog);
186 $file{log} = $newlog;
190 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
191 &compress($file{log});
193 &status("cycling log file.");
196 ### check if all the logs exceed size.
197 if (opendir(LOGS, $bot_log_dir)) {
201 while (defined($_ = readdir LOGS)) {
202 my $logfile = "$bot_log_dir/$_";
204 next unless ( -f $logfile);
205 my $size = -s $logfile;
206 my $age = (stat $logfile)[9];
208 $age{$age} = $logfile;
209 $size{$logfile} = $size;
216 while ($tsize > $param{'maxLogSize'}) {
217 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
218 my $oldest = (sort {$a <=> $b} keys %age)[0];
219 &status("LOG: unlinking $age{$oldest}.");
220 unlink $age{$oldest};
225 ### TODO: add how many b,kb,mb removed?
226 &status("LOG: removed $delete logs.") if ($delete);
228 &WARN("could not open dir $bot_log_dir");
235 &ScheduleThis(1440, "seenFlushOld");
236 return if ($_[0] eq "2"); # defer.
239 # is this global-only?
240 return unless (&IsChanConf("seen") > 0);
241 return unless (&IsChanConf("seenFlushInterval") > 0);
243 # global setting. does not make sense for per-channel.
244 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
247 if ($param{'DBType'} =~ /^pgsql|mysql/i) {
250 if ($param{'DBType'} =~ /^mysql$/i) {
251 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
252 "UNIX_TIMESTAMP() - time > $max_time";
254 $query = "SELECT nick,time FROM seen WHERE ".
255 "extract(epoch from timestamp 'now') - time > $max_time";
258 my $sth = $dbh->prepare($query);
261 while (my @row = $sth->fetchrow_array) {
262 my ($nick,$time) = @row;
264 &dbDel("seen","nick",$nick);
268 } elsif ($param{'DBType'} =~ /^dbm/i) {
271 foreach (keys %seen) {
272 my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
273 next unless ($delta_time > $max_time);
275 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
280 &FIXME("seenFlushOld: for PG/NO-DB.");
282 &VERB("SEEN deleted $delete seen entries.",2);
288 &ScheduleThis(60, "newsFlush");
289 return if ($_[0] eq "2"); # defer.
292 if (!&ChanConfList("news")) {
293 &DEBUG("newsFlush: news disabled? (chan => $chan)");
300 foreach $chan (keys %::news) {
302 my $total = scalar(keys %{ $::news{$chan} });
305 delete $::news{$chan};
309 foreach $item (keys %{ $::news{$chan} }) {
310 my $t = $::news{$chan}{$item}{Expire};
312 my $tadd = $::news{$chan}{$item}{Time};
313 $oldest = $tadd if ($oldest > $tadd);
315 next if ($t == 0 or $t == -1);
317 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
318 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
322 my $delta = $t - time();
324 next unless (time() > $t);
326 # todo: show how old it was.
327 delete $::news{$chan}{$item};
328 &status("NEWS: (newsflush) deleted '$item'");
333 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
334 $none{$chan} = 1 if ($total == $i);
337 # todo: flush users aswell.
339 foreach $chan (keys %::newsuser) {
340 next if (exists $none{$chan});
342 foreach (keys %{ $::newsuser{$chan} }) {
343 my $t = $::newsuser{$chan}{$_};
344 if (!defined $t or ($t > 2 and $t < 1000)) {
345 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
349 next unless ($oldest > $t);
351 delete $::newsuser{$chan}{$_};
355 my $i = scalar(keys %{ $::newsuser{$chan} });
356 delete $::newsuser{$chan} unless ($i);
359 if ($delete or $duser) {
361 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
366 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
369 &ScheduleThis($interval, "chanlimitCheck");
370 return if ($_[0] eq "2");
373 my $str = join(' ', &ChanConfList("chanlimitcheck") );
375 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
376 next unless (&validChan($chan));
378 if ($chan eq "_default") {
379 &WARN("chanlimit: we're doing $chan!! HELP ME!");
383 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
384 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
385 my $limit = $channels{$chan}{'l'};
387 if (scalar keys %netsplitservers) {
388 if (defined $limit) {
389 &status("chanlimit: netsplit; removing it for $chan.");
390 &rawout("MODE $chan -l");
391 $cache{chanlimitChange}{$chan} = time();
392 &status("chanlimit: netsplit; removed.");
398 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
399 &FIXME("LIMIT: set too low!!! FIXME");
400 ### run NAMES again and flush it.
403 if (defined $limit and $limit == $newlimit) {
404 $cache{chanlimitChange}{$chan} = time();
408 if (!exists $channels{$chan}{'o'}{$ident}) {
409 &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
410 $cache{warn}{chanlimit}{$chan} = 1;
411 &chanServCheck($chan);
414 delete $cache{warn}{chanlimit}{$chan};
416 if (!defined $limit) {
417 &status("chanLimit: setting for first time or from netsplit, for $chan");
420 if (exists $cache{chanlimitChange}{$chan}) {
421 my $delta = time() - $cache{chanlimitChange}{$chan};
422 if ($delta < $interval*60) {
423 &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
428 &rawout("MODE $chan +l $newlimit");
429 $cache{chanlimitChange}{$chan} = time();
437 &ScheduleThis(15, "netsplitCheck");
438 return if ($_[0] eq "2");
441 $cache{'netsplitCache'}++;
442 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
444 if (!scalar %netsplit and scalar %netsplitservers) {
445 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
446 undef %netsplitservers;
450 # well... this shouldn't happen since %netsplit code does it anyway.
451 foreach $s1 (keys %netsplitservers) {
453 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
454 my $delta = time() - $netsplitservers{$s1}{$s2};
456 if ($delta > 60*30) {
457 &status("netsplit between $s1 and $s2 appears to be stale.");
458 delete $netsplitservers{$s1}{$s2};
463 my $i = scalar(keys %{ $netsplitservers{$s1} });
464 delete $netsplitservers{$s1} unless ($i);
467 # %netsplit hash checker.
468 my $count = scalar keys %netsplit;
470 foreach (keys %netsplit) {
471 if (&IsNickInAnyChan($_)) { # why would this happen?
472 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
473 delete $netsplit{$_};
478 next unless (time() - $netsplit{$_} > 60*15);
481 delete $netsplit{$_};
485 foreach (keys %channels) {
486 my $i = $cache{maxpeeps}{$chan} || 0;
487 my $j = scalar(keys %{ $channels{$chan} });
488 next unless ($i > 10 and 0.25*$i > $j);
490 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
494 my $j = scalar(keys %netsplit);
495 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
498 if (!scalar %netsplit and scalar %netsplitservers) {
499 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
500 undef %netsplitservers;
503 if ($count and !scalar keys %netsplit) {
504 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
514 &ScheduleThis(60, "floodLoop"); # minutes.
515 return if ($_[0] eq "2");
519 my $interval = &getChanConfDefault("floodCycle",60);
521 foreach $who (keys %flood) {
522 foreach (keys %{ $flood{$who} }) {
523 if (!exists $flood{$who}{$_}) {
524 &WARN("flood{$who}{$_} undefined?");
528 if ($time - $flood{$who}{$_} > $interval) {
529 delete $flood{$who}{$_};
534 &VERB("floodLoop: deleted $delete items.",2);
539 my $interval = &getChanConfDefault("seenFlushInterval", 60);
540 &ScheduleThis($interval, "seenFlush");
541 return if ($_[0] eq "2");
547 $stats{'count_old'} = &countKeys("seen") || 0;
551 if ($param{'DBType'} =~ /^(mysql|pgsql)$/i) {
552 foreach $nick (keys %seencache) {
553 my $retval = &dbReplace("seen", "nick", (
554 "nick" => lc $seencache{$nick}{'nick'},
555 "time" => $seencache{$nick}{'time'},
556 "host" => $seencache{$nick}{'host'},
557 "channel" => $seencache{$nick}{'chan'},
558 "message" => $seencache{$nick}{'msg'},
560 delete $seencache{$nick};
569 my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
571 if (defined $exists and $exists) {
572 &dbUpdate("seen", "nick", $nick, (
573 "time" => $seencache{$nick}{'time'},
574 "host" => $seencache{$nick}{'host'},
575 "channel" => $seencache{$nick}{'chan'},
576 "message" => $seencache{$nick}{'msg'},
580 my $retval = &dbInsert("seen", $nick, (
581 "nick" => $seencache{$nick}{'nick'},
582 "time" => $seencache{$nick}{'time'},
583 "host" => $seencache{$nick}{'host'},
584 "channel" => $seencache{$nick}{'chan'},
585 "message" => $seencache{$nick}{'msg'},
589 ### TODO: put bad nick into a list and don't do it again!
590 &FIXME("Should never happen! (nick => $nick)") if !$retval;
593 delete $seencache{$nick};
597 } elsif ($param{'DBType'} =~ /^dbm/i) {
599 foreach $nick (keys %seencache) {
600 my $retval = &dbInsert("seen", $nick, (
601 "nick" => $seencache{$nick}{'nick'},
602 "time" => $seencache{$nick}{'time'},
603 "host" => $seencache{$nick}{'host'},
604 "channel" => $seencache{$nick}{'chan'},
605 "message" => $seencache{$nick}{'msg'},
608 ### TODO: put bad nick into a list and don't do it again!
609 &FIXME("Should never happen! (nick => $nick)") if !$retval;
611 delete $seencache{$nick};
615 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
618 &status("Seen: Flushed $flushed entries.") if ($flushed);
619 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
620 $stats{'new'}*100/($stats{'count_old'} || 1),
621 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
622 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
623 $stats{'old'}*100 / ( &countKeys("seen") || 1),
624 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
626 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
634 &ScheduleThis(240, "leakCheck");
635 return if ($_[0] eq "2");
638 # flood. this is dealt with in floodLoop()
639 foreach $blah1 (keys %flood) {
640 foreach $blah2 (keys %{ $flood{$blah1} }) {
641 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
644 &VERB("leak: hash flood has $count total keys.",2);
648 foreach $blah1 (keys %floodjoin) {
649 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
650 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
653 &VERB("leak: hash floodjoin has $count total keys.",2);
656 $count = scalar(keys %floodwarn);
657 &VERB("leak: hash floodwarn has $count total keys.",2);
660 foreach $chan (grep /[A-Z]/, keys %channels) {
661 &DEBUG("leak: chan => '$chan'.");
663 foreach $i (keys %{ $channels{$chan} }) {
664 foreach (keys %{ $channels{$chan}{$i} }) {
665 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
671 $count = scalar(keys %chanstats);
672 &VERB("leak: hash chanstats has $count total keys.",2);
676 foreach (keys %nuh) {
677 next if (&IsNickInAnyChan($_));
678 next if (exists $dcc{CHAT}{$_});
684 &status("leak: $delete nuh{} items deleted; now have ".
685 scalar(keys %nuh) ) if ($delete);
690 &ScheduleThis(60, "ignoreCheck");
691 return if ($_[0] eq "2"); # defer.
697 foreach (keys %ignore) {
700 foreach (keys %{ $ignore{$chan} }) {
701 my @array = @{ $ignore{$chan}{$_} };
703 next unless ($array[0] and $time > $array[0]);
705 delete $ignore{$chan}{$_};
706 &status("ignore: $_/$chan has expired.");
711 $cache{ignoreCheckTime} = time();
713 &VERB("ignore: $count items deleted.",2);
718 &ScheduleThis(15, "ircCheck");
719 return if ($_[0] eq "2"); # defer.
722 $cache{statusSafe} = 1;
724 my @x = &getJoinChans();
725 my $iconf = scalar( @x );
726 my $inow = scalar( keys %channels );
727 if ($iconf > 2 and $inow * 2 <= $iconf) {
728 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
729 &FIXME("ircCheck: iconf = $iconf");
730 &FIXME("ircCheck: inow = $inow");
735 if (!$conn->connected or time() - $msgtime > 3600) {
736 # todo: shouldn't we use cache{connect} somewhere?
737 if (exists $cache{connect}) {
738 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
739 $msgtime = time(); # just in case.
741 delete $cache{connect};
743 &status("IRCTEST: possible lost in space; checking. ".
745 &msg($ident, "TEST");
746 $cache{connect} = time();
750 if ($ident !~ /^\Q$param{ircNick}\E$/) {
751 # this does not work unfortunately.
752 &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
754 # this check is misleading... perhaps we should do a notify.
755 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
756 &DEBUG("$param{ircNick} not in use... changing!");
757 &nick( $param{ircNick} );
759 &WARN("$param{ircNick} is still in use...");
763 if (grep /^\s*$/, keys %channels) {
764 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
765 if (!exists $channels{''}) {
766 &DEBUG("ircCheck: this should never happen!");
769 delete $channels{''};
772 $cache{statusSafe} = 0;
775 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
777 $wtime_userfile = time();
780 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
782 $wtime_chanfile = time();
788 &ScheduleThis(120, "miscCheck");
789 return if ($_[0] eq "2"); # defer.
794 if ( -x "/usr/bin/ipcs") {
795 @ipcs = `/usr/bin/ipcs`;
797 &WARN("ircCheck: no 'ipcs' binary.");
801 # shmid stale remove.
805 # key, shmid, owner, perms, bytes, nattch
806 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
808 my ($shmid, $size) = ($2,$5);
809 next unless ($shmid != $shm and $size == 2000);
810 my $z = &shmRead($shmid);
811 if ($z =~ /^(\d+): /) {
813 next if (time() - $time < 60*60);
816 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
820 &status("SHM: nuking shmid $shmid");
821 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
824 # make backup of important files.
825 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
826 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
827 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
829 # flush cache{lobotomy}
830 foreach (keys %{ $cache{lobotomy} }) {
831 next unless (time() - $cache{lobotomy}{$_} > 60*60);
832 delete $cache{lobotomy}{$_};
835 ### check modules if they've been modified. might be evil.
841 &ScheduleThis(240, "miscCheck2");
842 return if ($_[0] eq "2"); # defer.
846 opendir(DEBIAN, "$bot_state_dir/debian");
847 foreach ( grep /gz$/, readdir(DEBIAN) ) {
848 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
851 &status("debian: unlinking file => $_");
852 unlink "$bot_state_dir/debian/$_";
856 # compress logs that should have been compressed.
857 # todo: use strftime?
858 my ($day,$month,$year) = (localtime(time()))[3,4,5];
859 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
861 if (!opendir(DIR,"$bot_log_dir")) {
862 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
867 while (my $f = readdir(DIR)) {
868 next unless ( -f "$bot_log_dir/$f");
869 next if ($f =~ /gz|bz2/);
870 next unless ($f =~ /(\d{8})/);
871 next if ($date eq $1);
873 &compress("$bot_log_dir/$f");
878 ### this is semi-scheduled
880 if ($ident eq $param{'ircNick'}) {
881 &status("okay, got my nick back.");
886 &ScheduleThis(30, "getNickInUse");
887 return if ($_[0] eq "2"); # defer.
890 &nick( $param{'ircNick'} );
894 return unless &IsChanConf("uptime");
897 &ScheduleThis(60, "uptimeLoop");
898 return if ($_[0] eq "2"); # defer.
907 &ScheduleThis(60, "slashdotLoop");
908 return if ($_[0] eq "2");
911 my @chans = &ChanConfList("slashdotAnnounce");
912 return unless (scalar @chans);
914 &Forker("slashdot", sub {
915 my $line = &Slashdot::slashdotAnnounce();
916 return unless (defined $line);
919 next unless (&::validChan($_));
921 &::status("sending slashdot update to $_.");
922 ¬ice($_, "Slashdot: $line");
929 &ScheduleThis(60, "freshmeatLoop");
930 return if ($_[0] eq "2");
933 my @chans = &ChanConfList("freshmeatAnnounce");
934 return unless (scalar @chans);
936 &Forker("freshmeat", sub {
937 my $data = &Freshmeat::freshmeatAnnounce();
940 next unless (&::validChan($_));
942 &::status("sending freshmeat update to $_.");
950 &ScheduleThis(240, "kernelLoop");
951 return if ($_[0] eq "2");
954 my @chans = &ChanConfList("kernelAnnounce");
955 return unless (scalar @chans);
957 &Forker("kernel", sub {
958 my @data = &Kernel::kernelAnnounce();
961 next unless (&::validChan($_));
963 &::status("sending kernel update to $_.");
966 ¬ice($c, "Kernel: $_");
973 return unless &IsChanConf("wingate");
975 ### FILE CACHE OF OFFENDING WINGATES.
976 foreach (grep /^$host$/, @wingateBad) {
977 &status("Wingate: RUNNING ON $host BY $who");
978 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
980 my $reason = &getChanConf("wingateKick");
982 next unless ($reason);
983 &kick($who, "", $reason)
986 ### RUN CACHE OF TRIED WINGATES.
987 if (grep /^$host$/, @wingateCache) {
988 push(@wingateNow, $host); # per run.
989 push(@wingateCache, $host); # cache per run.
991 &DEBUG("Already scanned $host. good.");
994 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
995 return if (defined $forked{'wingate'});
996 return if (time() - $wingaterun <= $interval);
997 return unless (scalar(keys %wingateToDo));
999 $wingaterun = time();
1001 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
1006 sub wingateWriteFile {
1008 &ScheduleThis(60, "wingateWriteFile");
1009 return if ($_[0] eq "2"); # defer.
1012 return unless (scalar @wingateCache);
1014 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1015 if ($bot_pid != $$) {
1016 &DEBUG("wingateWriteFile: Reorganising!");
1021 push(@wingateNow, $_);
1026 my %hash = map { $_ => 1 } @wingateNow;
1027 @wingateNow = sort keys %hash;
1030 &DEBUG("wingateWF: writing...");
1031 open(OUT, ">$file");
1032 foreach (@wingateNow) {
1040 &ScheduleThis(720, "factoidCheck");
1041 return if ($_[0] eq "2"); # defer.
1044 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1045 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1047 # disable it since it's "illegal".
1054 my $age = &getFactInfo($_, "modified_time");
1056 if (!defined $age or $age !~ /^\d+$/) {
1057 if (scalar @list > 50) {
1058 if (!$cache{warnDel}) {
1059 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1060 $cache{warnDel} = 1;
1065 &WARN("del factoid: old cruft (no time): $_");
1070 next unless ($time - $age > $stale);
1073 $fix =~ s/ #DEL#$//g;
1074 my $agestr = &Time2String($time - $age);
1075 &status("safedel: Removing '$_' for good. [$agestr old]");
1082 return unless (scalar keys %{ $dcc{CHAT} });
1085 &ScheduleThis(10, "dccStatus");
1086 return if ($_[0] eq "2"); # defer.
1089 my $time = strftime("%H:%M", localtime(time()) );
1092 foreach (keys %channels) {
1094 my $users = keys %{ $channels{$c}{''} };
1095 my $chops = keys %{ $channels{$c}{o} };
1096 my $bans = keys %{ $channels{$c}{b} };
1098 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1099 foreach (keys %{ $dcc{'CHAT'} }) {
1100 next unless (exists $channels{$c}{''}{lc $_});
1101 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1114 foreach (keys %{ $irc->{_queue} }) {
1118 foreach (keys %sched) {
1119 next unless ($q eq $sched{$_});
1124 my $time = $irc->{_queue}->{$q}->[0] - time();
1126 if (defined $sched) {
1127 &DEBUG(" $sched($q): ".&Time2String($time) );
1129 &DEBUG(" NULL($q): ".&Time2String($time) );
1133 &DEBUG("end of sList.");
1137 my($file, $time) = @_;
1141 &VERB("mkB: file '$file' does not exist.",2);
1146 if ( -e "$file~" ) {
1147 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1148 my $delta = time() - (stat "$file~")[9];
1149 $age = &Time2String($delta);
1154 return unless ($backup);
1156 ### TODO: do internal copying.
1157 &status("Backup: $file ($age)");
1158 CORE::system("/bin/cp $file $file~");