| 1 | #!/usr/bin/env perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use 5.010; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 3 | ▶ | use Net::RCON::Minecraft; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 3 | ▶ | use Getopt::Long qw< GetOptionsFromArray >; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 3 | ▶ | use Pod::Usage; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 3 | ▶ | no warnings 'uninitialized'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 3 | ▶ | exit main(@ARGV) unless caller; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 3 | my $VER = Net::RCON::Minecraft->VERSION; | |||||||||||||
| 15 | |||||||||||||||
| 16 | 18 | ▶ | sub main { | ||||||||||||
|
Subroutine
main: called CC=8 SCAR=20.8
| |||||||||||||||
| 17 | 18 | my $ARGV = \@_; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 18 | my %o = ( command => [ ] ); | |||||||||||||
| 20 | 18 | ▶ | GetOptionsFromArray($ARGV, \%o, qw< host=s port=i password=s timeout=f | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | command|cmd=s@ color quiet echo help version > ) or return 2; | ||||||||||||||
| 22 | 12 | ▶ | if ($o{help}) { pod2usage -verbose => 1, -exitval => 'noexit'; return } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 11 | ▶ | if ($o{version}) { print "rcon-minecraft version $VER\n"; return } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 10 | ▶ | push @{$o{command}}, join(' ', @$ARGV) if @$ARGV; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 10 | $o{rcon} = Net::RCON::Minecraft->new(%o); | |||||||||||||
| 28 | 10 | $o{rcon}->connect; # Not necessary, but better here to fail early | |||||||||||||
| 29 | |||||||||||||||
| 30 | 9 | ▶ | if (@{$o{command}}) { for (@{$o{command}}) { run_command(\%o, $_) } } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 1 | ▶ | else { while (<STDIN>) { chomp; run_command(\%o, $_) } } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | |||||||||||||||
| 33 | 9 | return; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | # Run the command and display the output, echoing if so configured | ||||||||||||||
| 37 | 10 | ▶ | sub run_command { | ||||||||||||
|
Subroutine
run_command: called CC=5 SCAR=16.1
| |||||||||||||||
| 38 | 10 | my $o = shift; | |||||||||||||
| 39 | 10 | ▶ | print "> $_[0]\n" if $o->{echo}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | |||||||||||||||
| 41 | 10 | my $resp = $o->{rcon}->command($_[0]); | |||||||||||||
| 42 | 10 | ▶ | my $disp = $o->{color} ? $resp->ansi : $resp->plain; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | 10 | ▶ | print length $resp ? "$disp\n" : "[Command sent]\n" unless $o->{quiet}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | __END__ | ||||||||||||||