]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Irc.pl
clearIRCVars update
[infobot.git] / src / IRC / Irc.pl
index f3775984bca4e72da832a62fdd1835000ffefd7e..e3cae5683437a27076cf952329c8656bd7779970 100644 (file)
@@ -22,8 +22,9 @@ sub ircloop {
     while (1) {
        # JUST IN CASE. irq was complaining about this.
        if ($lastrun == time()) {
+           &DEBUG("hrm... lastrun == time()");
            $error++;
-           sleep 1;
+           sleep 10;
            next;
        }
 
@@ -33,7 +34,6 @@ sub ircloop {
                $lastrun = time();
                next;
            }
-           &DEBUG("ircloop: _ => '$_'.");
            next unless (exists $ircPort{$_});
 
            my $retval = &irc($_, $ircPort{$_});
@@ -61,7 +61,6 @@ sub irc {
 
     select STDOUT;
     &status("Connecting to port $port of server $server ...");
-    sleep 3;           # lame hack.
 
     # host->ip.
     if ($server =~ /\D$/) {
@@ -91,14 +90,12 @@ sub irc {
        return 1;
     }
 
-    # clear out hashes before connecting...
     &clearIRCVars();
 
-    $ident                     = $param{'ircNick'};
-    ### IRCSTATS.
-    $ircstats{'ConnectTime'}   = time();
-    $ircstats{'ConnectCount'}++;
-    $ircstats{'Server'}                = "$server:$port";
+    # change internal timeout value for scheduler.
+    $irc->{_timeout}   = 10;   # how about 60?
+
+    $ircstats{'Server'}        = "$server:$port";
 
     # handler stuff.
        $conn->add_handler('caction',   \&on_action);
@@ -131,7 +128,7 @@ sub irc {
        $conn->add_global_handler(352, \&on_who);
        $conn->add_global_handler(353, \&on_names);
        $conn->add_global_handler(366, \&on_endofnames);
-       $conn->add_global_handler(376, \&on_endofmotd);
+       $conn->add_global_handler(376, \&on_endofmotd); # on_connect.
        $conn->add_global_handler(433, \&on_nick_taken);
        $conn->add_global_handler(439, \&on_targettoofast);
     # end of handler stuff.
@@ -257,7 +254,7 @@ sub performReply {
     &checkMsgType($reply);
 
     if ($msgType eq 'public') {
-       if (rand() < 0.5) {
+       if (rand() < 0.5 or $reply =~ /[\.\?]$/) {
            $reply = "$orig{who}: ".$reply;
        } else {
            $reply = "$reply, ".$orig{who};
@@ -271,9 +268,11 @@ sub performReply {
        }
        &msg($who, $reply);
     } elsif ($msgType eq 'chat') {
-       &DEBUG("pR: chat: reply => '$reply'.");
-       &DEBUG("pR: chat: sock => '$dcc{'CHAT'}{$nick}'.");
-       &DEBUG("pR: chat: sock => '$dcc{'CHAT'}{$who}'.");
+       if (!exists $dcc{'CHAT'}{$who}) {
+           &WARN("pSR: dcc{'CHAT'}{$who} does not exist.");
+           return;
+       }
+       $conn->privmsg($dcc{'CHAT'}{$who}, $reply);
     } else {
        &ERROR("PR: msgType invalid? ($msgType).");
     }
@@ -296,11 +295,7 @@ sub performStrictReply {
     } elsif ($msgType eq 'public') {
        &say($reply);
     } elsif ($msgType eq 'chat') {
-       if (!exists $dcc{'CHAT'}{$who}) {
-           &WARN("pSR: dcc{'CHAT'}{$who} does not exist.");
-           return;
-       }
-       $conn->privmsg($dcc{'CHAT'}{$who}, $reply);
+       &dccsay($who,$reply);
     } else {
        &ERROR("pSR: msgType invalid? ($msgType).");
     }
@@ -308,6 +303,28 @@ sub performStrictReply {
     return '';
 }
 
+sub dccsay {
+    my ($who, $reply) = @_;
+    if (!exists $dcc{'CHAT'}{$who}) {
+       &WARN("pSR: dcc{'CHAT'}{$who} does not exist.");
+       return '';
+    }
+
+    $conn->privmsg($dcc{'CHAT'}{$who}, $reply);
+}
+
+sub dcc_close {
+    my($who) = @_;
+    my $type;
+
+    foreach $type (keys %dcc) {
+       &FIXME("dcc_close: $who");
+       my @who = grep /^\Q$who\E$/i, keys %{$dcc{$type}};
+       next unless (scalar @who);
+       $who = $who[0];
+    }
+}
+
 sub joinchan {
     my ($chankey) = @_;
     my $chan = lc $chankey;
@@ -352,6 +369,8 @@ sub mode {
        return;
     }
 
+    &DEBUG("MODE $chan $modes");
+
     rawout("MODE $chan $modes");
 }
 
@@ -463,6 +482,21 @@ sub joinNextChan {
        if (my $i = scalar @joinchan) {
            &status("joinNextChan: $i chans to join.");
        }
+    } else {
+       return unless (&IsParam("chanServ_ops"));
+       if (!$nickserv) {
+           &DEBUG("jNC: nickserv/chanserv not up?");
+       }
+
+       my @chans = split(/[\s\t]+/, $param{'chanServ_ops'});
+       foreach $chan (keys %channels) {
+           next unless (grep /^$chan$/i, @chans);
+
+           if (!exists $channels{$chan}{'o'}{$ident}) {
+               &status("ChanServ ==> Requesting ops for $chan.");
+               &rawout("PRIVMSG ChanServ :OP $chan $ident");
+            }
+       }
     }
 }
 
@@ -492,6 +526,10 @@ sub IsNickInChan {
     if (grep /^\Q$nick\E$/i, keys %{$channels{$chan}{''}}) {
        return 1;
     } else {
+       foreach (keys %channels) {
+           next unless (/[A-Z]/);
+           &DEBUG("hash channels contains mixed cased chan!!!");
+       }
        return 0;
     }
 }
@@ -546,7 +584,8 @@ sub clearChanVars {
 
 sub clearIRCVars {
     &DEBUG("clearIRCVars() called!");
-    %channels = ();
+    undef %channels;
+    undef %floodjoin;
     @joinchan = split /[\t\s]+/, $param{'join_channels'};
 }
 
@@ -573,12 +612,63 @@ sub makeChanList {
 }
 
 sub closeDCC {
+    &DEBUG("closeDCC called.");
+
     foreach $type (keys %dcc) {
+       next if ($type ne uc($type));
        foreach (keys %{$dcc{$type}}) {
            &DEBUG("closing DCC $type to $_ (FIXME).");
-###        $irc->removeconn($dcc{$type}{$_});
+           $dcc{$type}{$_}->close();
        }
     }
 }
 
+sub joinfloodCheck {
+    my($who,$chan,$userhost) = @_;
+
+    return unless (&IsParam("joinfloodCheck"));
+
+    if (exists $netsplit{lc $who}) {   # netsplit join.
+       &DEBUG("jfC: $who was in netsnipe; not checking.");
+    }
+
+    if (exists $floodjoin{$chan}{$who}{Time}) {
+       &WARN("floodjoin{$chan}{$who} already exists?");
+    }
+
+    $floodjoin{$chan}{$who}{Time} = time();
+    $floodjoin{$chan}{$who}{Host} = $userhost;
+
+    ### Check...
+    foreach (keys %floodjoin) {
+       my $c = $_;
+       my $count = scalar keys %{ $floodjoin{$c} };
+       next unless ($count > 5);
+       &DEBUG("count => $count");
+
+       my $time;
+       foreach (keys %{ $floodjoin{$c} }) {
+           $time += $floodjoin{$c}{$_}{Time};
+       }
+       &DEBUG("time => $time");
+       $time /= $count;
+
+       &DEBUG("new time => $time");
+    }
+
+    ### Clean it up.
+    my $delete = 0;
+    foreach $chan (keys %floodjoin) {
+       foreach $who (keys %{ $floodjoin{$chan} }) {
+           my $time = time() - $floodjoin{$chan}{$who}{Time};
+           next unless ($time > 10);
+           delete $floodjoin{$chan}{$who};
+           $delete++;
+       }
+    }
+
+    &DEBUG("jfC: $delete deleted.") if ($delete);
+}
+
 1;