3 # this is the operators console.
7 # console.pl [callsign]
9 # if the callsign isn't given then the sysop callsign in DXVars.pm is assumed
11 # Copyright (c) 1999 Dirk Koopman G1TLH
18 # search local then perl directories
20 # root of directory tree for this system
22 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
24 unshift @INC, "$root/perl"; # this IS the right way round!
25 unshift @INC, "$root/local";
42 $call = ""; # the callsign being used
43 $conn = 0; # the connection object for the cluster
44 $lasttime = time; # lasttime something happened on the interface
50 $spos = $pos = $lth = 0;
53 # cease communications
57 if ($conn && $sendz) {
58 $conn->send_now("Z$call|bye...\n");
66 # terminate program from signal
72 # display the top screen
75 my $p = $spos - $pages;
80 $top->attrset(COLOR_PAIR(0)) if $has_colors;
82 for ($i = 0; $i < $pages && $p < @shistory; $i++, $p++) {
83 my $line = $shistory[$p];
84 $line = substr($line, 0, COLS()) if length $line > COLS();
87 foreach my $ref (@colors) {
88 if ($line =~ m{$$ref[0]}) {
89 $top->attrset($$ref[1]);
95 $top->attrset(COLOR_PAIR(0)) if $has_colors;
101 # handle incoming messages
104 my ($con, $msg, $err) = @_;
105 if (defined $err && $err) {
109 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
112 push @shistory, $line;
113 shift @shistory if @shistory > $maxshist;
114 $spos = @shistory if $spos >= @shistory - 1;
116 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
132 # $prbuf =~ s/\r/\\r/;
133 # $prbuf =~ s/\n/\\n/;
134 # print "sys: $r ($prbuf)\n";
136 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
140 push @khistory, $inbuf if $inbuf;
141 shift @khistory if @khistory > $maxkhist;
142 $khistpos = @khistory;
145 $bot->addstr(substr($inbuf, 0, COLS));
148 # send it to the cluster
149 $inbuf = " " unless $inbuf;
150 $conn->send_later("I$call|$inbuf");
153 } elsif ($r eq KEY_UP || $r eq "\020") {
156 $inbuf = $khistory[$khistpos];
157 $pos = $lth = length $inbuf;
161 } elsif ($r eq KEY_DOWN || $r eq "\016") {
162 if ($khistpos < @khistory - 1) {
164 $inbuf = $khistory[$khistpos];
165 $pos = $lth = length $inbuf;
169 } elsif ($r eq KEY_PPAGE || $r eq "\026") {
172 $spos = 0 if $spos < 0;
177 } elsif ($r eq KEY_NPAGE || $r eq "\032") {
178 if ($spos < @shistory - 1) {
180 $spos = @shistory if $spos > @shistory;
185 } elsif ($r eq KEY_LEFT || $r eq "\002") {
191 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
197 } elsif ($r eq KEY_HOME || $r eq "\001") {
199 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
201 my $a = substr($inbuf, 0, $pos-1);
202 my $b = substr($inbuf, $pos) if $pos < $lth;
211 } elsif ($r eq KEY_DC || $r eq "\004") {
213 my $a = substr($inbuf, 0, $pos);
214 my $b = substr($inbuf, $pos+1) if $pos < $lth;
222 } elsif ($r ge ' ' && $r le '~') {
224 my $a = substr($inbuf, 0, $pos);
225 my $b = substr($inbuf, $pos);
226 $inbuf = $a . $r . $b;
232 } elsif ($r eq "\014" || $r eq "\022") {
235 } elsif ($r eq "\013") {
243 $bot->addstr($inbuf);
254 $call = uc shift @ARGV if @ARGV;
255 $call = uc $myalias if !$call;
257 if ($call eq $mycall) {
258 print "You cannot connect as your cluster callsign ($mycall)\n";
262 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
264 if (-r "$data/offline") {
265 open IN, "$data/offline" or die;
271 print "Sorry, the cluster $mycall is currently off-line\n";
277 $SIG{'INT'} = \&sig_term;
278 $SIG{'TERM'} = \&sig_term;
279 $SIG{'HUP'} = 'IGNORE';
284 $has_colors = has_colors();
288 init_pair(0, $foreground, $background);
289 init_pair(1, COLOR_RED, $background);
290 init_pair(2, COLOR_YELLOW, $background);
291 init_pair(3, COLOR_GREEN, $background);
292 init_pair(4, COLOR_CYAN, $background);
293 init_pair(5, COLOR_BLUE, $background);
294 init_pair(6, COLOR_MAGENTA, $background);
297 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
300 $scr->addstr(LINES()-4, 0, '-' x COLS);
301 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
308 $SIG{__DIE__} = \&sig_term;
311 my $dpages = $pages - 2;
313 $conn->send_now("A$call|$connsort");
314 $conn->send_now("I$call|set/page $dpages");
315 $conn->send_now("I$call|set/nobeep");
317 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
321 Msg->event_loop(1, 0.010);
322 $top->refresh() if $top->is_wintouched;
325 if ($t > $lasttime) {