mohaa-stats-ftp
Code (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?
class n3rd_mohaa_stats{
# VARS:
function n3rd_mohaa_stats($template, $maindir, $qconsole, $index_max, $version = '2.0 BETA'){
$this->template = $template;
$this->maindir = $maindir;
$this->qconsole = $qconsole;
$this->index_max = $index_max;
$this->version = $version;
}
# Mogelijke Death Messages:
# SELF & SPECIAL:
var $dm = array(
"took himself out of commision" => "suicide",
"was burned to a crisp" => "suicide",
"cratered" => "cratered",
"tripped on his own grenade" => "own grenade",
"played catch with himself" => "own grenade",
"blew himself up" => "suicide",
"rocketed himself" => "suicide",
"shot himself in the" => "suicide",
"died" => "suicide",
"blew up" => "blew up",
"was killed by" => "suicide",
# NADE:
"is picking" => "grenade",
"tripped on" => "grenade",
# ROCKET:
"was blown away by" => "rocket",
"took" => "rocket",
# GUN:
"was shot by" => "gun",
"was gunned down by" => "gun",
# SINPER:
"was sniped by" => "sniper",
# RIFLE:
"was rifled by" => "rifle",
# SMG:
"was perforated by" => "SMG",
# MG:
"was machine-gunned by" => "MG",
# BASH:
"was clubbed by" => "bash",
"was bashed by" => "bash",
# SHOTGUN:
"was pumped full of buckshot by" => "shotgun",
"was hunted down by" => "shotgun"
);
# Locaties waar iemand mogelijk dodelijk geraakt kan worden:
var $location = array(
"head",
"neck",
"upper torso",
"middle torso",
"lower torso",
"pelvis",
"upper right arm",
"upper left arm",
"upper right leg",
"upper left leg",
"lower right arm",
"lower left arm",
"lower right leg",
"lower left leg",
"right hand",
"left hand",
"right foot",
"left foot",
"face",
"kisser"
);
var $strip = array(
"'s shrapnel out of his teeth",
"'s grenade",
"'s rocket right",
"'s rocket",
"'s SMG",
"himself out of commision",
"his own grenade",
);
# // VARS
function kills(){
$file = file($this->qconsole);
foreach($file as $rule){
if(substr($rule, 0, 5) !== 'CHAT:' && substr($rule, 0, 2) !== 'SV' && substr($rule, 0, 4) !== 'Rcon' && substr($rule, 0, 6) !== 'status'){
foreach($this->dm as $message => $weapon){
if(strpos($rule, $message)){
$explode = explode($message, $rule);
$info[1] = addslashes(trim($explode[0]));
if(strpos($explode[1], ' in the ')){
$expl = explode(' in the ', $explode[1]);
$info[2] = addslashes(trim(str_replace($this->strip, '', $expl[0])));
$info[3] = addslashes(trim($expl[1]));
}else{
$info[2] = addslashes(trim(str_replace($this->strip, '', $explode[1])));
$info[3] = '';
}
$info[4] = addslashes(trim($weapon));
$result[] = $info;
}
}
}
}
return $result;
}
function count_kills(){
$kills = $this->kills();
$players = array();
foreach($kills as $nr => $kill){
# Killed person Check:
if(!in_array($kill[1], $players)){
$players[] = $kill[1];
$pid = array_search($kill[1], $players);
$data[$pid]['kills'] = 0;
$data[$pid]['deaths'] = 0;
foreach($this->dm as $dm_v){
$data[$pid][$dm_v] = 0;
}
foreach($this->location as $location_v){
$data[$pid][$location_v] = 0;
}
}
# Killer Check:
if(!empty($kill[2]) && !in_array($kill[2], $players)){
$players[] = $kill[2];
$pid = array_search($kill[2], $players);
$data[$pid]['kills'] = 0;
$data[$pid]['deaths'] = 0;
foreach($this->dm as $dm_v){
$data[$pid][$dm_v] = 0;
}
foreach($this->location as $location_v){
$data[$pid][$location_v] = 0;
}
}
# Optellen van de data:
$data[array_search($kill[1], $players)]['deaths']++;
if(!empty($kill[2])){ # Als de persoon door iemand anders gedood werd:
$data[array_search($kill[2], $players)]['kills']++;
if(!empty($kill[3])){
$data[array_search($kill[2], $players)][trim($kill[3])]++;
}
$data[array_search($kill[2], $players)][$kill[4]]++;
}else{ # Als de persoon zichzelf doode:
$data[array_search($kill[1], $players)][$kill[4]]++;
}
}
$return['players'] = $players;
$return['data'] = $data;
return $return;
}
function player_pages($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
# output plaatsen in:
$output = $this->maindir . '/players/' . $pid . '.html';
$file = fopen($output , 'w');
arsort($data[$pid]);
fwrite($file, $this->t_top('../', htmlspecialchars(stripslashes($pnick))));
fwrite($file, "<h2>General information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Ratio:</td><td colspan='2'>" . $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']) . "</td></tr>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Total kills:</td><td colspan='2'>" . $data[$pid]['kills'] . "</td></tr>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Total deaths:</td><td colspan='2'>" . $data[$pid]['deaths'] . "</td></tr>\n");
fwrite($file, "</table>\n");
fwrite($file, "<h2>Aim information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($data[$pid] as $k => $v){
if(in_array($k, $this->location)){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>" . $k . "</td><td>" . $v . "</td><td>" . $this->percent($v, $data[$pid]['kills']) . "%</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, "<h2>Weapon information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($data[$pid] as $k => $v){
if(in_array($k, $this->dm)){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>" . $k . "</td><td colspan='2'>" . $v . "</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('../', htmlspecialchars(stripslashes($pnick))));
fclose($file);
}
}
function ratio($kills, $deaths){
if($deaths == 0){
return $kills;
}else{
return round(($kills/$deaths) ,2);
}
}
function percent($part, $total){
if($total == 0){
return 0;
}else{
$percent = (100/$total);
return round(($percent*$part) ,2);
}
}
function t_top($basedir, $title){
$file = file('templates/' . $this->template . '/top.html');
$file = str_replace('%basedir%', $basedir, $file);
$file = str_replace('%date%', date('d/m/Y'), $file);
$file = str_replace('%version%', $this->version, $file);
$file = str_replace('%title%', $title, $file);
$file = str_replace('%time%', date('H:i:s'), $file);
$file = str_replace('%phpversion%', phpversion(), $file);
return implode('', $file);
}
function t_bottom($basedir, $title){
$file = file('templates/' . $this->template . '/bottom.html');
$file = str_replace('%basedir%', $basedir, $file);
$file = str_replace('%date%', date('d/m/Y'), $file);
$file = str_replace('%version%', $this->version , $file);
$file = str_replace('%title%', $title, $file);
$file = str_replace('%time%', date('H:i:s'), $file);
$file = str_replace('%phpversion%', phpversion(), $file);
return implode('', $file);
}
function awards_page($input){
$players = $input['players'];
$data = $input['data'];
$dm_order = array();
$output = $this->maindir . '/awards.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Awards'));
fwrite($file, "<h2>General:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($players as $pid => $pnick){
$most_kills[$pid] = $data[$pid]['kills'];
$most_deaths[$pid] = $data[$pid]['deaths'];
$highest_ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
arsort($highest_ratio);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest ratio:</td><td><a href='players/" . key($highest_ratio) . ".html'>" . htmlspecialchars(stripslashes($players[key($highest_ratio)])) . "</a></td><td>" . current($highest_ratio) . "</td></tr>\n");
arsort($most_kills);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Most kills:</td><td><a href='players/" . key($most_kills) . ".html'>" . htmlspecialchars(stripslashes($players[key($most_kills)])) . "</a></td><td>" . current($most_kills) . "</td></tr>\n");
arsort($most_deaths);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Most deaths:</td><td><a href='players/" . key($most_deaths) . ".html'>" . htmlspecialchars(stripslashes($players[key($most_deaths)])) . "</a></td><td>" . current($most_deaths) . "</td></tr>\n");
fwrite($file, "</table>\n");
fwrite($file, "<h2>Aim awards:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($this->location as $l_v){
foreach($players as $pid => $pnick){
$l_order[$l_v][$pid] = $this->percent($data[$pid][$l_v], $data[$pid]['kills']);
}
arsort($l_order[$l_v]);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest amount " . $l_v . " shots:</td><td><a href='players/" . key($l_order[$l_v]) . ".html'>" . htmlspecialchars(stripslashes($players[key($l_order[$l_v])])) . "</a></td><td>" . current($l_order[$l_v]) . "%</td><td>" . $data[key($l_order[$l_v])][$l_v] . " Kills</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, "<h2>Weapon awards:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($this->dm as $dm_v){
if(!array_key_exists($dm_v, $dm_order)){
foreach($players as $pid => $pnick){
$dm_order[$dm_v][$pid] = $this->percent($data[$pid][$dm_v], $data[$pid]['kills']);
}
arsort($dm_order[$dm_v]);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest amount " . $dm_v . " kills:</td><td><a href='players/" . key($dm_order[$dm_v]) . ".html'>" . htmlspecialchars(stripslashes($players[key($dm_order[$dm_v])])) . "</a></td><td>" . current($dm_order[$dm_v]) . "%</td><td>" . $data[key($dm_order[$dm_v])][$dm_v] . " Kills</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Awards'));
fclose($file);
}
function style(){
$style = implode('', file('templates/' . $this->template . '/style.css'));
$output = $this->maindir . '/style.css';
$file = fopen($output , 'w');
fwrite($file, $style);
fclose($file);
}
function ratio_page($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
$ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
$output = $this->maindir . '/ratio.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Ratio'));
fwrite($file, "<h2>Ratio ranking:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
arsort($ratio);
foreach($ratio as $pid => $value){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . $pid . ".html'>" . htmlspecialchars(stripslashes($players[$pid])) . "</a></td><td>" . $data[$pid]['kills'] . "</td><td>" . $data[$pid]['deaths'] . "</td><td>" . $value . "</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Ratio'));
fclose($file);
}
function kills_page($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
$kill[$pid] = $data[$pid]['kills'];
}
$output = $this->maindir . '/kills.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Kills'));
fwrite($file, "<h2>Kill ranking:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
arsort($kill);
foreach($kill as $pid => $value){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . $pid . ".html'>" . htmlspecialchars(stripslashes($players[$pid])) . "</a></td><td>" . $data[$pid]['kills'] . "</td><td>" . $data[$pid]['deaths'] . "</td><td>" . $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']) . "</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Kills'));
fclose($file);
}
function index_page($input){
$players = $input['players'];
$data = $input['data'];
$output = $this->maindir . '/index.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'N3RD\'s MoH:AA stats'));
foreach($players as $pid => $pnick){
$kill[$pid] = $data[$pid]['kills'];
$ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
arsort($ratio);
fwrite($file, "<h2>Ratio top " . $this->index_max . ":</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
for($i=0;$i<$this->index_max;$i++){
if(isset($ratio[key($ratio)])){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . key($ratio) . ".html'>" . htmlspecialchars(stripslashes($players[key($ratio)])) . "</a></td><td>" . $data[key($ratio)]['kills'] . "</td><td>" . $data[key($ratio)]['deaths'] . "</td><td>" . $this->ratio($data[key($ratio)]['kills'], $data[key($ratio)]['deaths']) . "</td></tr>\n");
}
next($ratio);
}
fwrite($file, "</table>\n");
arsort($kill);
fwrite($file, "<h2>Kill top " . $this->index_max . ":</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
for($i=0;$i<$this->index_max;$i++){
if(isset($kill[key($kill)])){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . key($kill) . ".html'>" . htmlspecialchars(stripslashes($players[key($kill)])) . "</a></td><td>" . $data[key($kill)]['kills'] . "</td><td>" . $data[key($kill)]['deaths'] . "</td><td>" . $this->ratio($data[key($kill)]['kills'], $data[key($kill)]['deaths']) . "</td></tr>\n");
}
next($kill);
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'N3RD\'s MoH:AA stats'));
fclose($file);
}
function temp_dir(){
if(!is_dir($this->maindir)){
mkdir($this->maindir, 0777);
}
if(!is_dir($this->maindir . '/players')){
mkdir($this->maindir . '/players', 0777);
}
}
}
?>
class n3rd_mohaa_stats{
# VARS:
function n3rd_mohaa_stats($template, $maindir, $qconsole, $index_max, $version = '2.0 BETA'){
$this->template = $template;
$this->maindir = $maindir;
$this->qconsole = $qconsole;
$this->index_max = $index_max;
$this->version = $version;
}
# Mogelijke Death Messages:
# SELF & SPECIAL:
var $dm = array(
"took himself out of commision" => "suicide",
"was burned to a crisp" => "suicide",
"cratered" => "cratered",
"tripped on his own grenade" => "own grenade",
"played catch with himself" => "own grenade",
"blew himself up" => "suicide",
"rocketed himself" => "suicide",
"shot himself in the" => "suicide",
"died" => "suicide",
"blew up" => "blew up",
"was killed by" => "suicide",
# NADE:
"is picking" => "grenade",
"tripped on" => "grenade",
# ROCKET:
"was blown away by" => "rocket",
"took" => "rocket",
# GUN:
"was shot by" => "gun",
"was gunned down by" => "gun",
# SINPER:
"was sniped by" => "sniper",
# RIFLE:
"was rifled by" => "rifle",
# SMG:
"was perforated by" => "SMG",
# MG:
"was machine-gunned by" => "MG",
# BASH:
"was clubbed by" => "bash",
"was bashed by" => "bash",
# SHOTGUN:
"was pumped full of buckshot by" => "shotgun",
"was hunted down by" => "shotgun"
);
# Locaties waar iemand mogelijk dodelijk geraakt kan worden:
var $location = array(
"head",
"neck",
"upper torso",
"middle torso",
"lower torso",
"pelvis",
"upper right arm",
"upper left arm",
"upper right leg",
"upper left leg",
"lower right arm",
"lower left arm",
"lower right leg",
"lower left leg",
"right hand",
"left hand",
"right foot",
"left foot",
"face",
"kisser"
);
var $strip = array(
"'s shrapnel out of his teeth",
"'s grenade",
"'s rocket right",
"'s rocket",
"'s SMG",
"himself out of commision",
"his own grenade",
);
# // VARS
function kills(){
$file = file($this->qconsole);
foreach($file as $rule){
if(substr($rule, 0, 5) !== 'CHAT:' && substr($rule, 0, 2) !== 'SV' && substr($rule, 0, 4) !== 'Rcon' && substr($rule, 0, 6) !== 'status'){
foreach($this->dm as $message => $weapon){
if(strpos($rule, $message)){
$explode = explode($message, $rule);
$info[1] = addslashes(trim($explode[0]));
if(strpos($explode[1], ' in the ')){
$expl = explode(' in the ', $explode[1]);
$info[2] = addslashes(trim(str_replace($this->strip, '', $expl[0])));
$info[3] = addslashes(trim($expl[1]));
}else{
$info[2] = addslashes(trim(str_replace($this->strip, '', $explode[1])));
$info[3] = '';
}
$info[4] = addslashes(trim($weapon));
$result[] = $info;
}
}
}
}
return $result;
}
function count_kills(){
$kills = $this->kills();
$players = array();
foreach($kills as $nr => $kill){
# Killed person Check:
if(!in_array($kill[1], $players)){
$players[] = $kill[1];
$pid = array_search($kill[1], $players);
$data[$pid]['kills'] = 0;
$data[$pid]['deaths'] = 0;
foreach($this->dm as $dm_v){
$data[$pid][$dm_v] = 0;
}
foreach($this->location as $location_v){
$data[$pid][$location_v] = 0;
}
}
# Killer Check:
if(!empty($kill[2]) && !in_array($kill[2], $players)){
$players[] = $kill[2];
$pid = array_search($kill[2], $players);
$data[$pid]['kills'] = 0;
$data[$pid]['deaths'] = 0;
foreach($this->dm as $dm_v){
$data[$pid][$dm_v] = 0;
}
foreach($this->location as $location_v){
$data[$pid][$location_v] = 0;
}
}
# Optellen van de data:
$data[array_search($kill[1], $players)]['deaths']++;
if(!empty($kill[2])){ # Als de persoon door iemand anders gedood werd:
$data[array_search($kill[2], $players)]['kills']++;
if(!empty($kill[3])){
$data[array_search($kill[2], $players)][trim($kill[3])]++;
}
$data[array_search($kill[2], $players)][$kill[4]]++;
}else{ # Als de persoon zichzelf doode:
$data[array_search($kill[1], $players)][$kill[4]]++;
}
}
$return['players'] = $players;
$return['data'] = $data;
return $return;
}
function player_pages($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
# output plaatsen in:
$output = $this->maindir . '/players/' . $pid . '.html';
$file = fopen($output , 'w');
arsort($data[$pid]);
fwrite($file, $this->t_top('../', htmlspecialchars(stripslashes($pnick))));
fwrite($file, "<h2>General information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Ratio:</td><td colspan='2'>" . $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']) . "</td></tr>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Total kills:</td><td colspan='2'>" . $data[$pid]['kills'] . "</td></tr>\n");
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Total deaths:</td><td colspan='2'>" . $data[$pid]['deaths'] . "</td></tr>\n");
fwrite($file, "</table>\n");
fwrite($file, "<h2>Aim information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($data[$pid] as $k => $v){
if(in_array($k, $this->location)){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>" . $k . "</td><td>" . $v . "</td><td>" . $this->percent($v, $data[$pid]['kills']) . "%</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, "<h2>Weapon information:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($data[$pid] as $k => $v){
if(in_array($k, $this->dm)){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>" . $k . "</td><td colspan='2'>" . $v . "</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('../', htmlspecialchars(stripslashes($pnick))));
fclose($file);
}
}
function ratio($kills, $deaths){
if($deaths == 0){
return $kills;
}else{
return round(($kills/$deaths) ,2);
}
}
function percent($part, $total){
if($total == 0){
return 0;
}else{
$percent = (100/$total);
return round(($percent*$part) ,2);
}
}
function t_top($basedir, $title){
$file = file('templates/' . $this->template . '/top.html');
$file = str_replace('%basedir%', $basedir, $file);
$file = str_replace('%date%', date('d/m/Y'), $file);
$file = str_replace('%version%', $this->version, $file);
$file = str_replace('%title%', $title, $file);
$file = str_replace('%time%', date('H:i:s'), $file);
$file = str_replace('%phpversion%', phpversion(), $file);
return implode('', $file);
}
function t_bottom($basedir, $title){
$file = file('templates/' . $this->template . '/bottom.html');
$file = str_replace('%basedir%', $basedir, $file);
$file = str_replace('%date%', date('d/m/Y'), $file);
$file = str_replace('%version%', $this->version , $file);
$file = str_replace('%title%', $title, $file);
$file = str_replace('%time%', date('H:i:s'), $file);
$file = str_replace('%phpversion%', phpversion(), $file);
return implode('', $file);
}
function awards_page($input){
$players = $input['players'];
$data = $input['data'];
$dm_order = array();
$output = $this->maindir . '/awards.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Awards'));
fwrite($file, "<h2>General:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($players as $pid => $pnick){
$most_kills[$pid] = $data[$pid]['kills'];
$most_deaths[$pid] = $data[$pid]['deaths'];
$highest_ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
arsort($highest_ratio);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest ratio:</td><td><a href='players/" . key($highest_ratio) . ".html'>" . htmlspecialchars(stripslashes($players[key($highest_ratio)])) . "</a></td><td>" . current($highest_ratio) . "</td></tr>\n");
arsort($most_kills);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Most kills:</td><td><a href='players/" . key($most_kills) . ".html'>" . htmlspecialchars(stripslashes($players[key($most_kills)])) . "</a></td><td>" . current($most_kills) . "</td></tr>\n");
arsort($most_deaths);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Most deaths:</td><td><a href='players/" . key($most_deaths) . ".html'>" . htmlspecialchars(stripslashes($players[key($most_deaths)])) . "</a></td><td>" . current($most_deaths) . "</td></tr>\n");
fwrite($file, "</table>\n");
fwrite($file, "<h2>Aim awards:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($this->location as $l_v){
foreach($players as $pid => $pnick){
$l_order[$l_v][$pid] = $this->percent($data[$pid][$l_v], $data[$pid]['kills']);
}
arsort($l_order[$l_v]);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest amount " . $l_v . " shots:</td><td><a href='players/" . key($l_order[$l_v]) . ".html'>" . htmlspecialchars(stripslashes($players[key($l_order[$l_v])])) . "</a></td><td>" . current($l_order[$l_v]) . "%</td><td>" . $data[key($l_order[$l_v])][$l_v] . " Kills</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, "<h2>Weapon awards:</h2>\n");
fwrite($file, "<table width='100%'>\n");
foreach($this->dm as $dm_v){
if(!array_key_exists($dm_v, $dm_order)){
foreach($players as $pid => $pnick){
$dm_order[$dm_v][$pid] = $this->percent($data[$pid][$dm_v], $data[$pid]['kills']);
}
arsort($dm_order[$dm_v]);
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td>Highest amount " . $dm_v . " kills:</td><td><a href='players/" . key($dm_order[$dm_v]) . ".html'>" . htmlspecialchars(stripslashes($players[key($dm_order[$dm_v])])) . "</a></td><td>" . current($dm_order[$dm_v]) . "%</td><td>" . $data[key($dm_order[$dm_v])][$dm_v] . " Kills</td></tr>\n");
}
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Awards'));
fclose($file);
}
function style(){
$style = implode('', file('templates/' . $this->template . '/style.css'));
$output = $this->maindir . '/style.css';
$file = fopen($output , 'w');
fwrite($file, $style);
fclose($file);
}
function ratio_page($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
$ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
$output = $this->maindir . '/ratio.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Ratio'));
fwrite($file, "<h2>Ratio ranking:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
arsort($ratio);
foreach($ratio as $pid => $value){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . $pid . ".html'>" . htmlspecialchars(stripslashes($players[$pid])) . "</a></td><td>" . $data[$pid]['kills'] . "</td><td>" . $data[$pid]['deaths'] . "</td><td>" . $value . "</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Ratio'));
fclose($file);
}
function kills_page($input){
$players = $input['players'];
$data = $input['data'];
foreach($players as $pid => $pnick){
$kill[$pid] = $data[$pid]['kills'];
}
$output = $this->maindir . '/kills.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'Kills'));
fwrite($file, "<h2>Kill ranking:</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
arsort($kill);
foreach($kill as $pid => $value){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . $pid . ".html'>" . htmlspecialchars(stripslashes($players[$pid])) . "</a></td><td>" . $data[$pid]['kills'] . "</td><td>" . $data[$pid]['deaths'] . "</td><td>" . $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']) . "</td></tr>\n");
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'Kills'));
fclose($file);
}
function index_page($input){
$players = $input['players'];
$data = $input['data'];
$output = $this->maindir . '/index.html';
$file = fopen($output , 'w');
fwrite($file, $this->t_top('', 'N3RD\'s MoH:AA stats'));
foreach($players as $pid => $pnick){
$kill[$pid] = $data[$pid]['kills'];
$ratio[$pid] = $this->ratio($data[$pid]['kills'], $data[$pid]['deaths']);
}
arsort($ratio);
fwrite($file, "<h2>Ratio top " . $this->index_max . ":</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
for($i=0;$i<$this->index_max;$i++){
if(isset($ratio[key($ratio)])){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . key($ratio) . ".html'>" . htmlspecialchars(stripslashes($players[key($ratio)])) . "</a></td><td>" . $data[key($ratio)]['kills'] . "</td><td>" . $data[key($ratio)]['deaths'] . "</td><td>" . $this->ratio($data[key($ratio)]['kills'], $data[key($ratio)]['deaths']) . "</td></tr>\n");
}
next($ratio);
}
fwrite($file, "</table>\n");
arsort($kill);
fwrite($file, "<h2>Kill top " . $this->index_max . ":</h2>\n");
fwrite($file, "<table width='100%'>\n");
fwrite($file, "<tr class='tr-out'><td>Player:</td><td>Kills:</td><td>Deaths:</td><td>Ratio:</td></tr>\n");
for($i=0;$i<$this->index_max;$i++){
if(isset($kill[key($kill)])){
fwrite($file, "<tr class='tr-out' onmouseover=\"this.className='tr-over'\" onmouseout=\"this.className='tr-out'\"><td><a href='players/" . key($kill) . ".html'>" . htmlspecialchars(stripslashes($players[key($kill)])) . "</a></td><td>" . $data[key($kill)]['kills'] . "</td><td>" . $data[key($kill)]['deaths'] . "</td><td>" . $this->ratio($data[key($kill)]['kills'], $data[key($kill)]['deaths']) . "</td></tr>\n");
}
next($kill);
}
fwrite($file, "</table>\n");
fwrite($file, $this->t_bottom('', 'N3RD\'s MoH:AA stats'));
fclose($file);
}
function temp_dir(){
if(!is_dir($this->maindir)){
mkdir($this->maindir, 0777);
}
if(!is_dir($this->maindir . '/players')){
mkdir($this->maindir . '/players', 0777);
}
}
}
?>