aaa070480ac3808b65f8dab29ce342b42ae06f06
[spider.git] / perl / DXProt.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the protocal mode for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8
9
10 package DXProt;
11
12 @ISA = qw(DXChannel);
13
14 use DXUtil;
15 use DXChannel;
16 use DXUser;
17 use DXM;
18 use DXProtVars;
19 use DXCommandmode;
20 use DXLog;
21 use Spot;
22 use DXProtout;
23 use DXDebug;
24 use Filter;
25 use Local;
26 use DXDb;
27 use AnnTalk;
28 use Geomag;
29 use WCY;
30 use BadWords;
31 use DXHash;
32 use Route;
33 use Route::Node;
34 use Script;
35 use Investigate;
36 use RouteDB;
37 use DXProtHandle;
38
39 use strict;
40
41 use vars qw($VERSION $BRANCH);
42 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
43 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
44 $main::build += $VERSION;
45 $main::branch += $BRANCH;
46
47 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
48                         $last_hour $last10 %eph  %pings %rcmds $ann_to_talk
49                         $pingint $obscount %pc19list $chatdupeage $chatimportfn
50                         $investigation_int $pc19_version $myprot_version
51                         %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
52                         $allowzero $decode_dk0wcy $send_opernam @checklist
53                         $eph_pc15_restime $pc92_update_period $last_pc92_update
54                    );
55
56 $pc11_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc11
57 $pc23_max_age = 1*3600;                 # the maximum age for an incoming 'real-time' pc23
58
59 $last_hour = time;                              # last time I did an hourly periodic update
60 %rcmds = ();                    # outstanding rcmd requests outbound
61 %nodehops = ();                 # node specific hop control
62 %pc19list = ();                                 # list of outstanding PC19s that haven't had PC16s on them
63
64 $censorpc = 1;                                  # Do a BadWords::check on text fields and reject things
65                                                                 # loads of 'bad things'
66 $baddx = new DXHash "baddx";
67 $badspotter = new DXHash "badspotter";
68 $badnode = new DXHash "badnode";
69 $last10 = $last_pc50 = time;
70 $ann_to_talk = 1;
71 $rspfcheck = 1;
72 $eph_restime = 180;
73 $eph_info_restime = 60*60;
74 $eph_pc15_restime = 6*60;
75 $eph_pc34_restime = 30;
76 $pingint = 5*60;
77 $obscount = 2;
78 $chatdupeage = 20 * 60 * 60;
79 $chatimportfn = "$main::root/chat_import";
80 $investigation_int = 12*60*60;  # time between checks to see if we can see this node
81 $pc19_version = 5466;                   # the visible version no for outgoing PC19s generated from pc59
82 $pc92_update_period = 60*60;    # the period between PC92 C updates
83 $last_pc92_update = time;               # the last time a PC92 config update
84
85
86 @checklist = 
87 (
88  [ qw(i c c m bp bc c) ],                       # pc10
89  [ qw(i f m d t m c c h) ],             # pc11
90  [ qw(i c bm m bm bm p h) ],            # pc12
91  [ qw(i c h) ],                                 # 
92  [ qw(i c h) ],                                 # 
93  [ qw(i c m h) ],                                       # 
94  undef ,                                                # pc16 has to be validated manually
95  [ qw(i c c h) ],                                       # pc17
96  [ qw(i m n) ],                                 # pc18
97  undef ,                                                # pc19 has to be validated manually
98  undef ,                                                # pc20 no validation
99  [ qw(i c m h) ],                                       # pc21
100  undef ,                                                # pc22 no validation
101  [ qw(i d n n n n m c c h) ],           # pc23
102  [ qw(i c p h) ],                                       # pc24
103  [ qw(i c c n n) ],                             # pc25
104  [ qw(i f m d t m c c bc) ],            # pc26
105  [ qw(i d n n n n m c c bc) ],  # pc27
106  [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
107  [ qw(i c c n m) ],                             # pc29
108  [ qw(i c c n) ],                                       # pc30
109  [ qw(i c c n) ],                                       # pc31
110  [ qw(i c c n) ],                                       # pc32
111  [ qw(i c c n) ],                                       # pc33
112  [ qw(i c c m) ],                                       # pc34
113  [ qw(i c c m) ],                                       # pc35
114  [ qw(i c c m) ],                                       # pc36
115  [ qw(i c c n m) ],                             # pc37
116  undef,                                                 # pc38 not interested
117  [ qw(i c m) ],                                 # pc39
118  [ qw(i c c m p n) ],                           # pc40
119  [ qw(i c n m h) ],                             # pc41
120  [ qw(i c c n) ],                                       # pc42
121  undef,                                                 # pc43 don't handle it
122  [ qw(i c c n m m c) ],                 # pc44
123  [ qw(i c c n m) ],                             # pc45
124  [ qw(i c c n) ],                                       # pc46
125  undef,                                                 # pc47
126  undef,                                                 # pc48
127  [ qw(i c m h) ],                                       # pc49
128  [ qw(i c n h) ],                                       # pc50
129  [ qw(i c c n) ],                                       # pc51
130  undef,
131  undef,
132  undef,
133  undef,
134  undef,
135  undef,
136  undef,
137  undef,
138  undef,                                                 # pc60
139  undef,
140  undef,
141  undef,
142  undef,
143  undef,
144  undef,
145  undef,
146  undef,
147  undef,
148  undef,                                                 # pc70
149  undef,
150  undef,
151  [ qw(i d n n n n n n m m m c c h) ],   # pc73
152  undef,
153  undef,
154  undef,
155  undef,
156  undef,
157  undef,
158  undef,                                                 # pc80
159  undef,
160  undef,
161  undef,
162  [ qw(i c c c m) ],                             # pc84
163  [ qw(i c c c m) ],                             # pc85
164  undef,
165  undef,
166  undef,
167  undef,
168  [ qw(i c n) ],                                 # pc90
169 );
170
171 # use the entry in the check list to check the field list presented
172 # return OK if line NOT in check list (for now)
173 sub check
174 {
175         my $n = shift;
176         $n -= 10;
177         return 0 if $n < 0 || $n > @checklist; 
178         my $ref = $checklist[$n];
179         return 0 unless ref $ref;
180         
181         my $i;
182         for ($i = 1; $i < @$ref; $i++) {
183                 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
184                 return 0 unless $act;
185                 next if $blank && $_[$i] =~ /^[ \*]$/;
186                 if ($act eq 'c') {
187                         return $i unless is_callsign($_[$i]);
188                 } elsif ($act eq 'i') {                 
189                         ;                                       # do nothing
190                 } elsif ($act eq 'm') {
191                         return $i unless is_pctext($_[$i]);
192                 } elsif ($act eq 'p') {
193                         return $i unless is_pcflag($_[$i]);
194                 } elsif ($act eq 'f') {
195                         return $i unless is_freq($_[$i]);
196                 } elsif ($act eq 'n') {
197                         return $i unless $_[$i] =~ /^[\d ]+$/;
198                 } elsif ($act eq 'h') {
199                         return $i unless $_[$i] =~ /^H\d\d?$/;
200                 } elsif ($act eq 'd') {
201                         return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
202                 } elsif ($act eq 't') {
203                         return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
204                 } 
205         }
206         return 0;
207 }
208
209 sub init
210 {
211         do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
212         confess $@ if $@;
213
214         my $user = DXUser->get($main::mycall);
215         die "User $main::mycall not setup or disappeared RTFM" unless $user;
216         
217         $myprot_version += $main::version*100;
218         $main::me = DXProt->new($main::mycall, 0, $user); 
219         $main::me->{here} = 1;
220         $main::me->{state} = "indifferent";
221         $main::me->{sort} = 'S';    # S for spider
222         $main::me->{priv} = 9;
223         $main::me->{metric} = 0;
224         $main::me->{pingave} = 0;
225         $main::me->{registered} = 1;
226         $main::me->{version} = $main::version;
227         $main::me->{build} = $main::build;
228 }
229
230 #
231 # obtain a new connection this is derived from dxchannel
232 #
233
234 sub new 
235 {
236         my $self = DXChannel::alloc(@_);
237
238         # add this node to the table, the values get filled in later
239         my $pkg = shift;
240         my $call = shift;
241         $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
242
243         return $self;
244 }
245
246 # this is how a pc connection starts (for an incoming connection)
247 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
248 # all the crap that comes between).
249 sub start
250 {
251         my ($self, $line, $sort) = @_;
252         my $call = $self->{call};
253         my $user = $self->{user};
254
255         # log it
256         my $host = $self->{conn}->{peerhost};
257         $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
258         $host ||= "unknown";
259
260         Log('DXProt', "$call connected from $host");
261         
262         # remember type of connection
263         $self->{consort} = $line;
264         $self->{outbound} = $sort eq 'O';
265         my $priv = $user->priv;
266         $priv = $user->priv(1) unless $priv;
267         $self->{priv} = $priv;     # other clusters can always be 'normal' users
268         $self->{lang} = $user->lang || 'en';
269         $self->{isolate} = $user->{isolate};
270         $self->{consort} = $line;       # save the connection type
271         $self->{here} = 1;
272         $self->{width} = 80;
273
274         # sort out registration
275         $self->{registered} = 1;
276
277         # get the output filters
278         $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
279         $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
280         $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
281         $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
282         $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
283
284
285         # get the INPUT filters (these only pertain to Clusters)
286         $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
287         $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
288         $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
289         $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
290         $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
291         
292         # set unbuffered and no echo
293         $self->send_now('B',"0");
294         $self->send_now('E',"0");
295         $self->conn->echo(0) if $self->conn->can('echo');
296         
297         # ping neighbour node stuff
298         my $ping = $user->pingint;
299         $ping = $pingint unless defined $ping;
300         $self->{pingint} = $ping;
301         $self->{nopings} = $user->nopings || $obscount;
302         $self->{pingtime} = [ ];
303         $self->{pingave} = 999;
304         $self->{metric} ||= 100;
305         $self->{lastping} = $main::systime;
306         
307         # send initialisation string
308         unless ($self->{outbound}) {
309                 $self->sendinit;
310         }
311         
312         $self->state('init');
313         $self->{pc50_t} = $main::systime;
314
315         # send info to all logged in thingies
316         $self->tell_login('loginn');
317
318         # run a script send the output to the debug file
319         my $script = new Script(lc $call) || new Script('node_default');
320         $script->run($self) if $script;
321 }
322
323 #
324 # send outgoing 'challenge'
325 #
326
327 sub sendinit
328 {
329         my $self = shift;
330         $self->send(pc18());
331 }
332
333 #
334 # This is the normal pcxx despatcher
335 #
336 sub normal
337 {
338         my ($self, $line) = @_;
339
340         if ($line =~ '^<\w+\s' && $main::do_xml) {
341                 DXXml::normal($self, $line);
342                 return;
343         }
344
345         my @field = split /\^/, $line;
346         return unless @field;
347         
348         pop @field if $field[-1] eq '~';
349         
350 #       print join(',', @field), "\n";
351                                                 
352         
353         # process PC frames, this will fail unless the frame starts PCnn
354         my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
355         unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
356                 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
357                 return;
358         }
359
360         # check for and dump bad protocol messages
361         my $n = check($pcno, @field);
362         if ($n) {
363                 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
364                 return;
365         }
366
367         # modify the hop count here
368         if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
369                 $trail ||= '';
370                 $hops--;
371                 return if $hops < 0;
372                 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
373                 $field[-1] = "H$hops";
374         }
375
376         # send it out for processing
377         my $origin = $self->{call};
378         no strict 'subs';
379         my $sub = "handle_$pcno";
380
381         if ($self->can($sub)) {
382                 $self->$sub($pcno, $line, $origin, @field);
383         } else {
384                 $self->handle_default($pcno, $line, $origin, @field);
385         }
386 }
387
388 #
389 # This is called from inside the main cluster processing loop and is used
390 # for despatching commands that are doing some long processing job
391 #
392 sub process
393 {
394         my $t = time;
395         my @dxchan = DXChannel::get_all();
396         my $dxchan;
397         my $pc50s;
398         
399         # send out a pc50 on EVERY channel all at once
400         if ($t >= $last_pc50 + $DXProt::pc50_interval) {
401                 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
402                 eph_dup($pc50s);
403                 $last_pc50 = $t;
404         }
405
406         foreach $dxchan (@dxchan) {
407                 next unless $dxchan->is_node;
408                 next if $dxchan->handle_xml;
409                 next if $dxchan == $main::me;
410
411                 # send the pc50
412                 $dxchan->send($pc50s) if $pc50s;
413                 
414                 # send a ping out on this channel
415                 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
416                         if ($dxchan->{nopings} <= 0) {
417                                 $dxchan->disconnect;
418                         } else {
419                                 DXXml::Ping::add($main::me, $dxchan->call);
420                                 $dxchan->{nopings} -= 1;
421                                 $dxchan->{lastping} = $t;
422                                 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
423                         }
424                 }
425         }
426
427         Investigate::process();
428
429         # every ten seconds
430         if ($t - $last10 >= 10) {       
431                 # clean out ephemera 
432
433                 eph_clean();
434                 import_chat();
435
436                 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
437                         send_pc92_update();
438                         $last_pc92_update = $main::systime;
439                 }
440                 
441                 $last10 = $t;
442         }
443         
444         if ($main::systime - 3600 > $last_hour) {
445                 $last_hour = $main::systime;
446         }
447 }
448
449 #
450 # finish up a pc context
451 #
452
453 #
454 # some active measures
455 #
456
457
458 sub send_dx_spot
459 {
460         my $self = shift;
461         my $line = shift;
462         my @dxchan = DXChannel::get_all();
463         my $dxchan;
464         
465         # send it if it isn't the except list and isn't isolated and still has a hop count
466         # taking into account filtering and so on
467         foreach $dxchan (@dxchan) {
468                 next if $dxchan == $main::me;
469                 next if $dxchan == $self && $self->is_node;
470                 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
471         }
472 }
473
474 sub dx_spot
475 {
476         my $self = shift;
477         my $line = shift;
478         my $isolate = shift;
479         my ($filter, $hops);
480
481         if ($self->{spotsfilter}) {
482                 ($filter, $hops) = $self->{spotsfilter}->it(@_);
483                 return unless $filter;
484         }
485         send_prot_line($self, $filter, $hops, $isolate, $line);
486 }
487
488 sub send_prot_line
489 {
490         my ($self, $filter, $hops, $isolate, $line) = @_;
491         my $routeit;
492
493
494         if ($hops) {
495                 $routeit = $line;
496                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
497         } else {
498                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
499                 return unless $routeit;
500         }
501         if ($filter) {
502                 $self->send($routeit);
503         } else {
504                 $self->send($routeit) unless $self->{isolate} || $isolate;
505         }
506 }
507
508
509 sub send_wwv_spot
510 {
511         my $self = shift;
512         my $line = shift;
513         my @dxchan = DXChannel::get_all();
514         my $dxchan;
515         my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
516
517         # send it if it isn't the except list and isn't isolated and still has a hop count
518         # taking into account filtering and so on
519         foreach $dxchan (@dxchan) {
520                 next if $dxchan == $main::me;
521                 next if $dxchan == $self && $self->is_node;
522                 my $routeit;
523                 my ($filter, $hops);
524
525                 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
526         }
527 }
528
529 sub wwv
530 {
531         my $self = shift;
532         my $line = shift;
533         my $isolate = shift;
534         my ($filter, $hops);
535         
536         if ($self->{wwvfilter}) {
537                 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
538                 return unless $filter;
539         }
540         send_prot_line($self, $filter, $hops, $isolate, $line)
541 }
542
543 sub send_wcy_spot
544 {
545         my $self = shift;
546         my $line = shift;
547         my @dxchan = DXChannel::get_all();
548         my $dxchan;
549         my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
550         
551         # send it if it isn't the except list and isn't isolated and still has a hop count
552         # taking into account filtering and so on
553         foreach $dxchan (@dxchan) {
554                 next if $dxchan == $main::me;
555                 next if $dxchan == $self;
556
557                 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
558         }
559 }
560
561 sub wcy
562 {
563         my $self = shift;
564         my $line = shift;
565         my $isolate = shift;
566         my ($filter, $hops);
567
568         if ($self->{wcyfilter}) {
569                 ($filter, $hops) = $self->{wcyfilter}->it(@_);
570                 return unless $filter;
571         }
572         send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
573 }
574
575 # send an announce
576 sub send_announce
577 {
578         my $self = shift;
579         my $line = shift;
580         my @dxchan = DXChannel::get_all();
581         my $dxchan;
582         my $target;
583         my $to = 'To ';
584         my $text = unpad($_[2]);
585                                 
586         if ($_[3] eq '*') {     # sysops
587                 $target = "SYSOP";
588         } elsif ($_[3] gt ' ') { # speciality list handling
589                 my ($name) = split /\./, $_[3]; 
590                 $target = "$name"; # put the rest in later (if bothered) 
591         } 
592         
593         if ($_[5] eq '1') {
594                 $target = "WX"; 
595                 $to = '';
596         }
597         $target = "ALL" if !$target;
598
599
600         # obtain country codes etc 
601         my @a = Prefix::cty_data($_[0]);
602         my @b = Prefix::cty_data($_[4]);
603         if ($self->{inannfilter}) {
604                 my ($filter, $hops) = 
605                         $self->{inannfilter}->it(@_, $self->{call}, 
606                                                                          @a[0..2],
607                                                                          @b[0..2], $a[3], $b[3]);
608                 unless ($filter) {
609                         dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
610                         return;
611                 }
612         }
613
614         if (AnnTalk::dup($_[0], $_[1], $_[2])) {
615                 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
616                 return;
617         }
618
619         Log('ann', $target, $_[0], $text);
620
621         # send it if it isn't the except list and isn't isolated and still has a hop count
622         # taking into account filtering and so on
623         foreach $dxchan (@dxchan) {
624                 next if $dxchan == $main::me;
625                 next if $dxchan == $self && $self->is_node;
626                 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
627                                                   @a[0..2], @b[0..2]);
628         }
629 }
630
631 my $msgid = 0;
632
633 sub nextchatmsgid
634 {
635         $msgid++;
636         $msgid = 1 if $msgid > 999;
637         return $msgid;
638 }
639
640 # send a chat line
641 sub send_chat
642 {
643         my $self = shift;
644         my $line = shift;
645         my @dxchan = DXChannel::get_all();
646         my $dxchan;
647         my $target = $_[3];
648         my $text = unpad($_[2]);
649         my $ak1a_line;
650                                 
651         # munge the group and recast the line if required
652         if ($target =~ s/\.LST$//) {
653                 $ak1a_line = $line;
654         }
655         
656         # obtain country codes etc 
657         my @a = Prefix::cty_data($_[0]);
658         my @b = Prefix::cty_data($_[4]);
659         if ($self->{inannfilter}) {
660                 my ($filter, $hops) = 
661                         $self->{inannfilter}->it(@_, $self->{call}, 
662                                                                          @a[0..2],
663                                                                          @b[0..2], $a[3], $b[3]);
664                 unless ($filter) {
665                         dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
666                         return;
667                 }
668         }
669
670         if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
671                 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
672                 return;
673         }
674
675
676         Log('chat', $target, $_[0], $text);
677
678         # send it if it isn't the except list and isn't isolated and still has a hop count
679         # taking into account filtering and so on
680         foreach $dxchan (@dxchan) {
681                 my $is_ak1a = $dxchan->is_ak1a;
682                 
683                 if ($dxchan->is_node) {
684                         next if $dxchan == $main::me;
685                         next if $dxchan == $self;
686                         next unless $dxchan->is_spider || $is_ak1a;
687                         next if $target eq 'LOCAL';
688                         if (!$ak1a_line && $is_ak1a) {
689                                 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
690                         }
691                 }
692                 
693                 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1], 
694                                           $text, @_, $self->{call}, @a[0..2], @b[0..2]);
695         }
696 }
697
698 sub announce
699 {
700         my $self = shift;
701         my $line = shift;
702         my $isolate = shift;
703         my $to = shift;
704         my $target = shift;
705         my $text = shift;
706         my ($filter, $hops);
707
708         if ($self->{annfilter}) {
709                 ($filter, $hops) = $self->{annfilter}->it(@_);
710                 return unless $filter;
711         }
712         send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
713 }
714
715 sub chat
716 {
717         goto &announce;
718 }
719
720
721 sub send_local_config
722 {
723         my $self = shift;
724
725         dbg('DXProt::send_local_config') if isdbg('trace');
726
727         # send our nodes
728         if ($self->{do_pc92}) { 
729                 $self->send_pc92_config;
730         } else {
731                 my $node;
732                 my @nodes;
733                 my @localnodes;
734                 my @remotenodes;
735
736                 if ($self->{isolate}) {
737                         @localnodes = ( $main::routeroot );
738                         $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
739                 } else {
740                         # create a list of all the nodes that are not connected to this connection
741                         # and are not themselves isolated, this to make sure that isolated nodes
742                         # don't appear outside of this node
743
744                         # send locally connected nodes
745                         my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
746                         @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
747                         $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
748
749                         my $node;
750                         my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
751                         my @intcalls;
752                         for $node (@rawintcalls) {
753                                 push @intcalls, $node unless grep $node eq $_, @intcalls; 
754                         }
755                         my $ref = Route::Node::get($self->{call});
756                         my @rnodes = $ref->nodes;
757                         for $node (@intcalls) {
758                                 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
759                         }
760                         $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
761                 }
762         
763                 # get all the users connected on the above nodes and send them out
764                 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
765                         if ($node) {
766                                 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
767                                 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
768                         } else {
769                                 dbg("sent a null value") if isdbg('chanerr');
770                         }
771                 }
772         }
773 }
774
775 sub gen_pc92_update
776 {
777         my $self = shift;
778         my $with_pc92_nodes = shift;
779         my $node;
780         my @lines;
781         
782         dbg('DXProt::send_pc92_update') if isdbg('trace');
783
784         # send 'my' configuration for all users and pc92 capable nodes
785         my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
786         my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
787 #       push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
788         push @lines, pc92c($main::routeroot, @localnodes);
789
790
791         if ($with_pc92_nodes) {
792                 # send out the configuration of all the PC92 nodes with current configuration
793                 # but with the dates that the last config came in with.
794                 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc92} } DXChannel::get_all_nodes();
795                 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
796                 foreach $node (@localnodes) {
797                         if ($node && $node->lastid->{92}) {
798                                 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
799                                 push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
800                         }
801                 }
802         }
803         
804         # send the configuration of all the 'external' nodes that don't handle PC92
805         # out with the 'external' marker on the first node.
806         @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
807         @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
808         foreach $node (@localnodes) {
809                 if ($node) {
810                         my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
811                         push @lines, pc92c($node, @rout);
812                 } 
813         }
814         return @lines;
815 }
816
817
818 sub send_pc92_config
819 {
820         my $self = shift;
821
822         dbg('DXProt::send_pc92_config') if isdbg('trace');
823
824         my @out = $self->gen_pc92_update(1);
825         
826         # send the complete config out on this interface
827         for (@out) {
828                 $self->send($_);
829         }
830
831
832 sub send_pc92_update
833 {
834         my @out = $main::me->gen_pc92_update(0);
835         
836         # broadcast the lines to all PC92 nodes
837         for (@out) {
838                 $main::me->broadcast_route_pc9x('', undef, $_, 0);
839         }
840
841
842 #
843 # route a message down an appropriate interface for a callsign
844 #
845 # is called route(to, pcline);
846 #
847
848 sub route
849 {
850         my ($self, $call, $line) = @_;
851
852         if (ref $self && $call eq $self->{call}) {
853                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
854                 return;
855         }
856
857         # always send it down the local interface if available
858         my $dxchan = DXChannel::get($call);
859         if ($dxchan) {
860                 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
861         } else {
862                 my $cl = Route::get($call);
863                 $dxchan = $cl->dxchan if $cl;
864                 if (ref $dxchan) {
865                         if (ref $self && $dxchan eq $self) {
866                                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
867                                 return;
868                         }
869                         dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
870                 }
871         }
872
873         # try the backstop method
874         unless ($dxchan) {
875                 my $rcall = RouteDB::get($call);
876                 if ($rcall) {
877                         if ($self && $rcall eq $self->{call}) {
878                                 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
879                                 return;
880                         }
881                         $dxchan = DXChannel::get($rcall);
882                         dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
883                 }
884         }
885
886         if ($dxchan) {
887                 my $routeit = adjust_hops($dxchan, $line);   # adjust its hop count by node name
888                 if ($routeit) {
889                         $dxchan->send($routeit) unless $dxchan == $main::me;
890                 }
891         } else {
892                 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
893         }
894 }
895
896 #
897 # obtain the hops from the list for this callsign and pc no 
898 #
899
900 sub get_hops
901 {
902         my $pcno = shift;
903         my $hops = $DXProt::hopcount{$pcno};
904         $hops = $DXProt::def_hopcount if !$hops;
905         return "H$hops";       
906 }
907
908
909 # adjust the hop count on a per node basis using the user loadable 
910 # hop table if available or else decrement an existing one
911 #
912
913 sub adjust_hops
914 {
915         my $self = shift;
916         my $s = shift;
917         my $call = $self->{call};
918         my $hops;
919         
920         if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
921                 my ($pcno) = $s =~ /^PC(\d\d)/o;
922                 confess "$call called adjust_hops with '$s'" unless $pcno;
923                 my $ref = $nodehops{$call} if %nodehops;
924                 if ($ref) {
925                         my $newhops = $ref->{$pcno};
926                         return "" if defined $newhops && $newhops == 0;
927                         $newhops = $ref->{default} unless $newhops;
928                         return "" if defined $newhops && $newhops == 0;
929                         $newhops = $hops if !$newhops;
930                         $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
931                 }
932         }
933         return $s;
934 }
935
936
937 # load hop tables
938 #
939 sub load_hops
940 {
941         my $self = shift;
942         return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
943         do "$main::data/hop_table.pl";
944         return $@ if $@;
945         return ();
946 }
947
948 sub process_rcmd
949 {
950         my ($self, $tonode, $fromnode, $user, $cmd) = @_;
951         if ($tonode eq $main::mycall) {
952                 my $ref = DXUser->get_current($fromnode);
953                 my $cref = Route::Node::get($fromnode);
954                 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
955                 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
956                         if ($ref->{priv}) {             # you have to have SOME privilege, the commands have further filtering
957                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
958                                 my $oldpriv = $self->{priv};
959                                 $self->{priv} = $ref->{priv}; # assume the user's privilege level
960                                 my @in = (DXCommandmode::run_cmd($self, $cmd));
961                                 $self->{priv} = $oldpriv;
962                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
963                                 delete $self->{remotecmd};
964                         } else {
965                                 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
966                         }
967                 } else {
968                         $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
969                 }
970         } else {
971                 my $ref = DXUser->get_current($tonode);
972                 if ($ref && $ref->is_clx) {
973                         $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
974                 } else {
975                         $self->route($tonode, pc34($fromnode, $tonode, $cmd));
976                 }
977         }
978 }
979
980 sub process_rcmd_reply
981 {
982         my ($self, $tonode, $fromnode, $user, $line) = @_;
983         if ($tonode eq $main::mycall) {
984                 my $s = $rcmds{$fromnode};
985                 if ($s) {
986                         my $dxchan = DXChannel::get($s->{call});
987                         my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
988                         $ref->send($line) if $ref;
989                         delete $rcmds{$fromnode} if !$dxchan;
990                 } else {
991                         # send unsolicited ones to the sysop
992                         my $dxchan = DXChannel::get($main::myalias);
993                         $dxchan->send($line) if $dxchan;
994                 }
995         } else {
996                 my $ref = DXUser->get_current($tonode);
997                 if ($ref && $ref->is_clx) {
998                         $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
999                 } else {
1000                         $self->route($tonode, pc35($fromnode, $tonode, $line));
1001                 }
1002         }
1003 }
1004
1005 sub send_rcmd_reply
1006 {
1007         my $self = shift;
1008         my $tonode = shift;
1009         my $fromnode = shift;
1010         my $user = shift;
1011         while (@_) {
1012                 my $line = shift;
1013                 $line =~ s/\s*$//;
1014                 Log('rcmd', 'out', $fromnode, $line);
1015                 if ($self->is_clx) {
1016                         $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1017                 } else {
1018                         $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1019                 }
1020         }
1021 }
1022
1023 # add a rcmd request to the rcmd queues
1024 sub addrcmd
1025 {
1026         my ($self, $to, $cmd) = @_;
1027
1028         my $r = {};
1029         $r->{call} = $self->{call};
1030         $r->{t} = $main::systime;
1031         $r->{cmd} = $cmd;
1032         $rcmds{$to} = $r;
1033         
1034         my $ref = Route::Node::get($to);
1035         my $dxchan = $ref->dxchan;
1036         if ($dxchan && $dxchan->is_clx) {
1037                 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1038         } else {
1039                 route(undef, $to, pc34($main::mycall, $to, $cmd));
1040         }
1041 }
1042
1043 sub disconnect
1044 {
1045         my $self = shift;
1046         my $pc39flag = shift;
1047         my $call = $self->call;
1048
1049         return if $self->{disconnecting}++;
1050         
1051         unless ($pc39flag && $pc39flag == 1) {
1052                 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1053         }
1054
1055         # get rid of any PC16/17/19
1056         eph_del_regex("^PC1[679]*$call");
1057
1058         # do routing stuff, remove me from routing table
1059         my $node = Route::Node::get($call);
1060         my @rout;
1061         if ($node) {
1062                 @rout = $node->del($main::routeroot);
1063                 
1064                 # and all my ephemera as well
1065                 for (@rout) {
1066                         my $c = $_->call;
1067                         eph_del_regex("^PC1[679].*$c");
1068                 }
1069         }
1070
1071         RouteDB::delete_interface($call);
1072         
1073         # unbusy and stop and outgoing mail
1074         my $mref = DXMsg::get_busy($call);
1075         $mref->stop_msg($call) if $mref;
1076         
1077         # broadcast to all other nodes that all the nodes connected to via me are gone
1078         unless ($pc39flag && $pc39flag == 2)  {
1079                 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1080                 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1081         }
1082
1083         # remove outstanding pings
1084         delete $pings{$call};
1085         
1086         # I was the last node visited
1087     $self->user->node($main::mycall);
1088
1089         # send info to all logged in thingies
1090         $self->tell_login('logoutn');
1091
1092         Log('DXProt', $call . " Disconnected");
1093
1094         $self->SUPER::disconnect;
1095 }
1096
1097
1098
1099 # send a talk message to this thingy
1100 #
1101 sub talk
1102 {
1103         my ($self, $from, $to, $via, $line, $origin) = @_;
1104         
1105         $line =~ s/\^/\\5E/g;                   # remove any ^ characters
1106         $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1107         Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1108 }
1109
1110 # send it if it isn't the except list and isn't isolated and still has a hop count
1111 # taking into account filtering and so on
1112
1113 sub send_route
1114 {
1115         my $self = shift;
1116         my $origin = shift;
1117         my $generate = shift;
1118         my $no = shift;     # the no of things to filter on 
1119         my $routeit;
1120         my ($filter, $hops);
1121         my @rin;
1122         
1123         for (; @_ && $no; $no--) {
1124                 my $r = shift;
1125                 
1126                 if (!$self->{isolate} && $self->{routefilter}) {
1127                         $filter = undef;
1128                         if ($r) {
1129                                 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->{state}, $r->{state});
1130                                 if ($filter) {
1131                                         push @rin, $r;
1132                                 } else {
1133                                         dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1134                                 }
1135                         } else {
1136                                 dbg("was sent a null value") if isdbg('chanerr');
1137                         }
1138                 } else {
1139                         push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1140                 }
1141         }
1142         if (@rin) {
1143                 foreach my $line (&$generate(@rin, @_)) {
1144                         if ($hops) {
1145                                 $routeit = $line;
1146                                 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1147                         } else {
1148                                 $routeit = adjust_hops($self, $line);  # adjust its hop count by node name
1149                                 next unless $routeit;
1150                         }
1151                         
1152                         $self->send($routeit);
1153                 }
1154         }
1155 }
1156
1157 sub broadcast_route
1158 {
1159         my $self = shift;
1160         my $origin = shift;
1161         my $generate = shift;
1162         my $line = shift;
1163         my @dxchan = DXChannel::get_all_nodes();
1164         my $dxchan;
1165
1166         if ($line) {
1167                 $line =~ /\^H(\d+)\^?\~?$/;
1168                 return unless $1 > 0;
1169         }
1170         unless ($self->{isolate}) {
1171                 foreach $dxchan (@dxchan) {
1172                         next if $dxchan == $self;
1173                         next if $dxchan == $main::me;
1174                         next unless $dxchan->isa('DXProt');
1175                         next if $dxchan->{do_pc92};
1176                         next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1177  
1178                         $dxchan->send_route($origin, $generate, @_);
1179                 }
1180         }
1181 }
1182
1183 # this is only used for next door nodes on init
1184 sub send_route_pc92
1185 {
1186         my $self = shift;
1187
1188         return unless $self->{do_pc92};
1189         
1190         my $origin = shift;
1191         my $generate = shift;
1192         my $no = shift;     # the no of things to filter on 
1193         my $line;
1194
1195         $line = &$generate(@_);
1196         $self->send($line);
1197 }
1198
1199 sub broadcast_route_pc9x
1200 {
1201         my $self = shift;
1202         my $origin = shift;
1203         my $generate = shift;
1204         my $line = shift;
1205         my $no = shift;
1206         my @dxchan = DXChannel::get_all_nodes();
1207         my $dxchan;
1208
1209         if ($origin eq $main::mycall) {
1210                 $line = &$generate(@_);
1211         } 
1212
1213         $line =~ /\^H(\d+)\^\~?$/;
1214         unless ($1 > 0 && $self->{isolate}) {
1215                 foreach $dxchan (@dxchan) {
1216                         next if $dxchan == $self;
1217                         next if $dxchan == $main::me;
1218                         next unless $dxchan->{do_pc92};
1219                         next unless $dxchan->isa('DXProt');
1220
1221                         $dxchan->send($line);
1222                 }
1223         }
1224 }
1225
1226 sub route_pc16
1227 {
1228         my $self = shift;
1229         return unless $self->user->wantpc16;
1230         my $origin = shift;
1231         my $line = shift;
1232         broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1233 }
1234
1235 sub route_pc17
1236 {
1237         my $self = shift;
1238         return unless $self->user->wantpc16;
1239         my $origin = shift;
1240         my $line = shift;
1241         broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1242 }
1243
1244 sub route_pc19
1245 {
1246         my $self = shift;
1247         my $origin = shift;
1248         my $line = shift;
1249         broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1250 }
1251
1252 sub route_pc21
1253 {
1254         my $self = shift;
1255         my $origin = shift;
1256         my $line = shift;
1257         broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1258 }
1259
1260 sub route_pc24
1261 {
1262         my $self = shift;
1263         my $origin = shift;
1264         my $line = shift;
1265         broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1266 }
1267
1268 sub route_pc41
1269 {
1270         my $self = shift;
1271         my $origin = shift;
1272         my $line = shift;
1273         broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1274 }
1275
1276 sub route_pc50
1277 {
1278         my $self = shift;
1279         my $origin = shift;
1280         my $line = shift;
1281         broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1282 }
1283
1284 sub route_pc92c
1285 {
1286         my $self = shift;
1287         my $origin = shift;
1288         my $line = shift;
1289         broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1290 }
1291
1292 sub route_pc92a
1293 {
1294         my $self = shift;
1295         my $origin = shift;
1296         my $line = shift;
1297         broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1298 }
1299
1300 sub route_pc92d
1301 {
1302         my $self = shift;
1303         my $origin = shift;
1304         my $line = shift;
1305         broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1306 }
1307
1308 sub in_filter_route
1309 {
1310         my $self = shift;
1311         my $r = shift;
1312         my ($filter, $hops) = (1, 1);
1313         
1314         if ($self->{inroutefilter}) {
1315                 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->state, $r->state);
1316                 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1317         }
1318         return $filter;
1319 }
1320
1321 sub eph_dup
1322 {
1323         my $s = shift;
1324         my $t = shift || $eph_restime;
1325         my $r;
1326
1327         # chop the end off
1328         $s =~ s/\^H\d\d?\^?\~?$//;
1329         $r = 1 if exists $eph{$s};    # pump up the dup if it keeps circulating
1330         $eph{$s} = $main::systime + $t;
1331         dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr'); 
1332         return $r;
1333 }
1334
1335 sub eph_del_regex
1336 {
1337         my $regex = shift;
1338         my ($key, $val);
1339         while (($key, $val) = each %eph) {
1340                 if ($key =~ m{$regex}) {
1341                         delete $eph{$key};
1342                 }
1343         }
1344 }
1345
1346 sub eph_clean
1347 {
1348         my ($key, $val);
1349         
1350         while (($key, $val) = each %eph) {
1351                 if ($main::systime >= $val) {
1352                         delete $eph{$key};
1353                 }
1354         }
1355 }
1356
1357 sub eph_list
1358 {
1359         my ($key, $val);
1360         my @out;
1361
1362         while (($key, $val) = each %eph) {
1363                 push @out, $key, $val;
1364         }
1365         return @out;
1366 }
1367
1368 sub run_cmd
1369 {
1370         goto &DXCommandmode::run_cmd;
1371 }
1372
1373
1374 # import any msgs in the chat directory
1375 # the messages are sent to the chat group which forms the
1376 # the first part of the name (eg: solar.1243.txt would be
1377 # sent to chat group SOLAR)
1378
1379 # Each message found is sent: one non-blank line to one chat
1380 # message. So 4 lines = 4 chat messages.
1381
1382 # The special name LOCAL is for local users ANN
1383 # The special name ALL is for ANN/FULL
1384 # The special name SYSOP is for ANN/SYSOP
1385 #
1386 sub import_chat
1387 {
1388         # are there any to do in this directory?
1389         return unless -d $chatimportfn;
1390         unless (opendir(DIR, $chatimportfn)) {
1391                 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1392                 Log('msg', "can\'t open $chatimportfn $!");
1393                 return;
1394         } 
1395
1396         my @names = readdir(DIR);
1397         closedir(DIR);
1398         my $name;
1399         foreach $name (@names) {
1400                 next if $name =~ /^\./;
1401                 my $splitit = $name =~ /^split/;
1402                 my $fn = "$chatimportfn/$name";
1403                 next unless -f $fn;
1404                 unless (open(MSG, $fn)) {
1405                         dbg("can\'t open import file $fn $!") if isdbg('msg');
1406                         Log('msg', "can\'t open import file $fn $!");
1407                         unlink($fn);
1408                         next;
1409                 }
1410                 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1411                 close(MSG);
1412                 unlink($fn);
1413
1414                 my @cat = split /\./, $name;
1415                 my $target = uc $cat[0];
1416
1417                 foreach my $text (@msg) {
1418                         next unless $text && $text !~ /^\s*#/;
1419                         if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1420                                 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1421                                 if ($target ne 'LOCAL') {
1422                                         send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1423                                 } else {
1424                                         Log('ann', 'LOCAL', $main::mycall, $text);
1425                                         DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1426                                 }
1427                         } else {
1428                                 my $msgid = nextchatmsgid();
1429                                 $text = "#$msgid $text";
1430                                 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');
1431                         }
1432                 }
1433         }
1434 }
1435
1436 1;
1437 __END__