-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.php
More file actions
109 lines (92 loc) · 3.65 KB
/
reader.php
File metadata and controls
109 lines (92 loc) · 3.65 KB
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
<?php
// By Flowlance
date_default_timezone_set("Europe/Amsterdam"); // Your server's timezone
$settings = array(
'DBCONN' => 'C:\\inetpub\\xomnhala\\config.php', // Path to db connection file
'TABLE' => 'UniqueKills', // Unique Ranking table name
'LOGTYPE' => 'EVALOGS', // "EVALOGS" or "FATALLOGS"
'LOGPATH' => 'C:\\Server\\evaLog\\', // Path to log files
'DONEDIR' => 'finished\\' // Proceeded/Scanned logs will be moved here
);
include($settings['DBCONN']);
class UniqueReader extends mssql {
var $table;
var $logptrn;
var $fileptrn;
var $path;
var $finished;
var $logfiles;
public function setVar($settings) {
$this->table = $settings['TABLE'];
$this->logfiles = $settings['LOGTYPE'];
$this->path = $settings['LOGPATH'];
$this->finished = $settings['DONEDIR'];
if($this->logfiles == "EVALOGS") {
$this->logptrn = "/\[([0-9_\-]{1,})\].*\[([a-zA-Z0-9_]{1,})\].*\[([a-zA-Z0-9_]{1,})\]/siU";
$this->fileptrn = "/^[0-9\-]{1,}\_uniquekills.txt$/";
} else {
$this->logptrn = "/([0-9_\-]{1,}\t[0-9_:]{1,})\t.*Unique\sMonster\sKilled!\sUNIQUE\[([a-zA-Z0-9_]{1,})\].*\sby\s\[([a-zA-Z0-9_]{1,})\]/siU";
$this->fileptrn = "/^[0-9\-]{1,}\_FatalLog.txt$/";
}
}
public function ts($datestr) {
if($this->logfiles == "EVALOGS") {
$split = split("_", $datestr);
$date = $split[0] . " " . str_replace("-", ":", $split[1]);
} else {
$date = str_replace("\t", " ", $datestr);
}
return strtotime($date);
}
public function match($search) {
if(preg_match_all($this->logptrn, $search, $m)) {
return $m;
} else {
return false;
}
}
public function isToday($filename) {
$split = split("_", $filename);
$date = $this->logfiles == "EVALOGS" ? date("j-n-Y") : date("Y-m-d");
if($date==$split[0]) {
return true;
}
}
public function move($v) {
if(!$this->isToday($v)) {
if(copy($this->path . $v,$this->path . $this->finished . $v)) {
unlink($this->path . $v);
}
}
}
public function folder_check() {
if(!file_exists($this->path . $this->finished)) {
mkdir($this->path . $this->finished);
}
}
public function scan() {
$this->folder_check();
$files = scandir($this->path);
foreach($files as $v) {
if(preg_match($this->fileptrn, $v)) {
$file = fopen($this->path . $v, "r");
while($line = fgets($file)) {
$cont = $this->match($line);
if($cont!=false) {
$exists = $this->get_num("SHARD", "SELECT * FROM ".$this->table." WHERE CharName16='".$this->safe($cont[3][0])."' AND Monster='".$this->safe($cont[2][0])."' AND Timestamp='".$this->ts($cont[1][0])."'");
if($exists==0) {
$params = array($this->safe($cont[3][0]), $this->safe($cont[2][0]), $this->ts($cont[1][0]));
$this->query("SHARD", "INSERT INTO ".$this->table." (CharName16, Monster, Timestamp) VALUES (?, ?, ?)", $params);
}
}
}
fclose($file);
$this->move($v);
}
}
}
}
$reader = new UniqueReader();
$reader->setVar($settings);
$reader->scan();
?>