2 # IrcHooks.pl: IRC Hooks stuff.
5 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
8 if (&IsParam("useStrict")) { use strict; }
12 my ($self, $event) = @_;
13 my $nick = $event->nick();
14 my $chan = ($event->to)[0];
16 &DEBUG("on_generic: nick => '$nick'.");
17 &DEBUG("on_generic: chan => '$chan'.");
19 foreach ($event->args) {
20 &DEBUG("on_generic: args => '$_'.");
25 my ($self, $event) = @_;
26 my ($nick, @args) = ($event->nick, $event->args);
27 my $chan = ($event->to)[0];
31 if ($chan eq $ident) {
32 &status("* [$nick] @args");
34 &status("* $nick/$chan @args");
39 my ($self, $event) = @_;
40 my $msg = ($event->args)[0];
41 my $sock = ($event->to)[0];
42 my $nick = lc $event->nick();
44 if (!exists $nuh{$nick}) {
45 &DEBUG("chat: nuh{$nick} doesn't exist; trying WHOIS .");
50 ### set vars that would have been set in hookMsg.
51 $userHandle = ""; # reset.
55 $orig{message} = $msg;
57 $uh = (split /\!/, $nuh)[1];
61 if (!exists $dcc{'CHATvrfy'}{$nick}) {
62 $userHandle = &verifyUser($who, $nuh);
63 my $crypto = $users{$userHandle}{PASS};
66 ### TODO: prevent users without CRYPT chatting.
67 if (!defined $crypto) {
68 &DEBUG("todo: dcc close chat");
69 &msg($who, "nope, no guest logins allowed...");
73 if (&ckpasswd($msg, $crypto)) {
74 # stolen from eggdrop.
75 $self->privmsg($sock, "Connected to $ident");
76 $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
77 $self->privmsg($sock, "Everything else goes out to the party line.");
79 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
84 &status("DCC CHAT: incorrect pass; closing connection.");
85 &DEBUG("chat: sock => '$sock'.");
87 delete $dcc{'CHAT'}{$nick};
88 &DEBUG("chat: after closing sock. FIXME");
89 ### BUG: close seizes bot. why?
93 &status("DCC CHAT: user $nick is here!");
94 &DCCBroadcast("*** $nick ($uh) joined the party line.");
96 $dcc{'CHATvrfy'}{$nick} = $userHandle;
98 return if ($userHandle eq "_default");
100 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
106 &status("$b_red=$b_cyan$who$b_red=$ob $message");
108 if ($message =~ s/^\.//) { # dcc chat commands.
109 ### TODO: make use of &Forker(); here?
110 &loadMyModule( $myModules{'ircdcc'} );
112 &DCCBroadcast("#$who# $message","m");
114 my $retval = &userDCC();
115 return unless (defined $retval);
116 return if ($retval eq $noreply);
118 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
120 } else { # dcc chat arena.
122 foreach (keys %{$dcc{'CHAT'}}) {
123 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
127 return 'DCC CHAT MESSAGE';
133 # what's the following for?
134 $ident = $param{'ircNick'};
136 $ircstats{'ConnectTime'} = time();
137 $ircstats{'ConnectCount'}++;
138 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'}
139 if (defined $ircstats{'DisconnectTime'});
142 if (!exists $users{_default}) {
143 &status("First time run... adding _default user.");
144 $users{_default}{FLAGS} = "mrt";
145 $users{_default}{HOSTS} = "*!*@*";
148 if (scalar keys %users < 2) {
149 &status("Ok... now /msg $ident PASS <pass> to get master access through DCC CHAT.");
151 # end of first time run.
153 if (&IsChanConf("wingate")) {
154 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
158 next unless (/^(\S+)\*$/);
159 push(@wingateBad, $_);
165 &ScheduleThis(1, \&setupSchedulers);
169 if (&IsParam("ircUMode")) {
170 &status("Attempting change of user modes to $param{'ircUMode'}.");
171 &rawout("MODE $ident $param{'ircUMode'}");
174 &status("End of motd. Now lets join some channels...");
175 if (!scalar @joinchan) {
176 &WARN("joinchan array is empty!!!");
177 @joinchan = &getJoinChans();
184 my ($self, $event) = @_;
185 my $type = uc( ($event->args)[1] );
186 my $nick = lc $event->nick();
188 # pity Net::IRC doesn't store nuh. Here's a hack :)
189 if (!exists $nuh{lc $nick}) {
191 $nuh{$nick} = "GETTING-NOW"; # trying.
195 if ($type eq 'SEND') { # GET for us.
196 # incoming DCC SEND. we're receiving a file.
197 my $get = ($event->args)[2];
198 open(DCCGET,">$get");
200 $self->new_get($nick,
207 } elsif ($type eq 'GET') { # SEND for us?
208 &status("DCC: Initializing SEND for $nick.");
209 $self->new_send($event->args);
210 } elsif ($type eq 'CHAT') {
211 &status("DCC: Initializing CHAT for $nick.");
212 $self->new_chat($event);
214 &WARN("${b_green}DCC $type$ob (1)");
219 my ($self, $event) = @_;
220 my $nick = $event->nick();
221 my $sock = ($event->to)[0];
223 # DCC CHAT close on fork exit workaround.
224 if ($bot_pid != $$) {
225 &WARN("run-away fork; exiting.");
229 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
230 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
232 &status("dcc_close: purging $nick.txt from Debian.pl");
233 unlink "$param{tempDir}/$nick.txt";
235 delete $dcc{'SEND'}{$nick};
236 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
237 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
238 delete $dcc{'CHAT'}{$nick};
239 delete $dcc{'CHATvrfy'}{$nick};
241 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
246 my ($self, $event) = @_;
247 my $type = uc( ($event->args)[0] );
248 my $nick = lc $event->nick();
249 my $sock = ($event->to)[0];
253 ### BUG: who is set to bot's nick?
256 if ($type eq 'SEND') {
257 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
259 } elsif ($type eq 'CHAT') {
261 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
262 ### 1,3,5,10 seconds then fail.
263 if ($nuh{$nick} eq "GETTING-NOW") {
264 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
266 on_dcc_open_chat(undef, $nick, $sock);
269 } elsif ($type eq 'SEND') {
270 &DEBUG("Starting DCC receive.");
271 foreach ($event->args) {
276 &WARN("${b_green}DCC $type$ob (3)");
281 # really custom sub to get NUH since Net::IRC doesn't appear to support
283 sub on_dcc_open_chat {
284 my(undef, $nick, $sock) = @_;
286 if ($nuh{$nick} eq "GETTING-NOW") {
287 &DEBUG("getting nuh for $nick failed. FIXME.");
291 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
293 &verifyUser($nick, $nuh{lc $nick});
295 if (!exists $users{$userHandle}{HOSTS}) {
296 &pSReply("you have no hosts defined in my user file; rejecting.");
297 ### TODO: $sock->close();
301 my $crypto = $users{$userHandle}{PASS};
302 $dcc{'CHAT'}{$nick} = $sock;
304 if (defined $crypto) {
305 &dccsay($nick,"Enter your password.");
307 &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
312 my ($self, $event) = @_;
313 my $from = $event->from();
314 my $what = ($event->args)[0];
316 &status("disconnect from $from ($what).");
317 $ircstats{'DisconnectTime'} = time();
318 $ircstats{'DisconnectReason'} = $what;
319 $ircstats{'DisconnectCount'}++;
320 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'};
322 # clear any variables on reconnection.
326 if (!$self->connect()) {
327 &WARN("not connected? help me. gonna call ircCheck() in 1800s");
328 &ScheduleThis(30, "ircCheck");
333 my ($self, $event) = @_;
334 my $chan = ($event->args)[1];
336 if (exists $cache{jointime}{$chan}) {
337 my $delta_time = sprintf("%.03f", &gettimeofday() - $cache{jointime}{$chan});
338 $delta_time = 0 if ($delta_time < 0);
340 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
343 rawout("MODE $chan");
347 foreach ("o","v","") {
348 my $count = scalar(keys %{ $channels{$chan}{$_} });
349 next unless ($count);
351 $txt = "total" if ($_ eq "");
352 $txt = "voice" if ($_ eq "v");
353 $txt = "ops" if ($_ eq "o");
355 push(@array, "$count $txt");
357 my $chanstats = join(' || ', @array);
358 &status("$b_blue$chan$ob: [$chanstats]");
360 if (scalar @joinchan) { # remaining channels to join.
363 &DEBUG("running ircCheck to get chanserv ops.");
367 return unless (&IsChanConf("chanServ_ops") > 0);
368 return unless ($nickserv);
370 if (!exists $channels{$chan}{'o'}{$ident}) {
371 &status("ChanServ ==> Requesting ops for $chan.");
372 &rawout("PRIVMSG ChanServ :OP $chan $ident");
377 my ($self, $event) = @_;
378 my (@args) = ($event->args);
385 my ($self, $event) = @_;
386 my $chan = lc( ($event->args)[0] );
387 my $nick = $event->nick;
389 if ($nick =~ /^\Q$ident\E$/) {
390 &DEBUG("on_invite: self invite.");
395 if (exists $chanconf{$chan}) {
396 if (&validChan($chan)) {
397 &msg($who, "i'm already in \002$chan\002.");
401 &status("invited to $b_blue$_$ob by $b_cyan$who$ob");
402 &joinchan($self, $_);
407 my ($self, $event) = @_;
408 my ($user,$host) = split(/\@/, $event->userhost);
409 $chan = lc( ($event->to)[0] ); # CASING!!!!
410 $who = $event->nick();
412 $chanstats{$chan}{'Join'}++;
413 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
415 &joinfloodCheck($who, $chan, $event->userhost);
419 if (exists $netsplit{lc $who}) {
420 delete $netsplit{lc $who};
424 if ($netsplit and !$netsplittime) {
425 &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
426 $conn->schedule(60, sub {
428 $netsplittime = undef;
431 $netsplittime = time();
434 # how to tell if there's a netjoin???
436 my $netsplitstr = "";
437 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
438 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
440 $channels{$chan}{''}{$who}++;
441 $nuh = $who."!".$user."\@".$host;
442 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
446 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
447 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
453 next unless ($nuh =~ /^$mask$/i);
455 ### TODO: check $channels{$chan}{'b'} if ban already exists.
456 foreach (keys %{ $channels{$chan}{'b'} }) {
457 &DEBUG(" bans_on_chan($chan) => $_");
460 my $reason = "no reason";
461 foreach ($chan, "*") {
462 next unless (exists $bans{$_});
463 next unless (exists $bans{$_}{$ban});
465 my @array = @{ $bans{$_}{$ban} };
467 $reason = $array[4] if ($array[4]);
472 &kick($who, $chan, $reason);
478 &rootWarn($who,$user,$host,$chan)
479 if (&IsChanConf("rootWarn") &&
480 $user =~ /^r(oo|ew|00)t$/i &&
481 $channels{$chan}{'o'}{$ident});
484 if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
485 # todo: what if it hasn't been loaded?
486 &News::latest($chan);
490 &chanLimitVerify($chan);
492 # used to determine sync time.
493 if ($who =~ /^$ident$/i) {
494 if (defined( my $whojoin = $cache{join}{$chan} )) {
495 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
496 delete $cache{join}{$chan};
499 ### TODO: move this to &joinchan()?
500 $cache{jointime}{$chan} = &gettimeofday();
503 ### TODO: this may go wild on a netjoin :)
510 my ($self, $event) = @_;
511 my ($chan,$reason) = $event->args;
512 my $kicker = $event->nick;
513 my $kickee = ($event->to)[0];
514 my $uh = $event->userhost();
516 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
518 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
519 $chanstats{$chan}{'Kick'}++;
521 if ($kickee eq $ident) {
522 &clearChanVars($chan);
524 &status("SELF attempting to rejoin lost channel $chan");
527 &DeleteUserInfo($kickee,$chan);
532 my ($self, $event) = @_;
533 my ($user, $host) = split(/\@/, $event->userhost);
534 my @args = $event->args();
535 my $nick = $event->nick();
536 my $chan = ($event->to)[0];
540 if ($nick eq $chan) { # UMODE
541 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
543 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
544 &hookMode($chan, @args);
549 my ($self, $event) = @_;
550 my $nick = $event->nick();
551 my ($myself,$chan,@args) = $event->args();
553 &hookMode(lc $chan, @args); # CASING.
557 my ($self, $event) = @_;
558 my $nick = $event->nick;
559 my $msg = ($event->args)[0];
561 ($user,$host) = split(/\@/, $event->userhost);
562 $uh = $event->userhost();
563 $nuh = $nick."!".$uh;
566 if ($nick eq $ident) { # hopefully ourselves.
567 if ($msg eq "TEST") {
568 &status("IRCTEST: Yes, we're alive.");
569 delete $cache{connect};
574 &hookMsg('private', undef, $nick, $msg);
578 my ($self, $event) = @_;
579 my @args = $event->args;
580 my $chan = lc $args[2]; # CASING, the last of them!
582 foreach (split / /, @args[3..$#args]) {
583 $channels{$chan}{'o'}{$_}++ if s/\@//;
584 $channels{$chan}{'v'}{$_}++ if s/\+//;
585 $channels{$chan}{''}{$_}++;
590 my ($self, $event) = @_;
591 my $nick = $event->nick();
592 my $newnick = ($event->args)[0];
594 if (exists $netsplit{lc $newnick}) {
595 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
596 delete $netsplit{lc $newnick};
600 foreach $chan (keys %channels) {
601 foreach $mode (keys %{$channels{$chan}}) {
602 next unless (exists $channels{$chan}{$mode}{$nick});
604 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
607 &DeleteUserInfo($nick,keys %channels);
608 $nuh{lc $newnick} = $nuh{lc $nick};
609 delete $nuh{lc $nick};
611 # successful self-nick change.
612 if ($nick eq $ident) {
613 &status(">>> I materialized into $b_green$newnick$ob from $nick");
616 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
622 my $nick = $self->nick;
623 my $newnick = substr($nick,0,7)."-";
625 &status("nick taken; changing to temporary nick.");
631 my ($self, $event) = @_;
632 my $nick = $event->nick();
633 my $chan = ($event->to)[0];
634 my $args = ($event->args)[0];
636 if ($nick =~ /^NickServ$/i) { # nickserv.
637 &status("NickServ: <== '$args'");
640 $check++ if ($args =~ /^This nickname is registered/i);
641 $check++ if ($args =~ /nickname.*owned/i);
644 &status("nickserv told us to register; doing it.");
645 if (&IsParam("nickServ_pass")) {
646 &status("NickServ: ==> Identifying.");
647 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
650 &status("We can't tell nickserv a passwd ;(");
655 if ($args =~ /^Password a/i) {
658 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
659 &status("ChanServ: <== '$args'.");
661 if ($chan =~ /^$mask{chan}$/) { # channel notice.
662 &status("-$nick/$chan- $args");
664 $server = $nick unless (defined $server);
665 &status("-$nick- $args"); # private or server notice.
671 my ($self, $event) = @_;
672 my $chan = ($event->to)[0];
673 my $nick = $event->nick;
675 &status("!!! other called.");
676 &status("!!! $event->args");
680 my ($self, $event) = @_;
681 my $chan = lc( ($event->to)[0] ); # CASING!!!
682 my $nick = $event->nick;
683 my $userhost = $event->userhost;
685 if (exists $floodjoin{$chan}{$nick}{Time}) {
686 delete $floodjoin{$chan}{$nick};
689 $chanstats{$chan}{'Part'}++;
690 &DeleteUserInfo($nick,$chan);
691 &clearChanVars($chan) if ($nick eq $ident);
692 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
693 delete $userstats{lc $nick};
696 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
700 my ($self, $event) = @_;
701 my $nick = $event->nick;
703 $self->ctcp_reply($nick, join(' ', ($event->args)));
704 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
708 my ($self, $event) = @_;
709 my $nick = $event->nick;
710 my $lag = time() - ($event->args)[1];
712 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
716 my ($self, $event) = @_;
717 my $msg = ($event->args)[0];
718 my $chan = lc( ($event->to)[0] ); # CASING.
719 my $nick = $event->nick;
720 $uh = $event->userhost();
721 $nuh = $nick."!".$uh;
722 ($user,$host) = split(/\@/, $uh);
724 if ($bot_pid != $$) {
725 &ERROR("run-away fork; exiting.");
730 if ($statcount < 200) {
731 foreach $chan (grep /[A-Z]/, keys %channels) {
732 &DEBUG("leak: chan => '$chan'.");
734 foreach $i (keys %{$channels{$chan}}) {
735 foreach (keys %{$channels{$chan}{$i}}) {
736 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
743 $lastWho{$chan} = $nick;
744 ### TODO: use $nick or lc $nick?
745 if (&IsChanConf("seenStats")) {
746 $userstats{lc $nick}{'Count'}++;
747 $userstats{lc $nick}{'Time'} = time();
750 # if (&IsChanConf("hehCounter")) {
754 &hookMsg('public', $chan, $nick, $msg);
755 $chanstats{$chan}{'PublicMsg'}++;
759 my ($self, $event) = @_;
760 my $nick = $event->nick();
761 my $reason = ($event->args)[0];
764 foreach (keys %channels) {
765 # fixes inconsistent chanstats bug #1.
766 if (!&IsNickInChan($nick,$_)) {
770 $chanstats{$_}{'SignOff'}++;
773 if ($count == scalar keys %channels) {
774 &DEBUG("on_quit: nick $nick was not found in any chan.");
777 &DeleteUserInfo($nick, keys %channels);
779 if (exists $nuh{lc $nick}) {
780 delete $nuh{lc $nick};
782 &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
784 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
786 # should fix chanstats inconsistencies bug #2.
787 if ($reason=~/^($mask{host})\s($mask{host})$/) { # netsplit.
788 $reason = "NETSPLIT: $1 <=> $2";
790 if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
791 &DEBUG("on_quit: netsplit detected; disabling chan limit.");
792 &rawout("MODE $chan -l");
795 $netsplit{lc $nick} = time();
796 if (!exists $netsplitservers{$1}{$2}) {
797 &status("netsplit detected between $1 and $2.");
798 $netsplitservers{$1}{$2} = time();
802 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob");
803 if ($nick =~ /^\Q$ident\E$/) {
804 &DEBUG("^^^ THIS SHOULD NEVER HAPPEN.");
807 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
808 &status("own nickname became free; changing.");
809 &nick($param{'ircNick'});
813 sub on_targettoofast {
814 my ($self, $event) = @_;
815 my $nick = $event->nick();
816 my($me,$chan,$why) = $event->args();
818 ### TODO: incomplete.
819 ### .* wait (\d+) second/) {
820 &status("on_ttf: X1 $msg") if (defined $msg);
822 &status("going to sleep for $sleep...");
829 my ($self, $event) = @_;
831 if (scalar($event->args) == 1) { # change.
832 my $topic = ($event->args)[0];
833 my $chan = ($event->to)[0];
834 my $nick = $event->nick();
838 # race condition here. To fix, change '1' to '0'.
839 # This will keep track of topics set by bot only.
842 # this may be fixed at a later date with topic queueing.
845 $topic{$chan}{'Current'} = $topic if (1);
846 $chanstats{$chan}{'Topic'}++;
848 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
850 my ($nick, $chan, $topic) = $event->args;
851 if (&IsChanConf("topic")) {
852 $topic{$chan}{'Current'} = $topic;
853 &topicAddHistory($chan,$topic);
856 $topic = &fixString($topic, 1);
857 &status(">>> topic/$b_blue$chan$ob is $topic");
862 my ($self, $event) = @_;
863 my ($myself,$chan,$setby,$time) = $event->args();
866 if (time() - $time > 60*60*24) {
867 $timestr = "at ". localtime $time;
869 $timestr = &Time2String(time() - $time) ." ago";
872 &status(">>> set by $b_cyan$setby$ob $timestr");
876 my ($self, $event) = @_;
877 my $nick = $event->nick();
880 if (scalar $event->args() != 1) { # old.
881 $ver = join ' ', $event->args();
882 $ver =~ s/^VERSION //;
884 $ver = ($event->args())[0];
887 if (grep /^\Q$nick\E$/i, @vernick) {
888 &WARN("nick $nick found in vernick; skipping.");
891 push(@vernick, $nick);
893 if ($ver =~ /bitchx/i) {
894 $ver{bitchx}{$nick} = $ver;
895 } elsif ($ver =~ /xc\!|xchat/i) {
896 $ver{xchat}{$nick} = $ver;
897 } elsif ($ver =~ /irssi/i) {
898 $ver{irssi}{$nick} = $ver;
899 } elsif ($ver =~ /epic/i) {
900 $ver{epic}{$nick} = $ver;
901 } elsif ($ver =~ /mirc/i) {
902 $ver{mirc}{$nick} = $ver;
903 } elsif ($ver =~ /ircle/i) {
904 $ver{ircle}{$nick} = $ver;
905 } elsif ($ver =~ /ircII/i) {
906 $ver{ircII}{$nick} = $ver;
907 } elsif ($ver =~ /sirc /i) {
908 $ver{sirc}{$nick} = $ver;
909 } elsif ($ver =~ /kvirc/i) {
910 $ver{kvirc}{$nick} = $ver;
911 } elsif ($ver =~ /eggdrop/i) {
912 $ver{eggdrop}{$nick} = $ver;
913 } elsif ($ver =~ /xircon/i) {
914 $ver{xircon}{$nick} = $ver;
916 $ver{other}{$nick} = $ver;
921 my ($self, $event) = @_;
922 my $nick = $event->nick;
924 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
925 $self->ctcp_reply($nick, "VERSION $bot_version");
929 my ($self, $event) = @_;
930 my @args = $event->args;
932 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
936 my ($self, $event) = @_;
937 my @args = $event->args;
939 &DEBUG("on_whoisuser: @args");
941 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
944 #######################################################################
945 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
946 #######################################################################
949 # Usage: &hookMode($chan, $modes, @targets);
951 my ($chan, $modes, @targets) = @_;
954 $chan = lc $chan; # !!!.
957 foreach $mode (split(//, $modes)) {
959 if ($mode =~ /[-+]/) {
960 $parity = 1 if ($mode eq "+");
961 $parity = 0 if ($mode eq "-");
966 if ($mode =~ /[bklov]/) {
967 my $target = shift @targets;
970 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
971 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
973 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
974 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
977 # modes w/ target affecting nick => cache it.
978 if ($mode =~ /[bov]/) {
979 $channels{$chan}{$mode}{$target}++ if $parity;
980 delete $channels{$chan}{$mode}{$target} if !$parity;
983 if ($mode =~ /[l]/) {
984 $channels{$chan}{$mode} = $target if $parity;
985 delete $channels{$chan}{$mode} if !$parity;
989 # important channel modes, targetless.
990 if ($mode =~ /[mt]/) {
991 $channels{$chan}{$mode}++ if $parity;
992 delete $channels{$chan}{$mode} if !$parity;
998 ($msgType, $chan, $who, $message) = @_;
1001 $addressedother = 0;
1002 $orig{message} = $message;
1006 $message =~ s/[\cA-\c_]//ig; # strip control characters
1007 $message =~ s/^\s+//; # initial whitespaces.
1008 $who =~ tr/A-Z/a-z/; # lowercase.
1013 if ($msgType =~ /private/) {
1018 # addressing revamped by the xk.
1019 ### below needs to be fixed...
1020 if (&IsParam("addressCharacter")) {
1021 if ($message =~ s/^$param{'addressCharacter'}//) {
1027 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
1028 my $newmessage = $';
1029 if ($1 =~ /^\Q$ident\E$/i) {
1030 $message = $newmessage;
1033 # ignore messages addressed to other people or unaddressed.
1034 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
1039 # Determine floodwho.
1041 if ($msgType =~ /public/i) { # public.
1042 $floodwho = $c = lc $chan;
1043 } elsif ($msgType =~ /private/i) { # private.
1044 $floodwho = lc $who;
1046 &DEBUG("FIXME: floodwho = ???");
1049 my $val = &getChanConfDefault("floodRepeat", "2:10", $c);
1050 my ($count, $interval) = split /:/, $val;
1052 # flood repeat protection.
1054 my $time = $flood{$floodwho}{$message} || 0;
1056 if ($msgType eq "public" and (time() - $time < $interval)) {
1057 ### public != personal who so the below is kind of pointless.
1059 foreach (keys %flood) {
1060 next if (/^\Q$floodwho\E$/);
1061 next if (defined $chan and /^\Q$chan\E$/);
1063 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
1066 return if ($lobotomized);
1069 &msg($who, "you already said what ".
1070 join(' ', @who)." have said.");
1072 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
1075 ### TODO: delete old floodwarn{} keys.
1077 if (!exists $floodwarn{$floodwho}) {
1080 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
1084 &status("FLOOD repetition detected from $floodwho.");
1085 $floodwarn{$floodwho} = time();
1092 &status("$b_cyan$who$ob is short-addressing me");
1093 } elsif ($msgType eq "private") { # private.
1094 &status("$b_cyan$who$ob is /msg'ing me");
1096 &status("$b_cyan$who$ob is addressing me");
1099 $flood{$floodwho}{$message} = time();
1100 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
1101 # unaddressed, public only.
1103 ### TODO: use a separate "short-time" hash.
1105 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
1108 $val = &getChanConfDefault("floodMessages", "5:30", $c);
1109 ($count, $interval) = split /:/, $val;
1111 # flood overflow protection.
1113 foreach (keys %{$flood{$floodwho}}) {
1114 next unless (time() - $flood{$floodwho}{$_} > $interval);
1115 delete $flood{$floodwho}{$_};
1118 my $i = scalar keys %{$flood{$floodwho}};
1120 &msg($who,"overflow of messages ($i > $count)");
1121 &status("FLOOD overflow detected from $floodwho; ignoring");
1123 my $expire = $param{'ignoreAutoExpire'} || 5;
1124 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
1128 $flood{$floodwho}{$message} = time();
1132 if ($msgType =~ /public/i) { # public.
1133 $talkchannel = $chan;
1134 &status("<$orig{who}/$chan> $orig{message}");
1135 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
1136 } elsif ($msgType =~ /private/i) { # private.
1137 &status("[$orig{who}] $orig{message}");
1138 $talkchannel = undef;
1141 &DEBUG("unknown msgType => $msgType.");
1143 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
1145 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
1146 &IsChanConf("seen") and
1147 $msgType =~ /public/
1149 $seencache{$who}{'time'} = time();
1150 $seencache{$who}{'nick'} = $orig{who};
1151 $seencache{$who}{'host'} = $uh;
1152 $seencache{$who}{'chan'} = $talkchannel;
1153 $seencache{$who}{'msg'} = $orig{message};
1154 $seencache{$who}{'msgcount'}++;
1157 return if ($skipmessage);
1158 return unless (&IsParam("minVolunteerLength") or $addressed);
1163 next unless (eval { $nuh =~ /^$_$/i });
1165 &status("IGNORE <$who> $message");
1170 if (!defined $userHandle) {
1171 &DEBUG("line 1074: need verifyUser?");
1172 &verifyUser($who, $nuh);
1175 &DEBUG("hookMsg: 'nuh' not defined?");
1178 ### For extra debugging purposes...
1179 if ($_ = &process()) {
1180 # &DEBUG("IrcHooks: process returned '$_'.");
1186 sub chanLimitVerify {
1188 my $l = $channels{$chan}{'l'};
1190 # only change it if it's not set.
1191 if (defined $l and &IsChanConf("chanlimitcheck")) {
1192 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
1193 my $nowl = scalar(keys %{ $channels{$chan}{''} });
1194 my $delta = $nowl - $l;
1198 &WARN("clc: stupid to have plus at $plus, fix it!");
1201 ### todo: check if we have ops.
1202 ### todo: if not, check if nickserv/chanserv is avail.
1203 ### todo: unify code with chanlimitcheck()
1205 &status("clc: big change in limit; changing.");
1206 &rawout("MODE $chan +l ".($nowl+$plus) );