| 1 | # Declare our package | ||||||||||||||||||||||||||||||||
| 2 | package POE::Component::AssaultCube::ServerQuery::Server; | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | # import the Moose stuff | ||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | # Initialize our version | ||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | $VERSION = '0.04'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Games::AssaultCube::Utils qw( default_port ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Time::HiRes qw( time ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | # TODO improve validation for everything here, ha! | ||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | has 'ID' => ( | ||||||||||||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 20 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 22 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 23 | 0 | return $self->server . ':' . $self->port; | |||||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||||||
| 25 | 1 | ); | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 1 | has 'server' => ( | |||||||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | has 'port' => ( | ||||||||||||||||||||||||||||||||
| 34 | isa => 'Int', | ||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 38 | 0 | return default_port; | |||||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||||
| 40 | 1 | ); | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 1 | has 'last_pingtime' => ( | |||||||||||||||||||||||||||||||
| 43 | isa => 'Num', | ||||||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 45 | default => 0, | ||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 1 | has 'frequency' => ( | |||||||||||||||||||||||||||||||
| 49 | isa => 'Num', | ||||||||||||||||||||||||||||||||
| 50 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 51 | default => 300, | ||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 1 | has 'get_players' => ( | |||||||||||||||||||||||||||||||
| 55 | isa => 'Bool', | ||||||||||||||||||||||||||||||||
| 56 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 57 | default => 0, | ||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub nextping { | ||||||||||||||||||||||||||||||
|
Subroutine
nextping: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | # if it was never pinged, do it now! | ||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $self->last_pingtime == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | my $pingtime = ( $self->last_pingtime + $self->frequency ) - time(); | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | #warn "server(" . $self->ID . ") last_pingtime(" . $self->last_pingtime . ") frequency(" . $self->frequency . ") time(" . time() . ") pingtime(" . $pingtime . ")"; | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( $pingtime < 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||
| 75 | 0 | return $pingtime; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 80 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( @_ == 1 && ! ref $_[0] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@_ == 1 and not ref $_[0]
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||||||
| 83 | # set the server as the first argument | ||||||||||||||||||||||||||||||||
| 84 | 0 | return { server => $_[0] }; | |||||||||||||||||||||||||||||||
| 85 | ▶ | } elsif ( @_ == 2 && ! ref $_[0] ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
@_ == 2 and not ref $_[0]
MC/DC0%0/2
@_ == 2 and not ref $_[0]
@_ == 2
not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 2B= not ref $_[0]
| |||||||||||||||||||||||||||||||||
| 86 | # server/port argument | ||||||||||||||||||||||||||||||||
| 87 | 0 | return { server => $_[0], port => $_[1] }; | |||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||
| 89 | # normal hash/hashref way | ||||||||||||||||||||||||||||||||
| 90 | 0 | return $class->SUPER::BUILDARGS(@_); | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | # from Moose::Manual::BestPractices | ||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 96 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 1 | 1; | |||||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||||||