« POE/Component/AssaultCube/ServerQuery.pm
↑ Summary
POE/Component/AssaultCube/ServerQuery/Server.pm »
| 1 | # Declare our package | ||||||||||||||||||||||||||||
| 2 | package Games::AssaultCube::Utils; | ||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # Initialize our version | ||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # set ourself up for exporting | ||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | our @EXPORT_OK = qw( default_port stripcolors htmlcolors tostr getpongflag get_ac_pingport | |||||||||||||||||||||||||||
| 12 | getint getstring parse_pingresponse parse_masterserverresponse | ||||||||||||||||||||||||||||
| 13 | get_gamemode get_gamemode_name get_gamemode_from_name get_gamemode_fullname get_gamemode_from_fullname | ||||||||||||||||||||||||||||
| 14 | get_team_from_name get_team_name get_role_from_name get_role_name | ||||||||||||||||||||||||||||
| 15 | get_mastermode_from_name get_mastermode_name get_gun_from_name get_gun_name | ||||||||||||||||||||||||||||
| 16 | get_disconnect_reason_name get_disconnect_reason_from_name | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub get_ac_pingport { | ||||||||||||||||||||||||||
|
Subroutine
get_ac_pingport: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $port = shift; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | return if ! defined $port; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # from protocol.h | ||||||||||||||||||||||||||||
| 24 | # #define CUBE_SERVINFO_PORT(serverport) (serverport+1) | ||||||||||||||||||||||||||||
| 25 | 0 | return $port + 1; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | # from protocol.h | ||||||||||||||||||||||||||||
| 30 | # enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_BANREFUSE, DISC_WRONGPW, DISC_SOPLOGINFAIL, DISC_MAXCLIENTS, DISC_MASTERMODE, DISC_AUTOKICK, DISC_AUTOBAN, DISC_DUP, DISC_NUM }; | ||||||||||||||||||||||||||||
| 31 | # static const char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by server operator", "banned by server operator", "tag type", "connection refused due to ban", "wrong password", "failed admin login", "server FULL - maxclients", "server mastermode is \"private\"", "auto kick - did your score drop below the threshold?", "auto ban - did your score drop below the threshold?", "duplicate connection" }; | ||||||||||||||||||||||||||||
| 32 | 4 | my %reason_name = ( | |||||||||||||||||||||||||||
| 33 | 0 => 'normal', | ||||||||||||||||||||||||||||
| 34 | 1 => 'end of packet', | ||||||||||||||||||||||||||||
| 35 | 2 => 'client num', | ||||||||||||||||||||||||||||
| 36 | 3 => 'kicked by server operator', | ||||||||||||||||||||||||||||
| 37 | 4 => 'banned by server operator', | ||||||||||||||||||||||||||||
| 38 | 5 => 'tag type', | ||||||||||||||||||||||||||||
| 39 | 6 => 'connection refused due to ban', | ||||||||||||||||||||||||||||
| 40 | 7 => 'wrong password', | ||||||||||||||||||||||||||||
| 41 | 8 => 'failed admin login', | ||||||||||||||||||||||||||||
| 42 | 9 => 'server FULL - maxclients', | ||||||||||||||||||||||||||||
| 43 | 10 => 'server mastermode is "private"', | ||||||||||||||||||||||||||||
| 44 | 11 => 'auto kick - did your score drop below the threshold?', | ||||||||||||||||||||||||||||
| 45 | 12 => 'auto ban - did your score drop below the threshold?', | ||||||||||||||||||||||||||||
| 46 | 13 => 'duplicate connection', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | 4 | my %name_reason = map { $reason_name{ $_ } => $_ } keys %reason_name; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub get_disconnect_reason_name { | ||||||||||||||||||||||||||
|
Subroutine
get_disconnect_reason_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $reason = shift; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | return unless defined $reason; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( exists $reason_name{ $reason } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | return $reason_name{ $reason }; | |||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub get_disconnect_reason_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_disconnect_reason_from_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $reason = lc( shift ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | return unless defined $reason; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( exists $name_reason{ $reason } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | return $name_reason{ $reason }; | |||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | sub get_gamemode { | ||||||||||||||||||||||||||
|
Subroutine
get_gamemode: not called CC=2 SCAR=15.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $m = shift; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # try the fullname first? | ||||||||||||||||||||||||||||
| 75 | 0 | my $result = get_gamemode_from_fullname( $m ); | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( defined $result ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | return $result; | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | # try the acronym? | ||||||||||||||||||||||||||||
| 80 | 0 | return get_gamemode_from_name( $m ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | # from entity.h | ||||||||||||||||||||||||||||
| 86 | # enum { GUN_KNIFE = 0, GUN_PISTOL, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAULT, GUN_GRENADE, GUN_AKIMBO, NUMGUNS }; | ||||||||||||||||||||||||||||
| 87 | 4 | my %gun_name = ( | |||||||||||||||||||||||||||
| 88 | 0 => 'KNIFE', | ||||||||||||||||||||||||||||
| 89 | 1 => 'PISTOL', | ||||||||||||||||||||||||||||
| 90 | 2 => 'SHOTGUN', | ||||||||||||||||||||||||||||
| 91 | 3 => 'SUBMACHINE', | ||||||||||||||||||||||||||||
| 92 | 4 => 'SNIPER', | ||||||||||||||||||||||||||||
| 93 | 5 => 'ASSAULT', | ||||||||||||||||||||||||||||
| 94 | 6 => 'GRENADE', | ||||||||||||||||||||||||||||
| 95 | 7 => 'AKIMBO', | ||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | 4 | my %name_gun = map { $gun_name{ $_ } => $_ } keys %gun_name; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub get_gun_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_gun_from_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $gun = uc( shift ); | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | return unless defined $gun; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( exists $name_gun{ $gun } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | return $name_gun{ $gun }; | |||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | 0 | return; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub get_gun_name { | ||||||||||||||||||||||||||
|
Subroutine
get_gun_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 0 | my $gun = shift; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | return unless defined $gun; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( exists $gun_name{ $gun } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | return $gun_name{ $gun }; | |||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | # from entity.h | ||||||||||||||||||||||||||||
| 122 | #define TEAM_CLA 0 | ||||||||||||||||||||||||||||
| 123 | #define TEAM_RVSF 1 | ||||||||||||||||||||||||||||
| 124 | 4 | my %team_name = ( | |||||||||||||||||||||||||||
| 125 | 0 => 'CLA', | ||||||||||||||||||||||||||||
| 126 | 1 => 'RVSF', | ||||||||||||||||||||||||||||
| 127 | 2 => 'NONE', | ||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||
| 129 | 4 | my %name_team = map { $team_name{ $_ } => $_ } keys %team_name; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 18 | ▶ | sub get_team_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_team_from_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 18 | my $team = uc( shift ); | |||||||||||||||||||||||||||
| 133 | 18 | ▶ | return unless defined $team; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 18 | ▶ | if ( exists $name_team{ $team } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 18 | return $name_team{ $team }; | |||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub get_team_name { | ||||||||||||||||||||||||||
|
Subroutine
get_team_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $team = shift; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | return unless defined $team; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ( exists $team_name{ $team } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | return $team_name{ $team }; | |||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||
| 147 | 0 | return; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||
| 153 | # from entity.h | ||||||||||||||||||||||||||||
| 154 | # enum { CR_DEFAULT = 0, CR_ADMIN }; | ||||||||||||||||||||||||||||
| 155 | 4 | my %role_name = ( | |||||||||||||||||||||||||||
| 156 | 0 => 'DEFAULT', | ||||||||||||||||||||||||||||
| 157 | 1 => 'ADMIN', | ||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||
| 159 | 4 | my %name_role = map { $role_name{ $_ } => $_ } keys %role_name; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 14 | ▶ | sub get_role_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_role_from_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 14 | my $role = uc( shift ); | |||||||||||||||||||||||||||
| 163 | 14 | ▶ | return unless defined $role; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 14 | ▶ | if ( exists $name_role{ $role } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 14 | return $name_role{ $role }; | |||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||
| 167 | 0 | return; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub get_role_name { | ||||||||||||||||||||||||||
|
Subroutine
get_role_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | 0 | my $role = shift; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | return unless defined $role; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( exists $role_name{ $role } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | return $role_name{ $role }; | |||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 0 | return; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||
| 183 | # from protocol.h | ||||||||||||||||||||||||||||
| 184 | # enum { MM_OPEN, MM_PRIVATE, MM_NUM }; | ||||||||||||||||||||||||||||
| 185 | 4 | my %mode_name = ( | |||||||||||||||||||||||||||
| 186 | 0 => 'OPEN', | ||||||||||||||||||||||||||||
| 187 | 1 => 'PRIVATE', | ||||||||||||||||||||||||||||
| 188 | 2 => 'NUM', | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | 4 | my %name_mode = map { $mode_name{ $_ } => $_ } keys %mode_name; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 4 | ▶ | sub get_mastermode_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_mastermode_from_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 193 | 4 | my $mode = uc( shift ); | |||||||||||||||||||||||||||
| 194 | 4 | ▶ | return unless defined $mode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 4 | ▶ | if ( exists $name_mode{ $mode } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 4 | return $name_mode{ $mode }; | |||||||||||||||||||||||||||
| 197 | } else { | ||||||||||||||||||||||||||||
| 198 | 0 | return; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | sub get_mastermode_name { | ||||||||||||||||||||||||||
|
Subroutine
get_mastermode_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 2 | my $mode = shift; | |||||||||||||||||||||||||||
| 204 | 2 | ▶ | return unless defined $mode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 2 | ▶ | if ( exists $mode_name{ $mode } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 2 | return $mode_name{ $mode }; | |||||||||||||||||||||||||||
| 207 | } else { | ||||||||||||||||||||||||||||
| 208 | 0 | return; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # parses a HTTP::Response object from the Masterserver | ||||||||||||||||||||||||||||
| 214 | 4 | ▶ | sub parse_masterserverresponse { | ||||||||||||||||||||||||||
|
Subroutine
parse_masterserverresponse: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 215 | 5 | my $response = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # construct the arrayref of hashrefs of servers, zOMG! | ||||||||||||||||||||||||||||
| 218 | 5 | my $result = []; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # go through the content, and add server/port to the result | ||||||||||||||||||||||||||||
| 221 | 5 | foreach my $l ( split( /[\r\n]+/, $response->content ) ) { | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ( ! length $l ) { next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # TODO make this more robust but what the heck! | ||||||||||||||||||||||||||||
| 225 | 20 | ▶ | if ( $l =~ /^addserver\s+(\S+)\s+(\d+)\;$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 18 | my $server = { | |||||||||||||||||||||||||||
| 227 | 'ip' => $1, | ||||||||||||||||||||||||||||
| 228 | 'port' => $2, | ||||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||
| 230 | 18 | push( @$result, $server ); | |||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||
| 232 | 2 | die "Unknown string in response: $l"; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | # all done! | ||||||||||||||||||||||||||||
| 237 | 3 | return $result; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # the default AssaultCube server port | ||||||||||||||||||||||||||||
| 241 | 2 | ▶ | sub default_port { | ||||||||||||||||||||||||||
|
Subroutine
default_port: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 242 | 2 | return 28763; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | # based on the PHP code, thanks PxL! | ||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub tostr { | ||||||||||||||||||||||||||
|
Subroutine
tostr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 247 | 0 | my $hs = shift; | |||||||||||||||||||||||||||
| 248 | 0 | my $rsp = ''; | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | for(my $i = 0; $i < length($hs); $i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 0 | $rsp .= chr(hex(substr($hs,$i).substr($hs,$i+1))); | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 0 | return $rsp; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 48 | ▶ | sub getint { | ||||||||||||||||||||||||||
|
Subroutine
getint: called CC=4 SCAR=16.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 256 | 48 | my $str = shift; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # from protocol.cpp | ||||||||||||||||||||||||||||
| 259 | #int getint(ucharbuf &p) | ||||||||||||||||||||||||||||
| 260 | #{ | ||||||||||||||||||||||||||||
| 261 | # int c = (char)p.get(); | ||||||||||||||||||||||||||||
| 262 | # if(c==-128) { int n = p.get(); n |= char(p.get())<<8; DEBUGVAR(n); return n; } | ||||||||||||||||||||||||||||
| 263 | # else if(c==-127) { int n = p.get(); n |= p.get()<<8; n |= p.get()<<16; n |= (p.get()<<24); DEBUGVAR(n); return n; } | ||||||||||||||||||||||||||||
| 264 | # else | ||||||||||||||||||||||||||||
| 265 | # { | ||||||||||||||||||||||||||||
| 266 | # DEBUGVAR(c); | ||||||||||||||||||||||||||||
| 267 | # return c; | ||||||||||||||||||||||||||||
| 268 | # } | ||||||||||||||||||||||||||||
| 269 | #} | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 48 | ▶ | if ( ! length $$str ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | return; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 48 | my $c = ord( substr( $$str, 0, 1 ) ); | |||||||||||||||||||||||||||
| 276 | 47 | ▶ | if ( $c == 128 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 277 | 5 | my $n = ord( substr( $$str, 1, 1 ) ); | |||||||||||||||||||||||||||
| 278 | 5 | $n |= ( ord( substr( $$str, 2, 1 ) ) << 8 ); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # cleanup the string | ||||||||||||||||||||||||||||
| 281 | 5 | $$str = substr( $$str, 3 ); | |||||||||||||||||||||||||||
| 282 | 5 | return $n; | |||||||||||||||||||||||||||
| 283 | } elsif ( $c == 127 ) { | ||||||||||||||||||||||||||||
| 284 | 0 | my $n = ord( substr( $$str, 1, 1 ) ); | |||||||||||||||||||||||||||
| 285 | 0 | $n |= ( ord( substr( $$str, 2, 1 ) ) << 8 ); | |||||||||||||||||||||||||||
| 286 | 0 | $n |= ( ord( substr( $$str, 3, 1 ) ) << 16 ); | |||||||||||||||||||||||||||
| 287 | 0 | $n |= ( ord( substr( $$str, 4, 1 ) ) << 24 ); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | # cleanup the string | ||||||||||||||||||||||||||||
| 290 | 0 | $$str = substr( $$str, 5 ); | |||||||||||||||||||||||||||
| 291 | 0 | return $n; | |||||||||||||||||||||||||||
| 292 | } else { | ||||||||||||||||||||||||||||
| 293 | # cleanup the string | ||||||||||||||||||||||||||||
| 294 | 42 | $$str = substr( $$str, 1 ); | |||||||||||||||||||||||||||
| 295 | 42 | return $c; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 16 | ▶ | sub getstring { | ||||||||||||||||||||||||||
|
Subroutine
getstring: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 300 | 16 | my $str = shift; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # from protocol.cpp | ||||||||||||||||||||||||||||
| 303 | #void getstring(char *text, ucharbuf &p, int len) | ||||||||||||||||||||||||||||
| 304 | #{ | ||||||||||||||||||||||||||||
| 305 | # char *t = text; | ||||||||||||||||||||||||||||
| 306 | # do | ||||||||||||||||||||||||||||
| 307 | # { | ||||||||||||||||||||||||||||
| 308 | # if(t>=&text[len]) { text[len-1] = 0; return; } | ||||||||||||||||||||||||||||
| 309 | # if(!p.remaining()) { *t = 0; return; } | ||||||||||||||||||||||||||||
| 310 | # *t = getint(p); | ||||||||||||||||||||||||||||
| 311 | # } | ||||||||||||||||||||||||||||
| 312 | # while(*t++); | ||||||||||||||||||||||||||||
| 313 | # DEBUGVAR(text); | ||||||||||||||||||||||||||||
| 314 | #} | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 16 | ▶ | if ( ! length $$str ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 0 | return; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 16 | my $ret = ''; | |||||||||||||||||||||||||||
| 321 | 16 | my $i = 0; | |||||||||||||||||||||||||||
| 322 | 16 | ▶ | while ( ord( substr( $$str, $i, 1 ) ) != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 259 | $ret .= substr( $$str, $i, 1 ); | |||||||||||||||||||||||||||
| 324 | 259 | $i++; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # cleanup the string | ||||||||||||||||||||||||||||
| 328 | 16 | $$str = substr( $$str, $i + 1 ); | |||||||||||||||||||||||||||
| 329 | 16 | return $ret; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||
| 333 | # from protocol.cpp | ||||||||||||||||||||||||||||
| 334 | #const char *modefullnames[] = | ||||||||||||||||||||||||||||
| 335 | #{ | ||||||||||||||||||||||||||||
| 336 | # "demo playback", | ||||||||||||||||||||||||||||
| 337 | # "team deathmatch", "coopedit", "deathmatch", "survivor", | ||||||||||||||||||||||||||||
| 338 | # "team survivor", "ctf", "pistol frenzy", "bot team deathmatch", "bot deathmatch", "last swiss standing", | ||||||||||||||||||||||||||||
| 339 | # "one shot, one kill", "team one shot, one kill", "bot one shot, one kill", "hunt the flag", "team keep the flag", "keep the flag" | ||||||||||||||||||||||||||||
| 340 | #}; | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 4 | my %mode_name = ( | |||||||||||||||||||||||||||
| 343 | 0 => 'demo playback', | ||||||||||||||||||||||||||||
| 344 | 1 => 'team deathmatch', | ||||||||||||||||||||||||||||
| 345 | 2 => 'coopedit', | ||||||||||||||||||||||||||||
| 346 | 3 => 'deathmatch', | ||||||||||||||||||||||||||||
| 347 | 4 => 'survivor', | ||||||||||||||||||||||||||||
| 348 | 5 => 'team survivor', | ||||||||||||||||||||||||||||
| 349 | 6 => 'capture the flag', # this is expanded, because I felt "ctf" was silly | ||||||||||||||||||||||||||||
| 350 | 7 => 'pistol frenzy', | ||||||||||||||||||||||||||||
| 351 | 8 => 'bot team deathmatch', | ||||||||||||||||||||||||||||
| 352 | 9 => 'bot deathmatch', | ||||||||||||||||||||||||||||
| 353 | 10 => 'last swiss standing', | ||||||||||||||||||||||||||||
| 354 | 11 => 'one shot, one kill', | ||||||||||||||||||||||||||||
| 355 | 12 => 'team one shot, one kill', | ||||||||||||||||||||||||||||
| 356 | 13 => 'bot one shot, one kill', | ||||||||||||||||||||||||||||
| 357 | 14 => 'hunt the flag', | ||||||||||||||||||||||||||||
| 358 | 15 => 'team keep the flag', | ||||||||||||||||||||||||||||
| 359 | 16 => 'keep the flag', | ||||||||||||||||||||||||||||
| 360 | ); | ||||||||||||||||||||||||||||
| 361 | 4 | my %name_mode = map { $mode_name{ $_ } => $_ } keys %mode_name; | |||||||||||||||||||||||||||
| 362 | 4 | $name_mode{'ctf'} = 6; # added so we have full round-trip between perl + AC | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 0 | ▶ | sub get_gamemode_fullname { | ||||||||||||||||||||||||||
|
Subroutine
get_gamemode_fullname: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 365 | 0 | my $m = shift; | |||||||||||||||||||||||||||
| 366 | 0 | ▶ | return unless defined $m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ( exists $mode_name{ $m } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | return $mode_name{ $m }; | |||||||||||||||||||||||||||
| 369 | } else { | ||||||||||||||||||||||||||||
| 370 | 0 | return; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 7 | ▶ | sub get_gamemode_from_fullname { | ||||||||||||||||||||||||||
|
Subroutine
get_gamemode_from_fullname: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 375 | 7 | my $m = lc( shift ); | |||||||||||||||||||||||||||
| 376 | 7 | ▶ | return unless defined $m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 7 | ▶ | if ( exists $name_mode{ $m } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 7 | return $name_mode{ $m }; | |||||||||||||||||||||||||||
| 379 | } else { | ||||||||||||||||||||||||||||
| 380 | 0 | return; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | { | ||||||||||||||||||||||||||||
| 386 | # from protocol.cpp | ||||||||||||||||||||||||||||
| 387 | #const char *modeacronymnames[] = | ||||||||||||||||||||||||||||
| 388 | #{ | ||||||||||||||||||||||||||||
| 389 | # "DEMO", | ||||||||||||||||||||||||||||
| 390 | # "TDM", "coop", "DM", "SURV", "TSURV", "CTF", "PF", "BTDM", "BDM", "LSS", | ||||||||||||||||||||||||||||
| 391 | # "OSOK", "TOSOK", "BOSOK", "HTF", "TKTF", "KTF" | ||||||||||||||||||||||||||||
| 392 | #}; | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 4 | my %mode_name = ( | |||||||||||||||||||||||||||
| 395 | 0 => 'DEMO', | ||||||||||||||||||||||||||||
| 396 | 1 => 'TDM', | ||||||||||||||||||||||||||||
| 397 | 2 => 'COOP', # uppercased for consistency... | ||||||||||||||||||||||||||||
| 398 | 3 => 'DM', | ||||||||||||||||||||||||||||
| 399 | 4 => 'SURV', | ||||||||||||||||||||||||||||
| 400 | 5 => 'TSURV', | ||||||||||||||||||||||||||||
| 401 | 6 => 'CTF', | ||||||||||||||||||||||||||||
| 402 | 7 => 'PF', | ||||||||||||||||||||||||||||
| 403 | 8 => 'BTDM', | ||||||||||||||||||||||||||||
| 404 | 9 => 'BDM', | ||||||||||||||||||||||||||||
| 405 | 10 => 'LSS', | ||||||||||||||||||||||||||||
| 406 | 11 => 'OSOK', | ||||||||||||||||||||||||||||
| 407 | 12 => 'TOSOK', | ||||||||||||||||||||||||||||
| 408 | 13 => 'BOSOK', | ||||||||||||||||||||||||||||
| 409 | 14 => 'HTF', | ||||||||||||||||||||||||||||
| 410 | 15 => 'TKTF', | ||||||||||||||||||||||||||||
| 411 | 16 => 'KTF', | ||||||||||||||||||||||||||||
| 412 | ); | ||||||||||||||||||||||||||||
| 413 | 4 | my %name_mode = map { $mode_name{ $_ } => $_ } keys %mode_name; | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 6 | ▶ | sub get_gamemode_name { | ||||||||||||||||||||||||||
|
Subroutine
get_gamemode_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 416 | 6 | my $m = shift; | |||||||||||||||||||||||||||
| 417 | 6 | ▶ | return unless defined $m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | 6 | ▶ | if ( exists $mode_name{ $m } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 6 | return $mode_name{ $m }; | |||||||||||||||||||||||||||
| 420 | } else { | ||||||||||||||||||||||||||||
| 421 | 0 | return; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 11 | ▶ | sub get_gamemode_from_name { | ||||||||||||||||||||||||||
|
Subroutine
get_gamemode_from_name: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 426 | 11 | my $m = uc( shift ); | |||||||||||||||||||||||||||
| 427 | 11 | ▶ | return unless defined $m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 11 | ▶ | if ( exists $name_mode{ $m } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 11 | return $name_mode{ $m }; | |||||||||||||||||||||||||||
| 430 | } else { | ||||||||||||||||||||||||||||
| 431 | 0 | return; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 4 | ▶ | sub getpongflag { | ||||||||||||||||||||||||||
|
Subroutine
getpongflag: not called CC=9 SCAR=44.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 437 | 0 | my $pong = shift; | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | # FIXME convert this to proper enums | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | # from protocol.h | ||||||||||||||||||||||||||||
| 442 | #enum { PONGFLAG_PASSWORD = 0, PONGFLAG_BANNED, PONGFLAG_BLACKLIST, PONGFLAG_MASTERMODE = 6, PONGFLAG_NUM }; | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | # from serverbrowser.cpp | ||||||||||||||||||||||||||||
| 445 | # if(si->pongflags > 0) | ||||||||||||||||||||||||||||
| 446 | # { | ||||||||||||||||||||||||||||
| 447 | # const char *sp = ""; | ||||||||||||||||||||||||||||
| 448 | # int mm = si->pongflags >> PONGFLAG_MASTERMODE; | ||||||||||||||||||||||||||||
| 449 | # if(si->pongflags & (1 << PONGFLAG_BANNED)) | ||||||||||||||||||||||||||||
| 450 | # sp = "you are banned from this server"; | ||||||||||||||||||||||||||||
| 451 | # if(si->pongflags & (1 << PONGFLAG_BLACKLIST)) | ||||||||||||||||||||||||||||
| 452 | # sp = "you are blacklisted on this server"; | ||||||||||||||||||||||||||||
| 453 | # else if(si->pongflags & (1 << PONGFLAG_PASSWORD)) | ||||||||||||||||||||||||||||
| 454 | # sp = "this server is password-protected"; | ||||||||||||||||||||||||||||
| 455 | # else if(mm) sp = mmfullname(mm); | ||||||||||||||||||||||||||||
| 456 | # s_sprintf(si->description)("%s \f1(%s)", si->sdesc, sp); | ||||||||||||||||||||||||||||
| 457 | # } | ||||||||||||||||||||||||||||
| 458 | # | ||||||||||||||||||||||||||||
| 459 | # // from protocol.cpp | ||||||||||||||||||||||||||||
| 460 | # const char *mmfullnames[] = { "open", "private" }; | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ( defined $pong and $pong > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pong and $pong > 0
MC/DC0%0/2
defined $pong and $pong > 0
defined $pong
$pong > 0
Truth table0%0/3
A and B
A= defined $pongB= $pong > 0
| |||||||||||||||||||||||||||||
| 463 | 0 | my $mm = $pong >> 6; | |||||||||||||||||||||||||||
| 464 | 0 | ▶ | if ( $pong & ( 1 << 1 ) ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 465 | 0 | return "you are banned from this server"; | |||||||||||||||||||||||||||
| 466 | } elsif ( $pong & ( 1 << 2 ) ) { | ||||||||||||||||||||||||||||
| 467 | 0 | return "you are blacklisted on this server"; | |||||||||||||||||||||||||||
| 468 | } elsif ( $pong & ( 1 << 0 ) ) { | ||||||||||||||||||||||||||||
| 469 | 0 | return "this server is password-protected"; | |||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ( $mm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | 0 | ▶ | if ( $mm == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 473 | 0 | return "open"; | |||||||||||||||||||||||||||
| 474 | } elsif ( $mm == 2 ) { | ||||||||||||||||||||||||||||
| 475 | 0 | return "private"; | |||||||||||||||||||||||||||
| 476 | } else { | ||||||||||||||||||||||||||||
| 477 | 0 | return "UNKNOWN"; | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | } else { | ||||||||||||||||||||||||||||
| 480 | 0 | return "UNKNOWN"; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | } else { | ||||||||||||||||||||||||||||
| 484 | 0 | return "none"; | |||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 5 | ▶ | sub stripcolors { | ||||||||||||||||||||||||||
|
Subroutine
stripcolors: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 489 | 5 | my $str = shift; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | # From AC docs/colouredtext.txt | ||||||||||||||||||||||||||||
| 492 | # also, look at the PHP code for reference :) | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | 5 | my $output = ''; | |||||||||||||||||||||||||||
| 495 | 5 | my $foundcolor = 0; | |||||||||||||||||||||||||||
| 496 | 5 | foreach my $c ( split( //, $str ) ) { | |||||||||||||||||||||||||||
| 497 | 174 | ▶ | if ( $foundcolor ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 498 | # skip the damn thing | ||||||||||||||||||||||||||||
| 499 | 15 | $foundcolor = 0; | |||||||||||||||||||||||||||
| 500 | } elsif ( ord( $c ) == 12 ) { | ||||||||||||||||||||||||||||
| 501 | 15 | $foundcolor++ | |||||||||||||||||||||||||||
| 502 | } else { | ||||||||||||||||||||||||||||
| 503 | 144 | $output .= $c; | |||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 5 | return $output; | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | { | ||||||||||||||||||||||||||||
| 511 | # From AC docs/colouredtext.txt | ||||||||||||||||||||||||||||
| 512 | # also, look at the PHP code for reference :) | ||||||||||||||||||||||||||||
| 513 | # $html_colors = array( | ||||||||||||||||||||||||||||
| 514 | # "<span style='color: #00ee00'>", | ||||||||||||||||||||||||||||
| 515 | # "<span style='color: #0000ee'>", | ||||||||||||||||||||||||||||
| 516 | # "<span style='color: #f7de12'>", | ||||||||||||||||||||||||||||
| 517 | # "<span style='color: #ee0000'>", | ||||||||||||||||||||||||||||
| 518 | # "<span style='color: #767676'>", | ||||||||||||||||||||||||||||
| 519 | # "<span style='color: #eeeeee'>", | ||||||||||||||||||||||||||||
| 520 | # "<span style='color: #824f03'>", | ||||||||||||||||||||||||||||
| 521 | # "<span style='color: #9a0000'>" | ||||||||||||||||||||||||||||
| 522 | # ); | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 4 | my %htmlcolors = ( | |||||||||||||||||||||||||||
| 525 | 0 => '<font color="#00ee00">', | ||||||||||||||||||||||||||||
| 526 | 1 => '<font color="#0000ee">', | ||||||||||||||||||||||||||||
| 527 | 2 => '<font color="#f7de12">', | ||||||||||||||||||||||||||||
| 528 | 3 => '<font color="#ee0000">', | ||||||||||||||||||||||||||||
| 529 | 4 => '<font color="#767676">', | ||||||||||||||||||||||||||||
| 530 | 5 => '<font color="#eeeeee">', | ||||||||||||||||||||||||||||
| 531 | 6 => '<font color="#824f03">', | ||||||||||||||||||||||||||||
| 532 | 7 => '<font color="#9a0000">', | ||||||||||||||||||||||||||||
| 533 | ); | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | 0 | ▶ | sub htmlcolors { | ||||||||||||||||||||||||||
|
Subroutine
htmlcolors: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 536 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 0 | my $found = 0; | |||||||||||||||||||||||||||
| 539 | 0 | my $incolor = 0; | |||||||||||||||||||||||||||
| 540 | 0 | my $ret = ''; | |||||||||||||||||||||||||||
| 541 | 0 | my @chars = split( //, $str ); | |||||||||||||||||||||||||||
| 542 | 0 | foreach my $i ( 0 .. $#chars ) { | |||||||||||||||||||||||||||
| 543 | 0 | ▶ | if ( $found ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 544 | 0 | ▶ | if ( exists $htmlcolors{ $chars[$i] } and defined $chars[$i+1] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $htmlcolors{$chars[$i]} and defined $chars[$i + 1]
MC/DC0%0/2
exists $htmlcolors{$chars[$i]} and defined $chars[$i + 1]
exists $htmlcolors{$chars[$i]}
defined $chars[$i + 1]
Truth table0%0/3
A and B
A= exists $htmlcolors{$chars[$i]}B= defined $chars[$i + 1]
| |||||||||||||||||||||||||||||
| 545 | 0 | $ret .= $htmlcolors{ $chars[$i] }; | |||||||||||||||||||||||||||
| 546 | 0 | $incolor = 1; | |||||||||||||||||||||||||||
| 547 | } else { | ||||||||||||||||||||||||||||
| 548 | 0 | warn "unknown AC color code: $chars[$i]"; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | 0 | $found = 0; | |||||||||||||||||||||||||||
| 551 | } elsif ( ord( $chars[$i] ) == 12 ) { | ||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if ( $incolor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | 0 | $ret .= '</font>'; | |||||||||||||||||||||||||||
| 554 | 0 | $incolor = 0; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | 0 | $found = 1; | |||||||||||||||||||||||||||
| 557 | } else { | ||||||||||||||||||||||||||||
| 558 | 0 | $ret .= $chars[$i]; | |||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | 0 | ▶ | if ( $found ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 562 | 0 | $ret .= '</font>'; | |||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | return $ret; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | 4 | ▶ | sub parse_pingresponse { | ||||||||||||||||||||||||||
|
Subroutine
parse_pingresponse: called CC=9 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 570 | 6 | my $r = shift; | |||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | # from serverbrowser.cpp | ||||||||||||||||||||||||||||
| 573 | #ucharbuf p(ping, len); | ||||||||||||||||||||||||||||
| 574 | # si->lastpingmillis = totalmillis; | ||||||||||||||||||||||||||||
| 575 | # int pingtm = pingbuf[(getint(p) - 1) % PINGBUFSIZE]; | ||||||||||||||||||||||||||||
| 576 | # si->ping = pingtm ? totalmillis - pingtm : 9997; | ||||||||||||||||||||||||||||
| 577 | # int query = getint(p); | ||||||||||||||||||||||||||||
| 578 | # si->protocol = getint(p); | ||||||||||||||||||||||||||||
| 579 | # if(si->protocol!=PROTOCOL_VERSION) si->ping = 9998; | ||||||||||||||||||||||||||||
| 580 | # si->mode = getint(p); | ||||||||||||||||||||||||||||
| 581 | # si->numplayers = getint(p); | ||||||||||||||||||||||||||||
| 582 | # si->minremain = getint(p); | ||||||||||||||||||||||||||||
| 583 | # getstring(text, p); | ||||||||||||||||||||||||||||
| 584 | # filtertext(si->map, text, 1); | ||||||||||||||||||||||||||||
| 585 | # getstring(text, p); | ||||||||||||||||||||||||||||
| 586 | # filterservdesc(si->sdesc, text); | ||||||||||||||||||||||||||||
| 587 | # s_strcpy(si->description, si->sdesc); | ||||||||||||||||||||||||||||
| 588 | # si->maxclients = getint(p); | ||||||||||||||||||||||||||||
| 589 | # if(p.remaining()) | ||||||||||||||||||||||||||||
| 590 | # { | ||||||||||||||||||||||||||||
| 591 | # si->pongflags = getint(p); | ||||||||||||||||||||||||||||
| 592 | # if(p.remaining() && getint(p) == query) | ||||||||||||||||||||||||||||
| 593 | # { | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 6 | my %data; | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 6 | $data{'pingtime'} = getint( \$r ); | |||||||||||||||||||||||||||
| 598 | 6 | $data{'query'} = getint( \$r ); | |||||||||||||||||||||||||||
| 599 | 6 | $data{'protocol'} = getint( \$r ); | |||||||||||||||||||||||||||
| 600 | 5 | $data{'gamemode'} = getint( \$r ) + 1; # for some reason, AC returns mode - 1 | |||||||||||||||||||||||||||
| 601 | 5 | $data{'players'} = getint( \$r ); | |||||||||||||||||||||||||||
| 602 | 5 | $data{'minutes_left'} = getint( \$r ); | |||||||||||||||||||||||||||
| 603 | 5 | $data{'map'} = getstring( \$r ); | |||||||||||||||||||||||||||
| 604 | 5 | $data{'desc'} = getstring( \$r ); | |||||||||||||||||||||||||||
| 605 | 5 | $data{'max_players'} = getint( \$r ); | |||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | # sometimes we don't get pongflags | ||||||||||||||||||||||||||||
| 608 | 5 | ▶ | if ( length( $r ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 5 | $data{'pong'} = getint( \$r ); | |||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | # sometimes there is no player data... | ||||||||||||||||||||||||||||
| 612 | 5 | ▶ | if ( length( $r ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 613 | 5 | my $query = getint( \$r ); | |||||||||||||||||||||||||||
| 614 | 5 | ▶ | if ( defined $query ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 615 | 5 | ▶ | if ( $query == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 616 | # no extra data | ||||||||||||||||||||||||||||
| 617 | } elsif ( $query == 1 ) { | ||||||||||||||||||||||||||||
| 618 | 2 | ▶ | while ( length( $r ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 619 | 6 | my $player = getstring( \$r ); | |||||||||||||||||||||||||||
| 620 | 6 | ▶ | if ( defined $player and $player ne '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $player and $player ne ""
MC/DC50%1/2
defined $player and $player ne ""
defined $player
$player ne ""
Truth table66%2/3
A and B
A= defined $playerB= $player ne ""
| |||||||||||||||||||||||||||||
| 621 | 4 | push( @{ $data{'player_list'} }, $player ); | |||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | } else { | ||||||||||||||||||||||||||||
| 625 | # unknown PINGMODE | ||||||||||||||||||||||||||||
| 626 | 0 | die "unknown PINGMODE: $query"; | |||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | 5 | return \%data; | |||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | 4 | 1; | |||||||||||||||||||||||||||
| 636 | __END__ | ||||||||||||||||||||||||||||