X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FIRC%2FIrc.pl;h=49d0438ef576933c861ad69d40632a6ff4f812d5;hb=130fc9d79663d571b32c8a625e3487e7b42c10da;hp=3acce09ceb3a1cf45f40595a84e9876ad389a756;hpb=64b1ab9e23f7895f1ab62a8168d77955a11451fc;p=infobot.git diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 3acce09..49d0438 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -40,25 +40,25 @@ loop:; } next unless (exists $ircPort{$host}); - my $retval = &irc($host, $ircPort{$host}); - &DEBUG("ircloop: after irc()"); - + my $retval = &irc($host, $ircPort{$host}); next unless (defined $retval and $retval == 0); - $error++; if ($error % 3 == 0 and $error != 0) { - &ERROR("CANNOT connect to this server; next!"); + &status("IRC: Could not connect."); + &status("IRC: "); next; } - if ($error >= 3*3) { - &ERROR("CANNOT connect to any irc server; stopping."); + if ($error >= 3*2) { + &status("IRC: cannot connect to any IRC servers; stopping."); + &shutdown(); exit 1; } } - &DEBUG("ircloop: end... going back."); + &status("IRC: ok, done one cycle of IRC servers; trying again."); + &loadIRCServers(); goto loop; } @@ -90,16 +90,19 @@ sub irc { $irc = new Net::IRC; - $conn = $irc->newconn( + my %args = ( Nick => $param{'ircNick'}, Server => $server, Port => $port, Ircname => $param{'ircName'}, - LocalAddr => $param{'ircHost'}, ); + $args{'LocalAddr'} = $param{'ircHost'} if ($param{'ircHost'}); + $args{'Password'} = $param{'ircPasswd'} if ($param{'ircPasswd'}); + + $conn = $irc->newconn(%args); if (!defined $conn) { - &ERROR("irc: conn was not created!defined!!!"); + &ERROR("internal: perl IRC connection object does not exist."); return 1; } @@ -107,6 +110,8 @@ sub irc { # change internal timeout value for scheduler. $irc->{_timeout} = 10; # how about 60? + # Net::IRC debugging. + $irc->{_debug} = 1; $ircstats{'Server'} = "$server:$port"; @@ -131,12 +136,15 @@ sub irc { $conn->add_handler('nick', \&on_nick); $conn->add_handler('quit', \&on_quit); $conn->add_handler('notice', \&on_notice); - $conn->add_handler('whoisuser', \&on_whoisuser); + $conn->add_handler('whoischannels', \&on_whoischannels); + $conn->add_handler('useronchannel', \&on_useronchannel); + $conn->add_handler('whois', \&on_whois); $conn->add_handler('other', \&on_other); $conn->add_global_handler('disconnect', \&on_disconnect); $conn->add_global_handler([251,252,253,254,255], \&on_init); ### $conn->add_global_handler([251,252,253,254,255,302], \&on_init); $conn->add_global_handler(315, \&on_endofwho); + $conn->add_global_handler(422, \&on_endofwho); # nomotd. $conn->add_global_handler(324, \&on_modeis); $conn->add_global_handler(333, \&on_topicinfo); $conn->add_global_handler(352, \&on_who); @@ -150,6 +158,7 @@ sub irc { $conn->add_global_handler(473, \&on_inviteonly); $conn->add_global_handler(474, \&on_banned); $conn->add_global_handler(475, \&on_badchankey); + $conn->add_global_handler(443, \&on_useronchan); # end of handler stuff. @@ -197,11 +206,9 @@ sub say { if ( ($pubcount % $i) == 0 and $pubcount) { sleep 1; - $pubsleep++; } elsif ($pubsize > $j) { sleep 1; $pubsize -= $j; - $pubsleep++; } } else { @@ -227,6 +234,13 @@ sub msg { return; } + if ($msgType =~ /chat/i) { + # todo: warn that we're using msg() to do DCC CHAT? + &dccsay($nick, $msg); + # todo: make dccsay deal with flood protection? + return; + } + &status(">$nick< $msg"); if (&whatInterface() =~ /IRC/) { @@ -240,11 +254,9 @@ sub msg { my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000); if ( ($msgcount % $i) == 0 and $msgcount) { sleep 1; - $msgsleep++; } elsif ($msgsize > $j) { sleep 1; $msgsize -= $j; - $msgsleep++; } } else { @@ -298,11 +310,9 @@ sub notice { if ( ($notcount % $i) == 0 and $notcount) { sleep 1; - $notsleep++; } elsif ($notsize > $j) { sleep 1; $notsize -= $j; - $notsleep++; } } else { @@ -351,7 +361,7 @@ sub performReply { &msg($who, $reply); } elsif ($msgType eq 'chat') { if (!exists $dcc{'CHAT'}{$who}) { - &WARN("pSR: dcc{'CHAT'}{$who} does not exist."); + &VERB("pSR: dcc{'CHAT'}{$who} does not exist.",2); return; } $conn->privmsg($dcc{'CHAT'}{$who}, $reply); @@ -381,17 +391,23 @@ sub performStrictReply { } elsif ($msgType eq 'public') { &say($reply); } elsif ($msgType eq 'chat') { - &dccsay(lc $who,$reply); + &dccsay(lc $who, $reply); } else { &ERROR("pSR: msgType invalid? ($msgType)."); } } sub dccsay { - my ($who, $reply) = @_; + my($who, $reply) = @_; + + if (!defined $reply or $reply =~ /^\s*$/) { + &WARN("dccsay: reply == NULL."); + return; + } + if (!exists $dcc{'CHAT'}{$who}) { - &WARN("pSR: dcc{'CHAT'}{$who} does not exist."); - return ''; + &VERB("pSR: dcc{'CHAT'}{$who} does not exist. (2)",2); + return; } &status("=>$who<= $reply"); # dcc chat. @@ -407,6 +423,7 @@ sub dcc_close { my @who = grep /^\Q$who\E$/i, keys %{ $dcc{$type} }; next unless (scalar @who); $who = $who[0]; + &DEBUG("dcc_close... close $who!"); } } @@ -418,13 +435,14 @@ sub joinchan { $chan = lc $1; } - &status("joining $b_blue$chan$ob"); - + # hopefully validChan is right. if (&validChan($chan)) { &status("join: already on $chan"); } else { + &status("joining $b_blue$chan$ob"); if (!$conn->join($chan)) { &DEBUG("joinchan: join failed. trying connect!"); + &clearIRCVars(); $conn->connect(); } } @@ -437,6 +455,11 @@ sub part { next if ($chan eq ""); $chan =~ tr/A-Z/a-z/; # lowercase. + if ($chan !~ /^$mask{chan}$/) { + &WARN("part: chan is invalid ($chan)"); + next; + } + &status("parting $chan"); if (!&validChan($chan)) { &WARN("part: not on $chan; doing anyway"); @@ -555,7 +578,11 @@ sub unban { sub quit { my ($quitmsg) = @_; &status("QUIT $param{'ircNick'} has quit IRC ($quitmsg)"); - $conn->quit($quitmsg); + if (defined $conn) { + $conn->quit($quitmsg); + } else { + &WARN("quit: could not quit!"); + } } sub nick { @@ -618,20 +645,20 @@ sub joinNextChan { } return; - } # !scalar @joinchan: - if (exists $cache{joinTime}) { - my $delta = time() - $cache{joinTime}; + my @c = &getJoinChans(); + if (exists $cache{joinTime} and scalar @c) { + my $delta = time() - $cache{joinTime} - 5; my $timestr = &Time2String($delta); - my $rate = sprintf("%.1f", $delta / &getJoinChans() ); + my $rate = sprintf("%.1f", $delta / @c); delete $cache{joinTime}; - &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join"); + &status("time taken to join all chans: $timestr; rate: $rate sec/join"); } - # chanserv check: global channels, in case we missed one. + # chanserv check: global channels, in case we missed one. foreach ( &ChanConfList("chanServ_ops") ) { &chanServCheck($_); } @@ -691,14 +718,25 @@ sub IsNickInAnyChan { # Usage: &validChan($chan); sub validChan { + # todo: use $c instead? my ($chan) = @_; + if (!defined $chan or $chan =~ /^\s*$/) { + return 0; + } + if (lc $chan ne $chan) { &WARN("validChan: lc chan != chan. ($chan); fixing."); $chan =~ tr/A-Z/a-z/; } - if (exists $channels{$chan}) { + # it's possible that this check creates the hash if empty. + if (defined $channels{$chan} or exists $channels{$chan}) { + if ($chan eq "_default") { +# &WARN("validC: chan cannot be _default! returning 0!"); + return 0; + } + return 1; } else { return 0; @@ -728,7 +766,7 @@ sub clearChanVars { } sub clearIRCVars { -### &DEBUG("clearIRCVars() called!"); + &DEBUG("clearIRCVars() called!"); undef %channels; undef %floodjoin; @@ -774,21 +812,23 @@ sub getJoinChans { } sub closeDCC { -### &DEBUG("closeDCC called."); +# &DEBUG("closeDCC called."); foreach $type (keys %dcc) { next if ($type ne uc($type)); foreach $nick (keys %{ $dcc{$type} }) { next unless (defined $nick); - &DEBUG("closing DCC $type to $nick (FIXME)."); + &status("DCC CHAT: closing DCC $type to $nick."); next unless (defined $dcc{$type}{$nick}); my $ref = $dcc{$type}{$nick}; - &DEBUG("ref => $ref"); - -# $dcc{$type}{$nick}->close(); + &dccsay($nick, "bye bye, $nick") if ($type =~ /^chat$/i); + $dcc{$type}{$nick}->close(); + delete $dcc{$type}{$nick}; + &DEBUG("after close for $nick"); } + delete $dcc{$type}; } } @@ -827,10 +867,15 @@ sub joinfloodCheck { ### Clean it up. my $delete = 0; + my $time = time(); foreach $chan (keys %floodjoin) { foreach $who (keys %{ $floodjoin{$chan} }) { - my $time = time() - $floodjoin{$chan}{$who}{Time}; - next unless ($time > 10); + my $t = $floodjoin{$chan}{$who}{Time}; + next unless (defined $t); + + my $delta = $time - $t; + next unless ($delta > 10); + delete $floodjoin{$chan}{$who}; $delete++; } @@ -842,7 +887,12 @@ sub joinfloodCheck { sub getHostMask { my($n) = @_; - &FIXME("getHostMask($n) called..."); + if (exists $nuh{$n}) { + return &makeHostMask($nuh{$n}); + } else { + $cache{on_who_Hack} = 1; + &rawout("WHO $n"); + } } 1;