}
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;
}
$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'});
+
+ $conn = $irc->newconn(%args);
if (!defined $conn) {
&ERROR("irc: conn was not created!defined!!!");
# change internal timeout value for scheduler.
$irc->{_timeout} = 10; # how about 60?
+ # Net::IRC debugging.
+ $irc->{_debug} = 1;
$ircstats{'Server'} = "$server:$port";
$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(324, \&on_modeis);
$conn->add_global_handler(333, \&on_topicinfo);
$conn->add_global_handler(352, \&on_who);
$conn->add_global_handler(376, \&on_endofmotd); # on_connect.
$conn->add_global_handler(433, \&on_nick_taken);
$conn->add_global_handler(439, \&on_targettoofast);
+ # for proper joinnextChan behaviour
+ $conn->add_global_handler(471, \&on_chanfull);
+ $conn->add_global_handler(473, \&on_inviteonly);
+ $conn->add_global_handler(474, \&on_banned);
+ $conn->add_global_handler(475, \&on_badchankey);
# end of handler stuff.
$pubcount++;
$pubsize += length $msg;
- if ( ($pubcount % 4) == 0 and $pubcount) {
+ my $i = &getChanConfDefault("sendPublicLimitLines", 3);
+ my $j = &getChanConfDefault("sendPublicLimitBytes", 1000);
+
+ if ( ($pubcount % $i) == 0 and $pubcount) {
sleep 1;
- } elsif ($pubsize > 1500) {
+ $pubsleep++;
+ } elsif ($pubsize > $j) {
sleep 1;
- $pubsize -= 1500;
+ $pubsize -= $j;
+ $pubsleep++;
}
} else {
$msgcount++;
$msgsize += length $msg;
- if ( ($msgcount % 4) == 0 and $msgcount) {
+ my $i = &getChanConfDefault("sendPrivateLimitLines", 3);
+ my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
+ if ( ($msgcount % $i) == 0 and $msgcount) {
sleep 1;
- } elsif ($msgsize > 1000) {
+ $msgsleep++;
+ } elsif ($msgsize > $j) {
sleep 1;
- $msgsize -= 1000;
+ $msgsize -= $j;
+ $msgsleep++;
}
} else {
$notcount++;
$notsize += length $txt;
- if ( ($notcount % 4) == 0 and $notcount) {
+ my $i = &getChanConfDefault("sendNoticeLimitLines", 3);
+ my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000);
+
+ if ( ($notcount % $i) == 0 and $notcount) {
sleep 1;
- } elsif ($notsize > 1500) {
+ $notsleep++;
+ } elsif ($notsize > $j) {
sleep 1;
- $notsize -= 1500;
+ $notsize -= $j;
+ $notsleep++;
}
} else {
$conn->notice($target, $txt);
}
-
sub DCCBroadcast {
my ($txt,$flag) = @_;
### FIXME: flag not supported yet.
- foreach (keys %{$dcc{'CHAT'}}) {
+ foreach (keys %{ $dcc{'CHAT'} }) {
$conn->privmsg($dcc{'CHAT'}{$_}, $txt);
}
}
foreach $type (keys %dcc) {
&FIXME("dcc_close: $who");
- my @who = grep /^\Q$who\E$/i, keys %{$dcc{$type}};
+ my @who = grep /^\Q$who\E$/i, keys %{ $dcc{$type} };
next unless (scalar @who);
$who = $who[0];
}
&status("parting $chan");
if (!&validChan($chan)) {
- &status("part: not on $chan");
- next;
+ &WARN("part: not on $chan; doing anyway");
+# next;
}
rawout("PART $chan");
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 {
my ($nick) = @_;
+ if (!defined $nick) {
+ &ERROR("nick: nick == NULL.");
+ return;
+ }
+
+ if (defined $ident and $nick eq $ident) {
+ &WARN("nick: nick == ident == '$ident'.");
+ }
+
+ my $bad = 0;
+ $bad++ if (exists $nuh{ $param{'ircNick'} });
+ $bad++ if (&IsNickInAnyChan($param{'ircNick'}));
+
+ if ($bad) {
+ &WARN("Nick: not going to try and get my nick back. [".
+ scalar(localtime). "]");
+ return;
+ }
+
if ($nick =~ /^$mask{nick}$/) {
- &DEBUG("nick: Changing nick to $nick (from $ident)");
rawout("NICK ".$nick);
+
+ if (defined $ident) {
+ &status("nick: Changing nick to $nick (from $ident)");
+ } else {
+ &DEBUG("first time nick change.");
+ $ident = $nick;
+ }
+
return 1;
}
&DEBUG("nick: failed... why oh why (nick => $nick)");
# Usage: &joinNextChan();
sub joinNextChan {
if (scalar @joinchan) {
- my $chan = shift @joinchan;
+ $chan = shift @joinchan;
&joinchan($chan);
if (my $i = scalar @joinchan) {
&status("joinNextChan: $i chans to join.");
}
+
return;
+
}
- if (&IsParam("nickServ_pass") and $nickserv < 1) {
- &WARN("jNC: nickserv/chanserv not up.") if (!$nickserv);
- $nickserv--;
+ # !scalar @joinchan:
+ 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 / @c);
+ delete $cache{joinTime};
+
+ &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join");
}
- my %chan = &getChanConfList("chanServ");
- foreach $chan (keys %chan) {
- next unless ($chan{$chan} > 0);
-
- if (!exists $channels{$chan}{'o'}{$ident}) {
- &status("ChanServ ==> Requesting ops for $chan. (1)");
- &rawout("PRIVMSG ChanServ :OP $chan $ident");
- }
+ # chanserv check: global channels, in case we missed one.
+ foreach ( &ChanConfList("chanServ_ops") ) {
+ &chanServCheck($_);
}
}
-# Usage: &GetNickInChans($nick,$chan);
-sub GetNickInChans {
+# Usage: &getNickInChans($nick);
+sub getNickInChans {
my ($nick) = @_;
my @array;
foreach (keys %channels) {
- next unless (grep /^\Q$nick\E$/i, keys %{$channels{$_}{''}});
+ next unless (grep /^\Q$nick\E$/i, keys %{ $channels{$_}{''} });
push(@array, $_);
}
return @array;
}
-# Usage: &GetNicksInChan($chan);
-sub GetNicksInChan {
+# Usage: &getNicksInChan($chan);
+sub getNicksInChan {
my ($chan) = @_;
my @array;
return 0;
}
- if (grep /^\Q$nick\E$/i, keys %{$channels{$chan}{''}}) {
+ if (grep /^\Q$nick\E$/i, keys %{ $channels{$chan}{''} }) {
return 1;
} else {
foreach (keys %channels) {
my ($nick) = @_;
foreach $chan (keys %channels) {
- next unless (grep /^\Q$nick\E$/i, keys %{$channels{$chan}{''}});
+ next unless (grep /^\Q$nick\E$/i, keys %{ $channels{$chan}{''} });
return 1;
}
return 0;
}
###
-# Usage: &DeleteUserInfo($nick,@chans);
-sub DeleteUserInfo {
+# Usage: &delUserInfo($nick,@chans);
+sub delUserInfo {
my ($nick,@chans) = @_;
my ($mode,$chan);
foreach $chan (@chans) {
- foreach $mode (keys %{$channels{$chan}}) {
+ foreach $mode (keys %{ $channels{$chan} }) {
# use grep here?
next unless (exists $channels{$chan}{$mode}{$nick});
}
sub clearIRCVars {
-### &DEBUG("clearIRCVars() called!");
+# &DEBUG("clearIRCVars() called!");
undef %channels;
undef %floodjoin;
- @joinchan = &getJoinChans();
+ @joinchan = &getJoinChans(1);
+ $cache{joinTime} = time();
}
sub getJoinChans {
+ my($show) = @_;
my @chans;
my @skip;
push(@chans, $_);
}
+ my $str;
if (scalar @skip) {
- &status("gJC: channels not auto-joining: @skip");
+ $str = "channels not auto-joining: @skip (joining: @chans)";
} else {
- &status("gJC: auto-joining all chans.");
+ $str = "auto-joining all chans: @chans";
}
+ &status("Chans: ".$str) if ($show);
+
return @chans;
}
foreach $type (keys %dcc) {
next if ($type ne uc($type));
- foreach $nick (keys %{$dcc{$type}}) {
+ foreach $nick (keys %{ $dcc{$type} }) {
next unless (defined $nick);
&DEBUG("closing DCC $type to $nick (FIXME).");
next unless (defined $dcc{$type}{$nick});
return unless (&IsChanConf("joinfloodCheck"));
if (exists $netsplit{lc $who}) { # netsplit join.
- &DEBUG("jfC: $who was in netsplit; not checking.");
+ &DEBUG("joinfloodCheck: $who was in netsplit; not checking.");
}
if (exists $floodjoin{$chan}{$who}{Time}) {
}
}
- &DEBUG("jfC: $delete deleted.") if ($delete);
+ &DEBUG("joinfloodCheck: $delete deleted.") if ($delete);
}
sub getHostMask {
my($n) = @_;
- &FIXME("getHostMask...");
+ &FIXME("getHostMask($n) called...");
}
1;