# NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
#
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+no strict 'refs';
+
+use vars qw(%floodjoin %nuh %dcc %cache %channels %param %mask
+ %chanconf %orig %ircPort %ircstats %last %netsplit);
+use vars qw($irc $nickserv $ident $conn $msgType $who $talkchannel
+ $addressed);
+use vars qw($notcount $nottime $notsize $msgcount $msgtime $msgsize
+ $pubcount $pubtime $pubsize);
+use vars qw($b_blue $ob);
+use vars qw(@joinchan @ircServers);
-use vars qw($nickserv);
$nickserv = 0;
-# static scalar variables.
-$mask{ip} = '(\d+)\.(\d+)\.(\d+)\.(\d+)';
-$mask{host} = '[\d\w\_\-\/]+\.[\.\d\w\_\-\/]+';
-$mask{chan} = '[\#\&]\S*|_default';
-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;
my $lastrun = 0;
$conn = $irc->newconn(%args);
if (!defined $conn) {
- &ERROR("irc: conn was not created!defined!!!");
+ &ERROR("IRC: connection failed.");
+ &ERROR("add \"set ircHost 0.0.0.0\" to your config. If that does not work");
+ &ERROR("Please check /etc/hosts to see if you have a localhost line like:");
+ &ERROR("127.0.0.1 localhost localhost");
+ &ERROR("If this is still a problem, please contact the maintainer.");
return 1;
}
$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(303, \&on_ison); # notify.
$conn->add_global_handler(315, \&on_endofwho);
$conn->add_global_handler(422, \&on_endofwho); # nomotd.
$conn->add_global_handler(324, \&on_modeis);
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/) {
- my $t = time();
+ return unless (&whatInterface() =~ /IRC/);
+ my $t = time();
- if ($t == $msgtime) {
- $msgcount++;
- $msgsize += length $msg;
+ if ($t == $msgtime) {
+ $msgcount++;
+ $msgsize += length $msg;
- my $i = &getChanConfDefault("sendPrivateLimitLines", 3);
- my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
- if ( ($msgcount % $i) == 0 and $msgcount) {
- sleep 1;
- } elsif ($msgsize > $j) {
- sleep 1;
- $msgsize -= $j;
- }
-
- } else {
- $msgcount = 0;
- $msgtime = $t;
- $msgsize = length $msg;
+ my $i = &getChanConfDefault("sendPrivateLimitLines", 3);
+ my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
+ if ( ($msgcount % $i) == 0 and $msgcount) {
+ sleep 1;
+ } elsif ($msgsize > $j) {
+ sleep 1;
+ $msgsize -= $j;
}
- $conn->privmsg($nick, $msg);
+ } else {
+ $msgcount = 0;
+ $msgtime = $t;
+ $msgsize = length $msg;
}
+
+ $conn->privmsg($nick, $msg);
}
# Usage: &action(nick || chan, txt);
return;
}
- my $rawout = "PRIVMSG $target :\001ACTION $txt\001";
- if (length $rawout > 510) {
+ if (length $txt > 480) {
&status("action: txt too long; truncating.");
-
- chop($rawout) while (length($rawout) > 510);
- $rawout .= "\001";
+ chop($txt) while (length $txt > 480);
}
&status("* $ident/$target $txt");
- rawout($rawout);
+ $conn->me($target, $txt);
}
# Usage: ¬ice(nick || chan, txt);
# Usage: &performReply($reply);
sub performReply {
my ($reply) = @_;
+
+ if (!defined $reply or $reply =~ /^\s*$/) {
+ &DEBUG("performReply: reply == NULL.");
+ return;
+ }
+
$reply =~ /([\.\?\s]+)$/;
&checkMsgType($reply);
$reply = "$reply, ".$orig{who};
}
&say($reply);
+
} elsif ($msgType eq 'private') {
- if (rand() < 0.5) {
- $reply = $reply;
- } else {
+ if (rand() > 0.5) {
$reply = "$reply, ".$orig{who};
}
&msg($who, $reply);
+
} elsif ($msgType eq 'chat') {
if (!exists $dcc{'CHAT'}{$who}) {
&VERB("pSR: dcc{'CHAT'}{$who} does not exist.",2);
return;
}
$conn->privmsg($dcc{'CHAT'}{$who}, $reply);
+
} else {
&ERROR("PR: msgType invalid? ($msgType).");
}
}
sub joinchan {
- my ($chankey) = @_;
- my $chan = lc $chankey;
+ my ($chan) = @_;
+ my $key = &getChanConf("chankey", $chan) || "";
- if ($chankey =~ s/^($mask{chan}),\S+/ /) {
- $chan = lc $1;
- }
+ # forgot for about 2 years to implement channel keys when moving
+ # over to Net::IRC...
# 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();
- }
+
+ return if ($conn->join($chan, $key));
+
+ &DEBUG("joinchan: join failed. trying connect!");
+ &clearIRCVars();
+ $conn->connect();
}
}
# next;
}
- rawout("PART $chan");
+ $conn->part($chan);
# deletion of $channels{chan} is done in &entryEvt().
}
}
&DEBUG("mode: MODE $chan $modes");
+ # should move to use Net::IRC's $conn->mode()... but too lazy.
rawout("MODE $chan $modes");
}
foreach $chan (@chans) {
if (!&IsNickInChan($nick,$chan)) {
- &status("Kick: $nick is not on $chan.") if (scalar @chans == 1);
+ &status("kick: $nick is not on $chan.") if (scalar @chans == 1);
next;
}
if (!exists $channels{$chan}{o}{$ident}) {
- &status("Kick: do not have ops on $chan :(");
+ &status("kick: do not have ops on $chan :(");
next;
}
&status("Kicking $nick from $chan.");
- if ($msg eq "") {
- &rawout("KICK $chan $nick");
- } else {
- &rawout("KICK $chan $nick :$msg");
- }
+ $conn->kick($chan, $nick, $msg);
}
}
foreach $chan (@chans) {
if (!exists $channels{$chan}{o}{$ident}) {
- &status("Ban: do not have ops on $chan :(");
+ &status("ban: do not have ops on $chan :(");
next;
}
if (defined $ident and $nick eq $ident) {
&WARN("nick: nick == ident == '$ident'.");
+ return;
}
my $bad = 0;
if ($bad) {
&WARN("Nick: not going to try and get my nick back. [".
- scalar(localtime). "]");
- return;
+ scalar(gmtime). "]");
+# hrm... over time we lose track of our own nick.
+# return;
}
if ($nick =~ /^$mask{nick}$/) {
- rawout("NICK ".$nick);
+ &rawout("NICK ".$nick);
if (defined $ident) {
&status("nick: Changing nick to $nick (from $ident)");
+ # following shouldn't be here :(
+ $ident = $nick;
} else {
&DEBUG("first time nick change.");
$ident = $nick;
sub invite {
my($who, $chan) = @_;
- rawout("INVITE $who $chan");
-}
+ # todo: check if $who or $chan are invalid.
+ $conn->invite($who, $chan);
+}
##########
# Channel related functions...
# Usage: &joinNextChan();
sub joinNextChan {
if (scalar @joinchan) {
- $chan = shift @joinchan;
+ my $chan = shift @joinchan;
&joinchan($chan);
if (my $i = scalar @joinchan) {
$chan =~ tr/A-Z/a-z/; # not lowercase unfortunately.
+ if ($chan =~ /^$/) {
+ &DEBUG("INIC: chan == NULL.");
+ return 0;
+ }
+
if (&validChan($chan) == 0) {
&ERROR("INIC: invalid channel $chan.");
return 0;
sub IsNickInAnyChan {
my ($nick) = @_;
+ my $chan;
foreach $chan (keys %channels) {
next unless (grep /^\Q$nick\E$/i, keys %{ $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") {
+ if ($chan =~ /^_?default$/) {
# &WARN("validC: chan cannot be _default! returning 0!");
return 0;
}
}
sub clearIRCVars {
- &DEBUG("clearIRCVars() called!");
undef %channels;
undef %floodjoin;
sub closeDCC {
# &DEBUG("closeDCC called.");
+ my $type;
foreach $type (keys %dcc) {
next if ($type ne uc($type));
-
+
+ my $nick;
foreach $nick (keys %{ $dcc{$type} }) {
next unless (defined $nick);
&status("DCC CHAT: closing DCC $type to $nick.");
my $time;
foreach (keys %{ $floodjoin{$c} }) {
- $time += $floodjoin{$c}{$_}{Time};
+ my $t = $floodjoin{$c}{$_}{Time};
+ next unless (defined $t);
+
+ $time += $t;
}
&DEBUG("joinflood: time => $time");
$time /= $count;
return &makeHostMask($nuh{$n});
} else {
$cache{on_who_Hack} = 1;
- &rawout("WHO $n");
+ $conn->who($n);
}
}