line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
82633
|
use 5.010; |
|
3
|
|
|
|
|
22
|
|
4
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
60
|
|
5
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
86
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1555
|
use Net::RCON::Minecraft; |
|
3
|
|
|
|
|
340
|
|
|
3
|
|
|
|
|
150
|
|
8
|
3
|
|
|
3
|
|
2832
|
use Getopt::Long qw< GetOptionsFromArray >; |
|
3
|
|
|
|
|
33621
|
|
|
3
|
|
|
|
|
17
|
|
9
|
3
|
|
|
3
|
|
2845
|
use Pod::Usage; |
|
3
|
|
|
|
|
157522
|
|
|
3
|
|
|
|
|
529
|
|
10
|
3
|
|
|
3
|
|
33
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1194
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
exit main(@ARGV) unless caller; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub main { |
15
|
18
|
|
|
18
|
|
26097
|
my $ARGV = \@_; |
16
|
|
|
|
|
|
|
|
17
|
18
|
|
|
|
|
56
|
my %o = ( command => [ ] ); |
18
|
18
|
100
|
|
|
|
81
|
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
|
|
|
|
10406
|
if ($o{help}) { pod2usage -verbose => 1, -exitval => 'noexit'; return } |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
8582
|
|
21
|
11
|
100
|
|
|
|
33
|
if ($o{version}) { print "rcon-minecraft version 0.04\n"; return } |
|
1
|
|
|
|
|
88
|
|
|
1
|
|
|
|
|
10
|
|
22
|
|
|
|
|
|
|
|
23
|
10
|
100
|
|
|
|
29
|
push @{$o{command}}, join(' ', @$ARGV) if @$ARGV; |
|
6
|
|
|
|
|
21
|
|
24
|
|
|
|
|
|
|
|
25
|
10
|
|
|
|
|
339
|
$o{rcon} = Net::RCON::Minecraft->new(%o); |
26
|
10
|
|
|
|
|
242
|
$o{rcon}->connect; # Not necessary, but better here to fail early |
27
|
|
|
|
|
|
|
|
28
|
9
|
100
|
|
|
|
30
|
if (@{$o{command}}) { for (@{$o{command}}) { run_command(\%o, $_) } } |
|
9
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
18
|
|
29
|
1
|
|
|
|
|
8
|
else { while () { chomp; run_command(\%o, $_) } } |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
5
|
|
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
99
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Run the command and display the output, echoing if so configured |
35
|
|
|
|
|
|
|
sub run_command { |
36
|
10
|
|
|
10
|
|
19
|
my $o = shift; |
37
|
10
|
100
|
|
|
|
121
|
print "> $_[0]\n" if $o->{echo}; |
38
|
|
|
|
|
|
|
|
39
|
10
|
|
|
|
|
44
|
my $resp = $o->{rcon}->command($_[0]); |
40
|
10
|
100
|
|
|
|
323
|
my $disp = $o->{color} ? $resp->ansi : $resp->plain; |
41
|
|
|
|
|
|
|
|
42
|
10
|
100
|
|
|
|
106
|
print length $resp ? "$disp\n" : "[Command sent]\n" unless $o->{quiet}; |
|
|
100
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |