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 # do the screen initialisation
59 $has_colors = has_colors();
63 init_pair(0, $foreground, $background);
64 init_pair(1, COLOR_RED, $background);
65 init_pair(2, COLOR_YELLOW, $background);
66 init_pair(3, COLOR_GREEN, $background);
67 init_pair(4, COLOR_CYAN, $background);
68 init_pair(5, COLOR_BLUE, $background);
69 init_pair(6, COLOR_MAGENTA, $background);
72 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
75 $scr->addstr(LINES()-4, 0, '-' x COLS);
76 $bot = $scr->subwin(3, COLS, LINES()-3, 0);
92 # cease communications
96 if ($conn && $sendz) {
97 $conn->send_now("Z$call|bye...\n");
105 # terminate program from signal
111 # determine the colour of the line
115 foreach my $ref (@colors) {
116 if ($_[0] =~ m{$$ref[0]}) {
117 $top->attrset($$ref[1]);
124 # measure the no of screen lines a line will take
128 return 0 unless $line;
130 my $l = length $line;
131 my $lines = int ($l / COLS());
132 $lines++ if $l / COLS() > $lines;
136 # display the top screen
139 if ($spos == @shistory - 1) {
141 # if we really are scrolling thru at the end of the history
142 my $line = $shistory[-1];
143 $top->addstr("\n") if $spos > 0;
146 $top->attrset(COLOR_PAIR(0)) if $has_colors;
154 for ($i = 0; $i <= $pagel && $p >= 0; ) {
155 $l = measure($shistory[$p]);
162 $top->attrset(COLOR_PAIR(0)) if $has_colors;
164 for ($i = 0; $i <= $pagel && $p < @shistory; $p++) {
165 my $line = $shistory[$p];
166 my $lines = measure($line);
167 last if $i + $lines > $pagel;
171 $top->attrset(COLOR_PAIR(0)) if $has_colors;
179 # add a line to the end of the top screen
183 push @shistory, $inbuf;
184 shift @shistory if @shistory > $maxshist;
188 # handle incoming messages
191 my ($con, $msg, $err) = @_;
192 if (defined $err && $err) {
196 my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
200 } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
216 # $prbuf =~ s/\r/\\r/;
217 # $prbuf =~ s/\n/\\n/;
218 # print "sys: $r ($prbuf)\n";
221 if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
225 # check for a pling and do a search back for a command
226 if ($inbuf =~ /^!/o) {
229 for ($i = $#khistory; $i >= 0; $i--) {
230 if ($khistory[$i] =~ /^$inbuf/) {
231 $inbuf = $khistory[$i];
240 push @khistory, $inbuf if $inbuf;
241 shift @khistory if @khistory > $maxkhist;
242 $khistpos = @khistory;
245 $bot->addstr(substr($inbuf, 0, COLS));
248 # add it to the monitor window
249 addtotop($inbuf) if $inbuf;
251 # send it to the cluster
252 $inbuf = " " unless $inbuf;
253 $conn->send_later("I$call|$inbuf");
256 } elsif ($r eq KEY_UP || $r eq "\020") {
259 $inbuf = $khistory[$khistpos];
260 $pos = $lth = length $inbuf;
264 } elsif ($r eq KEY_DOWN || $r eq "\016") {
265 if ($khistpos < @khistory - 1) {
267 $inbuf = $khistory[$khistpos];
268 $pos = $lth = length $inbuf;
272 } elsif ($r eq KEY_PPAGE || $r eq "\032") {
275 for ($i = 0; $i <= $pagel && $spos >= 0; ) {
276 $l = measure($shistory[$spos]);
278 $spos-- if $i <= $pagel;
280 $spos = 0 if $spos < 0;
285 } elsif ($r eq KEY_NPAGE || $r eq "\026") {
286 if ($spos < @shistory - 1) {
288 for ($i = 0; $i <= $pagel && $spos <= @shistory; ) {
289 $l = measure($shistory[$spos]);
291 $spos++ if $i <= $pagel;
293 $spos = @shistory if $spos > @shistory;
298 } elsif ($r eq KEY_LEFT || $r eq "\002") {
304 } elsif ($r eq KEY_RIGHT || $r eq "\006") {
310 } elsif ($r eq KEY_HOME || $r eq "\001") {
312 } elsif ($r eq KEY_END || $r eq "\005") {
314 } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
316 my $a = substr($inbuf, 0, $pos-1);
317 my $b = substr($inbuf, $pos) if $pos < $lth;
326 } elsif ($r eq KEY_DC || $r eq "\004") {
328 my $a = substr($inbuf, 0, $pos);
329 my $b = substr($inbuf, $pos+1) if $pos < $lth;
337 } elsif ($r ge ' ' && $r le '~') {
338 # move the top screen back to the bottom if you type something
339 if ($spos < @shistory - 1) {
344 # insert the character into the keyboard buffer
346 my $a = substr($inbuf, 0, $pos);
347 my $b = substr($inbuf, $pos);
348 $inbuf = $a . $r . $b;
354 } elsif ($r eq "\014" || $r eq "\022") {
357 } elsif ($r eq "\013") {
358 $inbuf = substr($inbuf, 0, $pos);
359 $lth = length $inbuf;
365 $bot->addstr($inbuf);
376 $call = uc shift @ARGV if @ARGV;
377 $call = uc $myalias if !$call;
379 if ($call eq $mycall) {
380 print "You cannot connect as your cluster callsign ($mycall)\n";
384 $conn = Msg->connect("$clusteraddr", $clusterport, \&rec_socket);
386 if (-r "$data/offline") {
387 open IN, "$data/offline" or die;
393 print "Sorry, the cluster $mycall is currently off-line\n";
399 $SIG{'INT'} = \&sig_term;
400 $SIG{'TERM'} = \&sig_term;
401 #$SIG{'WINCH'} = \&do_resize;
402 $SIG{'HUP'} = 'IGNORE';
406 $SIG{__DIE__} = \&sig_term;
408 $conn->send_now("A$call|$connsort");
409 $conn->send_now("I$call|set/page $maxshist");
410 $conn->send_now("I$call|set/nobeep");
412 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);
416 Msg->event_loop(1, 0.010);
417 $top->refresh() if $top->is_wintouched;
420 if ($t > $lasttime) {