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