well on the way to having a working cluster database
[spider.git] / perl / DXProtout.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the outgoing PCxx generation routines
4 #
5 # These are all the namespace of DXProt and are separated for "clarity"
6 #
7 # Copyright (c) 1998 Dirk Koopman G1TLH
8 #
9 # $Id$
10
11
12 package DXProt;
13
14 @ISA = qw(DXProt DXChannel);
15
16 use DXUtil;
17 use DXM;
18
19 use strict;
20
21 #
22 # All the PCxx generation routines
23 #
24
25 # create a talk string (called $self->pc10(...)
26 sub pc10
27 {
28   my ($self, $to, $via, $text) = @_;
29   my $user2 = $via ? $to : ' ';
30   my $user1 = $via ? $via : $to;
31   my $mycall = $self->call;
32   $text = unpad($text);
33   $text = ' ' if !$text;
34   return "PC10^$mycall^$user1^$text^*^$user2^$main::mycall^~";  
35 }
36
37 # create a dx message (called $self->pc11(...)
38 sub pc11
39 {
40   my ($self, $freq, $dxcall, $text) = @_;
41   my $mycall = $self->call;
42   my $hops = get_hops(11);
43   my $t = time;
44   $text = ' ' if !$text;
45   return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$hops^~", $freq, cldate($t), ztime($t);
46 }
47
48 # create an announce message
49 sub pc12
50 {
51   my ($self, $text, $tonode, $sysop, $wx) = @_;
52   my $hops = get_hops(12);
53   $sysop = $sysop ? '*' : ' ';
54   $text = ' ' if !$text;
55   $wx = '0' if !$wx;
56   $tonode = '*' if !$tonode;
57   return "PC12^$self->{call}^$tonode^$text^$sysop^$main::mycall^$wx^$hops^~";
58 }
59
60 #
61 # add one or more users (I am expecting references that have 'call', 
62 # 'confmode' & 'here' method) 
63 #
64 # this will create a list of PC16 with up pc16_max_users in each
65 # called $self->pc16(..)
66 #
67 sub pc16
68 {
69   my $self = shift;
70   my @out;
71
72   while (@_) {
73     my $str = "PC16^$self->{call}";
74     my $i;
75     
76     for ($i = 0; @_ && $i < $DXProt::pc16_max_users; $i++) {
77       my $ref = shift;
78           $str .= sprintf "^%s %s %d", $ref->call, $ref->confmode ? '*' : '-', $ref->here;
79         }
80     $str .= sprintf "^%s^", get_hops(16);
81         push @out, $str;
82   }
83   return (@out);
84 }
85
86 # remove a local user
87 sub pc17
88 {
89   my $self = shift;
90   my $hops = get_hops(17);
91   return "PC17^$self->{call}^$main::mycall^$hops^";
92 }
93
94 # Request init string
95 sub pc18
96 {
97   return "PC18^wot a load of twaddle^$DXProt::myprot_version^~";
98 }
99
100 #
101 # add one or more nodes 
102
103 sub pc19
104 {
105   my $self = shift;
106   my @out;
107
108   while (@_) {
109     my $str = "PC19^$self->{call}";
110     my $i;
111     
112     for ($i = 0; @_ && $i < $DXProt::pc19_max_nodes; $i++) {
113       my $ref = shift;
114       $str .= "^$ref->{here}^$ref->{call}^$ref->{confmode}^$ref->{pcversion}";
115         }
116     $str .= sprintf "^%s^", get_hops(19);
117         push @out, $str;
118   }
119   return @out;
120 }
121
122 # end of Rinit phase
123 sub pc20
124 {
125   return 'PC20^';
126 }
127
128 # delete a node
129 sub pc21
130 {
131   my ($ref, $reason) = @_;
132   my $call = $ref->call;
133   my $hops = get_hops(21);
134   $reason = "Gone." if !$reason;
135   return "PC21^$call^$reason^$hops^";
136 }
137
138 # end of init phase
139 sub pc22
140 {
141   return 'PC22^';
142 }
143
144 # send all the DX clusters I reckon are connected
145 sub pc38
146 {
147   my @list = DXNode->get_all();
148   my $list;
149   my @nodes;
150   
151   foreach $list (@list) {
152     push @nodes, $list->call;
153   }
154   return "PC38^" . join(',', @nodes) . "^~";
155 }
156
157 # periodic update of users, plus keep link alive device (always H99)
158 sub pc50
159 {
160   my $n = DXNodeuser->count;
161   return "PC50^$main::mycall^$n^H99^";
162 }
163
164 # generate pings
165 sub pc51
166 {
167   my ($self, $to, $from, $val) = @_;
168   return "PC51^$to^$from^$val^";
169 }
170 1;
171 __END__