2 # IrcHooks.pl: IRC Hooks stuff.
5 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
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];
58 $h = (split /\@/, $uh)[1];
62 if (!exists $dcc{'CHATvrfy'}{$nick}) {
63 $userHandle = &verifyUser($who, $nuh);
64 my $crypto = $users{$userHandle}{PASS};
67 if ($userHandle eq "_default") {
68 &WARN("DCC CHAT: _default/guest not allowed.");
72 ### TODO: prevent users without CRYPT chatting.
73 if (!defined $crypto) {
74 &DEBUG("todo: dcc close chat");
75 &msg($who, "nope, no guest logins allowed...");
79 if (&ckpasswd($msg, $crypto)) {
80 # stolen from eggdrop.
81 $self->privmsg($sock, "Connected to $ident");
82 $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
83 $self->privmsg($sock, "Everything else goes out to the party line.");
85 &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
90 &status("DCC CHAT: incorrect pass; closing connection.");
91 &DEBUG("chat: sock => '$sock'.");
93 delete $dcc{'CHAT'}{$nick};
94 &DEBUG("chat: after closing sock. FIXME");
95 ### BUG: close seizes bot. why?
99 &status("DCC CHAT: user $nick is here!");
100 &DCCBroadcast("*** $nick ($uh) joined the party line.");
102 $dcc{'CHATvrfy'}{$nick} = $userHandle;
104 return if ($userHandle eq "_default");
106 &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
112 &status("$b_red=$b_cyan$who$b_red=$ob $message");
114 if ($message =~ s/^\.//) { # dcc chat commands.
115 ### TODO: make use of &Forker(); here?
116 &loadMyModule( $myModules{'ircdcc'} );
118 &DCCBroadcast("#$who# $message","m");
120 my $retval = &userDCC();
121 return unless (defined $retval);
122 return if ($retval eq $noreply);
124 $conn->privmsg($dcc{'CHAT'}{$who}, "Invalid command.");
126 } else { # dcc chat arena.
128 foreach (keys %{ $dcc{'CHAT'} }) {
129 $conn->privmsg($dcc{'CHAT'}{$_}, "<$who> $orig{message}");
133 return 'DCC CHAT MESSAGE';
136 # is there isoff? how do we know if someone signs off?
138 my ($self, $event) = @_;
139 my $x1 = ($event->args)[0];
140 my $x2 = ($event->args)[1];
142 # &nick( $param{'ircNick'} );
144 &DEBUG("on_ison: x1 = '$x1', x2 => '$x2'");
151 $ident ||= $param{'ircNick'}; # hack.
152 $ircstats{'ConnectTime'} = time();
153 $ircstats{'ConnectCount'}++;
154 $ircstats{'OffTime'} += time() - $ircstats{'DisconnectTime'}
155 if (defined $ircstats{'DisconnectTime'});
158 if (!exists $users{_default}) {
159 &status("!!! First time run... adding _default user.");
160 $users{_default}{FLAGS} = "mrt";
161 $users{_default}{HOSTS}{"*!*@*"} = 1;
164 if (scalar keys %users < 2) {
166 &status("!!! Ok. Now type '/msg $ident PASS <pass>' to get master access through DCC CHAT.");
169 # end of first time run.
171 if (&IsChanConf("wingate")) {
172 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
176 next unless (/^(\S+)\*$/);
177 push(@wingateBad, $_);
183 &ScheduleThis(1, \&setupSchedulers);
187 if (&IsParam("ircUMode")) {
188 &VERB("Attempting change of user modes to $param{'ircUMode'}.", 2);
189 if ($param{'ircUMode'} !~ /^[-+]/) {
190 &WARN("ircUMode had no +- prefix; adding +");
191 $param{'ircUMode'} = "+".$param{'ircUMode'};
194 &rawout("MODE $ident $param{'ircUMode'}");
197 &status("End of motd. Now lets join some channels...");
198 if (!scalar @joinchan) {
199 &WARN("joinchan array is empty!");
200 @joinchan = &getJoinChans(1);
203 # ok, we're free to do whatever we want now. go for it!
206 # add ourself to notify.
207 $conn->ison( $param{'ircNick'} );
209 # Q, as on quakenet.org.
210 if (&IsParam("Q_pass")) {
211 &status("Authing to Q...");
212 &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}");
219 my ($self, $event) = @_;
220 # &DEBUG("endofwho: chan => $chan");
221 $chan ||= ($event->args)[1];
222 # &DEBUG("endofwho: chan => $chan");
224 if (exists $cache{countryStats}) {
230 my ($self, $event) = @_;
231 my $type = uc( ($event->args)[1] );
232 my $nick = lc $event->nick();
234 # pity Net::IRC doesn't store nuh. Here's a hack :)
235 if (!exists $nuh{lc $nick}) {
237 $nuh{$nick} = "GETTING-NOW"; # trying.
241 if ($type eq 'SEND') { # GET for us.
242 # incoming DCC SEND. we're receiving a file.
243 my $get = ($event->args)[2];
244 open(DCCGET,">$get");
246 $self->new_get($event, \*DCCGET);
248 } elsif ($type eq 'GET') { # SEND for us?
249 &status("DCC: Initializing SEND for $nick.");
250 $self->new_send($event->args);
252 } elsif ($type eq 'CHAT') {
253 &status("DCC: Initializing CHAT for $nick.");
254 $self->new_chat($event);
255 # $self->new_chat(1, $nick, $event->host);
258 &WARN("${b_green}DCC $type$ob (1)");
263 my ($self, $event) = @_;
264 my $nick = $event->nick();
265 my $sock = ($event->to)[0];
267 # DCC CHAT close on fork exit workaround.
268 if ($bot_pid != $$) {
269 &WARN("run-away fork; exiting.");
273 if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
274 &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
276 &status("dcc_close: purging $nick.txt from Debian.pl");
277 unlink "$param{tempDir}/$nick.txt";
279 delete $dcc{'SEND'}{$nick};
280 } elsif (exists $dcc{'CHAT'}{$nick} and $dcc{'CHAT'}{$nick} eq $sock) {
281 &status("${b_green}DCC CHAT$ob close from $b_cyan$nick$ob");
282 delete $dcc{'CHAT'}{$nick};
283 delete $dcc{'CHATvrfy'}{$nick};
285 &status("${b_green}DCC$ob UNKNOWN close from $b_cyan$nick$ob (2)");
290 my ($self, $event) = @_;
291 my $type = uc( ($event->args)[0] );
292 my $nick = lc $event->nick();
293 my $sock = ($event->to)[0];
297 ### BUG: who is set to bot's nick?
300 if ($type eq 'SEND') {
301 &status("${b_green}DCC lGET$ob established with $b_cyan$nick$ob");
303 } elsif ($type eq 'CHAT') {
305 ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
306 ### 1,3,5,10 seconds then fail.
307 if ($nuh{$nick} eq "GETTING-NOW") {
308 &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
310 on_dcc_open_chat(undef, $nick, $sock);
313 } elsif ($type eq 'SEND') {
314 &DEBUG("Starting DCC receive.");
315 foreach ($event->args) {
320 &WARN("${b_green}DCC $type$ob (3)");
324 # really custom sub to get NUH since Net::IRC doesn't appear to support
326 sub on_dcc_open_chat {
327 my(undef, $nick, $sock) = @_;
329 if ($nuh{$nick} eq "GETTING-NOW") {
330 &DEBUG("getting nuh for $nick failed. FIXME.");
334 &status("${b_green}DCC CHAT$ob established with $b_cyan$nick$ob $b_yellow($ob$nuh{$nick}$b_yellow)$ob");
336 &verifyUser($nick, $nuh{lc $nick});
338 if (!exists $users{$userHandle}{HOSTS}) {
339 &pSReply("you have no hosts defined in my user file; rejecting.");
344 my $crypto = $users{$userHandle}{PASS};
345 $dcc{'CHAT'}{$nick} = $sock;
347 # todo: don't make DCC CHAT established in the first place.
348 if ($userHandle eq "_default") {
349 &dccsay($nick, "_default/guest not allowed");
354 if (defined $crypto) {
355 &status("DCC CHAT: going to use ".$nick."'s crypt.");
356 &dccsay($nick,"Enter your password.");
358 # &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
363 my ($self, $event) = @_;
364 my $from = $event->from();
365 my $what = ($event->args)[0];
367 &status("disconnect from $from ($what).");
368 $ircstats{'DisconnectTime'} = time();
369 $ircstats{'DisconnectReason'} = $what;
370 $ircstats{'DisconnectCount'}++;
371 $ircstats{'TotalTime'} += time() - $ircstats{'ConnectTime'}
372 if ($ircstats{'ConnectTime'});
374 # clear any variables on reconnection.
377 &DEBUG("on_disconnect: 1");
379 &DEBUG("on_disconnect: 2");
381 if (!defined $self) {
382 &WARN("on_disconnect: self is undefined! WTF");
383 &DEBUG("running function irc... lets hope this works.");
388 if (!$self->connect()) {
389 &DEBUG("on_disconnect: 3");
390 &WARN("not connected? help me. gonna call ircCheck() in 60s");
392 &ScheduleThis(1, "ircCheck");
397 my ($self, $event) = @_;
398 my $chan = ($event->args)[1];
400 # sync time should be done in on_endofwho like in BitchX
401 if (exists $cache{jointime}{$chan}) {
402 my $delta_time = sprintf("%.03f", &timedelta($cache{jointime}{$chan}) );
403 $delta_time = 0 if ($delta_time <= 0);
404 if ($delta_time > 100) {
405 &WARN("endofnames: delta_time > 100 ($delta_time)");
408 &status("$b_blue$chan$ob: sync in ${delta_time}s.");
415 foreach ("o","v","") {
416 my $count = scalar(keys %{ $channels{$chan}{$_} });
417 next unless ($count);
419 $txt = "total" if ($_ eq "");
420 $txt = "voice" if ($_ eq "v");
421 $txt = "ops" if ($_ eq "o");
423 push(@array, "$count $txt");
425 my $chanstats = join(' || ', @array);
426 &status("$b_blue$chan$ob: [$chanstats]");
428 &chanServCheck($chan);
429 # schedule used to solve ircu (OPN) "target too fast" problems.
430 $conn->schedule(5, sub { &joinNextChan(); } );
434 my ($self, $event) = @_;
435 my (@args) = ($event->args);
442 my ($self, $event) = @_;
443 my $chan = lc( ($event->args)[0] );
444 my $nick = $event->nick;
446 if ($nick =~ /^\Q$ident\E$/) {
447 &DEBUG("on_invite: self invite.");
452 if (exists $chanconf{$chan}) {
453 # it's still buggy :/
454 if (&validChan($chan)) {
455 &msg($who, "i'm already in \002$chan\002.");
459 &status("invited to $b_blue$chan$ob by $b_cyan$nick$ob");
465 my ($self, $event) = @_;
466 my ($user,$host) = split(/\@/, $event->userhost);
467 $chan = lc( ($event->to)[0] ); # CASING!!!!
468 $who = $event->nick();
470 my $i = scalar(keys %{ $channels{$chan} });
471 my $j = $cache{maxpeeps}{$chan} || 0;
473 if (!&IsParam("noSHM") && time() > ($sched{shmFlush}{TIME} || time()) + 3600) {
474 &DEBUG("looks like schedulers died somewhere... restarting...");
478 $chanstats{$chan}{'Join'}++;
479 $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats"));
480 $cache{maxpeeps}{$chan} = $i if ($i > $j);
482 &joinfloodCheck($who, $chan, $event->userhost);
486 if (exists $netsplit{lc $who}) {
487 delete $netsplit{lc $who};
490 if (!scalar keys %netsplit) {
491 &DEBUG("on_join: netsplit hash is now empty!");
492 undef %netsplitservers;
493 &netsplitCheck(); # any point in running this?
498 if ($netsplit and !exists $cache{netsplit}) {
499 &VERB("on_join: ok.... re-running chanlimitCheck in 60.",2);
500 $conn->schedule(60, sub {
502 delete $cache{netsplit};
505 $cache{netsplit} = time();
508 # how to tell if there's a netjoin???
510 my $netsplitstr = "";
511 $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
512 &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
514 $channels{$chan}{''}{$who}++;
515 $nuh = $who."!".$user."\@".$host;
516 $nuh{lc $who} = $nuh unless (exists $nuh{lc $who});
520 push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
521 push(@bans, keys %{ $bans{"*"} }) if (exists $bans{"*"});
528 next unless ($nuh =~ /^$mask$/i);
530 ### TODO: check $channels{$chan}{'b'} if ban already exists.
531 foreach (keys %{ $channels{$chan}{'b'} }) {
532 &DEBUG(" bans_on_chan($chan) => $_");
535 my $reason = "no reason";
536 foreach ($chan, "*") {
537 next unless (exists $bans{$_});
538 next unless (exists $bans{$_}{$ban});
540 my @array = @{ $bans{$_}{$ban} };
542 $reason = $array[4] if ($array[4]);
547 &kick($who, $chan, $reason);
552 # no need to go further.
553 return if ($netsplit);
556 if ($who eq $ident or $who =~ /^$ident$/i) {
557 if (defined( my $whojoin = $cache{join}{$chan} )) {
558 &msg($chan, "Okay, I'm here. (courtesy of $whojoin)");
559 delete $cache{join}{$chan};
560 &joinNextChan(); # hack.
563 ### TODO: move this to &joinchan()?
564 $cache{jointime}{$chan} = &timeget();
571 &rootWarn($who,$user,$host,$chan) if (
572 &IsChanConf("rootWarn") &&
573 $user =~ /^~?r(oo|ew|00)t$/i
577 if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
578 if (!&loadMyModule("news")) { # just in case.
579 &DEBUG("could not load news.");
581 &News::latest($chan);
586 if (&IsChanConf("botmail")) {
587 &botmail::check(lc $who);
595 my ($self, $event) = @_;
596 my ($chan,$reason) = $event->args;
597 my $kicker = $event->nick;
598 my $kickee = ($event->to)[0];
599 my $uh = $event->userhost();
601 &status(">>> kick/$b_blue$chan$ob [$b$kickee!$uh$ob] by $b_cyan$kicker$ob $b_yellow($ob$reason$b_yellow)$ob");
603 $chan = lc $chan; # forgot about this, found by xsdg, 20001229.
604 $chanstats{$chan}{'Kick'}++;
606 if ($kickee eq $ident) {
607 &clearChanVars($chan);
609 &status("SELF attempting to rejoin lost channel $chan");
612 &delUserInfo($kickee,$chan);
617 my ($self, $event) = @_;
618 my ($user, $host) = split(/\@/, $event->userhost);
619 my @args = $event->args();
620 my $nick = $event->nick();
621 $chan = ($event->to)[0];
623 # last element is empty... so nuke it.
624 pop @args while ($args[$#args] eq "");
626 if ($nick eq $chan) { # UMODE
627 &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
629 &status(">>> mode/$b_blue$chan$ob $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
630 &hookMode($nick, @args);
635 my ($self, $event) = @_;
636 my ($myself, undef,@args) = $event->args();
637 my $nick = $event->nick();
638 $chan = ($event->args())[1];
640 &hookMode($nick, @args);
644 my ($self, $event) = @_;
645 my $nick = $event->nick;
646 my $msg = ($event->args)[0];
648 ($user,$host) = split(/\@/, $event->userhost);
649 $uh = $event->userhost();
650 $nuh = $nick."!".$uh;
654 if ($nick eq $ident) { # hopefully ourselves.
655 if ($msg eq "TEST") {
656 &status("IRCTEST: Yes, we're alive.");
657 delete $cache{connect};
662 &hookMsg('private', undef, $nick, $msg);
669 my ($self, $event) = @_;
670 my @args = $event->args;
671 my $chan = lc $args[2]; # CASING, the last of them!
673 foreach (split / /, @args[3..$#args]) {
674 $channels{$chan}{'o'}{$_}++ if s/\@//;
675 $channels{$chan}{'v'}{$_}++ if s/\+//;
676 $channels{$chan}{''}{$_}++;
681 my ($self, $event) = @_;
682 my $nick = $event->nick();
683 my $newnick = ($event->args)[0];
685 if (exists $netsplit{lc $newnick}) {
686 &status("Netsplit: $newnick/$nick came back from netsplit and changed to original nick! removing from hash.");
687 delete $netsplit{lc $newnick};
688 &netsplitCheck() if (time() != $sched{netsplitCheck}{TIME});
692 foreach $chan (keys %channels) {
693 foreach $mode (keys %{ $channels{$chan} }) {
694 next unless (exists $channels{$chan}{$mode}{$nick});
696 $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick};
699 # todo: do %flood* aswell.
701 &delUserInfo($nick, keys %channels);
702 $nuh{lc $newnick} = $nuh{lc $nick};
703 delete $nuh{lc $nick};
705 if ($nick eq $ident) {
706 &status(">>> I materialized into $b_green$newnick$ob from $nick");
709 &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
711 if ($nick =~ /^\Q$param{'ircNick'}\E$/i) {
719 my $nick = $self->nick;
720 my $newnick = $nick."-";
722 &status("nick taken ($nick); preparing nick change.");
725 $conn->schedule(5, sub {
726 &status("nick taken; changing to temporary nick ($nick -> $newnick).");
732 my ($self, $event) = @_;
733 my $nick = $event->nick();
734 my $chan = ($event->to)[0];
735 my $args = ($event->args)[0];
737 if ($nick =~ /^NickServ$/i) { # nickserv.
738 &status("NickServ: <== '$args'");
741 $check++ if ($args =~ /^This nickname is registered/i);
742 $check++ if ($args =~ /nickname.*owned/i);
745 &status("nickserv told us to register; doing it.");
747 if (&IsParam("nickServ_pass")) {
748 &status("NickServ: ==> Identifying.");
749 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
752 &status("We can't tell nickserv a passwd ;(");
757 if ($args =~ /^Password a/i) {
760 foreach ( &ChanConfList("chanServ_ops") ) {
761 next unless &chanServCheck($_);
763 &DEBUG("nickserv activated or restarted; doing chanserv check.");
770 } elsif ($nick =~ /^ChanServ$/i) { # chanserv.
771 &status("ChanServ: <== '$args'.");
774 if ($chan =~ /^$mask{chan}$/) { # channel notice.
775 &status("-$nick/$chan- $args");
777 $server = $nick unless (defined $server);
778 &status("-$nick- $args"); # private or server notice.
784 my ($self, $event) = @_;
785 my $chan = ($event->to)[0];
786 my $nick = $event->nick;
788 &status("!!! other called.");
789 &status("!!! $event->args");
793 my ($self, $event) = @_;
794 $chan = lc( ($event->to)[0] ); # CASING!!!
795 my $nick = $event->nick;
796 my $userhost = $event->userhost;
800 if (0 and !exists $channels{$chan}) {
801 &DEBUG("on_part: found out we're on $chan!");
802 $channels{$chan} = 1;
805 if (exists $floodjoin{$chan}{$nick}{Time}) {
806 delete $floodjoin{$chan}{$nick};
809 $chanstats{$chan}{'Part'}++;
810 &delUserInfo($nick,$chan);
811 if ($nick eq $ident) {
812 &DEBUG("on_part: ok, I left $chan... clearChanVars...");
813 &clearChanVars($chan);
816 if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
817 delete $userstats{lc $nick};
820 &status(">>> part/$b_blue$chan$ob $b_cyan$nick$ob $b_yellow($ob$userhost$b_yellow)$ob");
824 my ($self, $event) = @_;
825 my $nick = $event->nick;
827 $self->ctcp_reply($nick, join(' ', ($event->args)));
828 &status(">>> ${b_green}CTCP PING$ob request from $b_cyan$nick$ob received.");
832 my ($self, $event) = @_;
833 my $nick = $event->nick;
834 my $t = ($event->args)[1];
836 &WARN("on_ping_reply: t == undefined.");
840 my $lag = time() - $t;
842 &status(">>> ${b_green}CTCP PING$ob reply from $b_cyan$nick$ob: $lag sec.");
846 my ($self, $event) = @_;
847 my $msg = ($event->args)[0];
848 $chan = lc( ($event->to)[0] ); # CASING.
849 my $nick = $event->nick;
851 $uh = $event->userhost();
852 $nuh = $nick."!".$uh;
854 # todo: move this out of hookMsg to here?
855 ($user,$host) = split(/\@/, $uh);
858 # rare case should this happen - catch it just in case.
859 if ($bot_pid != $$) {
860 &ERROR("run-away fork; exiting.");
865 $lastWho{$chan} = $nick;
866 ### TODO: use $nick or lc $nick?
867 if (&IsChanConf("seenStats")) {
868 $userstats{lc $nick}{'Count'}++;
869 $userstats{lc $nick}{'Time'} = time();
872 # would this slow things down?
873 if ($_ = &getChanConf("ircTextCounters")) {
876 foreach (split /[\s]+/) {
879 # either full word or ends with a space, etc...
880 next unless ($msg =~ /^\Q$x\E[\$\s!.]/i);
882 &VERB("textcounters: $x matched for $who",2);
883 my $c = $chan || "PRIVATE";
885 my ($v,$t) = &sqlSelect("stats", "counter,time", {
892 # don't allow ppl to cheat the stats :-)
893 next unless (defined $t);
894 next unless ($time - $t > 10);
896 &sqlReplace("stats", {
906 &hookMsg('public', $chan, $nick, $msg);
907 $chanstats{$chan}{'PublicMsg'}++;
914 my ($self, $event) = @_;
915 my $nick = $event->nick();
916 my $reason = ($event->args)[0];
921 ### $chan = $reason; # no.
924 foreach (grep !/^_default$/, keys %channels) {
925 # fixes inconsistent chanstats bug #1.
926 if (!&IsNickInChan($nick,$_)) {
930 $chanstats{$_}{'SignOff'}++;
933 if ($count == scalar keys %channels) {
934 &DEBUG("on_quit: nick $nick was not found in any chan.");
937 # should fix chanstats inconsistencies bug #2.
938 if ($reason =~ /^($mask{host})\s($mask{host})$/) { # netsplit.
939 $reason = "NETSPLIT: $1 <=> $2";
942 foreach $chan ( &getNickInChans($nick) ) {
943 next unless ( &IsChanConf("chanlimitcheck") );
944 next unless ( exists $channels{$_}{'l'} );
946 &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
947 $conn->mode($_, "-l");
950 $netsplit{lc $nick} = time();
951 if (!exists $netsplitservers{$1}{$2}) {
952 &status("netsplit detected between $1 and $2 at [".scalar(gmtime)."]");
953 $netsplitservers{$1}{$2} = time();
957 my $chans = join(' ', &getNickInChans($nick) );
958 &status(">>> $b_cyan$nick$ob has signed off IRC $b_red($ob$reason$b_red)$ob [$chans]");
959 if ($nick =~ /^\Q$ident\E$/) {
960 &ERROR("^^^ THIS SHOULD NEVER HAPPEN (10).");
964 ### ok... lets clear out the cache
966 &delUserInfo($nick, keys %channels);
967 if (exists $nuh{lc $nick}) {
968 delete $nuh{lc $nick};
970 # well.. it's good but weird that this has happened - lets just
973 delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
974 delete $chanstats{lc $nick};
978 if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
979 &status("nickchange: own nickname became free; changing.");
980 &nick($param{'ircNick'});
984 sub on_targettoofast {
985 my ($self, $event) = @_;
986 my $nick = $event->nick();
987 my($me,$chan,$why) = $event->args();
989 ### TODO: incomplete.
990 if ($why =~ /.* wait (\d+) second/) {
995 &status("targettoofast: going to sleep for $max ($sleep)...");
998 &status("targettoofast: going to sleep for $sleep");
1001 my $delta = time() - ($cache{sleepTime} || 0);
1002 if ($delta > $max+2) {
1004 $cache{sleepTime} = time();
1010 if (!exists $cache{TargetTooFast}) {
1011 &DEBUG("on_ttf: failed: $why");
1012 $cache{TargetTooFast}++;
1017 my ($self, $event) = @_;
1019 if (scalar($event->args) == 1) { # change.
1020 my $topic = ($event->args)[0];
1021 my $chan = ($event->to)[0];
1022 my $nick = $event->nick();
1026 # race condition here. To fix, change '1' to '0'.
1027 # This will keep track of topics set by bot only.
1030 # this may be fixed at a later date with topic queueing.
1033 $topic{$chan}{'Current'} = $topic if (1);
1034 $chanstats{$chan}{'Topic'}++;
1036 &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
1038 my ($nick, $chan, $topic) = $event->args;
1039 if (&IsChanConf("topic")) {
1040 $topic{$chan}{'Current'} = $topic;
1041 &topicAddHistory($chan,$topic);
1044 $topic = &fixString($topic, 1);
1045 &status(">>> topic/$b_blue$chan$ob is $topic");
1050 my ($self, $event) = @_;
1051 my ($myself,$chan,$setby,$time) = $event->args();
1054 if (time() - $time > 60*60*24) {
1055 $timestr = "at ". gmtime $time;
1057 $timestr = &Time2String(time() - $time) ." ago";
1060 &status(">>> set by $b_cyan$setby$ob $timestr");
1064 my ($self, $event) = @_;
1065 my $nick = $event->nick();
1068 if (scalar $event->args() != 1) { # old.
1069 $ver = join ' ', $event->args();
1070 $ver =~ s/^VERSION //;
1072 $ver = ($event->args())[0];
1075 if (grep /^\Q$nick\E$/i, @vernick) {
1076 &WARN("nick $nick found in vernick ($ver); skipping.");
1079 push(@vernick, $nick);
1081 if ($ver =~ /bitchx/i) {
1082 $ver{bitchx}{$nick} = $ver;
1084 } elsif ($ver =~ /xc\!|xchat/i) {
1085 $ver{xchat}{$nick} = $ver;
1087 } elsif ($ver =~ /irssi/i) {
1088 $ver{irssi}{$nick} = $ver;
1090 } elsif ($ver =~ /epic|(Third Eye)/i) {
1091 $ver{epic}{$nick} = $ver;
1093 } elsif ($ver =~ /ircII|PhoEniX/i) {
1094 $ver{ircII}{$nick} = $ver;
1096 } elsif ($ver =~ /mirc/i) {
1097 # &DEBUG("verstats: mirc: $nick => '$ver'.");
1098 $ver{mirc}{$nick} = $ver;
1100 # ok... then we get to the lesser known/used clients.
1101 } elsif ($ver =~ /ircle/i) {
1102 $ver{ircle}{$nick} = $ver;
1104 } elsif ($ver =~ /chatzilla/i) {
1105 $ver{chatzilla}{$nick} = $ver;
1107 } elsif ($ver =~ /pirch/i) {
1108 $ver{pirch}{$nick} = $ver;
1110 } elsif ($ver =~ /sirc /i) {
1111 $ver{sirc}{$nick} = $ver;
1113 } elsif ($ver =~ /kvirc/i) {
1114 $ver{kvirc}{$nick} = $ver;
1116 } elsif ($ver =~ /eggdrop/i) {
1117 $ver{eggdrop}{$nick} = $ver;
1119 } elsif ($ver =~ /xircon/i) {
1120 $ver{xircon}{$nick} = $ver;
1123 &DEBUG("verstats: other: $nick => '$ver'.");
1124 $ver{other}{$nick} = $ver;
1129 my ($self, $event) = @_;
1130 my $nick = $event->nick;
1132 &status(">>> ${b_green}CTCP VERSION$ob request from $b_cyan$nick$ob");
1133 $self->ctcp_reply($nick, "VERSION $bot_version");
1137 my ($self, $event) = @_;
1138 my @args = $event->args;
1139 my $str = $args[5]."!".$args[2]."\@".$args[3];
1141 if ($cache{on_who_Hack}) {
1142 $cache{nuhInfo}{lc $args[5]}{Nick} = $args[5];
1143 $cache{nuhInfo}{lc $args[5]}{User} = $args[2];
1144 $cache{nuhInfo}{lc $args[5]}{Host} = $args[3];
1145 $cache{nuhInfo}{lc $args[5]}{NUH} = "$args[5]!$args[2]\@$args[3]";
1149 if ($args[5] =~ /^nickserv$/i and !$nickserv) {
1150 &DEBUG("ok... we did a who for nickserv.");
1151 &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
1154 $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
1158 my ($self, $event) = @_;
1159 my @args = $event->args;
1161 $nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
1164 sub on_whoischannels {
1165 my ($self, $event) = @_;
1166 my @args = $event->args;
1168 &DEBUG("on_whoischannels: @args");
1171 sub on_useronchannel {
1172 my ($self, $event) = @_;
1173 my @args = $event->args;
1175 &DEBUG("on_useronchannel: @args");
1180 ### since joinnextchan is hooked onto on_endofnames, these are needed.
1184 my ($self, $event) = @_;
1185 my @args = $event->args;
1187 &status(">>> chanfull/$b_blue$args[1]$ob");
1193 my ($self, $event) = @_;
1194 my @args = $event->args;
1196 &status(">>> inviteonly/$b_cyan$args[1]$ob");
1202 my ($self, $event) = @_;
1203 my @args = $event->args;
1204 my $chan = $args[1];
1206 &status(">>> banned/$b_blue$chan$ob $b_cyan$args[0]$ob");
1212 my ($self, $event) = @_;
1213 my @args = $event->args;
1215 &DEBUG("on_badchankey: args => @args");
1220 my ($self, $event) = @_;
1221 my @args = $event->args;
1223 &DEBUG("on_useronchan: args => @args");