Games/AssaultCube/Log/Line.pm

filter: Statementstmt 88.5% 108 / 122 Branchbran 83.9% 146 / 174 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 83.8% 269 / 321 CC 91 SCAR 43.9
CC
91
Cov
85%
parse
90.8
new
21.5
create_subclass
2.0
CRAP 80.3
↑ Summary Games/AssaultCube/ServerQuery.pm »
1 # Declare our package
2 package Games::AssaultCube::Log::Line;
3 2 ▶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 2 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $VERSION = '0.04';
8  
9 # the factory constructor
10 74 ▶sub new {
Subroutine new: called CC=7 SCAR=30.7
Pod undocumented
11 74 my $class = shift;
12 74 my $line = shift;
13 74 my $subclass = shift;
14  
15 # sanity checking
16 74 ▶ if ( ! defined $line or ! length $line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line and length $line) 0 74 74
Condition33%1/3
defined $line and length $line
!ll&&!rl&&r
0074
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
17 0 die "Please supply a valid line";
18 }
19  
20 # Do we have a subclass to hand off the line?
21 74 ▶ if ( defined $subclass ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subclass) 0 74 74
22 # object or coderef?
23 0 ▶ if ( ref( $subclass ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subclass eq 'CODE') { } 0 0 0
24 0 my $result = $subclass->( $line );
25 0 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
26 0 return $result;
27 }
28 } else {
29 0 my $result = $subclass->parse( $line );
30 0 ▶ if ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result) 0 0 0
31 0 return $result;
32 }
33 }
34 }
35  
36 # parse the line!
37 74 return parse( $line );
38 }
39  
40 74 ▶sub create_subclass {
Subroutine create_subclass: called CC=2 SCAR=7.1
Pod undocumented
41 74 my $line = shift;
42 74 my $event = shift;
43 74 my $data = shift;
44  
45 # Load the subclass we need
46 74 eval "require Games::AssaultCube::Log::Line::$event"; ## no critic (ProhibitStringyEval)
47 74 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 74 74
48 0 die "Unable to load our subclass: $@";
49 }
50  
51 # Store the data
52 74 $data->{'event'} = $event;
53 74 $data->{'line'} = $line;
54  
55 # create the object!
56 74 return "Games::AssaultCube::Log::Line::$event"->new( $data );
57 }
58  
59 74 ▶sub parse {
Subroutine parse: called CC=84 SCAR=45.1
Pod undocumented
60 74 my $text = shift;
61 74 ▶ if ($text =~ m!^\[([\d\.]*)\]\s+(.+)$!) {
Branch: 28 branches
BranchTrueFalseTotal
if ($text =~ /^\[([\d\.]*)\]\s+(.+)$/) { } 39 35 74
elsif ($text =~ /^\s*(\d+)\s+([^\s]+)\s+(\w+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$/) { } 2 33 35
elsif ($text =~ /^\s*(\d+)\s+([^\s]+)\s+(\w+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$/) { } 1 32 33
elsif ($text =~ /^\s*(\d+)\s+([^\s]+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$/) { } 1 31 32
elsif ($text =~ /^\s*(\d+)\s+([^\s]+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$/) { } 1 30 31
elsif ($text =~ /^Team\s+(\w+):\s+(\d+)\s+players,\s+(-?\d+)\s+frags(?:,\s+(-?\d+)\s+flags)?$/) { } 2 28 30
elsif ($text =~ /^Game\s+status:\s+(.+)\s+on\s+([^,]*),\s+(\d+)\s+[^,]+,\s+(\w+)$/) { } 1 27 28
elsif ($text =~ /^Game\s+status:\s+(.+)\s+on\s+([^,]+),\s+game finished,\s+(\w+)$/) { } 1 26 27
elsif ($text =~ /cn\s+name\s+(?:team\s+)?frag\s+death\s+(?:flags\s+)?role\s+host$/) { } 4 22 26
elsif ($text =~ m[^Status\s+at\s+(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+):\s+(\d+)\s+remote\s+clients,\s+([\d\.]+)\s+send,\s+([\d\.]+)\s+rec\s+\(K/sec\)$]) { } 1 21 22
elsif ($text =~ /^Game\s+start:\s+(.+)\s+on\s+([^,]+),\s+(\d+)\s+[^,]+,\s+(\d+)\s+[^,]+,\s+mastermode\s+(\d+)/) { } 1 20 21
elsif ($text =~ /^at-target:\s+(-?\d+),\s+(.+)\s+pick:(\d+)$/) { } 1 19 20
elsif ($text =~ /^the\s+server\s+reset\s+the\s+flag\s+for\s+team\s+(\w+)$/) { } 1 18 19
elsif ($text =~ /^sending\s+request\s+to\s+(.+)...$/) { } 1 17 18
elsif ($text =~ /^masterserver\s+reply:\s+(.*)$/) { } 2 15 17
elsif ($text eq 'Registration successful. Due to caching it might take a few minutes to see the your server in the serverlist') { } 0 15 15
elsif ($text eq 'Server not registered, could not ping you. Make sure your server is accessible from the internet.') { } 1 14 15
elsif ($text eq 'logging local AssaultCube server now..' or $text eq 'dedicated server started, waiting for clients...' or $text eq 'Ctrl-C to exit') { } 2 12 14
elsif ($text =~ /^loaded\s+map\s+([^,]+),\s+(\d+)\s+\+\s+(\d+)\((\d+)\)\s+bytes\.$/) { } 1 11 12
elsif ($text =~ /^read\s+(\d+)\s+\((\d+)\)\s+blacklist\s+entries\s+from\s+(.+)$/) { } 1 10 11
elsif ($text =~ /^read\s+(\d+)\s+admin\s+passwords\s+from\s+(.*)$/) { } 1 9 10
elsif ($text =~ /^looking\s+up\s+(.+)\.\.\./) { } 1 8 9
elsif ($text =~ /^map\s+\"([^\"]+)\"\s+does\s+not\s+support\s+\"([^\"]+)\":\s+(.+)$/) { } 1 7 8
elsif ($text =~ /^could\s+not\s+read\s+config\s+file\s+\'(.+)\'$/) { } 1 6 7
elsif ($text =~ /^maprot\s+error:\s+map\s+\'(.+)\'\s+not\s+found$/) { } 1 5 6
elsif ($text =~ /^AssaultCube\s+fatal\s+error:\s+(.*)$/) { } 1 4 5
elsif ($text eq 'Demo recording started.') { } 1 3 4
elsif ($text =~ /^Demo\s+"\w+\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+):\s+([^\,]+),\s+([^\,]+),\s+([\d\.]+)(MB|kB)"\s+recorded.$/) { } 2 1 3
62 39 my $ip = $1;
63 39 my $etext = $2;
64 39 ▶ if ($ip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip) { } 39 0 39
65 39 ▶ if ($etext =~ m!^([^\s]+)\s+(fragged|gibbed)\s+(his\s+teammate\s+)?(.+)$!) {
Branch: 18 branches
BranchTrueFalseTotal
if ($etext =~ /^([^\s]+)\s+(fragged|gibbed)\s+(his\s+teammate\s+)?(.+)$/) { } 4 35 39
elsif ($etext =~ /^([^\s]+)\s+says(?:\s+to\s+team\s+(\w+))?:\s+\'(.*)\'(,\s+SPAM\s+detected)?$/) { } 3 32 35
elsif ($etext =~ /^disconnected\s+client\s+(.*)$/) { } 1 31 32
elsif ($etext =~ /^disconnecting\s+client\s+([^\s]*)\s+\((.+)\)$/) { } 1 30 31
elsif ($etext eq 'client connected') { } 1 29 30
elsif ($etext =~ /^([^\s]+)\s+(dropped|lost|returned|stole)\s+the\s+flag$/) { } 4 25 29
elsif ($etext =~ /^runs\s+AC\s+(\d+)\s+\(defs:\s+(.+)\)$/) { } 1 24 25
elsif ($etext =~ /^([^\s]+)\s+scored\s+with\s+the\s+flag\s+for\s+(\w+),\s+new\s+score\s+(-?\d+)$/) { } 1 23 24
elsif ($etext =~ /^client\s+([^\s]+)\s+(failed\s+to\s+)?call(?:ed)?\s+a\s+vote:\s+(.*)$/) { } 12 11 23
elsif ($etext =~ /^(.+)\s+suicided$/) { } 1 10 11
elsif ($etext =~ /^([^\s]+)\s+changed\s+his\s+name\s+to\s+(.+)$/) { } 1 9 10
elsif ($etext =~ /^([^\s]+)\s+scored,\s+carrying\s+for\s+(\d+)\s+seconds,\s+new\s+score\s+(\d+)$/) { } 1 8 9
elsif ($etext =~ /^set\s+role\s+of\s+player\s+([^\s]+)\s+to\s+(\w+)(?:\s+player)?$/) { } 2 6 8
elsif ($etext =~ /^player\s+([^\s]+)\s+used\s+admin\s+password\s+in\s+line\s+(\d+)$/) { } 1 5 6
elsif ($etext =~ /^([^\s]+)\s+got\s+forced\s+to\s+pickup\s+the\s+flag$/) { } 1 4 5
elsif ($etext =~ /^([^\s]+)\s+failed\s+to\s+score$/) { } 1 3 4
elsif ($etext =~ /^logged\s+in\s+using\s+the\s+admin\s+password\s+in\s+line\s+(\d+)(,\s+\(ban\s+removed\))?$/) { } 1 2 3
elsif ($etext =~ /^([^\s]+)\s+says(?:\s+to\s+team\s+(\w+))?:\s+\'([^']+)$/) { } 1 1 2
66 4 ▶ return create_subclass($text,'Killed',{
Branch: 2 branches
BranchTrueFalseTotal
$2 eq 'gibbed' ? : 2 2 4
defined $3 ? : 2 2 4
67 nick => $1,
68 gib => $2 eq 'gibbed' ? 1 : 0,
69 tk => defined $3 ? 1 : 0,
70 victim => $4,
71 ip => $ip,
72 });
73 } elsif ($etext =~ m!^([^\s]+)\s+says(?:\s+to\s+team\s+(\w+))?:\s+\'(.*)\'(,\s+SPAM\s+detected)?$!) {
74 # TODO what should we do with $2, the team name?
75 3 ▶ return create_subclass($text,'Says',{
Branch: 2 branches
BranchTrueFalseTotal
defined $2 ? : 1 2 3
defined $4 ? : 1 2 3
76 nick => $1,
77 isteam => defined $2 ? 1 : 0,
78 text => $3,
79 spam => defined $4 ? 1 : 0,
80 ip => $ip,
81 });
82 } elsif ($etext =~ m!^disconnected\s+client\s+(.*)$!) {
83 1 ▶ return create_subclass($text,'ClientDisconnected',{
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 1 0 1
84 ( defined $1 ? ( nick => $1 ) : () ),
85 ip => $ip,
86 forced => 0,
87 });
88 } elsif ($etext =~ m!^disconnecting\s+client\s+([^\s]*)\s+\((.+)\)$!) {
89 1 return create_subclass($text,'ClientDisconnected',{
90 nick => $1,
91 reason => $2,
92 ip => $ip,
93 forced => 1,
94 });
95 } elsif ($etext eq 'client connected') {
96 1 return create_subclass($text,'ClientConnected',{
97 ip => $ip,
98 });
99 } elsif ($etext =~ m!^([^\s]+)\s+(dropped|lost|returned|stole)\s+the\s+flag$!) {
100 4 return create_subclass($text,'Flag' . ucfirst( $2 ),{
101 nick => $1,
102 ip => $ip,
103 });
104 } elsif ($etext =~ m!^runs\s+AC\s+(\d+)\s+\(defs:\s+(.+)\)$!) {
105 1 return create_subclass($text,'ClientVersion',{
106 version => $1,
107 defs => $2,
108 ip => $ip,
109 });
110 } elsif ($etext =~ m!^([^\s]+)\s+scored\s+with\s+the\s+flag\s+for\s+(\w+),\s+new\s+score\s+(-?\d+)$!) {
111 1 return create_subclass($text,'FlagScored',{
112 nick => $1,
113 team_name => $2,
114 score => $3,
115 ip => $ip,
116 });
117 } elsif ($etext =~ m!^client\s+([^\s]+)\s+(failed\s+to\s+)?call(?:ed)?\s+a\s+vote:\s+(.*)$!) {
118 12 my $nick = $1;
119 12 my $failure = $2;
120 12 my $vote = $3;
121 12 ▶ if ( defined $failure ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $failure) { } 5 7 12
122 5 $failure = 1;
123 } else {
124 7 $failure = 0;
125 }
126  
127 # parse the vote...
128 12 ▶ if (! length $vote) {
Branch: 8 branches
BranchTrueFalseTotal
if (not length $vote) { } 1 11 12
elsif ($vote =~ /^load\s+map\s+\'(.*)\'\s+in\s+mode\s+\'(.+)\'(?:\s+\((.+)\))?$/) { } 2 9 11
elsif ($vote =~ /^(\w+)\s+player\s+([^\s]*)(?:\s+to\s+the\s+enemy\s+team)?(?:\s+\((.+)\))?$/) { } 3 6 9
elsif ($vote =~ /^shuffle\s+teams(?:\s+\((.+)\))?$/) { } 1 5 6
elsif ($vote =~ /^(enable|disable|remove|stop)\s+([^\(]+)(?:\s+\((.+)\))?$/) { } 3 2 5
elsif ($vote =~ /^change\s+(.+)(?:\s+\((.+)\))?$/) { } 1 1 2
elsif ($vote =~ /^set\s+(.+)(?:\s+\((.+)\))?$/) { } 0 1 1
elsif ($vote =~ /^\((.+)\)$/) { } 1 0 1
129 1 return create_subclass($text,'CallVote',{
130 nick => $nick,
131 type => 'invalid',
132 failure => 1,
133 target => 'invalid',
134 failure_reason => 'empty vote',
135 ip => $ip,
136 });
137 } elsif ($vote =~ m!^load\s+map\s+\'(.*)\'\s+in\s+mode\s+\'(.+)\'(?:\s+\((.+)\))?$!) {
138 2 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 1 1 2
139 nick => $nick,
140 type => 'loadmap',
141 failure => $failure,
142 target => $1 . ' - ' . $2,
143 ip => $ip,
144 ( defined $3 ? ( failure_reason => $3 ) : () ),
145 });
146 } elsif ($vote =~ m!^(\w+)\s+player\s+([^\s]*)(?:\s+to\s+the\s+enemy\s+team)?(?:\s+\((.+)\))?$!) {
147 3 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 2 1 3
148 nick => $nick,
149 type => $1,
150 failure => $failure,
151 target => $2,
152 ip => $ip,
153 ( defined $3 ? ( failure_reason => $3 ) : () ),
154 });
155 } elsif ($vote =~ m!^shuffle\s+teams(?:\s+\((.+)\))?$!) {
156 1 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 1 1
157 nick => $nick,
158 type => 'shuffle',
159 failure => $failure,
160 target => 'teams',
161 ip => $ip,
162 ( defined $2 ? ( failure_reason => $2 ) : () ),
163 });
164 } elsif ($vote =~ m!^(enable|disable|remove|stop)\s+([^\(]+)(?:\s+\((.+)\))?$!) {
165 3 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 1 2 3
166 nick => $nick,
167 type => $1,
168 failure => $failure,
169 target => $2,
170 ip => $ip,
171 ( defined $3 ? ( failure_reason => $3 ) : () ),
172 });
173 } elsif ($vote =~ m!^change\s+(.+)(?:\s+\((.+)\))?$!) {
174 1 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 1 1
175 nick => $nick,
176 type => 'change',
177 failure => $failure,
178 target => $1,
179 ip => $ip,
180 ( defined $2 ? ( failure_reason => $2 ) : () ),
181 });
182 } elsif ($vote =~ m!^set\s+(.+)(?:\s+\((.+)\))?$!) {
183 0 ▶ return create_subclass($text,'CallVote',{
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 0 0
184 nick => $nick,
185 type => 'set',
186 failure => $failure,
187 target => $1,
188 ip => $ip,
189 ( defined $2 ? ( failure_reason => $2 ) : () ),
190 });
191 } elsif ($vote =~ m!^\((.+)\)$!) {
192 1 return create_subclass($text,'CallVote',{
193 nick => $nick,
194 type => 'invalid',
195 failure => $failure,
196 target => 'invalid',
197 failure_reason => $1,
198 ip => $ip,
199 });
200 } else {
201 0 die "unknown vote type: $text - $vote";
202 }
203 } elsif ($etext =~ m!^(.+)\s+suicided$!) {
204 1 return create_subclass($text,'Suicide',{
205 nick => $1,
206 ip => $ip,
207 });
208 } elsif ($etext =~ m!^([^\s]+)\s+changed\s+his\s+name\s+to\s+(.+)$!) {
209 1 return create_subclass($text,'ClientNickChange',{
210 oldnick => $1,
211 nick => $2,
212 ip => $ip,
213 });
214 } elsif ($etext =~ m!^([^\s]+)\s+scored,\s+carrying\s+for\s+(\d+)\s+seconds,\s+new\s+score\s+(\d+)$!) {
215 1 return create_subclass($text,'FlagScoredKTF',{
216 nick => $1,
217 carried => $2,
218 score => $3,
219 ip => $ip,
220 });
221 } elsif ($etext =~ m!^set\s+role\s+of\s+player\s+([^\s]+)\s+to\s+(\w+)(?:\s+player)?$!) {
222 # AC prints "normal" instead of "default", argh!
223 2 my $role = 'ADMIN';
224 2 ▶ if ( $2 eq 'normal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "normal") 1 1 2
225 1 $role = 'DEFAULT';
226 }
227  
228 2 return create_subclass($text,'ClientChangeRole',{
229 nick => $1,
230 role_name => $role,
231 ip => $ip,
232 });
233 } elsif ($etext =~ m!^player\s+([^\s]+)\s+used\s+admin\s+password\s+in\s+line\s+(\d+)$!) {
234 1 return create_subclass($text,'ClientAdmin',{
235 nick => $1,
236 password => $2,
237 ip => $ip,
238 });
239 } elsif ($etext =~ m!^([^\s]+)\s+got\s+forced\s+to\s+pickup\s+the\s+flag$!) {
240 1 return create_subclass($text,'FlagForcedPickup',{
241 nick => $1,
242 ip => $ip,
243 });
244 } elsif ($etext =~ m!^([^\s]+)\s+failed\s+to\s+score$!) {
245 1 return create_subclass($text,'FlagFailedScore',{
246 nick => $1,
247 ip => $ip,
248 });
249 } elsif ($etext =~ m!^logged\s+in\s+using\s+the\s+admin\s+password\s+in\s+line\s+(\d+)(,\s+\(ban\s+removed\))?$!) {
250 1 ▶ return create_subclass($text,'ClientAdmin',{
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 1 0 1
251 password => $1,
252 ip => $ip,
253 ( defined $2 ? ( unbanned => 1 ) : () ),
254 });
255  
256 # ARGH, sometimes ac_server "overflows" and fails to print the message properly...
257 } elsif ($etext =~ m!^([^\s]+)\s+says(?:\s+to\s+team\s+(\w+))?:\s+\'([^']+)$!) {
258 # TODO what should we do with $2, the team name?
259 1 ▶ return create_subclass($text,'Says',{
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 1 1
260 nick => $1,
261 isteam => defined $2 ? 1 : 0,
262 text => $3,
263 spam => 0,
264 ip => $ip,
265 });
266 } else {
267 1 return create_subclass($text,'Unknown',{
268 ip => $ip,
269 text => $etext,
270 });
271 }
272 } else {
273 0 return create_subclass($text,'Unknown',{});
274 }
275 } elsif ($text =~ m!^\s*(\d+)\s+([^\s]+)\s+(\w+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$!) {
276 2 ▶ return create_subclass($text,'ClientStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$7 eq 'normal' ? : 1 1 2
277 cn => $1,
278 nick => $2,
279 team_name => $3,
280 frags => $4,
281 deaths => $5,
282 flags => $6,
283 role_name => ( $7 eq 'normal' ? 'DEFAULT' : 'ADMIN' ), # AC prints "normal" instead of "default", argh!
284 ip => $8,
285 });
286 } elsif ($text =~ m!^\s*(\d+)\s+([^\s]+)\s+(\w+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$!) {
287 1 ▶ return create_subclass($text,'ClientStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$6 eq 'normal' ? : 1 0 1
288 cn => $1,
289 nick => $2,
290 team_name => $3,
291 frags => $4,
292 deaths => $5,
293 role_name => ( $6 eq 'normal' ? 'DEFAULT' : 'ADMIN' ), # AC prints "normal" instead of "default", argh!
294 ip => $7,
295 });
296 } elsif ($text =~ m!^\s*(\d+)\s+([^\s]+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$!) {
297 1 ▶ return create_subclass($text,'ClientStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$6 eq 'normal' ? : 1 0 1
298 cn => $1,
299 nick => $2,
300 team_name => 'NONE',
301 frags => $3,
302 deaths => $4,
303 flags => $5,
304 role_name => ( $6 eq 'normal' ? 'DEFAULT' : 'ADMIN' ), # AC prints "normal" instead of "default", argh!
305 ip => $7,
306 });
307 } elsif ($text =~ m!^\s*(\d+)\s+([^\s]+)\s+(-?\d+)\s+(-?\d+)\s+(\w+)\s+([\d\.]+)$!) {
308 1 ▶ return create_subclass($text,'ClientStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$5 eq 'normal' ? : 1 0 1
309 cn => $1,
310 nick => $2,
311 team_name => 'NONE',
312 frags => $3,
313 deaths => $4,
314 role_name => ( $5 eq 'normal' ? 'DEFAULT' : 'ADMIN' ), # AC prints "normal" instead of "default", argh!
315 ip => $6,
316 });
317 } elsif ($text =~ m!^Team\s+(\w+):\s+(\d+)\s+players,\s+(-?\d+)\s+frags(?:,\s+(-?\d+)\s+flags)?$!) {
318 2 ▶ return create_subclass($text,'TeamStatus',{
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 1 1 2
319 team_name => $1,
320 players => $2,
321 frags => $3,
322 ( defined $4 ? ( flags => $4 ) : () ),
323 });
324 } elsif ($text =~ m!^Game\s+status:\s+(.+)\s+on\s+([^,]*),\s+(\d+)\s+[^,]+,\s+(\w+)$!) {
325 1 ▶ return create_subclass($text,'GameStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'ctf' ? : 1 0 1
326 gamemode_fullname => ( $1 eq 'ctf' ? 'capture the flag' : $1 ), # ctf is annoying because of our "substitution" from 'ctf' to "capture the flag"
327 'map' => $2,
328 minutes => $3,
329 mastermode_name => uc( $4 ),
330 finished => 0,
331 });
332 } elsif ($text =~ m!^Game\s+status:\s+(.+)\s+on\s+([^,]+),\s+game finished,\s+(\w+)$!) {
333 1 ▶ return create_subclass($text,'GameStatus',{
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'ctf' ? : 0 1 1
334 gamemode_fullname => ( $1 eq 'ctf' ? 'capture the flag' : $1 ), # ctf is annoying because of our "substitution" from 'ctf' to "capture the flag"
335 'map' => $2,
336 minutes => 0,
337 mastermode_name => uc( $3 ),
338 finished => 1,
339 });
340 } elsif ($text =~ m!cn\s+name\s+(?:team\s+)?frag\s+death\s+(?:flags\s+)?role\s+host$!) {
341 4 return create_subclass($text,'ScoreboardStart',{});
342 } elsif ($text =~ m!^Status\s+at\s+(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+):\s+(\d+)\s+remote\s+clients,\s+([\d\.]+)\s+send,\s+([\d\.]+)\s+rec\s+\(K/sec\)$!) {
343 1 require DateTime;
344 1 my $datetime = DateTime->new(
345 year => $3,
346 month => $2,
347 day => $1,
348 hour => $4,
349 minute => $5,
350 second => $6,
351 );
352 1 return create_subclass($text,'Status',{
353 datetime => $datetime,
354 players => $7,
355 sent => $8,
356 'recv' => $9,
357 });
358 } elsif ($text =~ m!^Game\s+start:\s+(.+)\s+on\s+([^,]+),\s+(\d+)\s+[^,]+,\s+(\d+)\s+[^,]+,\s+mastermode\s+(\d+)!) {
359 1 ▶ return create_subclass($text,'GameStart',{
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'ctf' ? : 0 1 1
360 gamemode_fullname => ( $1 eq 'ctf' ? 'capture the flag' : $1 ), # ctf is annoying because of our "substitution" from 'ctf' to "capture the flag"
361 'map' => $2,
362 players => $3,
363 minutes => $4,
364 mastermode => $5,
365 });
366 } elsif ($text =~ m!^at-target:\s+(-?\d+),\s+(.+)\s+pick:(\d+)$!) {
367 return create_subclass($text,'AutoBalance',{
368 target => $1,
369 1 players => { map { split( /:/, $_, 2 ) } split( ' ', $2 ) },
370 pick => $3,
371 });
372 } elsif ($text =~ m!^the\s+server\s+reset\s+the\s+flag\s+for\s+team\s+(\w+)$!) {
373 1 return create_subclass($text,'FlagReset',{
374 team_name => $1,
375 });
376 } elsif ($text =~ m!^sending\s+request\s+to\s+(.+)...$!) {
377 1 return create_subclass($text,'MasterserverRequest',{
378 server => $1,
379 });
380 } elsif ($text =~ m!^masterserver\s+reply:\s+(.*)$!) {
381 2 return create_subclass($text,'MasterserverReply',{
382 reply => $1,
383 success => 1,
384 });
385 } elsif ($text eq 'Registration successful. Due to caching it might take a few minutes to see the your server in the serverlist') {
386 0 return create_subclass($text,'MasterserverReply',{
387 reply => 'Registration successful. Due to caching it might take a few minutes to see the your server in the serverlist',
388 success => 1,
389 });
390 } elsif ($text eq 'Server not registered, could not ping you. Make sure your server is accessible from the internet.') {
391 1 return create_subclass($text,'MasterserverReply',{
392 reply => 'Server not registered, could not ping you. Make sure your server is accessible from the internet.',
393 success => 0,
394 });
395 ▶ } elsif ($text eq 'logging local AssaultCube server now..' or $text eq 'dedicated server started, waiting for clients...' or $text eq 'Ctrl-C to exit') {
Condition83%5/6
$text eq "logging local AssaultCube server now.." or $text eq "dedicated server started, waiting for clients..." or $text eq "Ctrl-C to exit"
l!l&&r!l&&!r
2012
$text eq "logging local AssaultCube server now.." or $text eq "dedicated server started, waiting for clients..."
l!l&&r!l&&!r
1112
MC/DC66%2/3
$text eq "logging local AssaultCube server now.." or $text eq "dedicated server started, waiting for clients..." or $text eq "Ctrl-C to exit"
$text eq "logging local AssaultCube server now.." $text eq "dedicated server started, waiting for clients..." $text eq "Ctrl-C to exit"
Truth table75%3/4
A or B or C
A= $text eq "logging local AssaultCube server now.."B= $text eq "dedicated server started, waiting for clients..."C= $text eq "Ctrl-C to exit"
ABCresult
1XX1
01X1
0011
0000
396 2 return create_subclass($text,'StartupText',{});
397 } elsif ($text =~ m!^loaded\s+map\s+([^,]+),\s+(\d+)\s+\+\s+(\d+)\((\d+)\)\s+bytes\.$!) {
398 # cleanup the map name
399 1 my( $mapname, $mapsize, $cfgsize, $cfgzsize ) = ( $1, $2, $3, $4 );
400 1 ▶ if ( $mapname =~ /([^\\\/]+)\.cgz$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mapname =~ m[([^\\/]+)\.cgz$]) { } 1 0 1
401 1 $mapname = $1;
402 } else {
403 0 die "unable to parse mapname: $mapname";
404 }
405  
406 1 return create_subclass($text,'LoadedMap',{
407 'map' => $mapname,
408 mapsize => $mapsize,
409 cfgsize => $cfgsize,
410 cfgzsize => $cfgzsize,
411 });
412 } elsif ($text =~ m!^read\s+(\d+)\s+\((\d+)\)\s+blacklist\s+entries\s+from\s+(.+)$!) {
413 1 return create_subclass($text,'BlacklistEntries',{
414 count => $1,
415 count_secondary => $2,
416 config => $3,
417 });
418 } elsif ($text =~ m!^read\s+(\d+)\s+admin\s+passwords\s+from\s+(.*)$!) {
419 1 return create_subclass($text,'AdminPasswords',{
420 count => $1,
421 config => $2,
422 });
423 } elsif ($text =~ m!^looking\s+up\s+(.+)\.\.\.!) {
424 1 return create_subclass($text,'DNSLookup',{
425 host => $1,
426 });
427 } elsif ($text =~ m!^map\s+\"([^\"]+)\"\s+does\s+not\s+support\s+\"([^\"]+)\":\s+(.+)$!) {
428 1 ▶ return create_subclass($text,'MapError',{
Branch: 1 branch
BranchTrueFalseTotal
$2 eq 'ctf' ? : 1 0 1
429 'map' => $1,
430 gamemode_fullname => ( $2 eq 'ctf' ? 'capture the flag' : $2 ), # ctf is annoying because of our "substitution" from 'ctf' to "capture the flag"
431 error => $3,
432 });
433 } elsif ($text =~ m!^could\s+not\s+read\s+config\s+file\s+\'(.+)\'$!) {
434 1 return create_subclass($text,'ConfigError',{
435 errortype => 'config read',
436 what => $1,
437 });
438 } elsif ($text =~ m!^maprot\s+error:\s+map\s+\'(.+)\'\s+not\s+found$!) {
439 1 return create_subclass($text,'ConfigError',{
440 errortype => 'maprot missing map',
441 what => $1,
442 });
443 } elsif ($text =~ m!^AssaultCube\s+fatal\s+error:\s+(.*)$!) {
444 1 return create_subclass($text,'FatalError',{
445 error => $1,
446 });
447 } elsif ($text eq 'Demo recording started.' ) {
448 1 return create_subclass($text,'DemoStart',{});
449  
450 # Demo "Tue Feb 17 11:14:58 2009: ctf, bs_dust2_0.6, 1.32MB" recorded.
451 } elsif ($text =~ m!^Demo\s+"\w+\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+):\s+([^\,]+),\s+([^\,]+),\s+([\d\.]+)(MB|kB)"\s+recorded.$!) {
452 2 require DateTime;
453 2 my $datetime = DateTime->new(
454 year => $6,
455 month => month2num( $1 ),
456 day => $2,
457 hour => $3,
458 minute => $4,
459 second => $5,
460 );
461  
462 # Figure out the size, ack!
463 2 my $size;
464 2 ▶ if ( $10 eq 'MB' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($10 eq 'MB') { } 1 1 2
465 1 $size = int( $9 * 1024 * 1024 );
466 } else {
467 1 $size = int( $9 * 1024 );
468 }
469  
470 2 return create_subclass($text,'DemoStop',{
471 datetime => $datetime,
472 gamemode_fullname => $7,
473 'map' => $8,
474 size => $size,
475 });
476 } else {
477 1 return create_subclass($text,'Unknown',{
478 text => $text,
479 });
480 }
481 }
482  
483 # TODO find a suitable module for this! ( DateTime::Format::xyz )
484 # We need this for the DemoStop DateTime conversions...
485 {
486 2 my %month_num = (
487 'Jan' => 1,
488 'Feb' => 2,
489 'Mar' => 3,
490 'Apr' => 4,
491 'May' => 5,
492 'Jun' => 6,
493 'Jul' => 7,
494 'Aug' => 8,
495 'Sep' => 9,
496 'Oct' => 10,
497 'Nov' => 11,
498 'Dec' => 12,
499 );
500 2 ▶ sub month2num {
Subroutine month2num: called CC=1 SCAR=0.0
Pod undocumented
501 2 return $month_num{ +shift };
502 }
503 }
504  
505 2 1;
506 __END__
↑ Summary Games/AssaultCube/ServerQuery.pm »