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