From 3c503c981f4bda09a84d2e950008d9fa3a7023de Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Thu, 7 Sep 2023 18:29:50 +0700 Subject: [PATCH] Updated --- bt/announce.php | 30 ++---------------------------- bt/includes/init_tr.php | 24 ++++++++++++++++++++++++ bt/scrape.php | 14 +------------- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index 9f7e55beb..93d5ba148 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -10,6 +10,7 @@ define('IN_TRACKER', true); define('BB_ROOT', './../'); require dirname(__DIR__) . '/common.php'; +require __DIR__ . '/includes/init_tr.php'; global $bb_cfg; @@ -135,9 +136,7 @@ if ($lp_info && (!isset($event) || $event !== 'stopped')) { drop_fast_announce($lp_info); } -// Start announcer -require __DIR__ . '/includes/init_tr.php'; - +// Events $seeder = ($left == 0) ? 1 : 0; $stopped = ($event === 'stopped'); $completed = ($event === 'completed'); @@ -400,31 +399,6 @@ if (!$output) { $peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE); } -// Functions -function drop_fast_announce($lp_info) -{ - global $announce_interval; - - if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) { - return; // if announce interval correct - } - - $new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW; - - dummy_exit($new_ann_intrv); -} - -function msg_die($msg) -{ - $output = \SandFox\Bencode\Bencode::encode([ - 'min interval' => (int)1800, - 'failure reason' => (string)$msg, - 'warning message' => (string)$msg, - ]); - - die($output); -} - // Return data to client echo \SandFox\Bencode\Bencode::encode($output); diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index 5e898857f..811da165c 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -36,3 +36,27 @@ function error_exit($msg = '') exit; } + +function drop_fast_announce($lp_info) +{ + global $announce_interval; + + if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) { + return; // if announce interval correct + } + + $new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW; + + dummy_exit($new_ann_intrv); +} + +function msg_die($msg) +{ + $output = \SandFox\Bencode\Bencode::encode([ + 'min interval' => (int)1800, + 'failure reason' => (string)$msg, + 'warning message' => (string)$msg, + ]); + + die($output); +} diff --git a/bt/scrape.php b/bt/scrape.php index 3d3edc0b0..dc2822a4a 100644 --- a/bt/scrape.php +++ b/bt/scrape.php @@ -10,6 +10,7 @@ define('IN_TRACKER', true); define('BB_ROOT', './../'); require dirname(__DIR__) . '/common.php'; +require __DIR__ . '/includes/init_tr.php'; global $bb_cfg; @@ -39,19 +40,6 @@ if (strlen($info_hash) == 32) { msg_die('Invalid info_hash'); } -function msg_die($msg) -{ - $output = \SandFox\Bencode\Bencode::encode([ - 'min interval' => (int)1800, - 'failure reason' => (string)$msg, - 'warning message' => (string)$msg, - ]); - - die($output); -} - -require __DIR__ . '/includes/init_tr.php'; - $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); /** * Поскольку торрент-клиенты в настоящее время обрезают инфо-хэш до 20 символов (независимо от его типа, как известно v1 = 20 символов, а v2 = 32 символа),