while (my $host = shift @ircServers) {
# JUST IN CASE. irq was complaining about this.
if ($lastrun == time()) {
- &DEBUG("hrm... lastrun == time()");
+ &DEBUG("ircloop: hrm... lastrun == time()");
$error++;
sleep 10;
next;
$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.
my ($msg) = @_;
if (!defined $msg) {
$msg ||= "NULL";
- &DEBUG("say: msg == $msg.");
+ &WARN("say: msg == $msg.");
return;
}
- if ($msg eq $last{say} and length($msg) > 256) {
- &status("say: detected repeated message; skipping.");
- return;
- }
- $last{say} = $msg;
-
&status("</$talkchannel> $msg");
if (&whatInterface() =~ /IRC/) {
- $msg = "zero" if ($msg =~ /^0+$/);
+ $msg = "zero" if ($msg =~ /^0+$/);
+ my $t = time();
+
+ if ($t == $pubtime) {
+ $pubcount++;
+ $pubsize += length $msg;
+
+ if ( ($pubcount % 4) == 0 and $pubcount) {
+ sleep 1;
+ } elsif ($pubsize > 1500) {
+ sleep 1;
+ $pubsize -= 1500;
+ }
+
+ } else {
+ $pubcount = 0;
+ $pubtime = $t;
+ $pubsize = length $msg;
+ }
$conn->privmsg($talkchannel, $msg);
}
if (!defined $msg) {
$msg ||= "NULL";
- &DEBUG("msg: msg == $msg.");
+ &WARN("msg: msg == $msg.");
return;
}
- if ($msg eq $last{msg} and length($msg) > 256) {
- &status("msg: detected repeated message; skipping.");
- return;
- }
- $last{msg} = $msg;
-
&status(">$nick< $msg");
- $conn->privmsg($nick, $msg) if (&whatInterface() =~ /IRC/);
+
+ if (&whatInterface() =~ /IRC/) {
+ my $t = time();
+
+ if ($t == $msgtime) {
+ $msgcount++;
+ $msgsize += length $msg;
+
+ if ( ($msgcount % 4) == 0 and $msgcount) {
+ sleep 1;
+ } elsif ($msgsize > 1000) {
+ sleep 1;
+ $msgsize -= 1000;
+ }
+
+ } else {
+ $msgcount = 0;
+ $msgtime = $t;
+ $msgsize = length $msg;
+ }
+
+ $conn->privmsg($nick, $msg);
+ }
}
# Usage: &action(nick || chan, txt);
sub action {
my ($target, $txt) = @_;
if (!defined $txt) {
- &DEBUG("action: txt == NULL.");
+ &WARN("action: txt == NULL.");
return;
}
rawout($rawout);
}
-# Usage: &action(nick || chan, txt);
-sub notice{
+# Usage: ¬ice(nick || chan, txt);
+sub notice {
my ($target, $txt) = @_;
if (!defined $txt) {
- &DEBUG("action: txt == NULL.");
+ &WARN("notice: txt == NULL.");
return;
}
&status("-$target- $txt");
+ my $t = time();
+
+ if ($t == $nottime) {
+ $notcount++;
+ $notsize += length $txt;
+
+ if ( ($notcount % 3) == 0 and $notcount) {
+ sleep 1;
+ } elsif ($notsize > 1000) {
+ sleep 1;
+ $notsize -= 1000;
+ }
+
+ } else {
+ $notcount = 0;
+ $nottime = $t;
+ $notsize = length $txt;
+ }
+
$conn->notice($target, $txt);
}
### 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("join: already on $chan");
} else {
if (!$conn->join($chan)) {
- &DEBUG("join failed. trying connect!");
+ &DEBUG("joinchan: join failed. trying connect!");
$conn->connect();
}
}
&status("parting $chan");
if (!&validChan($chan)) {
- &status("part: not on $chan");
- next;
+ &WARN("part: not on $chan; doing anyway");
+# next;
}
rawout("PART $chan");
return;
}
- &DEBUG("MODE $chan $modes");
+ &DEBUG("mode: MODE $chan $modes");
rawout("MODE $chan $modes");
}
my ($nick) = @_;
if ($nick =~ /^$mask{nick}$/) {
+ &DEBUG("nick: Changing nick to $nick (from $ident)");
rawout("NICK ".$nick);
+ # unfortunately, on_nick doesn't catch ourself.
+ $ident = $nick;
return 1;
}
+ &DEBUG("nick: failed... why oh why (nick => $nick)");
return 0;
}
# Usage: &joinNextChan();
sub joinNextChan {
+ &DEBUG("joinNextChan called.");
+
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--;
- }
+ } else {
+ if (exists $cache{joinTime}) {
+ my $delta = time() - $cache{joinTime};
+ my $timestr = &Time2String($delta);
+ my $rate = sprintf("%.1f", $delta / &getJoinChans() );
+ delete $cache{joinTime};
- 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.");
- &rawout("PRIVMSG ChanServ :OP $chan $ident");
+ &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join");
+ }
+ # chanserv check: global channels, in case we missed one.
+
+ foreach ( &ChanConfList("chanServ_ops") ) {
+ &chanServCheck($_);
}
}
}
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 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) {
next unless (/[A-Z]/);
- &DEBUG("hash channels contains mixed cased chan!!!");
+ &DEBUG("iNIC: hash channels contains mixed cased chan!!!");
}
return 0;
}
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;
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 = "gJC: channels not auto-joining: @skip";
} else {
- &status("gJC: auto-joining all chans.");
+ $str = "gJC: auto-joining all chans.";
}
+ &status($str) if ($show);
+
return @chans;
}
sub closeDCC {
- &DEBUG("closeDCC called.");
+### &DEBUG("closeDCC called.");
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});
- $dcc{$type}{$nick}->close();
+ my $ref = $dcc{$type}{$nick};
+ &DEBUG("ref => $ref");
+
+# $dcc{$type}{$nick}->close();
}
}
}
return unless (&IsChanConf("joinfloodCheck"));
if (exists $netsplit{lc $who}) { # netsplit join.
- &DEBUG("jfC: $who was in netsnipe; not checking.");
+ &DEBUG("joinfloodCheck: $who was in netsplit; not checking.");
}
if (exists $floodjoin{$chan}{$who}{Time}) {
my $c = $_;
my $count = scalar keys %{ $floodjoin{$c} };
next unless ($count > 5);
- &DEBUG("count => $count");
+ &DEBUG("joinflood: count => $count");
my $time;
foreach (keys %{ $floodjoin{$c} }) {
$time += $floodjoin{$c}{$_}{Time};
}
- &DEBUG("time => $time");
+ &DEBUG("joinflood: time => $time");
$time /= $count;
- &DEBUG("new time => $time");
+ &DEBUG("joinflood: new time => $time");
}
### Clean it up.
}
}
- &DEBUG("jfC: $delete deleted.") if ($delete);
+ &DEBUG("joinfloodCheck: $delete deleted.") if ($delete);
}
sub getHostMask {
my($n) = @_;
- &FIXME("getHostMask...");
+ &FIXME("getHostMask($n) called...");
}
1;