diff --git a/library/attach_mod/displaying_torrent.php b/library/attach_mod/displaying_torrent.php index d6d19c440..899e99949 100644 --- a/library/attach_mod/displaying_torrent.php +++ b/library/attach_mod/displaying_torrent.php @@ -143,7 +143,7 @@ if ($tor_reged && $tor_info) { // Magnet link $passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$bt_user_id . " LIMIT 1"); - $tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']); + $tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key']); // ratio limits $min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor']; diff --git a/library/includes/functions.php b/library/includes/functions.php index 9c153ae62..31d4fd11a 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -1912,11 +1912,30 @@ function pad_with_space($str) return $str ? " $str " : $str; } -function create_magnet($infohash, $auth_key, $logged_in) +/** + * Create magnet link + * + * @param string $infohash + * @param string|bool $auth_key + * + * @return string + */ +function create_magnet($infohash, $auth_key) { - global $bb_cfg, $_GET, $images; + global $bb_cfg, $images, $lang, $userdata; + + if (IS_GUEST && $bb_cfg['bt_tor_browse_only_reg']) { + $passkey = ''; + } elseif (empty($auth_key)) { + if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($userdata['user_id'], true)) { + bb_die($lang['PASSKEY_ERR_EMPTY']); + } + } else { + $passkey = $auth_key; + } + + $passkey_url = $passkey ? "?{$bb_cfg['passkey_key']}=$auth_key" : ''; - $passkey_url = ((!$logged_in || isset($_GET['no_passkey'])) && $bb_cfg['bt_tor_browse_only_reg']) ? '' : "?{$bb_cfg['passkey_key']}=$auth_key"; return ''; } diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index f58b5ce73..755c5c7b7 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -599,13 +599,12 @@ class Torrent // Insert new row DB()->query("INSERT IGNORE INTO " . BB_BT_USERS . " (user_id, auth_key) VALUES ($user_id, '$passkey_val')"); - if (DB()->affected_rows() == 1) { return $passkey_val; } + // Update DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id"); - if (DB()->affected_rows() == 1) { // Ocelot if ($bb_cfg['ocelot']['enabled']) { diff --git a/tracker.php b/tracker.php index 808972542..eecc0d03b 100644 --- a/tracker.php +++ b/tracker.php @@ -698,7 +698,7 @@ if ($allowed_forums) { $s_last = $tor['seeder_last_seen']; $att_id = $tor['attach_id']; $size = $tor['size']; - $tor_magnet = create_magnet($tor['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']); + $tor_magnet = create_magnet($tor['info_hash'], $passkey['auth_key']); $compl = $tor['complete_count']; $dl_sp = ($dl) ? humn_size($dl, 0, 'KB') . '/s' : '0 KB/s'; $ul_sp = ($ul) ? humn_size($ul, 0, 'KB') . '/s' : '0 KB/s'; diff --git a/viewforum.php b/viewforum.php index 8234e82dc..5eb470b77 100644 --- a/viewforum.php +++ b/viewforum.php @@ -470,7 +470,7 @@ foreach ($topic_rowset as $topic) { )); if (isset($topic['tor_size'])) { - $tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key'], $userdata['session_logged_in']); + $tor_magnet = create_magnet($topic['info_hash'], $topic['auth_key']); $template->assign_block_vars('t.tor', array( 'SEEDERS' => (int)$topic['seeders'],