3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
27 my $me; # the channel id for this cluster
31 my $user = DXUser->get($main::mycall);
32 $me = DXChannel::alloc('DXProt', $main::mycall, undef, $user);
33 $me->{sort} = 'M'; # M for me
37 # obtain a new connection this is derived from dxchannel
42 my $self = DXChannel::alloc(@_);
43 $self->{sort} = 'A'; # in absence of how to find out what sort of an object I am
47 # this is how a pc connection starts (for an incoming connection)
48 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
49 # all the crap that comes between).
52 my ($self, $line) = shift;
53 my $call = $self->call;
55 # remember type of connection
56 $self->{consort} = $line;
59 $self->send_now('B',"0");
61 # send initialisation string
62 $self->send(pc38()) if DXNode->get_all();
64 $self->state('normal');
69 # This is the normal pcxx despatcher
73 my ($self, $line) = @_;
74 my @field = split /[\^\~]/, $line;
76 # ignore any lines that don't start with PC
77 return if !$field[0] =~ /^PC/;
80 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
81 return if $pcno < 10 || $pcno > 51;
84 if ($pcno == 10) { # incoming talk
86 # is it for me or one of mine?
87 my $call = ($field[5] gt ' ') ? $field[5] : $field[2];
88 if ($call eq $main::mycall || grep $_ eq $call, get_all_user_calls()) {
91 my $text = unpad($field[3]);
92 my $ref = DXChannel->get($call);
93 $ref->send("$call de $field[1]: $text") if $ref;
95 route($field[2], $line); # relay it on its way
100 if ($pcno == 11) { # dx spot
102 # if this is a 'nodx' node then ignore it
103 last SWITCH if grep $field[7] =~ /^$_/, @DXProt::nodx_node;
105 # convert the date to a unix date
106 my $date = $field[3];
107 my $time = $field[4];
108 $date =~ s/^\s*(\d+)-(\w\w\w)-(19\d\d)$/$1 $2 $3/;
109 $time =~ s/^(\d\d)(\d\d)Z$/$1:$2 +0000/;
110 my $d = str2time("$date $time");
111 return if !$d; # bang out (and don't pass on) if date is invalid
113 # strip off the leading & trailing spaces from the comment
114 my $text = unpad($field[5]);
117 Spot::add($field[1], $field[2], $d, $text, $field[6]);
119 # format and broadcast it to users
120 my $spotter = $field[6];
121 $spotter =~ s/^(\w+)-\d+/$1/; # strip off the ssid from the spotter
122 $spotter .= ':'; # add a colon
124 # send orf to the users
125 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];
126 broadcast_users($buf);
131 if ($pcno == 12) { # announces
133 if ($field[2] eq '*' || $field[2] eq $main::mycall) {
135 # strip leading and trailing stuff
136 my $text = unpad($field[3]);
137 my $target = "To Sysops" if $field[4] eq '*';
138 $target = "WX" if $field[6];
139 $target = "To All" if !$target;
140 broadcast_users("$target de $field[1]: $text");
142 return if $field[2] eq $main::mycall; # it's routed to me
144 route($field[2], $line);
145 return; # only on a routed one
151 if ($pcno == 13) {last SWITCH;}
152 if ($pcno == 14) {last SWITCH;}
153 if ($pcno == 15) {last SWITCH;}
155 if ($pcno == 16) { # add a user
156 my $node = DXCluster->get($field[1]);
157 last SWITCH if !$node; # ignore if havn't seen a PC19 for this one yet
160 for ($i = 2; $i < $#field-1; $i++) {
161 my ($call, $confmode, $here) = $field[$i] =~ /^(\w+) (-) (\d)/o;
162 next if length $call < 3;
164 $call =~ s/^(\w+)-\d+/$1/; # remove ssid
165 next if DXCluster->get($call); # we already have this (loop?)
167 $confmode = $confmode eq '*';
168 DXNodeuser->new($self, $node, $call, $confmode, $here);
173 if ($pcno == 17) { # remove a user
174 my $ref = DXCluster->get($field[1]);
179 if ($pcno == 18) { # link request
182 my $hops = get_hops(19);
183 $self->send($me->pc19(get_all_ak1a()));
185 # get all the local users and send them out
186 $self->send($me->pc16(get_all_users()));
191 if ($pcno == 19) { # incoming cluster list
193 for ($i = 1; $i < $#field-1; $i += 4) {
194 my $here = $field[$i];
195 my $call = $field[$i+1];
196 my $confmode = $field[$i+2] eq '*';
197 my $ver = $field[$i+3];
199 # now check the call over
200 next if DXCluster->get($call); # we already have this
202 # check for sane parameters
203 next if $ver < 5000; # only works with version 5 software
204 next if length $call < 3; # min 3 letter callsigns
205 DXNode->new($self, $call, $confmode, $here, $ver);
210 if ($pcno == 20) { # send local configuration
213 my $hops = get_hops(19);
214 $self->send($me->pc19(get_all_ak1a()));
216 # get all the local users and send them out
217 $self->send($me->pc16(get_all_users()));
222 if ($pcno == 21) { # delete a cluster from the list
223 my $ref = DXCluster->get($field[1]);
228 if ($pcno == 22) {last SWITCH;}
229 if ($pcno == 23) {last SWITCH;}
230 if ($pcno == 24) {last SWITCH;}
231 if ($pcno == 25) {last SWITCH;}
232 if ($pcno == 26) {last SWITCH;}
233 if ($pcno == 27) {last SWITCH;}
234 if ($pcno == 28) {last SWITCH;}
235 if ($pcno == 29) {last SWITCH;}
236 if ($pcno == 30) {last SWITCH;}
237 if ($pcno == 31) {last SWITCH;}
238 if ($pcno == 32) {last SWITCH;}
239 if ($pcno == 33) {last SWITCH;}
240 if ($pcno == 34) {last SWITCH;}
241 if ($pcno == 35) {last SWITCH;}
242 if ($pcno == 36) {last SWITCH;}
243 if ($pcno == 37) {last SWITCH;}
244 if ($pcno == 38) {last SWITCH;}
245 if ($pcno == 39) {last SWITCH;}
246 if ($pcno == 40) {last SWITCH;}
247 if ($pcno == 41) {last SWITCH;}
248 if ($pcno == 42) {last SWITCH;}
249 if ($pcno == 43) {last SWITCH;}
250 if ($pcno == 44) {last SWITCH;}
251 if ($pcno == 45) {last SWITCH;}
252 if ($pcno == 46) {last SWITCH;}
253 if ($pcno == 47) {last SWITCH;}
254 if ($pcno == 48) {last SWITCH;}
255 if ($pcno == 49) {last SWITCH;}
257 if ($pcno == 50) { # keep alive/user list
258 my $ref = DXCluster->get($field[1]);
259 $ref->update_users($field[2]) if $ref;
263 if ($pcno == 51) { # incoming ping requests/answers
266 if ($field[1] eq $main::mycall) {
267 my $flag = $field[3];
269 $self->send($self->pc51($field[2], $field[1], $flag));
271 # route down an appropriate thingy
272 route($field[1], $line);
278 # if get here then rebroadcast the thing with its Hop count decremented (if
279 # there is one). If it has a hop count and it decrements to zero then don't
282 # NOTE - don't arrive here UNLESS YOU WANT this lump of protocol to be
286 my $hopfield = pop @field;
287 push @field, $hopfield;
290 if (($hops) = $hopfield =~ /H(\d+)\^\~?$/o) {
291 my $newhops = $hops - 1;
293 $line =~ s/\^H$hops(\^\~?)$/\^H$newhops$1/; # change the hop count
294 broadcast_ak1a($line, $self); # send it to everyone but me
300 # This is called from inside the main cluster processing loop and is used
301 # for despatching commands that are doing some long processing job
306 my @chan = DXChannel->get_all();
309 foreach $chan (@chan) {
310 next if !$chan->is_ak1a();
312 # send a pc50 out on this channel
313 if ($t >= $chan->pc50_t + $DXProt::pc50_interval) {
321 # finish up a pc context
326 broadcast_ak1a($self->pc21('Gone.'));
331 # add a (local) user to the cluster
340 # delete a (local) user to the cluster
346 my $ref = DXCluster->get($self->call);
351 # add a (locally connected) node to the cluster
360 # delete a (locally connected) node to the cluster
365 my $ref = DXCluster->get($self->call);
370 # some active measures
374 # route a message down an appropriate interface for a callsign
376 # is called route(to, pcline);
380 my ($call, $line) = @_;
381 my $cl = DXCluster->get($call);
383 my $dxchan = $cl->{dxchan};
384 $cl->send($line) if $dxchan;
388 # broadcast a message to all clusters [except those mentioned after buffer]
391 my $s = shift; # the line to be rebroadcast
392 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
393 my @chan = get_all_ak1a();
396 foreach $chan (@chan) {
397 $chan->send($s) if !grep $chan, @except; # send it if it isn't the except list
401 # broadcast to all users
404 my $s = shift; # the line to be rebroadcast
405 my @except = @_; # to all channels EXCEPT these (dxchannel refs)
406 my @chan = get_all_users();
409 foreach $chan (@chan) {
410 $chan->send($s) if !grep $chan, @except; # send it if it isn't the except list
415 # gimme all the ak1a nodes
419 my @list = DXChannel->get_all();
422 foreach $ref (@list) {
423 push @out, $ref if $ref->is_ak1a;
428 # return a list of all users
431 my @list = DXChannel->get_all();
434 foreach $ref (@list) {
435 push @out, $ref if $ref->is_user;
440 # return a list of all user callsigns
441 sub get_all_user_calls
443 my @list = DXChannel->get_all();
446 foreach $ref (@list) {
447 push @out, $ref->call if $ref->is_user;
453 # obtain the hops from the list for this callsign and pc no
459 my $hops = $DXProt::hopcount{$pcno};
460 $hops = $DXProt::def_hopcount if !$hops;
464 # remove leading and trailing spaces from an input string