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)) {
198 &WARN("logLoop: could not open dir '$bot_log_dir'");
204 while (defined($_ = readdir LOGS)) {
205 my $logfile = "$bot_log_dir/$_";
207 next unless ( -f $logfile);
209 my $size = -s $logfile;
210 my $age = (stat $logfile)[9];
211 $age{$age} = $logfile;
212 $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);
233 &ScheduleThis(1440, "seenFlushOld");
234 return if ($_[0] eq "2"); # defer.
237 # is this global-only?
238 return unless (&IsChanConf("seen") > 0);
239 return unless (&IsChanConf("seenFlushInterval") > 0);
241 # global setting. does not make sense for per-channel.
242 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
245 if ($param{'DBType'} =~ /^pgsql|mysql/i) {
248 if ($param{'DBType'} =~ /^mysql$/i) {
249 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
250 "UNIX_TIMESTAMP() - time > $max_time";
252 $query = "SELECT nick,time FROM seen WHERE ".
253 "extract(epoch from timestamp 'now') - time > $max_time";
256 my $sth = $dbh->prepare($query);
259 while (my @row = $sth->fetchrow_array) {
260 my ($nick,$time) = @row;
262 &dbDel("seen","nick",$nick);
266 } elsif ($param{'DBType'} =~ /^dbm/i) {
269 foreach (keys %seen) {
270 my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
271 next unless ($delta_time > $max_time);
273 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
278 &FIXME("seenFlushOld: for PG/NO-DB.");
280 &VERB("SEEN deleted $delete seen entries.",2);
286 &ScheduleThis(60, "newsFlush");
287 return if ($_[0] eq "2"); # defer.
290 if (!&ChanConfList("news")) {
291 &DEBUG("newsFlush: news disabled? (chan => $chan)");
298 foreach $chan (keys %::news) {
300 my $total = scalar(keys %{ $::news{$chan} });
303 delete $::news{$chan};
307 foreach $item (keys %{ $::news{$chan} }) {
308 my $t = $::news{$chan}{$item}{Expire};
310 my $tadd = $::news{$chan}{$item}{Time};
311 $oldest = $tadd if ($oldest > $tadd);
313 next if ($t == 0 or $t == -1);
315 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
316 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
320 my $delta = $t - time();
322 next unless (time() > $t);
324 # todo: show how old it was.
325 delete $::news{$chan}{$item};
326 &status("NEWS: (newsflush) deleted '$item'");
331 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
332 $none{$chan} = 1 if ($total == $i);
335 # todo: flush users aswell.
337 foreach $chan (keys %::newsuser) {
338 next if (exists $none{$chan});
340 foreach (keys %{ $::newsuser{$chan} }) {
341 my $t = $::newsuser{$chan}{$_};
342 if (!defined $t or ($t > 2 and $t < 1000)) {
343 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
347 next unless ($oldest > $t);
349 delete $::newsuser{$chan}{$_};
353 my $i = scalar(keys %{ $::newsuser{$chan} });
354 delete $::newsuser{$chan} unless ($i);
357 if ($delete or $duser) {
359 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
364 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
367 &ScheduleThis($interval, "chanlimitCheck");
368 return if ($_[0] eq "2");
371 my $str = join(' ', &ChanConfList("chanlimitcheck") );
373 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
374 next unless (&validChan($chan));
376 if ($chan eq "_default") {
377 &WARN("chanlimit: we're doing $chan!! HELP ME!");
381 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
382 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
383 my $limit = $channels{$chan}{'l'};
385 if (scalar keys %netsplitservers) {
386 if (defined $limit) {
387 &status("chanlimit: netsplit; removing it for $chan.");
388 &rawout("MODE $chan -l");
389 $cache{chanlimitChange}{$chan} = time();
390 &status("chanlimit: netsplit; removed.");
396 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
397 &FIXME("LIMIT: set too low!!! FIXME");
398 ### run NAMES again and flush it.
401 if (defined $limit and $limit == $newlimit) {
402 $cache{chanlimitChange}{$chan} = time();
406 if (!exists $channels{$chan}{'o'}{$ident}) {
407 &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
408 $cache{warn}{chanlimit}{$chan} = 1;
409 &chanServCheck($chan);
412 delete $cache{warn}{chanlimit}{$chan};
414 if (!defined $limit) {
415 &status("chanLimit: setting for first time or from netsplit, for $chan");
418 if (exists $cache{chanlimitChange}{$chan}) {
419 my $delta = time() - $cache{chanlimitChange}{$chan};
420 if ($delta < $interval*60) {
421 &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
426 &rawout("MODE $chan +l $newlimit");
427 $cache{chanlimitChange}{$chan} = time();
435 &ScheduleThis(15, "netsplitCheck");
436 return if ($_[0] eq "2");
439 $cache{'netsplitCache'}++;
440 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
442 if (!scalar %netsplit and scalar %netsplitservers) {
443 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
444 undef %netsplitservers;
448 # well... this shouldn't happen since %netsplit code does it anyway.
449 foreach $s1 (keys %netsplitservers) {
451 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
452 my $delta = time() - $netsplitservers{$s1}{$s2};
454 if ($delta > 60*30) {
455 &status("netsplit between $s1 and $s2 appears to be stale.");
456 delete $netsplitservers{$s1}{$s2};
461 my $i = scalar(keys %{ $netsplitservers{$s1} });
462 delete $netsplitservers{$s1} unless ($i);
465 # %netsplit hash checker.
466 my $count = scalar keys %netsplit;
468 foreach (keys %netsplit) {
469 if (&IsNickInAnyChan($_)) { # why would this happen?
470 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
471 delete $netsplit{$_};
476 next unless (time() - $netsplit{$_} > 60*15);
479 delete $netsplit{$_};
483 foreach (keys %channels) {
484 my $i = $cache{maxpeeps}{$chan} || 0;
485 my $j = scalar(keys %{ $channels{$chan} });
486 next unless ($i > 10 and 0.25*$i > $j);
488 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
492 my $j = scalar(keys %netsplit);
493 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
496 if (!scalar %netsplit and scalar %netsplitservers) {
497 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
498 undef %netsplitservers;
501 if ($count and !scalar keys %netsplit) {
502 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
512 &ScheduleThis(60, "floodLoop"); # minutes.
513 return if ($_[0] eq "2");
517 my $interval = &getChanConfDefault("floodCycle",60);
519 foreach $who (keys %flood) {
520 foreach (keys %{ $flood{$who} }) {
521 if (!exists $flood{$who}{$_}) {
522 &WARN("flood{$who}{$_} undefined?");
526 if ($time - $flood{$who}{$_} > $interval) {
527 delete $flood{$who}{$_};
532 &VERB("floodLoop: deleted $delete items.",2);
537 my $interval = &getChanConfDefault("seenFlushInterval", 60);
538 &ScheduleThis($interval, "seenFlush");
539 return if ($_[0] eq "2");
545 $stats{'count_old'} = &countKeys("seen") || 0;
549 if ($param{'DBType'} =~ /^(mysql|pgsql)$/i) {
550 foreach $nick (keys %seencache) {
551 my $retval = &dbReplace("seen", "nick", (
552 "nick" => lc $seencache{$nick}{'nick'},
553 "time" => $seencache{$nick}{'time'},
554 "host" => $seencache{$nick}{'host'},
555 "channel" => $seencache{$nick}{'chan'},
556 "message" => $seencache{$nick}{'msg'},
558 delete $seencache{$nick};
567 my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
569 if (defined $exists and $exists) {
570 &dbUpdate("seen", "nick", $nick, (
571 "time" => $seencache{$nick}{'time'},
572 "host" => $seencache{$nick}{'host'},
573 "channel" => $seencache{$nick}{'chan'},
574 "message" => $seencache{$nick}{'msg'},
578 my $retval = &dbInsert("seen", $nick, (
579 "nick" => $seencache{$nick}{'nick'},
580 "time" => $seencache{$nick}{'time'},
581 "host" => $seencache{$nick}{'host'},
582 "channel" => $seencache{$nick}{'chan'},
583 "message" => $seencache{$nick}{'msg'},
587 ### TODO: put bad nick into a list and don't do it again!
588 &FIXME("Should never happen! (nick => $nick)") if !$retval;
591 delete $seencache{$nick};
595 } elsif ($param{'DBType'} =~ /^dbm/i) {
597 foreach $nick (keys %seencache) {
598 my $retval = &dbInsert("seen", $nick, (
599 "nick" => $seencache{$nick}{'nick'},
600 "time" => $seencache{$nick}{'time'},
601 "host" => $seencache{$nick}{'host'},
602 "channel" => $seencache{$nick}{'chan'},
603 "message" => $seencache{$nick}{'msg'},
606 ### TODO: put bad nick into a list and don't do it again!
607 &FIXME("Should never happen! (nick => $nick)") if !$retval;
609 delete $seencache{$nick};
613 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
616 &status("Seen: Flushed $flushed entries.") if ($flushed);
617 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
618 $stats{'new'}*100/($stats{'count_old'} || 1),
619 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
620 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
621 $stats{'old'}*100 / ( &countKeys("seen") || 1),
622 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
624 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
632 &ScheduleThis(240, "leakCheck");
633 return if ($_[0] eq "2");
636 # flood. this is dealt with in floodLoop()
637 foreach $blah1 (keys %flood) {
638 foreach $blah2 (keys %{ $flood{$blah1} }) {
639 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
642 &VERB("leak: hash flood has $count total keys.",2);
646 foreach $blah1 (keys %floodjoin) {
647 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
648 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
651 &VERB("leak: hash floodjoin has $count total keys.",2);
654 $count = scalar(keys %floodwarn);
655 &VERB("leak: hash floodwarn has $count total keys.",2);
658 foreach $chan (grep /[A-Z]/, keys %channels) {
659 &DEBUG("leak: chan => '$chan'.");
661 foreach $i (keys %{ $channels{$chan} }) {
662 foreach (keys %{ $channels{$chan}{$i} }) {
663 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
669 $count = scalar(keys %chanstats);
670 &VERB("leak: hash chanstats has $count total keys.",2);
674 foreach (keys %nuh) {
675 next if (&IsNickInAnyChan($_));
676 next if (exists $dcc{CHAT}{$_});
682 &status("leak: $delete nuh{} items deleted; now have ".
683 scalar(keys %nuh) ) if ($delete);
688 &ScheduleThis(60, "ignoreCheck");
689 return if ($_[0] eq "2"); # defer.
695 foreach (keys %ignore) {
698 foreach (keys %{ $ignore{$chan} }) {
699 my @array = @{ $ignore{$chan}{$_} };
701 next unless ($array[0] and $time > $array[0]);
703 delete $ignore{$chan}{$_};
704 &status("ignore: $_/$chan has expired.");
709 $cache{ignoreCheckTime} = time();
711 &VERB("ignore: $count items deleted.",2);
716 &ScheduleThis(15, "ircCheck");
717 return if ($_[0] eq "2"); # defer.
720 $cache{statusSafe} = 1;
722 my @x = &getJoinChans();
723 my $iconf = scalar( @x );
724 my $inow = scalar( keys %channels );
725 if ($iconf > 2 and $inow * 2 <= $iconf) {
726 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
727 &FIXME("ircCheck: iconf = $iconf");
728 &FIXME("ircCheck: inow = $inow");
733 if (!$conn->connected or time() - $msgtime > 3600) {
734 # todo: shouldn't we use cache{connect} somewhere?
735 if (exists $cache{connect}) {
736 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
737 $msgtime = time(); # just in case.
739 delete $cache{connect};
741 &status("IRCTEST: possible lost in space; checking. ".
743 &msg($ident, "TEST");
744 $cache{connect} = time();
748 if ($ident !~ /^\Q$param{ircNick}\E$/) {
749 # this does not work unfortunately.
750 &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
752 # this check is misleading... perhaps we should do a notify.
753 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
754 &DEBUG("$param{ircNick} not in use... changing!");
755 &nick( $param{ircNick} );
757 &WARN("$param{ircNick} is still in use...");
761 if (grep /^\s*$/, keys %channels) {
762 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
763 if (!exists $channels{''}) {
764 &DEBUG("ircCheck: this should never happen!");
767 delete $channels{''};
770 $cache{statusSafe} = 0;
773 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
775 $wtime_userfile = time();
778 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
780 $wtime_chanfile = time();
786 &ScheduleThis(120, "miscCheck");
787 return if ($_[0] eq "2"); # defer.
792 if ( -x "/usr/bin/ipcs") {
793 @ipcs = `/usr/bin/ipcs`;
795 &WARN("ircCheck: no 'ipcs' binary.");
799 # shmid stale remove.
803 # key, shmid, owner, perms, bytes, nattch
804 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
806 my ($shmid, $size) = ($2,$5);
807 next unless ($shmid != $shm and $size == 2000);
808 my $z = &shmRead($shmid);
809 if ($z =~ /^(\d+): /) {
811 next if (time() - $time < 60*60);
814 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
818 &status("SHM: nuking shmid $shmid");
819 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
822 # make backup of important files.
823 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
824 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
825 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
827 # flush cache{lobotomy}
828 foreach (keys %{ $cache{lobotomy} }) {
829 next unless (time() - $cache{lobotomy}{$_} > 60*60);
830 delete $cache{lobotomy}{$_};
833 ### check modules if they've been modified. might be evil.
839 &ScheduleThis(240, "miscCheck2");
840 return if ($_[0] eq "2"); # defer.
844 opendir(DEBIAN, "$bot_state_dir/debian");
845 foreach ( grep /gz$/, readdir(DEBIAN) ) {
846 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
849 &status("debian: unlinking file => $_");
850 unlink "$bot_state_dir/debian/$_";
854 # compress logs that should have been compressed.
855 # todo: use strftime?
856 my ($day,$month,$year) = (localtime(time()))[3,4,5];
857 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
859 if (!opendir(DIR,"$bot_log_dir")) {
860 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
865 while (my $f = readdir(DIR)) {
866 next unless ( -f "$bot_log_dir/$f");
867 next if ($f =~ /gz|bz2/);
868 next unless ($f =~ /(\d{8})/);
869 next if ($date eq $1);
871 &compress("$bot_log_dir/$f");
876 ### this is semi-scheduled
878 if ($ident eq $param{'ircNick'}) {
879 &status("okay, got my nick back.");
884 &ScheduleThis(30, "getNickInUse");
885 return if ($_[0] eq "2"); # defer.
888 &nick( $param{'ircNick'} );
892 return unless &IsChanConf("uptime");
895 &ScheduleThis(60, "uptimeLoop");
896 return if ($_[0] eq "2"); # defer.
905 &ScheduleThis(60, "slashdotLoop");
906 return if ($_[0] eq "2");
909 my @chans = &ChanConfList("slashdotAnnounce");
910 return unless (scalar @chans);
912 &Forker("slashdot", sub {
913 my $line = &Slashdot::slashdotAnnounce();
914 return unless (defined $line);
917 next unless (&::validChan($_));
919 &::status("sending slashdot update to $_.");
920 ¬ice($_, "Slashdot: $line");
927 &ScheduleThis(60, "freshmeatLoop");
928 return if ($_[0] eq "2");
931 my @chans = &ChanConfList("freshmeatAnnounce");
932 return unless (scalar @chans);
934 &Forker("freshmeat", sub {
935 my $data = &Freshmeat::freshmeatAnnounce();
938 next unless (&::validChan($_));
940 &::status("sending freshmeat update to $_.");
948 &ScheduleThis(240, "kernelLoop");
949 return if ($_[0] eq "2");
952 my @chans = &ChanConfList("kernelAnnounce");
953 return unless (scalar @chans);
955 &Forker("kernel", sub {
956 my @data = &Kernel::kernelAnnounce();
959 next unless (&::validChan($_));
961 &::status("sending kernel update to $_.");
964 ¬ice($c, "Kernel: $_");
971 return unless &IsChanConf("wingate");
973 ### FILE CACHE OF OFFENDING WINGATES.
974 foreach (grep /^$host$/, @wingateBad) {
975 &status("Wingate: RUNNING ON $host BY $who");
976 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
978 my $reason = &getChanConf("wingateKick");
980 next unless ($reason);
981 &kick($who, "", $reason)
984 ### RUN CACHE OF TRIED WINGATES.
985 if (grep /^$host$/, @wingateCache) {
986 push(@wingateNow, $host); # per run.
987 push(@wingateCache, $host); # cache per run.
989 &DEBUG("Already scanned $host. good.");
992 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
993 return if (defined $forked{'wingate'});
994 return if (time() - $wingaterun <= $interval);
995 return unless (scalar(keys %wingateToDo));
997 $wingaterun = time();
999 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
1004 sub wingateWriteFile {
1006 &ScheduleThis(60, "wingateWriteFile");
1007 return if ($_[0] eq "2"); # defer.
1010 return unless (scalar @wingateCache);
1012 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1013 if ($bot_pid != $$) {
1014 &DEBUG("wingateWriteFile: Reorganising!");
1019 push(@wingateNow, $_);
1024 my %hash = map { $_ => 1 } @wingateNow;
1025 @wingateNow = sort keys %hash;
1028 &DEBUG("wingateWF: writing...");
1029 open(OUT, ">$file");
1030 foreach (@wingateNow) {
1038 &ScheduleThis(720, "factoidCheck");
1039 return if ($_[0] eq "2"); # defer.
1042 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1043 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1045 # disable it since it's "illegal".
1052 my $age = &getFactInfo($_, "modified_time");
1054 if (!defined $age or $age !~ /^\d+$/) {
1055 if (scalar @list > 50) {
1056 if (!$cache{warnDel}) {
1057 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1058 $cache{warnDel} = 1;
1063 &WARN("del factoid: old cruft (no time): $_");
1068 next unless ($time - $age > $stale);
1071 $fix =~ s/ #DEL#$//g;
1072 my $agestr = &Time2String($time - $age);
1073 &status("safedel: Removing '$_' for good. [$agestr old]");
1080 return unless (scalar keys %{ $dcc{CHAT} });
1083 &ScheduleThis(10, "dccStatus");
1084 return if ($_[0] eq "2"); # defer.
1087 my $time = strftime("%H:%M", localtime(time()) );
1090 foreach (keys %channels) {
1092 my $users = keys %{ $channels{$c}{''} };
1093 my $chops = keys %{ $channels{$c}{o} };
1094 my $bans = keys %{ $channels{$c}{b} };
1096 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1097 foreach (keys %{ $dcc{'CHAT'} }) {
1098 next unless (exists $channels{$c}{''}{lc $_});
1099 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1112 foreach (keys %{ $irc->{_queue} }) {
1116 foreach (keys %sched) {
1117 next unless ($q eq $sched{$_});
1122 my $time = $irc->{_queue}->{$q}->[0] - time();
1124 if (defined $sched) {
1125 &DEBUG(" $sched($q): ".&Time2String($time) );
1127 &DEBUG(" NULL($q): ".&Time2String($time) );
1131 &DEBUG("end of sList.");
1135 my($file, $time) = @_;
1139 &VERB("mkB: file '$file' does not exist.",2);
1144 if ( -e "$file~" ) {
1145 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1146 my $delta = time() - (stat "$file~")[9];
1147 $age = &Time2String($delta);
1152 return unless ($backup);
1154 ### TODO: do internal copying.
1155 &status("Backup: $file ($age)");
1156 CORE::system("/bin/cp $file $file~");