while (1) {
# JUST IN CASE. irq was complaining about this.
if ($lastrun == time()) {
+ &DEBUG("hrm... lastrun == time()");
$error++;
- sleep 1;
+ sleep 10;
next;
}
$lastrun = time();
next;
}
- &DEBUG("ircloop: _ => '$_'.");
next unless (exists $ircPort{$_});
my $retval = &irc($_, $ircPort{$_});
select STDOUT;
&status("Connecting to port $port of server $server ...");
- sleep 3; # lame hack.
# host->ip.
if ($server =~ /\D$/) {
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);
$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.
&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};
}
&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).");
}
} 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).");
}
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;
return;
}
+ &DEBUG("MODE $chan $modes");
+
rawout("MODE $chan $modes");
}
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");
+ }
+ }
}
}
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;
}
}
sub clearIRCVars {
&DEBUG("clearIRCVars() called!");
- %channels = ();
+ undef %channels;
+ undef %floodjoin;
@joinchan = split /[\t\s]+/, $param{'join_channels'};
}
}
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;