<?
require_once("include/bittorrent.php");

dbconn(false,true);	
header("Content-Type: text/html; charset=" .$tracker_lang['language_charset']);
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

$id = (isset($_POST["tid"]) ? (int) $_POST["tid"]:"");
$multi=(isset($_POST["multi"]) ? (string)$_POST["multi"]:"");

global $CURUSER,$announce_urls;

if (empty($CURUSER))
die;


if ($multi=="yes" && get_user_class() >= UC_MODERATOR){
	
require_once ROOT_PATH."include/benc.php";

$sql = sql_query("SELECT info_hash FROM torrents WHERE id=$id") or sqlerr(__FILE__,__LINE__);
while($torrent = mysql_fetch_array($sql)) {
    $tracker_cache = array(); 
    $f_leechers = 0; 
    $f_seeders = 0; 
    $announce_list=$announce_urls;
    foreach($announce_list as $announce) {
        $response = get_remote_peers($announce, $torrent['info_hash'],true); 
        if($response['state']=='ok'){
         $tracker_cache[] = $response['tracker'].':'.($response['leechers'] ? $response['leechers'] : 0).':'.($response['seeders'] ? $response['seeders'] : 0).':'.($response['downloaded'] ? $response['downloaded'] : 0); 
           // $f_leechers += $response['leechers']; 
            //$f_seeders += $response['seeders']; 
            if ($f_leechers < $response['leechers'])
            $f_leechers = $response['leechers'];
            
            if ($f_seeders < $response['seeders'])
            $f_seeders = $response['seeders']; 
        }
        else 
            $tracker_cache[] = $response['tracker'].':false'; 
    }
    $tracker_cache = implode("\n",$tracker_cache); 
     
    sql_query("UPDATE LOW_PRIORITY torrents SET f_leechers = ".sqlesc($f_leechers).', f_seeders = '.sqlesc($f_seeders).', f_trackers = '.sqlesc($tracker_cache).' WHERE id = '.$id) or sqlerr(__FILE__,__LINE__);
    die("<br><b>Новые данные о пирах</b>: <br>".str_replace("\n", "<br>", $tracker_cache)."<hr>");
}

} else die;




?> 