-
Notifications
You must be signed in to change notification settings - Fork 6
/
complete_stats.php
111 lines (93 loc) · 3.58 KB
/
complete_stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
$filename = (@$argv[1] ? $argv[1] : 'openarena.log' );
$file = @fopen( $filename, 'r' );
if (!$file ) {
echo "unable to open file: $filename\n";
die(1);
}
$player_ids = array();
$player_stats = array();
while (( $line = fgets( $file, 4096 ) ) !== false ) {
//strip \n
$line = substr($line, 0, -1);
$words = explode(' ', $line );
switch ( $words[0] ) {
case 'ClientUserinfoChanged:': {
$client_id = $words[1];
$playerdata = explode( '\\', str_replace( '\\\\', '|', $words[2] ) );
$player_name = $playerdata[1];
$player_ids[ $client_id ] = $player_name;
if (!isset( $player_stats[ $player_name ] )) {
$player_stats[$player_name] = array( 'items' => array(), 'kills' => array(), 'killed_by' => array(), 'kills_who' => array(), 'kills_method' => array(), 'killed_by_who' => array(), 'killed_by_method' => array(), 'suicides' => array(), 'rounds' => 1, 'awards' => array() );
} else {
$player_stats[$player_name]['rounds']++;
}
} break;
case 'Item:': {
$client_id = $words[1];
$item = $words[2];
$player_name = $player_ids[$client_id];
$item_parts = explode('_',$item);
$item_type = $item_parts[0];
@$player_stats[$player_name]['items'][$item_type][$item]++;
} break;
case 'Kill:': {
$victim_id = $words[2];
$attacker_id = ( $words[1] == 1022 ? $victim_id : $words[1]);
$method = $words[8];
$attacker_name = $player_ids[$attacker_id];
$victim_name = $player_ids[$victim_id];
if ( $victim_id == $attacker_id ) {
@$player_stats[$victim_name]['suicides'][$method]++;
} else {
@$player_stats[$victim_name]['killed_by'][$attacker_name][$method]++;
@$player_stats[$attacker_name]['kills'][$victim_name][$method]++;
}
} break;
case 'Award:': {
$player_id = $words[1];
$award = $words[6];
$player_name = $player_ids[$player_id];
@$player_stats[$player_name]['awards'][$award]++;
} break;
}
}
//Lists
foreach ($player_stats as &$player) {
//kills who list
foreach ( $player['kills'] as $victim => $data ) {
foreach ( $data as $method => $count ) {
@$player['kills_who'][$victim] += $count;
@$player['kills_method'][$method] += $count;
}
}
//killed by list
foreach ( $player['killed_by'] as $victim => $data ) {
foreach ( $data as $method => $count ) {
@$player['killed_by_who'][$victim] += $count;
@$player['killed_by_method'][$method] += $count;
}
}
}
//Sorting
foreach ($player_stats as &$stat ) {
//items
foreach ( $stat['items'] as &$item ) {
array_multisort( $item, SORT_DESC | SORT_REGULAR );
}
//kills
foreach ( $stat['kills'] as &$kill ) {
array_multisort( $kill, SORT_DESC | SORT_REGULAR );
}
array_multisort( $stat['kills_who'], SORT_DESC | SORT_REGULAR );
array_multisort( $stat['kills_method'], SORT_DESC | SORT_REGULAR );
foreach ( $stat['killed_by'] as &$killed ) {
array_multisort( $killed, SORT_DESC | SORT_REGULAR );
}
array_multisort( $stat['killed_by_who'], SORT_DESC | SORT_REGULAR );
array_multisort( $stat['killed_by_method'], SORT_DESC | SORT_REGULAR );
//awards
array_multisort( $stat['awards'], SORT_DESC | SORT_REGULAR );
}
print_r( $player_stats );
die(0);