3 function tool_las_get_file_list($path)
5 if (substr($path,-1) != '/') $path .= '/';
9 if ($handle = opendir($path))
11 while (false !== ($file = readdir($handle)))
13 if ($file != '.' && $file != '..')
15 if (!is_array($file_list)) $file_list = array();
17 $tmp = array( 'name' => $file,
19 'size' => filesize($path . $file),
20 'date' => filemtime($path . $file),
21 'code' => base64_encode($file),
28 if (is_array($file_list))
31 foreach($file_list as $tmp_key => $tmp_val)
33 $date_ary[$tmp_key] = $tmp_val['date'];
36 array_multisort($date_ary, SORT_DESC
, $file_list);
46 function tool_las_check_for_file($data, $name)
49 foreach($data as $filedata)
51 if ($filedata['name'] == $name) return $filedata;
57 function tool_las_parse_eids_to_array($eids)
60 $eids = ereg_replace("[[:space:]]+"," ",$eids);
61 $eids = str_replace(")(",") (",$eids);
63 $tmp = explode(" ",$eids);
66 foreach($tmp as $ktmp => $vtmp)
69 if (!eregi("^\(0x[^\)]+\)$",$vtmp)) unset($tmp[$ktmp]);
70 else $tmp[$ktmp] = $vtmp;
76 function tool_las_read_file($filename, $max_lines, $line_start, &$line_previous, &$line_next)
80 $line_previous = $line_start - $max_lines;
81 $line_next = $line_start +
$max_lines;
83 if ($line_previous < 0) $line_previous = -1;
87 if ($fp = fopen($filename,'r'))
89 // skip lines up to $line_start
90 for ($i = 0; $i < $line_start; ++
$i) fgets($fp);
92 for ($i = 0; $i < $max_lines; ++
$i)
98 if ($tmp != '') $data[] = $tmp;
108 if ($lines_read < $max_lines)
113 nt_common_add_debug("tool_las_read_file() : ". $max_lines ." - ". $line_start ." - ". $line_previous ." - ". $line_next);
122 function tool_las_trim_leading_zero($data)
124 while ($data[0] === '0')
126 $data = substr($data, 1);
132 function tool_las_parse_eid($eid, &$uid, &$slotid, &$charid)
141 if (ereg("^\(0x([[:alnum:]]{9})([[:digit:]])(\:[[:alnum:]]+)*[\)]?$", $eid, $eid_params))
143 $uid = intval('0x'. tool_las_trim_leading_zero($eid_params[1]),16);
144 $slotid = $eid_params[2];
145 $charid = ($uid * 16) +
$slotid;
153 function tool_las_parse_file($fname)
157 if ($fp = fopen($fname, "r"))
162 $input = trim($input);
164 if (substr($input, 0, 2) == '#$')
166 $input = trim(substr($input, 2));
167 //echo $input ."<br />";
169 if (ereg("^[^\ ]+\: LogChat[[:space:]]+\: ([^\ ]+) says '(.*)' to (.*)$", $input, $params))
171 tool_las_parse_eid($params[1], $_uid, $_slotid, $_charid);
173 $data[$_charid] = $params[1];
175 foreach(explode(' ', $params[3]) as $eid_listener)
177 tool_las_parse_eid($eid_listener, $listener_uid, $listener_slotid, $listener_charid);
179 if ($listener_uid != 0)
181 $data[$listener_charid] = $eid_listener;
194 function tool_las_get_character_names($dbname, $data)
198 $char_data = array();
200 if ($db->sql_select_db($dbname))
202 $sql = "SELECT char_id,char_name FROM characters WHERE char_id IN (". implode(',', array_keys($data)) .")";
203 if ($result = $db->sql_query($sql))
205 if ($db->sql_numrows($result))
207 while ($row = $db->sql_fetchrow($result))
209 $char_data[$row['char_id']] = $row['char_name'];
214 $db->sql_reselect_db();
220 function tool_las_fpassthru_replace($path, $fname, $search_eid_ary, $search_char_ary)
222 if ($fp = fopen($path . $fname, "r"))
224 stream_set_timeout($fp, 180);
226 header("Content-type: text/plain");
227 header("Content-Disposition: attachment; filename=las_parsed_". $fname);
228 header("Pragma: no-cache");
229 header("Expires: 0");
236 $tmp = str_replace($search_eid_ary, $search_char_ary, $tmp);