From 750f1890feb95bd1afc2df0bb06e3099dcc48e3f Mon Sep 17 00:00:00 2001 From: dms Date: Wed, 30 May 2001 14:20:40 +0000 Subject: [PATCH] - userAdd, if no mask is given, don't add it. - 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 --- src/DynaConfig.pl | 6 +++++- src/IRC/Irc.pl | 21 +++++++++++++++++++-- src/IRC/IrcHooks.pl | 1 + src/Misc.pl | 14 ++++++++++---- src/Modules/News.pl | 3 --- src/Modules/UserDCC.pl | 43 +++++++++++++++++++++++++++++++++++++----- src/Process.pl | 8 +++++++- src/modules.pl | 3 +++ 8 files changed, 83 insertions(+), 16 deletions(-) diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index 9fa01dd..fad4ab2 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -552,7 +552,11 @@ sub userAdd { $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; diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 48a077d..00269c0 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -229,6 +229,13 @@ sub msg { 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/) { @@ -253,7 +260,12 @@ sub msg { $msgsize = length $msg; } - $conn->privmsg($nick, $msg); + if ($msgType =~ /private/i) { # hack. + $conn->privmsg($nick, $msg); + + } else { + &DEBUG("msg: msgType is unknown!"); + } } } @@ -853,7 +865,12 @@ sub joinfloodCheck { 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; diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index d7277de..ece1314 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -1061,6 +1061,7 @@ sub on_who { $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; } diff --git a/src/Misc.pl b/src/Misc.pl index b03bef7..6264b00 100644 --- a/src/Misc.pl +++ b/src/Misc.pl @@ -467,15 +467,21 @@ sub isStale { # 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); diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 64ca9ee..a112d09 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -690,14 +690,11 @@ sub set { 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}) { diff --git a/src/Modules/UserDCC.pl b/src/Modules/UserDCC.pl index 58c67b4..d67fa36 100644 --- a/src/Modules/UserDCC.pl +++ b/src/Modules/UserDCC.pl @@ -1264,14 +1264,34 @@ sub userDCC { 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"); @@ -1318,6 +1338,19 @@ sub userDCC { 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"; } diff --git a/src/Process.pl b/src/Process.pl index 81c29a9..4591401 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -134,7 +134,13 @@ sub process { } # 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."); diff --git a/src/modules.pl b/src/modules.pl index 162279d..facd28b 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -86,6 +86,8 @@ sub loadCoreModules { sub loadDBModules { &status("Loading DB modules..."); + $moduleAge{"$bot_src_dir/modules.pl"} = time(); + if ($param{'DBType'} =~ /^mysql$/i) { eval "use DBI"; if ($@) { @@ -96,6 +98,7 @@ sub loadDBModules { &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"; -- 2.39.5