line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
74155
|
use 5.010; |
|
3
|
|
|
|
|
18
|
|
4
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
58
|
|
5
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
78
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1487
|
use Net::RCON::Minecraft; |
|
3
|
|
|
|
|
279
|
|
|
3
|
|
|
|
|
112
|
|
8
|
3
|
|
|
3
|
|
2339
|
use Getopt::Long qw< GetOptionsFromArray >; |
|
3
|
|
|
|
|
31627
|
|
|
3
|
|
|
|
|
11
|
|
9
|
3
|
|
|
3
|
|
2084
|
use Pod::Usage; |
|
3
|
|
|
|
|
149431
|
|
|
3
|
|
|
|
|
407
|
|
10
|
3
|
|
|
3
|
|
25
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1058
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
exit main(@ARGV) unless caller; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub main { |
15
|
18
|
|
|
18
|
|
22854
|
my $ARGV = \@_; |
16
|
|
|
|
|
|
|
|
17
|
18
|
|
|
|
|
45
|
my %o = ( command => [ ] ); |
18
|
18
|
100
|
|
|
|
54
|
GetOptionsFromArray($ARGV, \%o, qw< host=s port=i password=s timeout=f |
19
|
|
|
|
|
|
|
command|cmd=s@ color quiet echo help version > ) or return 2; |
20
|
12
|
100
|
|
|
|
9990
|
if ($o{help}) { pod2usage -verbose => 1, -exitval => 'noexit'; return } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
7639
|
|
21
|
11
|
100
|
|
|
|
26
|
if ($o{version}) { print "rcon-minecraft version 0.03\n"; return } |
|
1
|
|
|
|
|
58
|
|
|
1
|
|
|
|
|
8
|
|
22
|
|
|
|
|
|
|
|
23
|
10
|
100
|
|
|
|
15
|
push @{$o{command}}, join(' ', @$ARGV) if @$ARGV; |
|
6
|
|
|
|
|
20
|
|
24
|
|
|
|
|
|
|
|
25
|
10
|
|
|
|
|
191
|
$o{rcon} = Net::RCON::Minecraft->new(%o); |
26
|
10
|
|
|
|
|
178
|
$o{rcon}->connect; # Not necessary, but better here to fail early |
27
|
|
|
|
|
|
|
|
28
|
9
|
100
|
|
|
|
26
|
if (@{$o{command}}) { for (@{$o{command}}) { run_command(\%o, $_) } } |
|
9
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
13
|
|
29
|
1
|
|
|
|
|
8
|
else { while () { chomp; run_command(\%o, $_) } } |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
4
|
|
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
82
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Run the command and display the output, echoing if so configured |
35
|
|
|
|
|
|
|
sub run_command { |
36
|
10
|
|
|
10
|
|
14
|
my $o = shift; |
37
|
10
|
100
|
|
|
|
72
|
print "> $_[0]\n" if $o->{echo}; |
38
|
|
|
|
|
|
|
|
39
|
10
|
|
|
|
|
30
|
my $resp = $o->{rcon}->command($_[0]); |
40
|
10
|
100
|
|
|
|
242
|
my $disp = $o->{color} ? $resp->ansi : $resp->plain; |
41
|
|
|
|
|
|
|
|
42
|
10
|
100
|
|
|
|
81
|
print length $resp ? "$disp\n" : "[Command sent]\n" unless $o->{quiet}; |
|
|
100
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |