| 1 | # Declare our package | ||||||||||||||||||||||||||||
| 2 | package POE::Component::AssaultCube::ServerQuery; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # import the Moose stuff | ||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use MooseX::POE::SweetArgs; | ||||||||||||||||||||||||||
|
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 | # get some utility stuff | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Games::AssaultCube::ServerQuery::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use POE::Component::AssaultCube::ServerQuery::Server; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Games::AssaultCube::Utils qw( tostr get_ac_pingport ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # We need some POE stuff | ||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use POE::Wheel::UDP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use POE::Filter::Stream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Socket qw( INADDR_ANY ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Time::HiRes qw( time ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # TODO improve validation for everything here, ha! | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has 'alias' => ( | ||||||||||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 0 | return 'ServerQuery-' . $self->get_session_id; | |||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | 1 | ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | has 'wheel' => ( | |||||||||||||||||||||||||||
| 36 | isa => 'Maybe[POE::Wheel::UDP]', | ||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||
| 38 | default => undef, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | has 'watchers' => ( | ||||||||||||||||||||||||||||
| 42 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 1 | ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | has 'servers' => ( | ||||||||||||||||||||||||||||
| 48 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 1 | ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | has 'throttle' => ( | |||||||||||||||||||||||||||
| 54 | isa => 'Num', | ||||||||||||||||||||||||||||
| 55 | is => 'rw', | ||||||||||||||||||||||||||||
| 56 | default => 0.25, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # add this session to the watchers | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my( $self, $session, $event ) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( ! defined $session ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | # take from current session ID? | ||||||||||||||||||||||||||||
| 65 | 0 | $session = $poe_kernel->get_active_session; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( defined $session ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $session->isa( 'POE::Kernel' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | # no session running | ||||||||||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # set the default | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $event = 'ac_ping' if ! defined $event; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $session = $session->ID if ref $session; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | #warn "$session registered as a watcher\n"; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->watchers->{ $session } = $event; | |||||||||||||||||||||||||||
| 83 | 0 | return 1; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub unregister { | ||||||||||||||||||||||||||
|
Subroutine
unregister: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my( $self, $session ) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( ! defined $session ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | # take from current session ID? | ||||||||||||||||||||||||||||
| 91 | 0 | $session = $poe_kernel->get_active_session; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ( defined $session ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( $session->isa( 'POE::Kernel' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | # no session running | ||||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $session = $session->ID if ref $session; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | #warn "$session unregistered as a watcher\n"; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( exists $self->watchers->{ $session } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | delete $self->watchers->{ $session }; | |||||||||||||||||||||||||||
| 108 | 0 | return 1; | |||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||
| 110 | 0 | return; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub addserver { | ||||||||||||||||||||||||||
|
Subroutine
addserver: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # sanity | ||||||||||||||||||||||||||||
| 118 | 0 | my $server; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( defined $_[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( ref $_[0] and ref( $_[0] ) eq 'POE::Component::AssaultCube::ServerQuery::Server' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] and ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
ref $_[0]
ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
| |||||||||||||||||||||||||||||
| 121 | 0 | $server = $_[0]; | |||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | # convert it into an object | ||||||||||||||||||||||||||||
| 124 | 0 | eval { | |||||||||||||||||||||||||||
| 125 | 0 | $server = POE::Component::AssaultCube::ServerQuery::Server->new( @_ ); | |||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | die "invalid server data: $@"; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( ! defined $server ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | die "unable to parse server data"; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||
| 135 | 0 | return; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( exists $self->servers->{ $server->ID } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | return; | |||||||||||||||||||||||||||
| 140 | } else { | ||||||||||||||||||||||||||||
| 141 | #warn "added server " . $server->ID; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # start pinging this server | ||||||||||||||||||||||||||||
| 144 | 0 | $self->servers->{ $server->ID } = $server; | |||||||||||||||||||||||||||
| 145 | 0 | $poe_kernel->call( $self->get_session_id, 'start_pinger_delay' ); | |||||||||||||||||||||||||||
| 146 | 0 | return $server; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub delserver { | ||||||||||||||||||||||||||
|
Subroutine
delserver: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # sanity | ||||||||||||||||||||||||||||
| 154 | 0 | my $server; | |||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ( defined $_[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ( ref $_[0] and ref( $_[0] ) eq 'POE::Component::AssaultCube::ServerQuery::Server' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] and ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
ref $_[0]
ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
Truth table0%0/3
A and B
A= ref $_[0]B= ref $_[0] eq "POE::Component::AssaultCube::ServerQuery::Server"
| |||||||||||||||||||||||||||||
| 157 | 0 | $server = $_[0]; | |||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||
| 159 | # convert it into an object | ||||||||||||||||||||||||||||
| 160 | 0 | eval { | |||||||||||||||||||||||||||
| 161 | 0 | $server = POE::Component::AssaultCube::ServerQuery::Server->new( @_ ); | |||||||||||||||||||||||||||
| 162 | }; | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | die "invalid server data: $@"; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ( ! defined $server ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | die "unable to parse server data"; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||
| 171 | 0 | return; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( exists $self->servers->{ $server->ID } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | #warn "deleted server " . $server->ID; | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | delete $self->servers->{ $server->ID }; | |||||||||||||||||||||||||||
| 178 | 0 | $poe_kernel->call( $self->get_session_id, 'start_pinger_delay' ); | |||||||||||||||||||||||||||
| 179 | 0 | return 1; | |||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||
| 181 | 0 | return; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub STARTALL { | ||||||||||||||||||||||||||
|
Subroutine
STARTALL: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | #warn "in STARTALL"; | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | $poe_kernel->alias_set( $self->alias ); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # should we fire up the pinger? | ||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ( keys %{ $self->servers } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | $poe_kernel->post( $self->get_session_id, 'start_pinger_delay' ); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | return; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub STOPALL { | ||||||||||||||||||||||||||
|
Subroutine
STOPALL: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 201 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | #warn "in STOPALL"; | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | return; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub make_wheel { | ||||||||||||||||||||||||||
|
Subroutine
make_wheel: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 209 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # sanity | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | return if defined $self->wheel; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | #warn "creating POE::Wheel::UDP"; | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | $self->wheel( POE::Wheel::UDP->new( | |||||||||||||||||||||||||||
| 217 | LocalAddr => '0.0.0.0', | ||||||||||||||||||||||||||||
| 218 | LocalPort => INADDR_ANY, | ||||||||||||||||||||||||||||
| 219 | InputEvent => 'wheel_input', | ||||||||||||||||||||||||||||
| 220 | Filter => POE::Filter::Stream->new, | ||||||||||||||||||||||||||||
| 221 | ) ); | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # be evil but we need to do this... | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | binmode $self->wheel->{sock}, ":utf8" or die "Unable to set binmode: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | event start_pinger_delay => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 230 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | $poe_kernel->delay( 'start_pinger' => 0.1 ); | |||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||
| 234 | 1 | }; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | event start_pinger => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 237 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | # okay, get the next server timeout | ||||||||||||||||||||||||||||
| 240 | 0 | my( $server, $nexttime ) = $self->get_next_server; | |||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ( defined $server ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | # do we have a wheel? | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ( ! defined $self->wheel ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | $self->make_wheel; | |||||||||||||||||||||||||||
| 245 | 0 | $poe_kernel->delay( 'start_pinger' => 1 ); | |||||||||||||||||||||||||||
| 246 | 0 | return; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ( $nexttime != 0 and $nexttime < $self->throttle ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nexttime != 0 and $nexttime < $self->throttle
MC/DC0%0/2
$nexttime != 0 and $nexttime < $self->throttle
$nexttime != 0
$nexttime < $self->throttle
Truth table0%0/3
A and B
A= $nexttime != 0B= $nexttime < $self->throttle
| |||||||||||||||||||||||||||||
| 250 | 0 | $nexttime = $self->throttle; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | #warn "THROTTLE HIT!"; | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $nexttime = 0 if $nexttime < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | #warn "server(" . $server->ID . ") selected with $nexttime"; | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ( $nexttime == 0 or $self->throttle == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$nexttime == 0 or $self->throttle == 0
MC/DC0%0/2
$nexttime == 0 or $self->throttle == 0
$nexttime == 0
$self->throttle == 0
Truth table0%0/3
A or B
A= $nexttime == 0B= $self->throttle == 0
| |||||||||||||||||||||||||||||
| 260 | 0 | $self->ping_server( $server ); | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | # ping the next available server | ||||||||||||||||||||||||||||
| 263 | 0 | $poe_kernel->delay( 'start_pinger' => 0 ); | |||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||
| 265 | #warn "sleeping for $nexttime secs"; | ||||||||||||||||||||||||||||
| 266 | 0 | $poe_kernel->delay( 'start_pinger' => $nexttime ); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||
| 269 | # no server, wait until we add a server | ||||||||||||||||||||||||||||
| 270 | 0 | $poe_kernel->alarm_remove_all; | |||||||||||||||||||||||||||
| 271 | 0 | $self->wheel( undef ); | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | #warn "no server, waiting until addserver"; | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | return; | |||||||||||||||||||||||||||
| 278 | 1 | }; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub get_next_server { | ||||||||||||||||||||||||||
|
Subroutine
get_next_server: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 281 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | # shortcut | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ( keys %{ $self->servers } == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | return; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # okay, we order servers by last_pingtime and in respect to their pingfreq | ||||||||||||||||||||||||||||
| 289 | 0 | my @servers = sort { $a->[1] <=> $b->[1] } | |||||||||||||||||||||||||||
| 290 | 0 | map { [ $_, $_->nextping() ] } values %{ $self->servers }; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | #use Data::Dumper; | ||||||||||||||||||||||||||||
| 293 | #print Dumper( \@servers ); | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | # return the first server | ||||||||||||||||||||||||||||
| 296 | 0 | return( $servers[0]->[0], $servers[0]->[1] ); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub ping_server { | ||||||||||||||||||||||||||
|
Subroutine
ping_server: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 300 | 0 | my( $self, $server ) = @_; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # actually ping it! | ||||||||||||||||||||||||||||
| 303 | 0 | my $datagram; | |||||||||||||||||||||||||||
| 304 | 0 | ▶ | if ( $server->get_players ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 0 | $datagram = tostr('1') . tostr('1'); | |||||||||||||||||||||||||||
| 306 | } else { | ||||||||||||||||||||||||||||
| 307 | 0 | $datagram = tostr('1') . tostr('0'); | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | #warn "pinging " . $server->ID; | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | # send it! | ||||||||||||||||||||||||||||
| 313 | 0 | eval { | |||||||||||||||||||||||||||
| 314 | 0 | $self->wheel->put( { | |||||||||||||||||||||||||||
| 315 | payload => [ $datagram ], | ||||||||||||||||||||||||||||
| 316 | addr => $server->server, | ||||||||||||||||||||||||||||
| 317 | port => get_ac_pingport( $server->port ), | ||||||||||||||||||||||||||||
| 318 | } ); | ||||||||||||||||||||||||||||
| 319 | }; | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | # set the lastpingtime | ||||||||||||||||||||||||||||
| 322 | 0 | $server->last_pingtime( time() ); | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | return; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | event 'wheel_input' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 328 | 0 | my( $self, $input, $wheel_id ) = @_; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return if ! length $input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # make the server ID | ||||||||||||||||||||||||||||
| 333 | # TODO we hardcode the "$port - 1" behavior... | ||||||||||||||||||||||||||||
| 334 | 0 | $input->{ID} = $input->{addr} . ':' . ( $input->{port} - 1 ); | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | # do we know this server? | ||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ( exists $self->servers->{ $input->{ID} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | # yay, got a ping back! | ||||||||||||||||||||||||||||
| 339 | 0 | $self->process_ping( $input ); | |||||||||||||||||||||||||||
| 340 | } else { | ||||||||||||||||||||||||||||
| 341 | # hm, unknown ping... | ||||||||||||||||||||||||||||
| 342 | 0 | warn "unknown DATA from $input->{ID}"; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | return; | |||||||||||||||||||||||||||
| 346 | 1 | }; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 350 | 0 | $poe_kernel->post( $self->get_session_id, 'do_shutdown' ); | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | return; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | event 'do_shutdown' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 356 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | # cleanup | ||||||||||||||||||||||||||||
| 359 | 0 | $poe_kernel->alias_remove( $self->alias ); | |||||||||||||||||||||||||||
| 360 | 0 | $self->wheel( undef ); | |||||||||||||||||||||||||||
| 361 | 0 | $poe_kernel->alarm_remove_all; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | return; | |||||||||||||||||||||||||||
| 364 | 1 | }; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub process_ping { | ||||||||||||||||||||||||||
|
Subroutine
process_ping: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 367 | 0 | my( $self, $input ) = @_; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | #use Data::Dumper; | ||||||||||||||||||||||||||||
| 370 | #warn "got ping reply: " . Dumper( $input ); | ||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||
| 372 | #use Data::HexDump; | ||||||||||||||||||||||||||||
| 373 | #print HexDump( $input->{payload}->[0] ); | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | # okay, convert it into a response object | ||||||||||||||||||||||||||||
| 376 | 0 | my $response; | |||||||||||||||||||||||||||
| 377 | 0 | eval { | |||||||||||||||||||||||||||
| 378 | 0 | $response = Games::AssaultCube::ServerQuery::Response->new( $self, $input ); | |||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 0 | warn "unable to parse DATA from $input->{ID}: $@"; | |||||||||||||||||||||||||||
| 382 | }; | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | # pass it on to the watchers | ||||||||||||||||||||||||||||
| 385 | 0 | foreach my $w ( keys %{ $self->watchers } ) { | |||||||||||||||||||||||||||
| 386 | #warn "informing watcher $w of ping"; | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | $poe_kernel->post( $w, $self->watchers->{ $w }, $self->servers->{ $input->{ID} }, $response ); | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | return; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub clearservers { | ||||||||||||||||||||||||||
|
Subroutine
clearservers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 395 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | # get rid of all servers and reset the timer | ||||||||||||||||||||||||||||
| 398 | 0 | %{ $self->servers } = (); | |||||||||||||||||||||||||||
| 399 | 0 | $poe_kernel->call( $self->get_session_id, 'start_pinger_delay' ); | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 0 | return; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | # from Moose::Manual::BestPractices | ||||||||||||||||||||||||||||
| 405 | 1 | ▶ | no MooseX::POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 406 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 1 | 1; | |||||||||||||||||||||||||||
| 409 | __END__ | ||||||||||||||||||||||||||||