- maskHostMask deals with n!u@h properly - hack!
- if there are no +n users, treat bot as ownerless and waiting for an
owner.
- set moduleAge time for modules.pl and db_mysql.pl
- msg() deals with msgType = chat.
- getHostMask works half-assed
- ".adduser" without a mask - major and ugly hack!
- DCC CHAT now allows non DCC CHAT commands, req by lazarus
git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@504
c11ca15a-4712-0410-83d8-
924469b57eb5
$utime_userfile = time();
$ucount_userfile++;
- $users{$nick}{HOSTS}{$mask} = 1;
+ if (defined $mask and $mask !~ /^\s*$/) {
+ &DEBUG("userAdd: mask => $mask");
+ $users{$nick}{HOSTS}{$mask} = 1;
+ }
+
$users{$nick}{FLAGS} ||= $users{_default}{FLAGS};
return 1;
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/) {
$msgsize = length $msg;
}
- $conn->privmsg($nick, $msg);
+ if ($msgType =~ /private/i) { # hack.
+ $conn->privmsg($nick, $msg);
+
+ } else {
+ &DEBUG("msg: msgType is unknown!");
+ }
}
}
sub getHostMask {
my($n) = @_;
- &FIXME("getHostMask($n) called...");
+ if (exists $nuh{$n}) {
+ return &makeHostMask($nuh{$n});
+ } else {
+ $cache{on_who_Hack} = 1;
+ &rawout("WHO $n");
+ }
}
1;
$cache{nuhInfo}{lc $args[5]}{Nick} = $args[5];
$cache{nuhInfo}{lc $args[5]}{User} = $args[2];
$cache{nuhInfo}{lc $args[5]}{Host} = $args[3];
+ $cache{nuhInfo}{lc $args[5]}{NUH} = "$args[5]!$args[2]\@$args[3]";
return;
}
# Usage: &makeHostMask($host);
sub makeHostMask {
- my ($host) = @_;
+ my ($host) = @_;
+ my $nu = "";
+
+ if ($host =~ s/^(\S+!\S+\@)//) {
+ &DEBUG("mHM: detected nick!user\@ for host arg; fixing");
+ $nu = $1;
+ }
if ($host =~ /^$mask{ip}$/) {
- return "$1.$2.$3.*";
+ return $nu."$1.$2.$3.*";
}
my @array = split(/\./, $host);
- return $host if (scalar @array <= 3);
- return "*.".join('.',@{array}[1..$#array]);
+ return $nu.$host if (scalar @array <= 3);
+ return $nu."*.".join('.',@{array}[1..$#array]);
}
# Usage: &makeRandom(int);
sub latest {
my($tchan, $flag) = @_;
- &::DEBUG("news: latest(): who => $who, ::who => $::who");
# hack hack hack.
$chan ||= $tchan;
$who = $::who;
- &::DEBUG("news: latest(): who => $who, ::who => $::who");
-
# todo: if chan = undefined, guess.
# if (!exists $::news{$chan}) {
if (!exists $::channels{$chan}) {
if ($state) { # adduser.
if (scalar @args == 1) {
$args[1] = &getHostMask($args[0]);
- if (!defined $args[1]) {
- &ERROR("could not get hostmask?");
- return;
- }
+ &pSReply("Attemping to guess $args[0]'s hostmask...");
+
+ # crude hack... crappy Net::IRC
+ $conn->schedule(5, sub {
+ # hopefully this is right.
+ my $nick = (keys %{ $cache{nuhInfo} })[0];
+ if (!defined $nick) {
+ &pSReply("couldn't get nuhinfo... adding user without a hostmask.");
+ &userAdd($nick);
+ return;
+ }
+
+ my $mask = &makeHostMask( $cache{nuhInfo}{$nick}{NUH} );
+
+ if ( &userAdd($nick, $mask) ) { # success.
+ &pSReply("Added $nick with flags $users{$nick}{FLAGS}");
+ my @hosts = keys %{ $users{$nick}{HOSTS} };
+ &pSReply("hosts: @hosts");
+ }
+});
+ return;
}
+ &DEBUG("args => @args");
if ( &userAdd(@args) ) { # success.
- &pSReply("Added $args[0]...");
+ &pSReply("Added $args[0] with flags $users{$args[0]}{FLAGS}");
+ my @hosts = keys %{ $users{$args[0]}{HOSTS} };
+ &pSReply("hosts: @hosts");
} else { # failure.
&pSReply("User $args[0] already exists");
return;
}
+ # quite a cool hack: reply in DCC CHAT.
+ $msgType = "chat";
+
+ my $done = 0;
+ $done++ if &parseCmdHook("main", $message);
+ $done++ if &parseCmdHook("extra", $message);
+ $done++ unless (&Modules());
+
+ if ($done) {
+ &DEBUG("running non DCC CHAT command inside DCC CHAT!");
+ return;
+ }
+
return "REPLY";
}
}
# todo: use &getUser()?
- my $first = (scalar keys %users < 2) ? 1 : 0;
+ my $first = 1;
+ foreach (keys %users) {
+ if ($users{$_}{FLAGS} =~ /n/) {
+ $first = 0;
+ last;
+ }
+ }
if (!exists $users{$who} and !$first) {
&pSReply("nick $who is not in user list.");
sub loadDBModules {
&status("Loading DB modules...");
+ $moduleAge{"$bot_src_dir/modules.pl"} = time();
+
if ($param{'DBType'} =~ /^mysql$/i) {
eval "use DBI";
if ($@) {
&status(" using MySQL support.");
require "$bot_src_dir/db_mysql.pl";
+ $moduleAge{"$bot_src_dir/db_mysql.pl"} = time();
} elsif ($param{'DBType'} =~ /^pgsql$/i) {
eval "use Pg";