-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlister.php
130 lines (113 loc) · 3.34 KB
/
lister.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
<?
set_time_limit(0);
$blacklist = array('Antimat','Stukach','Guard','Opers','SiskaOP');
require_once(dirname(__FILE__).'/inc/config.inc');
if(isset($_SERVER['SERVER_NAME'])){
echo "<pre>";
}
try {
$DC = new DC_P2S( BOT_NICKNAME, BOT_SHARESIZE, BOT_EMAIL, BOT_SPEED, BOT_VERSION );
$DC->onEnter = 'enterFunc';
$DC->onQuit = 'quitFunc';
//$DC->onChatReceive = 'chatFunc';
$starttime = microtime(true);
$goodLists = 0;
$badLists = 0;
if( !$DC->connect( DC_SERVER, DC_PORT, BOT_TCP_PORT ) ) return;
if( !$DC->authenticate() ) return;
$nickList = Indexer::getNeedNicks(array_diff($DC->nickList, $blacklist) );
printlog(1, 'We are interested in ');
foreach($nickList as $k=>$v) {
if(CONSOLE_OUT_CHARSET){
printlog(1, @iconv('utf-8', CONSOLE_OUT_CHARSET, $v)." ");
}else{
printlog(1, $v." ");
}
}
printlog(1, "\n");
foreach($nickList as $k=>&$nick) {
if( !isset($nickList[$k]) || $nickList[$k] == null || !$nickList[$k] || !$nick){
continue;
}
$fn = getFileList($DC, $nick);
if($fn){
$goodLists++;
}else{
$badLists++;
}
Indexer::setNickList($nick, $fn);
}
unset($nick);
printlog(0, "Lists: $goodLists good, $badLists bad, ");
printlog(0, round(microtime(true)-$starttime,2)."s\n");
}catch (ForceMoveException $e) {
printlog(0, "ForceMove received\n");
}catch (ErrorReceivedException $e) {
printlog(0, "Error received\n");
}
//$DC->LoopProcessing();
/**
* FUNCTIONS
*/
function quitFunc($nickname){
printlog(1, "-=$nickname=-quitted\n");
global $nickList;
foreach ($nickList as $i=>$v){
if($v==$nickname){
unset($nickList[$i]);
}
}
}
function enterFunc($nickname){
printlog(1, "-=$nickname=-entered\n");
global $nickList;
global $blacklist;
$nick_array = array_diff(array($nickname), $blacklist);
if( !is_array($nick_array) || !count($nick_array)){
return;
}
$nick_array = Indexer::getNeedNicks( $nick_array );
if( !is_array($nick_array) || !count($nick_array)){
return;
}
$nickList[] = $nickname;
}
function printlog($debugLevel, $message){
$debug = defined('DEBUG')?constant('DEBUG'):0;
if($debug >= $debugLevel){
echo $message;
}
}
function getFileList($DC, $nick){
$st = microtime(true);
if(CONSOLE_OUT_CHARSET){
printlog(1, @iconv('utf-8',CONSOLE_OUT_CHARSET,$nick)." - ");
}else{
printlog(1, $nick." - ");
}
$bz2Content = $DC->getFile($nick, 'files.xml.bz2');
if($DC->connectedBack){
printlog(1, " backconnect ".$DC->connectedBack." - ");
$DC->connectedBack = false;
}
if($bz2Content === false){
printlog(1, "fail(".$DC->lasterror.")\n");
return false;
}elseif($bz2Content === '') {
printlog(1, "not bz2\n");
return false;
}
$fn = uniqid().'.bz2';
$fh = fopen(WORKER_TMPDIR.'/'.$fn, 'wb');
$written = fwrite($fh, $bz2Content);
fclose($fh);
if(!$written){
printlog(1, "nothing written\n");
if(file_exists(WORKER_TMPDIR.'/'.$fn)) unlink(WORKER_TMPDIR.'/'.$fn);
return false;
}
$et = microtime(true);
printlog(1, "ok (".sprintf("%01.2f",$et-$st)." s) \n");
return $fn;
}
?>