]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Irc.pl
- Remaining files that were changed due to removal of $noreply or
[infobot.git] / src / IRC / Irc.pl
index f3775984bca4e72da832a62fdd1835000ffefd7e..c12fe42004db92c2a042aac1bdea70cfaef9ed49 100644 (file)
@@ -10,10 +10,11 @@ if (&IsParam("useStrict")) { use strict; }
 # static scalar variables.
 $mask{ip}      = '(\d+)\.(\d+)\.(\d+)\.(\d+)';
 $mask{host}    = '[\d\w\_\-\/]+\.[\.\d\w\_\-\/]+';
-$mask{chan}    = '[\#\&\+]\S*';
+$mask{chan}    = '[\#\&]\S*';
 my $isnick1    = 'a-zA-Z\[\]\{\}\_\`\^\|\\\\';
 my $isnick2    = '0-9\-';
 $mask{nick}    = "[$isnick1]{1}[$isnick1$isnick2]*";
+$mask{nuh}     = '\S*!\S*\@\S*';
 
 sub ircloop {
     my $error  = 0;
@@ -22,8 +23,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 +35,6 @@ sub ircloop {
                $lastrun = time();
                next;
            }
-           &DEBUG("ircloop: _ => '$_'.");
            next unless (exists $ircPort{$_});
 
            my $retval = &irc($_, $ircPort{$_});
@@ -61,7 +62,6 @@ sub irc {
 
     select STDOUT;
     &status("Connecting to port $port of server $server ...");
-    sleep 3;           # lame hack.
 
     # host->ip.
     if ($server =~ /\D$/) {
@@ -91,14 +91,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 +129,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.
@@ -160,7 +158,7 @@ sub rawout {
 
 sub say {
     my ($msg) = @_;
-    if (!defined $msg or $msg eq $noreply) {
+    if (!defined $msg) {
        $msg ||= "NULL";
        &DEBUG("say: msg == $msg.");
        return;
@@ -187,7 +185,7 @@ sub msg {
        return;
     }
 
-    if (!defined $msg or $msg eq $noreply) {
+    if (!defined $msg) {
        $msg ||= "NULL";
        &DEBUG("msg: msg == $msg.");
        return;
@@ -238,7 +236,9 @@ sub notice{
 
 
 sub DCCBroadcast {
-    my ($txt) = @_;
+    my ($txt,$flag) = @_;
+
+    ### FIXME: flag not supported yet.
 
     foreach (keys %{$dcc{'CHAT'}}) {
        $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
@@ -257,7 +257,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 +271,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).");
     }
@@ -285,6 +287,10 @@ sub performAddressedReply {
     &performReply(@_);
 }
 
+sub pSReply {
+    &performStrictReply(@_);
+}
+
 # Usage: &performStrictReply($reply);
 sub performStrictReply {
     my ($reply) = @_;
@@ -296,16 +302,32 @@ 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).");
     }
+}
+
+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);
+}
 
-    return '';
+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 {
@@ -352,6 +374,8 @@ sub mode {
        return;
     }
 
+    &DEBUG("MODE $chan $modes");
+
     rawout("MODE $chan $modes");
 }
 
@@ -463,6 +487,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");
+            }
+       }
     }
 }
 
@@ -479,6 +518,14 @@ sub GetNickInChans {
     return @array;
 }
 
+# Usage: &GetNicksInChan($chan);
+sub GetNicksInChan {
+    my ($chan) = @_;
+    my @array;
+
+    return keys %{ $channels{$chan}{''} };
+}
+
 sub IsNickInChan {
     my ($nick,$chan) = @_;
 
@@ -492,6 +539,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,39 +597,104 @@ sub clearChanVars {
 
 sub clearIRCVars {
     &DEBUG("clearIRCVars() called!");
-    %channels = ();
-    @joinchan = split /[\t\s]+/, $param{'join_channels'};
+    undef %channels;
+    undef %floodjoin;
+
+    @joinchan  = &getJoinChans();
 }
 
-sub makeChanList {
-    my ($str)  = @_;
-    my $inverse        = 0;
+sub getJoinChans {
     my @chans;
+    my @skip;
 
-    if ($str eq "ALL") {
-       return(keys %channels);
-    } elsif ($str =~ s/^ALL but //i) {
-       @chans = keys %channels;
-       foreach (split /[\s\t\,]+/, lc $str) {
-           @chans = grep !/^$_$/, @chans;
+    foreach (keys %chanconf) {
+       my $val = $chanconf{$_}{autojoin};
+       my $skip = 0;
+       if (defined $val) {
+           $skip++ if ($val eq "0");
+       } else {
+           $skip++;
        }
-    } else {
-       foreach (split /[\s\t\,]+/, lc $str) {
-           next unless (&validChan($_));
-           push(@chans, $_);
+
+       if ($skip) {
+           push(@skip, $_);
+           next;
        }
+
+       push(@chans, $_);
+    }
+
+    if (scalar @skip) {
+       &status("channels not auto-joining: @skip");
     }
 
-    @chans;
+    return @chans;
 }
 
 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);
+}
+
+sub getHostMask {
+    my($n) = @_;
+
+    &FIXME("getHostMask...");
 }
 
 1;