3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
28 $me = undef; # the channel id for this cluster
32 my $user = DXUser->get($main::mycall);
33 $me = DXProt->new($main::mycall, undef, $user);
34 # $me->{sort} = 'M'; # M for me
38 # obtain a new connection this is derived from dxchannel
43 my $self = DXChannel::alloc(@_);
44 $self->{sort} = 'A'; # in absence of how to find out what sort of an object I am
48 # this is how a pc connection starts (for an incoming connection)
49 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
50 # all the crap that comes between).
53 my ($self, $line) = shift;
54 my $call = $self->call;
56 # remember type of connection
57 $self->{consort} = $line;
60 $self->send_now('B',"0");
62 # send initialisation string
63 $self->send(pc38()) if DXNode->get_all();
65 $self->state('normal');
70 # This is the normal pcxx despatcher
74 my ($self, $line) = @_;
75 my @field = split /[\^\~]/, $line;
77 # ignore any lines that don't start with PC
78 return if !$field[0] =~ /^PC/;
81 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
82 return if $pcno < 10 || $pcno > 51;
85 if ($pcno == 10) { # incoming talk
87 # is it for me or one of mine?
88 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
89 if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
92 my $text = unpad($field[3]);
93 my $ref = DXChannel->get($call);
94 $ref->send("$call de $field[1]: $text") if $ref;
96 route($field[2], $line); # relay it on its way
101 if ($pcno == 11) { # dx spot
103 # if this is a 'nodx' node then ignore it
104 last SWITCH if grep $field[7] =~ /^$_/, @DXProt::nodx_node;
106 # convert the date to a unix date
107 my $date = $field[3];
108 my $time = $field[4];
109 $date =~ s/^\s*(\d+)-(\w\w\w)-(19\d\d)$/$1 $2 $3/;
110 $time =~ s/^(\d\d)(\d\d)Z$/$1:$2 +0000/;
111 my $d = str2time("$date $time");
112 return if !$d; # bang out (and don't pass on) if date is invalid
114 # strip off the leading & trailing spaces from the comment
115 my $text = unpad($field[5]);
118 Spot::add($field[1], $field[2], $d, $text, $field[6]);
120 # format and broadcast it to users
121 my $spotter = $field[6];
122 $spotter =~ s/^(\w+)-\d+/$1/; # strip off the ssid from the spotter
123 $spotter .= ':'; # add a colon
125 # send orf to the users
126 my $buf = sprintf "DX de %-7.7s %13.13s %-12.12s %-30.30s %5.5s\a\a", $spotter, $field[1], $field[2], $text, $field[4];
127 broadcast_users($buf);
132 if ($pcno == 12) { # announces
134 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
136 # strip leading and trailing stuff
137 my $text = unpad($field[3]);
138 my $target = "To Sysops" if $field[4] eq '*';
139 $target = "WX" if $field[6];
140 $target = "To All" if !$target;
141 broadcast_users("$target de $field[1]: $text");
143 return if $field[2] eq $main::mycall; # it's routed to me
145 route($field[2], $line);
146 return; # only on a routed one
152 if ($pcno == 13) {last SWITCH;}
153 if ($pcno == 14) {last SWITCH;}
154 if ($pcno == 15) {last SWITCH;}
156 if ($pcno == 16) { # add a user
157 my $node = DXCluster->get($field[1]);
158 last SWITCH if !$node; # ignore if havn't seen a PC19 for this one yet
161 for ($i = 2; $i < $#field; $i++) {
162 my ($call, $confmode, $here) = $field[$i] =~ /^(\w+) (-) (\d)/o;
163 next if length $call < 3;
165 $call =~ s/^(\w+)-\d+/$1/; # remove ssid
166 next if DXCluster->get($call); # we already have this (loop?)
168 $confmode = $confmode eq '*';
169 DXNodeuser->new($self, $node, $call, $confmode, $here);
174 if ($pcno == 17) { # remove a user
175 my $ref = DXCluster->get($field[1]);
180 if ($pcno == 18) { # link request
183 my $hops = get_hops(19);
184 $self->send($me->pc19(get_all_ak1a()));
186 # get all the local users and send them out
187 $self->send($me->pc16(get_all_users()));
192 if ($pcno == 19) { # incoming cluster list
194 for ($i = 1; $i < $#field-1; $i += 4) {
195 my $here = $field[$i];
196 my $call = $field[$i+1];
197 my $confmode = $field[$i+2] eq '*';
198 my $ver = $field[$i+3];
200 # now check the call over
201 next if DXCluster->get($call); # we already have this
203 # check for sane parameters
204 next if $ver < 5000; # only works with version 5 software
205 next if length $call < 3; # min 3 letter callsigns
206 DXNode->new($self, $call, $confmode, $here, $ver);
211 if ($pcno == 20) { # send local configuration
214 my $hops = get_hops(19);
215 $self->send($me->pc19(get_all_ak1a()));
217 # get all the local users and send them out
218 $self->send($me->pc16(get_all_users()));
223 if ($pcno == 21) { # delete a cluster from the list
224 my $ref = DXCluster->get($field[1]);
229 if ($pcno == 22) {last SWITCH;}
230 if ($pcno == 23) {last SWITCH;}
231 if ($pcno == 24) {last SWITCH;}
232 if ($pcno == 25) {last SWITCH;}
233 if ($pcno == 26) {last SWITCH;}
234 if ($pcno == 27) {last SWITCH;}
235 if ($pcno == 28) {last SWITCH;}
236 if ($pcno == 29) {last SWITCH;}
237 if ($pcno == 30) {last SWITCH;}
238 if ($pcno == 31) {last SWITCH;}
239 if ($pcno == 32) {last SWITCH;}
240 if ($pcno == 33) {last SWITCH;}
241 if ($pcno == 34) {last SWITCH;}
242 if ($pcno == 35) {last SWITCH;}
243 if ($pcno == 36) {last SWITCH;}
244 if ($pcno == 37) {last SWITCH;}
245 if ($pcno == 38) {last SWITCH;}
246 if ($pcno == 39) {last SWITCH;}
247 if ($pcno == 40) {last SWITCH;}
248 if ($pcno == 41) {last SWITCH;}
249 if ($pcno == 42) {last SWITCH;}
250 if ($pcno == 43) {last SWITCH;}
251 if ($pcno == 44) {last SWITCH;}
252 if ($pcno == 45) {last SWITCH;}
253 if ($pcno == 46) {last SWITCH;}
254 if ($pcno == 47) {last SWITCH;}
255 if ($pcno == 48) {last SWITCH;}
256 if ($pcno == 49) {last SWITCH;}
258 if ($pcno == 50) { # keep alive/user list
259 my $ref = DXCluster->get($field[1]);
260 $ref->update_users($field[2]) if $ref;
264 if ($pcno == 51) { # incoming ping requests/answers
267 if ($field[1] eq $main::mycall) {
268 my $flag = $field[3];
270 $self->send($self->pc51($field[2], $field[1], $flag));
272 # route down an appropriate thingy
273 route($field[1], $line);
279 # if get here then rebroadcast the thing with its Hop count decremented (if
280 # there is one). If it has a hop count and it decrements to zero then don't
283 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
287 my $hopfield = pop @field;
288 push @field, $hopfield;
291 if (($hops) = $hopfield =~ /H(\d+)\^\~?$/o) {
292 my $newhops = $hops - 1;
294 $line =~ s/\^H$hops(\^\~?)$/\^H$newhops$1/; # change the hop count
295 broadcast_ak1a($line, $self); # send it to everyone but me
301 # This is called from inside the main cluster processing loop and is used
302 # for despatching commands that are doing some long processing job
307 my @chan = DXChannel->get_all();
310 foreach $chan (@chan) {
311 next if !$chan->is_ak1a();
313 # send a pc50 out on this channel
314 if ($t >= $chan->pc50_t + $DXProt::pc50_interval) {
322 # finish up a pc context
327 broadcast_ak1a($self->pc21('Gone.'));
328 my $ref = DXCluster->get($self->call);
333 # some active measures
337 # route a message down an appropriate interface for a callsign
339 # is called route(to, pcline);
343 my ($call, $line) = @_;
344 my $cl = DXCluster->get($call);
346 my $dxchan = $cl->{dxchan};
347 $cl->send($line) if $dxchan;
351 # broadcast a message to all clusters [except those mentioned after buffer]
354 my $s = shift; # the line to be rebroadcast
355 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
356 my @chan = get_all_ak1a();
359 foreach $chan (@chan) {
360 $chan->send($s) if !grep $chan, @except; # send it if it isn't the except list
364 # broadcast to all users
367 my $s = shift; # the line to be rebroadcast
368 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
369 my @chan = get_all_users();
372 foreach $chan (@chan) {
373 $chan->send($s) if !grep $chan, @except; # send it if it isn't the except list
378 # gimme all the ak1a nodes
382 my @list = DXChannel->get_all();
385 foreach $ref (@list) {
386 push @out, $ref if $ref->is_ak1a;
391 # return a list of all users
394 my @list = DXChannel->get_all();
397 foreach $ref (@list) {
398 push @out, $ref if $ref->is_user;
403 # return a list of all user callsigns
404 sub get_all_user_calls
406 my @list = DXChannel->get_all();
409 foreach $ref (@list) {
410 push @out, $ref->call if $ref->is_user;
416 # obtain the hops from the list for this callsign and pc no
422 my $hops = $DXProt::hopcount{$pcno};
423 $hops = $DXProt::def_hopcount if !$hops;
427 # remove leading and trailing spaces from an input string