#
use strict;
+
no strict 'refs';
+no strict 'subs'; # IN/STDIN
use vars qw(%floodjoin %nuh %dcc %cache %conns %channels %param %mask
%chanconf %orig %ircPort %ircstats %last %netsplit);
-use vars qw($irc $nickserv $ident $conn $msgType $who $talkchannel
+use vars qw($irc $nickserv $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(@ircServers);
+#use open ':utf8';
+#use open ':std';
+
$nickserv = 0;
my $maxlinelen = 400;
$args{'Password'} = $param{'ircPasswd'} if ($param{'ircPasswd'});
foreach my $mynick (split ',', $param{'ircNick'}) {
- &DEBUG("got $mynick");
&status("Connecting to port $port of server $server ($resolve) as $mynick ...");
$args{'Nick'} = $mynick;
$conns{$mynick} = $irc->newconn(%args);
$ircstats{'Server'} = "$server:$port";
+ # works? needs to actually do something
+ # should likely listen on a tcp port instead
+ #$irc->addfh(STDIN, \&on_stdin, "r");
+
+ &status("starting main loop");
+
$irc->start;
}
# Usage: &action(nick || chan, txt);
sub action {
+ my $mynick = $conn->nick();
my ($target, $txt) = @_;
if (!defined $txt) {
&WARN("action: txt == NULL.");
chop($txt) while (length $txt > 480);
}
- &status("* $ident/$target $txt");
+ &status("* $mynick/$target $txt");
$conn->me($target, $txt);
}
$reply =~ /([\.\?\s]+)$/;
+ # FIXME need real throttling....
+ if (length($reply) > $maxlinelen - 30) {
+ $reply = substr($reply, 0, $maxlinelen - 33);
+ $reply =~ s/ [^ ]*?$/ .../;
+ }
&checkMsgType($reply);
if ($msgType eq 'public') {
&performReply(@_);
}
-sub pSReply {
- &performStrictReply(@_);
-}
-
# Usage: &performStrictReply($reply);
sub performStrictReply {
my ($reply) = @_;
+ # FIXME need real throttling....
+ if (length($reply) > $maxlinelen - 30) {
+ $reply = substr($reply, 0, $maxlinelen - 33);
+ $reply =~ s/ [^ ]*?$/ .../;
+ }
&checkMsgType($reply);
if ($msgType eq 'private') {
}
sub joinchan {
- my ($chan) = @_;
- my $key = &getChanConf("chankey", $chan) || "";
+ my ($chan, $key) = @_;
+ $key ||= &getChanConf("chankey", $chan);
+ $key ||= "";
# forgot for about 2 years to implement channel keys when moving
# over to Net::IRC...
&status("join: already on $chan?");
}
#} else {
- &status("joining $b_blue$chan$ob");
+ &status("joining $b_blue$chan $key$ob");
return if ($conn->join($chan, $key));
- return if (&validChan($chan));
+ return if (&validChan($chan));
&DEBUG("joinchan: join failed. trying connect!");
&clearIRCVars();
sub kick {
my ($nick,$chan,$msg) = @_;
my (@chans) = ($chan eq "") ? (keys %channels) : lc($chan);
+ my $mynick = $conn->nick();
if ($chan ne "" and &validChan($chan) == 0) {
&ERROR("kick: invalid channel $chan.");
next;
}
- if (!exists $channels{$chan}{o}{$ident}) {
+ if (!exists $channels{$chan}{o}{$mynick}) {
&status("kick: do not have ops on $chan :(");
next;
}
sub ban {
my ($mask,$chan) = @_;
my (@chans) = ($chan =~ /^\*?$/) ? (keys %channels) : lc($chan);
+ my $mynick = $conn->nick();
my $ban = 0;
if ($chan !~ /^\*?$/ and &validChan($chan) == 0) {
}
foreach $chan (@chans) {
- if (!exists $channels{$chan}{o}{$ident}) {
+ if (!exists $channels{$chan}{o}{$mynick}) {
&status("ban: do not have ops on $chan :(");
next;
}
sub unban {
my ($mask,$chan) = @_;
my (@chans) = ($chan =~ /^\*?$/) ? (keys %channels) : lc($chan);
+ my $mynick = $conn->nick();
my $ban = 0;
&DEBUG("unban: mask = $mask, chan = @chans");
foreach $chan (@chans) {
- if (!exists $channels{$chan}{o}{$ident}) {
+ if (!exists $channels{$chan}{o}{$mynick}) {
&status("unBan: do not have ops on $chan :(");
next;
}
}
sub nick {
- my ($nick) = @_;
+ my ($newnick) = @_;
+ my $mynick = $conn->nick();
- if (!defined $nick) {
+ if (!defined $newnick) {
&ERROR("nick: nick == NULL.");
return;
}
- if (defined $ident and $nick eq $ident) {
- &WARN("nick: nick == ident == '$ident'.");
+ if (!defined $mynick) {
+ &WARN("nick: mynick == NULL.");
return;
}
- my $bad = 0;
- $bad++ if (exists $nuh{$conn->nick()});
- $bad++ if (&IsNickInAnyChan($conn->nick()));
+ my $bad = 0;
+ $bad++ if (exists $nuh{$newnick});
+ $bad++ if (&IsNickInAnyChan($newnick));
if ($bad) {
- &WARN("Nick: not going to try and get my nick back. [".
- scalar(gmtime). "]");
-# hrm... over time we lose track of our own nick.
-# return;
+ &WARN("Nick: not going to try to change from $mynick to $newnick. [". scalar(gmtime). "]");
+ # hrm... over time we lose track of our own nick.
+ #return;
}
-# FIXME broken for multiple nicks
-# if ($nick =~ /^$mask{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;
-# }
-#
-# return 1;
-# }
- &DEBUG("nick: failed... why oh why (nick => $nick)");
-
+ if ($newnick =~ /^$mask{nick}$/) {
+ &status("nick: Changing nick from $mynick to $newnick");
+ # ->nick() will NOT change cause we are using rawout?
+ &rawout("NICK $newnick");
+ return 1;
+ }
+ &DEBUG("nick: failed... why oh why (mynick=$mynick, newnick=$newnick)");
return 0;
}