Мультитрекер (подгрузка внешних пиров)

Мультитрекер (подгрузка внешних пиров) 1.1.0

Нет прав для скачивания
Совместимость
не проверялся на совместимость
Изменения в БД
требуются
Дополнительные требования
msqli.so, curl.so, серверный крон
Автор
_Xz_
Общественное достояние
да
Описание: возможность организации мультитрекерных раздач с подгрузкой пиров с других ресурсов.

Фактически добавляет пиров с других ресурсов. При скачивании они будут сразу же переданы пользователю в общем списке пиров.
Инструкция по установке
PHP:
#
#--[SQL]----------------------------------------
#

ALTER TABLE `bb_bt_torrents` ADD `tor_time` INT( 11 ) NOT NULL , ADD `tor_seeders` MEDIUMINT( 8 ) DEFAULT '0' NOT NULL , ADD `tor_leechers` MEDIUMINT( 8 ) DEFAULT '0' NOT NULL , ADD `tor_announcers` TEXT NOT NULL ;


config.php
// Мультитрекер
$bb_cfg['multitracker'] = array(
    'max_trackers'  => 1,
    'bad_trackers'    => array(
        $bb_cfg['server_name'],
        //'retracker.local',
        'bt.torrents.by',
    ),
    'search'  => array('udp://bt.rutor.org:2710'),
    'replace' => array('http://bt.rutor.org:2710/announce'),
);

functions_torrent.php

найти и заменить

    $reg_time = TIMENOW;
    $size = sprintf('%.0f', (float) $totallen);

    $tor_announcers = tor_announcers($tor);
    $tor_announcers = ($tor_announcers) ? serialize($tor_announcers) : '';

    $columns = ' info_hash,       post_id,  poster_id,  topic_id,  forum_id,  attach_id,    size,  reg_time,  tor_status,   tor_announcers';
    $values = "'$info_hash_sql', $post_id, $poster_id, $topic_id, $forum_id, $attach_id, '$size', $reg_time, $tor_status, '$tor_announcers'";

найти

    if($tr_cfg['tor_topic_up'])
    {
        DB()->query("UPDATE ". BB_TOPICS ." SET topic_last_post_time = GREATEST(topic_last_post_time, ". (TIMENOW - 3*86400) .") WHERE topic_id = $topic_id LIMIT 1");
    }
после добавить


    $tor_seeders = $tor_leechers = $tor_peers = 0;
    multitracker(array('tor_announcers' => $tor_announcers, 'info_hash' => $info_hash_sql, 'size' => $size),$tor_seeders, $tor_leechers, $tor_peers);
    $tor_time = TIMENOW + 900;
    if($tor_seeders) $last_seeder = ', seeder_last_seen = '. TIMENOW;
    else $last_seeder = '';
    DB()->query("UPDATE ". BB_BT_TORRENTS ." SET tor_seeders = '$tor_seeders', tor_leechers = '$tor_leechers', tor_time = '$tor_time' $last_seeder WHERE topic_id = $topic_id LIMIT 1");


вставить в конец

function tor_announcers($tor)
{
    global $bb_cfg;

    $tracker = array();
    if (array_key_exists('announce-list', $tor))
    {
        foreach ($tor['announce-list'] as $announcer)
        {
            if (preg_match('#rutracker.org#is', $announcer[0]))
            {
                if(!$tracker) $tracker[] = $tor['publisher-url'];
            }
            else if (!preg_match('#('. implode('|', $bb_cfg['multitracker']['bad_trackers']) .')#is', $announcer[0]))
            {
                $tracker[] = str_replace($bb_cfg['multitracker']['search'], $bb_cfg['multitracker']['replace'], $announcer[0]);
            }
        }
    }
    elseif (@$tor['announce'])
    {
        if (!preg_match('#('. implode('|', $bb_cfg['multitracker']['bad_trackers']) .')#is', $tor['announce']))
        {
            $tracker[] = str_replace($bb_cfg['multitracker']['search'], $bb_cfg['multitracker']['replace'], $tor['announce']);
        }
    }

    $announcers = array();
    if (count($tracker))
    {
        foreach ($tracker as $key => $url)
        {
            if($key < $bb_cfg['multitracker']['max_trackers'])
            {
                $announcers[] = $url;
            }
        }
    }
    return (count($announcers)) ? $announcers : '';
}

function multitracker($data, &$tor_seeders, &$tor_leechers, &$tor_peers, $left=false)
{
    global $bb_cfg;

    if($data['tor_announcers'])
    {
        require_once(INC_DIR .'class.snoopy.php');

        $snoopy = new Snoopy;

        if(preg_match('#rutracker.org/forum#is', $data['tor_announcers']))
        {
            $snoopy->proxy_host = '190.214.5.18';
            $snoopy->proxy_port = '8080';
            $snoopy->host = "rutracker.org";
            $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
            $snoopy->rawheaders["Pragma"] = "no-cache";

            $snoopy->cookies = array (
                'bb_data'  => '1-25846714-UU8CcMRwWpVfHlhuuei1-2994434152-1329935147-1329935147-1744992048-0',
            );

            $snoopy->_httpmethod = "GET";
            $tor_seeders = $tor_leechers = '';

            $tracker = array();
            foreach (unserialize($data['tor_announcers']) as $url)
            {
                if(preg_match('#rutracker.org/forum#is', $url)) $tracker[] = $url;
            }

            foreach ($tracker as $url)
            {
                $snoopy->fetch($url);
                if(!$snoopy->timed_out)
                {
                    $content = $snoopy->results;

                    preg_match_all('#<div class="mrg_4 pad_4">.*?<b>(.*?)</b>.*?<b>(.*?)</b>#is', $content, $tor, PREG_SET_ORDER);

                    @$tor_seeders += (int) $tor[0][1];
                    @$tor_leechers += (int) $tor[0][2];
                }
            }
        }
        else
        {
            $snoopy->agent = "uTorrent/3000(25583)";
            $snoopy->_httpmethod = "GET";

            $size = ($left) ? $data['size'] : '0';
            $announce = "info_hash=". urlencode($data['info_hash']) ."&peer_id=-UT3000-8H%17%94%08%ef%8c%0f%bd%0c%8d%3a&port=52085&uploaded=0&downloaded=0&left=". $size ."&corrupt=0&key=1F64382C&event=started&numwant=200&compact=1&no_peer_id=1";
            $tor_seeders = $tor_leechers = $tor_peers = '';

            $tracker = array();
            foreach (unserialize($data['tor_announcers']) as $url)
            {
                $ann = (preg_match("/\?/", $url)) ? '&' : '?';
                $tracker[] = str_replace($bb_cfg['multitracker']['search'], $bb_cfg['multitracker']['replace'], $url) . $ann;
            }

            foreach ($tracker as $url)
            {
                $snoopy->fetch($url . $announce);
                if(!$snoopy->timed_out)
                {
                    $tor = bdecode($snoopy->results);
                    @$tor_seeders += (int) $tor['complete'];
                    @$tor_leechers += (int) $tor['incomplete'];
                    @$tor_peers .= $tor['peers'];
                }
            }
        }
    }
}

ajax.php

найти

case 'view_post':
        require(INC_DIR .'bbcode.php');
    break;

вставить

case 'multitracker':
        require(INC_DIR .'functions_torrent.php');
    break;

найти

'view_post'         => array('guest'),

добавить

'multitracker'      => array('mod'),

перед последней скобкой вставить

    function multitracker()
    {
        global $lang;

        $attach_id = (int) $this->request['attach_id'];
        $tor = DB()->fetch_row("SELECT * FROM ". BB_BT_TORRENTS ." WHERE attach_id = $attach_id");
  
        if($tor['tor_announcers'])
        {
            $tor_seeders = $tor_leechers = $peers = '';
      
            multitracker($tor, $tor_seeders, $tor_leechers, $tor_peers, true);
            $tor_time = TIMENOW + 900;
            if (!($seeders + $tor_seeders) > 0) $last_seeder = ', seeder_last_seen = '. TIMENOW;
            else $last_seeder = '';
            DB()->query("UPDATE ". BB_BT_TORRENTS ." SET tor_seeders = '$tor_seeders', tor_leechers = '$tor_leechers', tor_time = '$tor_time' $last_seeder WHERE attach_id = '". $tor['attach_id'] ."' LIMIT 1");

            $html = '<div class="mrg_4 pad_4">';
            $html .= '<span class="seed">'. $lang['SEEDERS'] .':&nbsp; <b>'. $tor_seeders .'</b> &nbsp;[&nbsp; 0 KB/s &nbsp;]</span> &nbsp;';
            $html .= '<span class="leech">'. $lang['LEECHERS'] .':&nbsp; <b>'. $tor_leechers .'</b> &nbsp;[&nbsp; 0 KB/s &nbsp;]</span> &nbsp;';
            $html .= '<a href="'. TOPIC_URL . $tor['topic_id'] .'&spmode=full#seeders">'. $lang['SPMODE_FULL'] .'</a>';
            $html .= '</div>';

            $this->response['html']    = $html;
        }
        else $this->ajax_die('false');
    }

displaying_torrent.php

найти и заменить

$peers_cnt = $seed_count = $leech_count = 0;

найти и заменить

// SQL for each mode
        if ($s_mode == 'count')
        {
            $sql = "SELECT sn.seeders, sn.leechers, sn.speed_up, sn.speed_down,
                    tor.tor_seeders, tor.tor_leechers
                FROM ". BB_BT_TORRENTS ." tor
                    LEFT JOIN ". BB_BT_TRACKER_SNAP ." sn ON(sn.topic_id = tor.topic_id)
                WHERE tor.topic_id = $tor_id
                LIMIT 1";
        }
        else if ($s_mode == 'names')
        {
            $sql = "SELECT tr.user_id, tr.ip, tr.port, tr.remain, tr.seeder, u.username, u.user_rank,
                    tor.tor_seeders, tor.tor_leechers
                FROM ". BB_BT_TORRENTS ." tor
                    LEFT JOIN ". BB_BT_TRACKER ." tr ON(tr.topic_id = tor.topic_id)
                    LEFT JOIN ". BB_USERS ." u ON(u.user_id = tr.user_id)
                WHERE tor.topic_id = $tor_id
                GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
                ORDER BY u.username
                LIMIT $show_peers_limit";
        }
        else
        {
            $sql = "SELECT
                    tr.user_id, tr.ip, tr.port, tr.uploaded, tr.downloaded, tr.remain,
                    tr.seeder, tr.releaser, tr.speed_up, tr.speed_down, tr.update_time,
                    u.username, u.user_rank,
                    tor.tor_seeders, tor.tor_leechers
                FROM ". BB_BT_TORRENTS ." tor
                    LEFT JOIN ". BB_BT_TRACKER ." tr ON(tr.topic_id = tor.topic_id)
                    LEFT JOIN ". BB_USERS ." u ON (u.user_id = tr.user_id)
                WHERE tor.topic_id = $tor_id
                    AND tr.topic_id = tor.topic_id
                GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
                ORDER BY $full_mode_order $full_mode_sort_dir
                LIMIT $show_peers_limit";
        }

найти и заменить

if ($s_mode != 'full' && $seeders)
            {
                $seeders[strlen($seeders)-9] = ' ';
                $template->assign_vars(array(
                    'SEED_LIST'  => $seeders,
                    'SEED_COUNT' => ($seed_count) ? $seed_count : '',
                ));
            }
            if ($s_mode != 'full' && $leechers)
            {
                $leechers[strlen($leechers)-9] = ' ';
                $template->assign_vars(array(
                    'LEECH_LIST'  => $leechers,
                    'LEECH_COUNT' => ($leech_count) ? $leech_count : '',
                ));
            }


найти и заменить

$tmp[0]['username'] = (int) @$peers[0]['leechers'] + @$peers[0]['tor_leechers'];
                $tmp[1]['username'] = (int) @$peers[0]['seeders'] + @$peers[0]['tor_seeders'];
          
найти и заменить

if ($bb_cfg['bt_allow_spmode_change'] && $s_mode != 'full' && $seed_count || $leech_count)          


viewtopic_attach.tpl

найти

<!-- ELSEIF TOR_HELP_LINKS -->

заменить

<!-- IF IS_AM -->
        <script type="text/javascript">
        ajax.callback.multitracker = function(data) {
            $('#peers').html(data.html);
        };
        </script>
        <a class="txtb" href="#peers" onclick="ajax.exec({action : 'multitracker', attach_id: '{postrow.attach.tor_reged.ATTACH_ID}'});"><input type="submit" value="Обновить пиров" class="liteoption" /></a>
        <!-- ENDIF -->
        <!-- ELSEIF TOR_HELP_LINKS -->

viewtopic_torrent.tpl

найти и заменить

<td id="peers" colspan="2" class="<!-- IF SHOW_DL_LIST -->row2<!-- ELSE -->row1<!-- ENDIF --> pad_2">
                <a name="peers"></a>


announce.php

найти

$seeders  = $row['seeders'];
        $leechers = $row['leechers'];
    }

добавить

    $tor_seeders = $tor_leechers = $tor_peers = '';
    if (!$seeder)  // Выдём пиров только, если пользователь качает раздачу
    {
        $info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
        $tor = DB()->fetch_row("SELECT * FROM ". BB_BT_TORRENTS ." WHERE info_hash = '$info_hash_sql' LIMIT 1");

        if($tor['tor_announcers'])
        {
            define('IN_PHPBB', true);
            require(INC_DIR .'functions_torrent.php');
            $tor_seeders = $tor_leechers = $tor_peers = '';
            multitracker($tor, $tor_seeders, $tor_leechers, $tor_peers, true);
            if (!($seeders + $tor_seeders) > 0) $last_seeder = ', seeder_last_seen = '. TIMENOW;
            else $last_seeder = '';
            $tor_time = TIMENOW + 900;   // это интервал между запросами
            DB()->query("UPDATE ". BB_BT_TORRENTS ." SET tor_seeders = '$tor_seeders', tor_leechers = '$tor_leechers', tor_time = '$tor_time' $last_seeder WHERE attach_id = '". $tor['attach_id'] ."' LIMIT 1");
        }
    }

    $output = array(
        'interval'     => (int) $announce_interval,
        'min interval' => (int) $announce_interval,
        'peers'        => $peers . $tor_peers,
        'complete'     => (int) $seeders + $tor_seeders,
        'incomplete'   => (int) $leechers + $tor_leechers,
    );

viewforum.php

найти

sn.seeders, sn.leechers

добавить

, tor.tor_seeders, tor.tor_leechers

найти и заменить

'SEEDERS'    => (int) $topic['seeders'] + $topic['tor_seeders'],
            'LEECHERS'   => (int) $topic['leechers'] + $topic['tor_leechers'],
      
tracker.php

найти

sn.seeders, sn.leechers

добавить

, tor.tor_seeders, tor.tor_leechers

найти и заменить

$seeds  = $tor['seeders'] + $tor['tor_seeders'];
            $leechs = $tor['leechers'] + $tor['tor_leechers'];


build_stats.php
      
найти и заменить

// peers stat
$row = DB()->fetch_row("SELECT SUM(seeders) AS seeders, SUM(leechers) AS leechers, ((SUM(speed_up) + SUM(speed_down))/2) AS speed FROM ". BB_BT_TRACKER_SNAP);
$row2 = DB()->fetch_row("SELECT SUM(tor_seeders) AS seeders, SUM(tor_leechers) AS leechers FROM ". BB_BT_TORRENTS);
$data['seeders']  = number_format($row['seeders'] + $row2['seeders']);
$data['leechers'] = number_format($row['leechers'] + $row2['leechers']);
$data['peers']    = number_format($row['seeders'] + $row['leechers'] + $row2['seeders'] + $row2['leechers']);
$data['speed']    = $row['speed'];

torrent_userprofile.php

найти

, sn.seeders, sn.leechers

вставить

, tor_seeders, tor_leechers

найти и заменить

'TOPIC_SEEDERS' => $releasing[$i]['seeders'] + $releasing[$i]['tor_seeders'],
            'TOPIC_LEECHERS' => $releasing[$i]['leechers'] + $releasing[$i]['tor_leechers'],
      
найти и заменить

'TOPIC_SEEDERS' => $seeding[$i]['seeders'] + $seeding[$i]['tor_seeders'],
            'TOPIC_LEECHERS' => $seeding[$i]['leechers'] + $seeding[$i]['tor_leechers'],

найти и заменить

'TOPIC_SEEDERS' => $leeching[$i]['seeders'] + $leeching[$i]['tor_seeders'],
            'TOPIC_LEECHERS' => $leeching[$i]['leechers'] + $leeching[$i]['tor_leechers'],
Автор
Exile
Скачивания
93
Первый выпуск
Обновление
Оценка
5.00 звёзд 1 оценок

Другие ресурсы пользователя Exile

Последние обновления

  1. Обновление 1.1.0

    Обновление описания ресурса

Последние рецензии

спасибо