fiddle about with 'bye'
[spider.git] / perl / DXCommandmode.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the user facing command mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXCommandmode;
11
12 use POSIX;
13
14 @ISA = qw(DXChannel);
15
16 use DXUtil;
17 use DXChannel;
18 use DXUser;
19 use DXVars;
20 use DXDebug;
21 use DXM;
22 use DXLog;
23 use DXLogPrint;
24 use DXBearing;
25 use CmdAlias;
26 use Filter;
27 use Minimuf;
28 use DXDb;
29 use AnnTalk;
30 use WCY;
31 use Sun;
32 use Internet;
33 use Script;
34
35
36 use strict;
37 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug $maxbadcount);
38
39 %Cache = ();                                    # cache of dynamically loaded routine's mod times
40 %cmd_cache = ();                                # cache of short names
41 $errstr = ();                                   # error string from eval
42 %aliases = ();                                  # aliases for (parts of) commands
43 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
44 $maxerrors = 20;                                # the maximum number of concurrent errors allowed before disconnection
45 $maxbadcount = 3;                               # no of bad words allowed before disconnection
46
47
48 use vars qw($VERSION $BRANCH);
49 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
50 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
51 $main::build += $VERSION;
52 $main::branch += $BRANCH;
53
54 #
55 # obtain a new connection this is derived from dxchannel
56 #
57
58 sub new 
59 {
60         my $self = DXChannel::alloc(@_);
61
62         # routing, this must go out here to prevent race condx
63         my $pkg = shift;
64         my $call = shift;
65         my @rout = $main::routeroot->add_user($call, Route::here(1));
66         DXProt::route_pc16($main::me, $main::routeroot, @rout) if @rout;
67
68         return $self;
69 }
70
71 # this is how a a connection starts, you get a hello message and the motd with
72 # possibly some other messages asking you to set various things up if you are
73 # new (or nearly new and slacking) user.
74
75 sub start
76
77         my ($self, $line, $sort) = @_;
78         my $user = $self->{user};
79         my $call = $self->{call};
80         my $name = $user->{name};
81         
82         # log it
83         my $host = $self->{conn}->{peerhost} || "unknown";
84         Log('DXCommand', "$call connected from $host");
85
86         $self->{name} = $name ? $name : $call;
87         $self->send($self->msg('l2',$self->{name}));
88         $self->state('prompt');         # a bit of room for further expansion, passwords etc
89         $self->{priv} = $user->priv || 0;
90         $self->{lang} = $user->lang || $main::lang || 'en';
91         $self->{pagelth} = $user->pagelth || 20;
92         ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
93         $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
94         $self->{consort} = $line;       # save the connection type
95         
96         # set some necessary flags on the user if they are connecting
97         $self->{beep} = $user->wantbeep;
98         $self->{ann} = $user->wantann;
99         $self->{wwv} = $user->wantwwv;
100         $self->{wcy} = $user->wantwcy;
101         $self->{talk} = $user->wanttalk;
102         $self->{wx} = $user->wantwx;
103         $self->{dx} = $user->wantdx;
104         $self->{logininfo} = $user->wantlogininfo;
105         $self->{ann_talk} = $user->wantann_talk;
106         $self->{here} = 1;
107
108         # sort out registration
109         if ($main::reqreg == 1) {
110                 $self->{registered} = $user->registered;
111         } elsif ($main::reqreg == 2) {
112                 $self->{registered} = !$user->registered;
113         } else {
114                 $self->{registered} = 1;
115         }
116
117
118         # decide which motd to send
119         my $motd = "${main::motd}_nor" unless $self->{registered};
120         $motd = $main::motd unless $motd && -e $motd;
121         $self->send_file($motd) if -e $motd;
122
123         # sort out privilege reduction
124         $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
125
126         # get the filters
127         $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'user_default', 0);
128         $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'user_default', 0);
129         $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'user_default', 0);
130         $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'user_default', 0) ;
131
132         # clean up qra locators
133         my $qra = $user->qra;
134         $qra = undef if ($qra && !DXBearing::is_qra($qra));
135         unless ($qra) {
136                 my $lat = $user->lat;
137                 my $long = $user->long;
138                 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);  
139         }
140
141         # decide on echo
142         my $echo = $user->wantecho;
143         unless ($echo) {
144                 $self->send_now('E', "0");
145                 $self->send($self->msg('echow'));
146                 $self->conn->echo($echo) if $self->conn->can('echo');
147         }
148         
149         $self->tell_login('loginu');
150         
151         # do we need to send a forward/opernam?
152         my $lastoper = $user->lastoper || 0;
153         my $homenode = $user->homenode || ""; 
154         if ($homenode eq $main::mycall && $lastoper + $DXUser::lastoperinterval < $main::systime) {
155                 run_cmd($main::me, "forward/opernam $call");
156                 $user->lastoper($main::systime);
157         }
158
159         # run a script send the output to the punter
160         my $script = new Script(lc $call) || new Script('user_default');
161         $script->run($self) if $script;
162
163         # send cluster info
164         my $info = Route::cluster();
165         $self->send("Cluster:$info");
166
167         # send prompts and things
168         $self->send($self->msg('namee1')) if !$user->name;
169         $self->send($self->msg('qthe1')) if !$user->qth;
170         $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
171         $self->send($self->msg('hnodee1')) if !$user->qth;
172         $self->send($self->msg('m9')) if DXMsg::for_me($call);
173         $self->prompt;
174 }
175
176 #
177 # This is the normal command prompt driver
178 #
179
180 sub normal
181 {
182         my $self = shift;
183         my $cmdline = shift;
184         my @ans;
185         
186         # remove leading and trailing spaces
187         $cmdline =~ s/^\s*(.*)\s*$/$1/;
188         
189         if ($self->{state} eq 'page') {
190                 my $i = $self->{pagelth};
191                 my $ref = $self->{pagedata};
192                 my $tot = @$ref;
193                 
194                 # abort if we get a line starting in with a
195                 if ($cmdline =~ /^a/io) {
196                         undef $ref;
197                         $i = 0;
198                 }
199         
200                 # send a tranche of data
201                 while ($i-- > 0 && @$ref) {
202                         my $line = shift @$ref;
203                         $line =~ s/\s+$//o;     # why am having to do this? 
204                         $self->send($line);
205                 }
206                 
207                 # reset state if none or else chuck out an intermediate prompt
208                 if ($ref && @$ref) {
209                         $tot -= $self->{pagelth};
210                         $self->send($self->msg('page', $tot));
211                 } else {
212                         $self->state('prompt');
213                 }
214         } elsif ($self->{state} eq 'sysop') {
215                 my $passwd = $self->{user}->passwd;
216                 if ($passwd) {
217                         my @pw = grep {$_ !~ /\s/} split //, $passwd;
218                         my @l = @{$self->{passwd}};
219                         my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
220                         if ($cmdline =~ /$str/) {
221                                 $self->{priv} = $self->{user}->priv;
222                         } else {
223                                 $self->send($self->msg('sorry'));
224                         }
225                 } else {
226                         $self->send($self->msg('sorry'));
227                 }
228                 $self->state('prompt');
229         } elsif ($self->{state} eq 'passwd') {
230                 my $passwd = $self->{user}->passwd;
231                 if ($passwd && $cmdline eq $passwd) {
232                         $self->send($self->msg('pw1'));
233                         $self->state('passwd1');
234                 } else {
235                         $self->conn->{echo} = $self->conn->{decho};
236                         delete $self->conn->{decho};
237                         $self->send($self->msg('sorry'));
238                         $self->state('prompt');
239                 }
240         } elsif ($self->{state} eq 'passwd1') {
241                 $self->{passwd} = $cmdline;
242                 $self->send($self->msg('pw2'));
243                 $self->state('passwd2');
244         } elsif ($self->{state} eq 'passwd2') {
245                 if ($cmdline eq $self->{passwd}) {
246                         $self->{user}->passwd($cmdline);
247                         $self->send($self->msg('pw3'));
248                 } else {
249                         $self->send($self->msg('pw4'));
250                 }
251                 $self->conn->{echo} = $self->conn->{decho};
252                 delete $self->conn->{decho};
253                 $self->state('prompt');
254         } elsif ($self->{state} eq 'talk') {
255                 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
256                         for (@{$self->{talklist}}) {
257                                 $self->send_talks($_,  $self->msg('talkend'));
258                         }
259                         $self->state('prompt');
260                         delete $self->{talklist};
261                 } elsif ($cmdline =~ m(^/\w+)) {
262                         $cmdline =~ s(^/)();
263                         $self->send_ans(run_cmd($self, $cmdline));
264                         $self->send($self->talk_prompt);
265                 } elsif ($self->{talklist} && @{$self->{talklist}}) {
266                         # send what has been said to whoever is in this person's talk list
267                         my @bad;
268                         if (@bad = BadWords::check($cmdline)) {
269                                 $self->badcount(($self->badcount||0) + @bad);
270                                 Log('DXCommand', "$self->{call} swore: $cmdline");
271                         } else {
272                                 for (@{$self->{talklist}}) {
273                                         $self->send_talks($_, $cmdline);
274                                 }
275                         }
276                         $self->send($self->talk_prompt) if $self->{state} eq 'talk';
277                 } else {
278                         # for safety
279                         $self->state('prompt');
280                 }
281         } elsif (my $func = $self->{func}) {
282                 no strict 'refs';
283                 my @ans;
284                 if (ref $self->{edit}) {
285                         eval { @ans = $self->{edit}->$func($self, $cmdline)};
286                 } else {
287                         eval {  @ans = &{$self->{func}}($self, $cmdline) };
288                 }
289                 if ($@) {
290                         $self->send_ans("Syserr: on stored func $self->{func}", $@);
291                         delete $self->{func};
292                         $self->state('prompt');
293                         undef $@;
294                 }
295                 $self->send_ans(@ans);
296         } else {
297                 $self->send_ans(run_cmd($self, $cmdline));
298         } 
299
300         # check for excessive swearing
301         if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
302                 Log('DXCommand', "$self->{call} logged out for excessive swearing");
303                 $self->disconnect;
304                 return;
305         }
306
307         # send a prompt only if we are in a prompt state
308         $self->prompt() if $self->{state} =~ /^prompt/o;
309 }
310
311 # send out the talk messages taking into account vias and connectivity
312 sub send_talks
313 {
314         my ($self, $ent, $line) = @_;
315         
316         my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
317         $to = $ent unless $to;
318         my $call = $via ? $via : $to;
319         my $clref = Route::get($call);
320         my $dxchan = $clref->dxchan if $clref;
321         if ($dxchan) {
322                 $dxchan->talk($self->{call}, $to, $via, $line);
323         } else {
324                 $self->send($self->msg('disc2', $via ? $via : $to));
325                 my @l = grep { $_ ne $ent } @{$self->{talklist}};
326                 if (@l) {
327                         $self->{talklist} = \@l;
328                 } else {
329                         delete $self->{talklist};
330                         $self->state('prompt');
331                 }
332         }
333 }
334
335 sub talk_prompt
336 {
337         my $self = shift;
338         my @call;
339         for (@{$self->{talklist}}) {
340                 my ($to, $via) = /(\S+)>(\S+)/;
341                 $to = $_ unless $to;
342                 push @call, $to;
343         }
344         return $self->msg('talkprompt', join(',', @call));
345 }
346
347 #
348 # send a load of stuff to a command user with page prompting
349 # and stuff
350 #
351
352 sub send_ans
353 {
354         my $self = shift;
355         
356         if ($self->{pagelth} && @_ > $self->{pagelth}) {
357                 my $i;
358                 for ($i = $self->{pagelth}; $i-- > 0; ) {
359                         my $line = shift @_;
360                         $line =~ s/\s+$//o;     # why am having to do this? 
361                         $self->send($line);
362                 }
363                 $self->{pagedata} =  [ @_ ];
364                 $self->state('page');
365                 $self->send($self->msg('page', scalar @_));
366         } else {
367                 for (@_) {
368                         if (defined $_) {
369                                 $self->send($_);
370                         } else {
371                                 $self->send('');
372                         }
373                 }
374         } 
375 }
376
377 # this is the thing that runs the command, it is done like this for the 
378 # benefit of remote command execution
379 #
380
381 sub run_cmd
382 {
383         my $self = shift;
384         my $user = $self->{user};
385         my $call = $self->{call};
386         my $cmdline = shift;
387         my @ans;
388         
389
390         return () if length $cmdline == 0;
391                 
392         # strip out //
393         $cmdline =~ s|//|/|og;
394                 
395         # split the command line up into parts, the first part is the command
396         my ($cmd, $args) = split /\s+/, $cmdline, 2;
397         $args = "" unless defined $args;
398                 
399         if ($cmd) {
400                         
401                 my ($path, $fcmd);
402                         
403                 dbg("cmd: $cmd") if isdbg('command');
404                         
405                 # alias it if possible
406                 my $acmd = CmdAlias::get_cmd($cmd);
407                 if ($acmd) {
408                         ($cmd, $args) = split /\s+/, "$acmd $args", 2;
409                         $args = "" unless defined $args;
410                         dbg("aliased cmd: $cmd $args") if isdbg('command');
411                 }
412                         
413                 # first expand out the entry to a command
414                 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
415                 ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd;
416
417                 if ($path && $cmd) {
418                         dbg("path: $cmd cmd: $fcmd") if isdbg('command');
419                         
420                         my $package = find_cmd_name($path, $fcmd);
421                         return ($@) if $@;
422                                 
423                         if ($package) {
424                                 no strict 'refs';
425                                 dbg("package: $package") if isdbg('command');
426                                 eval { @ans = &$package($self, $args) };
427                                 return (DXDebug::shortmess($@)) if $@;
428                         }
429                 } else {
430                         dbg("cmd: $cmd not found") if isdbg('command');
431                         if (++$self->{errors} > $maxerrors) {
432                                 $self->send($self->msg('e26'));
433                                 $self->disconnect;
434                                 return ();
435                         } else {
436                                 return ($self->msg('e1'));
437                         }
438                 }
439         }
440         
441         my $ok = shift @ans;
442         if ($ok) {
443                 delete $self->{errors};
444         } else {
445                 if (++$self->{errors} > $maxerrors) {
446                         $self->send($self->msg('e26'));
447                         $self->disconnect;
448                         return ();
449                 }
450         }
451         return (@ans);
452 }
453
454 #
455 # This is called from inside the main cluster processing loop and is used
456 # for despatching commands that are doing some long processing job
457 #
458 sub process
459 {
460         my $t = time;
461         my @dxchan = DXChannel->get_all();
462         my $dxchan;
463         
464         foreach $dxchan (@dxchan) {
465                 next if $dxchan->sort ne 'U';  
466                 
467                 # send a prompt if no activity out on this channel
468                 if ($t >= $dxchan->t + $main::user_interval) {
469                         $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
470                         $dxchan->t($t);
471                 }
472         }
473
474         while (my ($k, $v) = each %nothereslug) {
475                 if ($main::systime >= $v + 300) {
476                         delete $nothereslug{$k};
477                 }
478         }
479 }
480
481 #
482 # finish up a user context
483 #
484 sub disconnect
485 {
486         my $self = shift;
487         my $call = $self->call;
488
489         return if $self->{disconnecting}++;
490
491         delete $self->{senddbg};
492
493         my $uref = Route::User::get($call);
494         my @rout;
495         if ($uref) {
496                 @rout = $main::routeroot->del_user($uref);
497                 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
498         } else {
499                 confess "trying to disconnect a non existant user $call";
500         }
501
502         # issue a pc17 to everybody interested
503         DXProt::route_pc17($main::me, $main::routeroot, @rout) if @rout;
504
505         # I was the last node visited
506     $self->user->node($main::mycall);
507                 
508         # send info to all logged in thingies
509         $self->tell_login('logoutu');
510
511         Log('DXCommand', "$call disconnected");
512
513         $self->SUPER::disconnect;
514 }
515
516 #
517 # short cut to output a prompt
518 #
519
520 sub prompt
521 {
522         my $self = shift;
523         $self->send($self->msg($self->here ? 'pr' : 'pr2', $self->call, cldate($main::systime), ztime($main::systime)));
524 }
525
526 # broadcast a message to all users [except those mentioned after buffer]
527 sub broadcast
528 {
529         my $pkg = shift;                        # ignored
530         my $s = shift;                          # the line to be rebroadcast
531         
532     foreach my $dxchan (DXChannel->get_all()) {
533                 next unless $dxchan->{sort} eq 'U'; # only interested in user channels  
534                 next if grep $dxchan == $_, @_;
535                 $dxchan->send($s);                      # send it
536         }
537 }
538
539 # gimme all the users
540 sub get_all
541 {
542         return grep {$_->{sort} eq 'U'} DXChannel->get_all();
543 }
544
545 # run a script for this user
546 sub run_script
547 {
548         my $self = shift;
549         my $silent = shift || 0;
550         
551 }
552
553 #
554 # search for the command in the cache of short->long form commands
555 #
556
557 sub search
558 {
559         my ($path, $short_cmd, $suffix) = @_;
560         my ($apath, $acmd);
561         
562         # commands are lower case
563         $short_cmd = lc $short_cmd;
564         dbg("command: $path $short_cmd\n") if isdbg('command');
565
566         # do some checking for funny characters
567         return () if $short_cmd =~ /\/$/;
568
569         # return immediately if we have it
570         ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
571         if ($apath && $acmd) {
572                 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
573                 return ($apath, $acmd);
574         }
575         
576         # if not guess
577         my @parts = split '/', $short_cmd;
578         my $dirfn;
579         my $curdir = $path;
580         my $p;
581         my $i;
582         my @lparts;
583         
584         for ($i = 0; $i < @parts; $i++) {
585                 my  $p = $parts[$i];
586                 opendir(D, $curdir) or confess "can't open $curdir $!";
587                 my @ls = readdir D;
588                 closedir D;
589                 my $l;
590                 foreach $l (sort @ls) {
591                         next if $l =~ /^\./;
592                         if ($i < $#parts) {             # we are dealing with directories
593                                 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
594                                         dbg("got dir: $curdir/$l\n") if isdbg('command');
595                                         $dirfn .= "$l/";
596                                         $curdir .= "/$l";
597                                         last;
598                                 }
599                         } else {                        # we are dealing with commands
600                                 @lparts = split /\./, $l;                  
601                                 next if $lparts[$#lparts] ne $suffix;        # only look for .$suffix files
602                                 if ($p eq substr($l, 0, length $p)) {
603                                         pop @lparts; #  remove the suffix
604                                         $l = join '.', @lparts;
605                                         #                 chop $dirfn;               # remove trailing /
606                                         $dirfn = "" unless $dirfn;
607                                         $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
608                                         dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
609                                         return ($path, "$dirfn$l"); 
610                                 }
611                         }
612                 }
613         }
614         return ();  
615 }  
616
617 # clear the command name cache
618 sub clear_cmd_cache
619 {
620         no strict 'refs';
621         
622         for (keys %Cache) {
623                 undef *{$_};
624                 dbg("Undefining cmd $_") if isdbg('command');
625         }
626         %cmd_cache = ();
627         %Cache = ();
628 }
629
630 #
631 # the persistant execution of things from the command directories
632 #
633 #
634 # This allows perl programs to call functions dynamically
635
636 # This has been nicked directly from the perlembed pages
637 #
638
639 #require Devel::Symdump;  
640
641 sub valid_package_name {
642         my($string) = @_;
643         $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
644         
645         $string =~ s|/|_|g;
646         return "cmd_$string";
647 }
648
649
650 # this bit of magic finds a command in the offered directory
651 sub find_cmd_name {
652         my $path = shift;
653         my $cmdname = shift;
654         my $package = valid_package_name($cmdname);
655         my $filename = "$path/$cmdname.pl";
656         my $mtime = -M $filename;
657         
658         # return if we can't find it
659         $errstr = undef;
660         unless (defined $mtime) {
661                 $errstr = DXM::msg('e1');
662                 return undef;
663         }
664         
665         if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
666                 #we have compiled this subroutine already,
667                 #it has not been updated on disk, nothing left to do
668                 #print STDERR "already compiled $package->handler\n";
669                 ;
670         } else {
671
672                 my $sub = readfilestr($filename);
673                 unless ($sub) {
674                         $errstr = "Syserr: can't open '$filename' $!";
675                         return undef;
676                 };
677                 
678                 #wrap the code into a subroutine inside our unique package
679                 my $eval = qq( sub $package { $sub } );
680                 
681                 if (isdbg('eval')) {
682                         my @list = split /\n/, $eval;
683                         my $line;
684                         for (@list) {
685                                 dbg($_ . "\n") if isdbg('eval');
686                         }
687                 }
688                 
689                 # get rid of any existing sub and try to compile the new one
690                 no strict 'refs';
691
692                 if (exists $Cache{$package}) {
693                         dbg("Redefining $package") if isdbg('command');
694                         undef *$package;
695                 } else {
696                         dbg("Defining $package") if isdbg('command');
697                 }
698                 eval $eval;
699                 
700                 $Cache{$package} = {mtime => $mtime };
701             
702         }
703
704         return $package;
705 }
706
707 sub local_send
708 {
709         my ($self, $let, $buf) = @_;
710         if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
711                 if ($self->{enhanced}) {
712                         $self->send_later($let, $buf);
713                 } else {
714                         $self->send($buf);
715                 }
716         } else {
717                 $self->delay($buf);
718         }
719 }
720
721 # send a talk message here
722 sub talk
723 {
724         my ($self, $from, $to, $via, $line) = @_;
725         $line =~ s/\\5E/\^/g;
726         $self->local_send('T', "$to de $from: $line") if $self->{talk};
727         Log('talk', $to, $from, $via?$via:$main::mycall, $line);
728         # send a 'not here' message if required
729         unless ($self->{here} && $from ne $to) {
730                 my $key = "$to$from";
731                 unless (exists $nothereslug{$key}) {
732                         my ($ref, $dxchan);
733                         if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
734                                 my $name = $self->user->name || $to;
735                                 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
736                                 $nothereslug{$key} = $main::systime;
737                                 $dxchan->talk($to, $from, undef, $s);
738                         }
739                 }
740         }
741 }
742
743 # send an announce
744 sub announce
745 {
746         my $self = shift;
747         my $line = shift;
748         my $isolate = shift;
749         my $to = shift;
750         my $target = shift;
751         my $text = shift;
752         my ($filter, $hops);
753
754         if (!$self->{ann_talk} && $to ne $self->{call}) {
755                 my $call = AnnTalk::is_talk_candidate($_[0], $text);
756                 return if $call;
757         }
758
759         if ($self->{annfilter}) {
760                 ($filter, $hops) = $self->{annfilter}->it(@_ );
761                 return unless $filter;
762         }
763
764         unless ($self->{ann}) {
765                 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
766         }
767         return if $target eq 'SYSOP' && $self->{priv} < 5;
768         my $buf = "$to$target de $_[0]: $text";
769         $buf =~ s/\%5E/^/g;
770         $buf .= "\a\a" if $self->{beep};
771         $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
772 }
773
774 # send a dx spot
775 sub dx_spot
776 {
777         my $self = shift;
778         my $line = shift;
779         my $isolate = shift;
780         my ($filter, $hops);
781
782         return unless $self->{dx};
783         
784         if ($self->{spotsfilter}) {
785                 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
786                 return unless $filter;
787         }
788
789         my $buf = Spot::formatb($self->{user}->wantgrid, $_[0], $_[1], $_[2], $_[3], $_[4]);
790         $buf .= "\a\a" if $self->{beep};
791         $buf =~ s/\%5E/^/g;
792         $self->local_send('X', $buf);
793 }
794
795 sub wwv
796 {
797         my $self = shift;
798         my $line = shift;
799         my $isolate = shift;
800         my ($filter, $hops);
801
802         return unless $self->{wwv};
803         
804         if ($self->{wwvfilter}) {
805                 ($filter, $hops) = $self->{wwvfilter}->it(@_ );
806                 return unless $filter;
807         }
808
809         my $buf = "WWV de $_[6] <$_[1]>:   SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
810         $buf .= "\a\a" if $self->{beep};
811         $self->local_send('V', $buf);
812 }
813
814 sub wcy
815 {
816         my $self = shift;
817         my $line = shift;
818         my $isolate = shift;
819         my ($filter, $hops);
820
821         return unless $self->{wcy};
822         
823         if ($self->{wcyfilter}) {
824                 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
825                 return unless $filter;
826         }
827
828         my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
829         $buf .= "\a\a" if $self->{beep};
830         $self->local_send('Y', $buf);
831 }
832
833 # broadcast debug stuff to all interested parties
834 sub broadcast_debug
835 {
836         my $s = shift;                          # the line to be rebroadcast
837         
838         foreach my $dxchan (DXChannel->get_all) {
839                 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
840                 $dxchan->send_later('L', $s);
841         }
842 }
843
844
845 1;
846 __END__