diff --git a/bt/announce.php b/bt/announce.php index 26a5c60ba..531e1c376 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -171,13 +171,13 @@ function msg_die ($msg) { if (DBG_LOG) dbg_log(' ', '!die-'. clean_filename($msg)); - $output = bencode(array( + $output = \Rych\Bencode\Bencode::encode([ # 'interval' => (int) 1800, 'min interval' => (int) 1800, # 'peers' => (string) DUMMY_PEER, 'failure reason' => (string) $msg, 'warning message' => (string) $msg, - )); + ]); die($output); } @@ -502,7 +502,7 @@ if (!$output) } // Return data to client -echo bencode($output); +echo \Rych\Bencode\Bencode::encode($output); tracker_exit(); exit; \ No newline at end of file diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index f3f1b8298..6fc2d32d5 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -46,7 +46,7 @@ function error_exit ($msg = '') silent_exit(); - echo bencode(array('failure reason' => str_compact($msg))); + echo \Rych\Bencode\Bencode::encode(array('failure reason' => str_compact($msg))); tracker_exit(); } diff --git a/bt/scrape.php b/bt/scrape.php index e09ebbb9b..37dee699a 100644 --- a/bt/scrape.php +++ b/bt/scrape.php @@ -23,11 +23,11 @@ function msg_die ($msg) { if (DBG_LOG) dbg_log(' ', '!die-'. clean_filename($msg)); - $output = bencode(array( + $output = \Rych\Bencode\Bencode::encode([ 'min interval' => (int) 1800, 'failure reason' => (string) $msg, 'warning message' => (string) $msg, - )); + ]); die($output); } @@ -51,7 +51,7 @@ $output['files'][$info_hash] = array( 'incomplete' => (int) $row['leechers'], ); -echo bencode($output); +echo \Rych\Bencode\Bencode::encode($output); tracker_exit(); exit; \ No newline at end of file diff --git a/common.php b/common.php index 1ffe7d1ce..bb6184f97 100644 --- a/common.php +++ b/common.php @@ -357,69 +357,6 @@ function make_rand_str ($len = 10) return substr($str, 0, $len); } -// bencode: based on OpenTracker -function bencode ($var) -{ - if (is_string($var)) - { - return strlen($var) .':'. $var; - } - else if (is_int($var)) - { - return 'i'. $var .'e'; - } - else if (is_float($var)) - { - return 'i'. sprintf('%.0f', $var) .'e'; - } - else if (is_array($var)) - { - if (count($var) == 0) - { - return 'de'; - } - else - { - $assoc = false; - - foreach ($var as $key => $val) - { - if (!is_int($key)) - { - $assoc = true; - break; - } - } - - if ($assoc) - { - ksort($var, SORT_REGULAR); - $ret = 'd'; - - foreach ($var as $key => $val) - { - $ret .= bencode($key) . bencode($val); - } - return $ret .'e'; - } - else - { - $ret = 'l'; - - foreach ($var as $val) - { - $ret .= bencode($val); - } - return $ret .'e'; - } - } - } - else - { - trigger_error('bencode error: wrong data type', E_USER_ERROR); - } -} - function array_deep (&$var, $fn, $one_dimensional = false, $array_only = false) { if (is_array($var)) @@ -535,7 +472,7 @@ else if (defined('IN_TRACKER')) function dummy_exit ($interval = 1800) { - $output = bencode(array( + $output = \Rych\Bencode\Bencode::encode(array( 'interval' => (int) $interval, 'min interval' => (int) $interval, 'peers' => (string) DUMMY_PEER, diff --git a/library/includes/functions_torrent.php b/library/includes/functions_torrent.php index 9b14620fd..cbbedada2 100644 --- a/library/includes/functions_torrent.php +++ b/library/includes/functions_torrent.php @@ -169,7 +169,7 @@ function tracker_register ($topic_id, $mode = '', $tor_status = TOR_NOT_APPROVED { $tor_decoded['info']['private'] = (int) 1; $fp = fopen($filename, 'w+'); - fwrite($fp, bencode($tor_decoded)); + fwrite($fp, \Rych\Bencode\Bencode::encode($tor_decoded)); fclose($fp); } @@ -180,7 +180,7 @@ function tracker_register ($topic_id, $mode = '', $tor_status = TOR_NOT_APPROVED return torrent_error_exit($lang['TORFILE_INVALID']); } - $info_hash = pack('H*', sha1(bencode($info))); + $info_hash = pack('H*', sha1(\Rych\Bencode\Bencode::encode($info))); $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_md5 = md5($info_hash); @@ -470,7 +470,7 @@ function send_torrent_with_passkey ($t_data) unset($tor['comment.utf-8']); // Send torrent - $output = bencode($tor); + $output = \Rych\Bencode\Bencode::encode($tor); $dl_fname = '['.$bb_cfg['server_name'].'].t' . $topic_id . '.torrent'; if (!empty($_COOKIE['explain']))