#!/usr/bin/perl -w ###################################################################### # Artemis MainScren selector, (C) 2015-2020 Nosey Nick Waterman, # https://noseynick.org/artemis/ # All wrong righted, all rights reserved. Licensed under thev GNU # Affero General Public License v3.0 https://www.gnu.org/licenses/agpl.txt # with Commons Clause https://commonsclause.com/ v1.0 ###################################################################### use strict; use Time::HiRes qw(time); # for precise ping times select STDERR; $|=1; # output autoflush. DO NOT wait for LF before flushing. select STDOUT; $|=1; # output autoflush. DO NOT wait for LF before flushing. sub valueInt { print pack('V*', 0xdeadbeef, 24+(4*@_), # DEADBEEF, totlen 2,0, 4+(4*@_), # c2s, zero, len 0x4c821d3c, # JamCRC('valueInt'); @_); } sub ping { my $time = int(1000 * time()); print STDERR "# PING $time\n"; my $payload = "please ignore $time"; # gmText(0, 3000, UTF16("PING") => UTF16("pleasse ignore $secs $usecs")); # v2.6 idleTextFreeform $payload = pack('VVV', 0x809305a7, 0, 3000) # JamCRC('gmText'); idleTextFreeform . pack('V v*', 5, unpack('U*', 'PING'), 0) # UTF16('PING') . pack('V v*', 1+length($payload), unpack('U*', $payload), 0); # UTF16($payload); # c2s($payload); $payload = pack('VVVVV', 0xdeadbeef, 20+length($payload), 2,0, length($payload)) . $payload; print $payload; } my $heartbeat = $ENV{HEARTBEAT}; my $ping = $ENV{PING}; my $blink = $ENV{BLINK} // 1; for (@ARGV) { sleep 1; if (/^[1-8]$/) { valueInt(0x0d, $_-1); } # Set ship N elsif (/^main$/) { valueInt(0x0e, 0,1); } # SetConsole(Main=>1) elsif (/^com/) { valueInt(0x0e, 5,1); } # SetConsole(Comm=>1) elsif (/^fight/) { valueInt(0x0e, 6,1); } # SetConsole(Fighter=>1) elsif (/^helm/) { valueInt(0x0e, 1,1); } # SetConsole(Helm=>1) elsif (/^eng/) { valueInt(0x0e, 3,1); } # SetConsole(Eng=>1) elsif (/^fight/) { valueInt(0x0e, 6,1); } # SetConsole(Fighter=>1) elsif (/^front/) { valueInt(0x01, 0); } # SetMainScreen(front) elsif (/^left/) { valueInt(0x01, 1); } # SetMainScreen(left) elsif (/^right/) { valueInt(0x01, 2); } # SetMainScreen(right) elsif (/^rear/) { valueInt(0x01, 3); } # SetMainScreen(rear) elsif (/^tac/) { valueInt(0x01, 4); } # SetMainScreen(TAC) elsif (/^lrs/) { valueInt(0x01, 5); } # SetMainScreen(LRS) elsif (/^info/) { valueInt(0x01, 6); } # SetMainScreen(INFO) elsif (/^heart/) { $heartbeat = 1; } # Send periodic client heartbeats! elsif (/^ping/) { $ping = 1; } # Sent periodic ping packets too, for lag analysis elsif (/^blink/) { $blink = 1; } # Blink |-|- elsif (/^noblink/){ $blink = 0; } # Don't blink |-|- else { valueInt(0x0f, 0); # Ready(): print STDERR "# $0 Waiting for $_\n"; while (-f $_) { sleep 3; valueInt(0x24) if $heartbeat; # yeah with no actual INTS! :-) ping() if $ping; if ($blink > 1) { print STDERR "\r-\r"; $blink=1; } elsif ($blink) { print STDERR "\r|\r"; $blink++; } } exit; } } sleep 1; valueInt(0x0f, 0); # Ready():