summaryrefslogtreecommitdiffstats
path: root/old/admin/parse_Everquest2German.php
blob: 1e6e087f1d24855ca4eb0477a5419e57e0ee3fb3 (plain)
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * parse_Everquest2.php
 * Began: Tue December 24 2002
 * 
 * $Id: parse_Everquest2German.php 46 2007-06-19 07:29:11Z tsigo $
 * 
 ******************************/
 
define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

class Parse_Log extends EQdkp_Admin
{
    function parse_log()
    {
        global $db, $eqdkp, $user, $tpl, $pm;
        global $SID;
        
        parent::eqdkp_admin();
        
        $this->assoc_buttons(array(
            'parse' => array(
                'name'    => 'parse',
                'process' => 'process_parse',
                'check'   => 'a_raid_'),
            'form' => array(
                'name'    => '',
                'process' => 'display_form',
                'check'   => 'a_raid_'))
        );
    }
    
    // ---------------------------------------------------------
    // Process Parse
    // ---------------------------------------------------------
    function process_parse()
    {
        global $db, $eqdkp, $user, $tpl, $pm;
        global $SID;
        
        $channel_members  = '';
        $line             = '';
        $valid_date_found = false;
        
        $log_file = explode("\n", $_POST['log']);
        $log_file = str_replace('&lt;', '<', str_replace('&gt;', '>', $log_file));
        $line_count = sizeof($log_file);
        
        // Go through each line and
        //      - Check for/get a valid member in the /who
        //      - Check if there's a valid date we can use
        //      - Check for/get valid members from /list <channel>
        $log_date = array();
        session_start(); // Hold our array of name => class/level/race
        for ( $i = 0; $i < $line_count; $i++ )
        {
            $line = '';
            if ( (isset($_POST['findall'])) || (strpos($log_file[$i], '<')) )
            {
                $member_name = $this->line_parse($log_file[$i]);

                // Make sure that each member's name is properly capitalized
                $mname = strtolower(preg_replace('/[[:space:]]/i', ' ', $member_name));
                $member_name = ucwords($mname);

                if ( trim($member_name) != '')
                {
                    $member_names[] = $member_name;
                }
            }
            
        } // for ... log_file
        
        // If there were channel members, join the two arrays
        if ( !empty($channel_members) )
        {
            $channel_members = explode(', ', $channel_members);
            $member_names = array_merge($member_names, $channel_members);
        }
        
        $date['mo'] = date('M');
        $date['d']  = date('d');
        $date['y']  = date('Y');
        $date['h']  = date('h');
        $date['mi'] = date('i');
        $date['s']  = date('s');
        
        // Process the member_names array: replaces spaces, make it unique, sort it and reset it
        if ( (isset($member_names)) && (is_array($member_names)) )
        {
            $name_count = sizeof($member_names);
        }
        else
        {
            $name_count = 0;
            $member_names = array();
        }
        
        for ( $i = 0; $i < $name_count; $i++ )
        {
            $member_names[$i] = str_replace(' ', '', $member_names[$i]);
        }
        $member_names = array_unique($member_names);
        sort($member_names);
        reset($member_names);
        
        $tpl->assign_vars(array(
            'S_STEP1'         => false,
            'L_FOUND_MEMBERS' => sprintf($user->lang['found_members'], $line_count, sizeof($member_names)),
            'L_LOG_DATE_TIME' => $user->lang['log_date_time'],
            'L_LOG_ADD_DATA'  => $user->lang['log_add_data'],
            
            'FOUND_MEMBERS' => implode("\n", $member_names),
            'MO'            => $this->M_to_n($date['mo']),
            'D'             => $date['d'],
            'Y'             => $date['y'],
            'H'             => $date['h'],
            'MI'            => $date['mi'],
            'S'             => $date['s'])
        );
        
        $eqdkp->set_vars(array(
            'page_title'        => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['parselog_title'],
            'gen_simple_header' => true,
            'template_file'     => 'admin/parse_Everquest2.html',
            'display'           => true)
        );
    }
    
    // ---------------------------------------------------------
    // Process helper methods
    // ---------------------------------------------------------
    function line_parse($log_line)
    {
        global $db, $eqdkp, $user;
        static $member_ranks = array();
        
        //$log_line = stripslashes($log_line);

	// First off, we don't care about afk or lfg, so remove them
	$log_line = str_replace(' (AFK)', '', $log_line);
	$log_line = str_replace(' (LFG)', '', $log_line);

        // Build a clean array of guildtags we might be looking for
        $parsetags = explode("\n", $eqdkp->config['parsetags']);
        foreach ( $parsetags as $k => $v )
        {
            $parsetags[$k] = trim(stripslashes($v));
        }
        
        // Cache the member name / member rank info
        if ( @sizeof($member_ranks) == 0 )
        {
            $sql = 'SELECT r.rank_name, m.member_name
                    FROM ' . MEMBER_RANKS_TABLE . ' r, ' . MEMBERS_TABLE . ' m
                    WHERE (r.rank_id = m.member_rank_id)
                    ORDER BY m.member_name';
            $result = $db->query($sql);
            while ( $row = $db->fetch_record($result) )
            {
                $member_ranks[ $row['member_name'] ] = 'r_' . str_replace(' ', '_', trim($row['rank_name']));
            }
            $db->free_result($result);
        }
        
        $name_check = false;
        $role_check = true;
        $rank_check = true;

/* Sample EQ2 log file format :: the three patterns to match are:

#1 guilded normal
#2 non-guilded normal
#3 role (guilded; unguilded matches like /anon)
#4 anon (guilded or not)

 (neither anon or role shows zone FYI)


(1121902422)[Wed Jul 20 19:33:42 2005] [43 Guardian] Goosage (Barbarian) <The Knights of Dawn Fire> Zone: The Feerrott
(1121902422)[Wed Jul 20 19:33:42 2005] [47 Paladin] Maskie (Barbarian) Zone: The Feerrott
(1121907805)[Wed Jul 20 21:03:25 2005] [Anonymous] Mildew (Gnome) <The Knights of Dawn Fire>
(1121907951)[Wed Jul 20 21:05:51 2005] [Anonymous] Greywind (Human)


German log file looks like this :
(1122498819)[Wed Jul 27 23:13:39 2005] [50 Inquisitor] Chryorn (Dunkelelf) <Feral Fires>ZONE: Shattered Stillness: Epic
(1122498819)[Wed Jul 27 23:13:39 2005] [50 Brigand] Xandros (Dunkelelf) <Feral Fires>ZONE: Shattered Stillness: Epic
(1122498819)[Wed Jul 27 23:13:39 2005] [50 Wächter] Achilless (Barbar) <Feral Fires>ZONE: Shattered Stillness: Epic

*/

        // Date
        $pattern   = "/^\([0-9]{10}\)\[[a-zA-Z]{3} [a-zA-Z]{3} [0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2} [0-9]{4}\](.*)";
        $pattern1  = "/^\([0-9]{10}\)\[[a-zA-Z]{3} [a-zA-Z]{3} [0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2} [0-9]{4}\](.*)";
        $pattern2  = "/^\([0-9]{10}\)\[[a-zA-Z]{3} [a-zA-Z]{3} [0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2} [0-9]{4}\](.*)";
        $pattern3  = "/^\([0-9]{10}\)\[[a-zA-Z]{3} [a-zA-Z]{3} [0-9]{2} [0-9]{2}\:[0-9]{2}\:[0-9]{2} [0-9]{4}\](.*)";

        // Level / Class 
        $pattern  .= "\[([0-9]{1,2}) (.+)\]";
        $pattern1 .= "\[([0-9]{1,2}) (.+)\]";
        $pattern2 .= "\[Anonymous\]";
        $pattern3 .= "\[Anonymous\]";

        // Name
        $pattern  .= " ([A-Za-z]{1,})";
        $pattern1 .= " ([A-Za-z]{1,})";
        $pattern2 .= " ([A-Za-z]{1,})";
        $pattern3 .= " ([A-Za-z]{1,})";

        // Race
        $pattern  .= " \((.*)\)";
        $pattern1 .= " \((.*)\)";
        $pattern2 .= " \((.*)\)";
        $pattern3 .= " \((.*)\)";

        // Guild Tag
	$pattern .= " \<(.*)\>";
	$pattern2 .= " \<(.*)\>";

        // Zone:
        $pattern  .= "ZONE: (.*)";
        $pattern1 .= "ZONE: (.*)";

	// End pattern regexp
        $pattern .= '/';
        $pattern1 .= '/';
        $pattern2 .= '/';
        $pattern3 .= '/';


	// unset a line match type identifier
	unset($type_line);

	// match things the hard way..one type of line at a time
	// crappy way to do it, but VERY easy to read and alter

	// Normal	
        if ( preg_match($pattern, $log_line, $log_parsed) ) { 
		$name = trim($log_parsed[4]);
		$race = trim($log_parsed[5]);
		$class = trim($log_parsed[3]);
		$level = trim($log_parsed[2]);
		$guildtag = trim($log_parsed[6]);
		$zone = trim($log_parsed[7]);
	    $type_line = 1;
	}

	// Unguilded
        if ( preg_match($pattern1, $log_line, $log_parsed) ) { 
		$name = trim($log_parsed[4]);
		$race = trim($log_parsed[5]);
		$class = trim($log_parsed[3]);
		$level = trim($log_parsed[2]);
		$guildtag = "";
		$zone = trim($log_parsed[6]);
	   if (!isset($type_line) ){ $type_line = 2;}
	}

	// Roleplaying
        if ( preg_match($pattern2, $log_line, $log_parsed) ) { 
		$name = trim($log_parsed[2]);
		$race = trim($log_parsed[3]);
		$class = "Unknown";
		$level = "50";
		$guildtag = trim($log_parsed[4]);
		$zone = "";
	   if (!isset($type_line) ){ $type_line = 3;}
	}

	// Anon
        if ( preg_match($pattern3, $log_line, $log_parsed) ) { 
		$name = trim($log_parsed[2]);
		$race = trim($log_parsed[3]);
		$class = "Unknown";
		$level = "50";
		$guildtag = "";
		$zone = "";
	   if (!isset($type_line) ){ $type_line = 4;}
	}


	// Jeezus this is a pain in the ass, ain't it?

	/* Sample EQ2 log file format :: the three patterns to match are (one more time)

(1121902422)[Wed Jul 20 19:33:42 2005] [43 Guardian] Goosage (Barbarian) <The Knights of Dawn Fire> Zone: The Feerrott
(1121902422)[Wed Jul 20 19:33:42 2005] [47 Paladin] Maskie (Barbarian) Zone: The Feerrott
(1121907805)[Wed Jul 20 21:03:25 2005] [Anonymous] Mildew (Gnome) <The Knights of Dawn Fire>
(1121907951)[Wed Jul 20 21:05:51 2005] [Anonymous] Greywind (Human)

After using the above 4, we now test with the same members in different states of anon/role/guilded

(1121902422)[Wed Jul 20 19:33:42 2005] [Anonymous] Goosage (Barbarian)
(1121902422)[Wed Jul 20 19:33:42 2005] [Anonymous] Maskie (Barbarian) <The Knights of Dawn Fire
(1121907805)[Wed Jul 20 21:03:25 2005] [47 Cleric] Mildew (Gnome) <The Knights of Dawn Fire> Zone: The Feerrott
(1121907951)[Wed Jul 20 21:05:51 2005] [49 Monk] Greywind (Human) Zone: The Feerrott

	*/


	if ($type_line == 1) {
	print"Name: $name , Race: $race , Class: $class , Guild: $guildtag , Level: $level , Zone: $zone<br>";
	} 

	if ($type_line == 2) {
	print"Name: $name , Race: $race , Class: $class , Level: $level , Zone: $zone<br>";
	} 

	if ($type_line == 3) {
	print"Name: $name , Race: $race , Class_Guess: $class , Level_Guess: $level , Guild: $guildtag<br>";
	} 

	if ($type_line == 4) {
	print"Name: $name , Race: $race , Class_Guess: $class , Level_Guess: $level<br>";
	} 


	    // Looking for roleplaying folks? Is this valid for EQ2?
            if ( !isset($_POST['findrole']) )
            {
                if ( (isset($class)) && ($class == 'Unknown') )
                {
                    $role_check = false;
                }
            }

            if ( (isset($name)) && ($name != '') )
            {
                $name_check = true;
            }
            
            // Check if we're including this member's rank
            if ( isset($member_ranks[$name]) )
            {
                // If POST[r_<rank_name>] isn't set, we're ignoring this member
                if ( !isset($_POST[ $member_ranks[$name] ]) )
                {
                    $rank_check = false;
                }
            }
            
            if ( ($name_check) && ($role_check) && ($rank_check) )
            {
                $_SESSION[$name] = array(
		    'tag'   => $guildtag,
                    'name'  => $name,
                    'level' => $level,
                    'class' => $class,
                    'race'  => $race);
                    
                return $name;
            }
        return false;
    }
    
    function M_to_n($m)
    {
        switch($m)
        {
            case 'Jan':
                return '01';
                break;
            case 'Feb':
                return '02'; 
                break;
            case 'Mar':
                return '03'; 
                break;
            case 'Apr':
                return '04'; 
                break;
             case 'May': 
                return '05';
                break;
             case 'Jun':
                return '06';
                break;
             case 'Jul':
                return '07'; 
                break;
             case 'Aug': 
                return '08';
                break;
             case 'Sep':
                return '09'; 
                break;
             case 'Oct': 
                return '10';
                break;
             case 'Nov':
                return '11'; 
                break;
             case 'Dec':
                return '12';
                break;
        }
    }
    
    // ---------------------------------------------------------
    // Display form
    // ---------------------------------------------------------
    function display_form()
    {
        global $db, $eqdkp, $user, $tpl, $pm;
        global $SID;
        
        $log_columns = ( preg_match("/Mozilla\/4\.[1-9]{1}.+/", $_SERVER['HTTP_USER_AGENT']) ) ? '50' : '90';
        
        // Options to parse
        $options = array(
            0 => array(
                'CBNAME'    => 'findall',
                'CBVALUE'   => '1',
                'CBCHECKED' => '',
                'OPTION'    => $user->lang['log_find_all']),
            1 => array(
                'CBNAME'    => 'findrole',
                'CBVALUE'   => '1',
                'CBCHECKED' => ' checked="checked"',
                'OPTION'    => 'Include Roleplay')
        );
        
        // Guildtags to parse
        if ( !empty($eqdkp->config['parsetags']) )
        {
            $parsetags = explode("\n", $eqdkp->config['parsetags']);
            foreach ( $parsetags as $index => $guildtag )
            {
                $tagoptions[] = array(
                    'CBNAME'    => str_replace(' ', '_', trim($guildtag)),
                    'CBVALUE'   => '1',
                    'CBCHECKED' => ' checked="checked"',
                    'OPTION'    => '&lt;' . trim($guildtag) . '&gt;');
            }
            $options = array_merge($options, $tagoptions);
        }
        
        foreach ( $options as $row )
        {
            $tpl->assign_block_vars('options_row', $row);
        }
        
        // Member tags to parse
        // Find out how many members have each rank
        $rank_counts = array();
        $sql = 'SELECT member_rank_id, count(member_rank_id) as count
                FROM ' . MEMBERS_TABLE . '
                GROUP BY member_rank_id';
        $result = $db->query($sql);
        while ( $row = $db->fetch_record($result) )
        {
            $rank_counts[ $row['member_rank_id'] ] = $row['count'];
        }
        $db->free_result($result);
        
        $ranks = array();
        $sql = 'SELECT rank_id, rank_name, rank_prefix, rank_suffix
                FROM ' . MEMBER_RANKS_TABLE . '
                ORDER BY rank_name';
        $result = $db->query($sql);
        while ( $row = $db->fetch_record($result) )
        {
            // Make sure there's not a guildtag with the same name as the rank
            if ( !in_array($row['rank_name'], $options) )
            {
                $rank_count = ( isset($rank_counts[ $row['rank_id'] ]) ) ? $rank_counts[ $row['rank_id'] ] : 0;
                $format = ( $rank_count == 1 ) ? $user->lang['x_members_s'] : $user->lang['x_members_p'];
                
                $ranks[] = array(
                    'CBNAME'    => 'r_' . str_replace(' ', '_', trim($row['rank_name'])),
                    'CBVALUE'   => intval($row['rank_id']),
                    'CBCHECKED' => ' checked="checked"',
                    'OPTION'    => $user->lang['rank'] . ': ' . (( empty($row['rank_name']) ) ? '(None)' : $row['rank_prefix'] . $row['rank_name'] . $row['rank_suffix'])
                                   . ' <span class="small">(' . sprintf($format, $rank_count) . ')</span>');
            }
        }
        $db->free_result($result);
        
        foreach ( $ranks as $row )
        {
            $tpl->assign_block_vars('ranks_row', $row);
        }
        
        $tpl->assign_vars(array(
            'F_PARSE_LOG'    => 'parse_Everquest2.php' . $SID,
            
            'S_STEP1'        => true,
            'L_PASTE_LOG'    => $user->lang['paste_log'],
            'L_OPTIONS'      => $user->lang['options'],
            'L_PARSE_LOG'    => $user->lang['parse_log'],
            'L_CLOSE_WINDOW' => $user->lang['close_window'],
            
            'LOG_COLS' => $log_columns)
        );
        
        $eqdkp->set_vars(array(
            'page_title'        => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['parselog_title'],
            'gen_simple_header' => true,
            'template_file'     => 'admin/parse_Everquest2.html',
            'display'           => true)
        );
    }
}

$parse_log = new Parse_Log;
$parse_log->process();
?>