Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Code TidBits
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / V4 / Support & Suggestions

2022-07-14 17:25:31

// Get available seed bonuse upgrades available for current user points balance
$bonus        = $db->query_params('SELECT * FROM bonus');
$getbonusinfo = $bonus->fetchAll();
$seedbonus    = $db->query_params('SELECT seedbonus FROM users WHERE user_id = :user_id LIMIT 1', array(
   'user_id' => 1
));
$current      = array(); // current points
foreach ($seedbonus->fetchAll() as $value) {
   array_push($current, floatval($value['seedbonus']));
}
foreach ($getbonusinfo as $row) {
   if ($current[0] > floatval($row['cost'])) {
       printf('You can get: %s <br>', $row['title']);
   }
}



// BEP-12 Multitracker Metadata Extension
$multitracker = array(
   'udp://tracker.com/announce1',
   'udp://tracker.com/announce2'
);
if (!empty($multitracker)) {
   $arr['announce-list'] = [['udp://tracker.com/announce1', 'udp://tracker.com/announce2'], [sprintf('%s/announce?%stoken=%s', $CONFIG['base_url'], 'v=1&', $token)]];
   shuffle($arr['announce-list']);
}



// BEP-38 Finding Local Data Via Torrent File Hints
$similar = $db->query_params("SELECT t.info_hash, c.name AS cat_name, t.name FROM torrents t LEFT JOIN categories c ON t.category = c.id WHERE t.name LIKE :match", array(
   'match' => '%' . strtok($name, ' ') . '%'
));
$hashes  = array();
foreach ($similar->fetchAll() as $row) {
   array_push($hashes, hex2bin($row['info_hash']));
   $parse['collections'] = sprintf('com.%s.%s', strtolower(strtok($row['cat_name'], ' ')), strtolower(strtok($row['name'], ' ')));
}
if (!empty($hashes)) {
   $parse['similar'] = $hashes;
}



public function verifyToken(string $passkey, string $token, string $peer_id): never
{
   $filter    = array(
       '_',
       '-',
       '[',
       ']',
       '!',
       '@',
       '$'
   );
   $getuserid = $this->query_params('SELECT u.user_id FROM peers p LEFT JOIN users u ON u.user_id = p.user_id WHERE p.chosen_peer_id = :peer_id LIMIT 1', array(
       'peer_id' => $peer_id
   ));
   foreach ($filter as $char) {
       if (strpbrk($token, $char) !== false) {
           $this->fail('Token invalid. Err(1)');
       }
   }
   if (strlen($this->decryptToken($token)) === 0) {
       if ($u = $getuserid->fetch()) {
           $this->sendNotif($u['user_id'], 'Client token is invalid.', 'Tracker');
       }
       $this->fail('Token invalid. Err(2)');
   }
   if (strpos($token, $filter[0]) !== false) {
       if ($u = $getuserid->fetch()) {
           $this->sendNotif($u['user_id'], 'Client token is invalid.', 'Tracker');
       }
       $this->fail('Token invalid. Err(3)');
   }
   if (hash_equals($this->decryptToken($token), $passkey) !== true) {
       $this->fail('Token invalid. Err(4)');
   }
}
Last edited by STorrents2020 on 2022-07-16 18:39:01
2022-07-15 11:37:47
How many BEP's are you using?

I was actually thinking a smart idea of the library im working on is to make little plugins to auto detect them.
2022-07-16 02:27:55
I use about 8 BEPs in total, maybe 10 due to the private torrents etc. All very tightly woven in place. I thank you dearly for your signing code, I would of paid money for that, easily.

—-

That’s a little what I’m doing too, only parsing /modules/* to allow extensibility to the code base.

I have a few more pages to convert to classes, and from there the module system will be implemented as well as providing the “blocks” seen on the homepage.

This kind of portability allows me to easily debug a single feature by file, and push updates fast without getting into the core of the entire site each time.

Have you developed a plug-in system before? Do you use SPL auto load for this?
Last edited by STorrents2020 on 2022-07-16 02:30:17
2022-07-16 06:41:10
No worries.

Yeah you can use SPL autoload for that, in the past i used a interface to ensure that plugin files always contained certain methods e.g: install, uninstall but alternatively you may be interested in a hook system.


<?php

class Hook
{
   protected $hooks = [];

   public function register(string $hookName, callable $callback)
   {
       $this->hooks[$hookName][] = $callback;
   }

   public function __call($method, $params)
   {
       if (! is_string($method)) {
           throw new InvalidArgumentException('$method should be typeof: string');
       }
       if (array_key_exists($this->hooks, $method)) {
           foreach ($this->hooks[$method] as $hook) {
               call_user_func_array($hook, $params);
           }
       }
   }
}

// Initialise hook system globally.
$hook = new Hook();

// Register potential hooks at start up.
$hook->register('onSignup', function($username, $password) {
   // Do something interesting...
});

// At locations call hooks.
$hook->onSignup('mostvotedplaya', 'foobar');

2022-07-16 18:37:08
I'll check that out - thanks! I am completely unaware of such a thing other than SPL auto load.

2022-07-16 23:14:30
Neat thing I moved from just POST + html to JSON and better handled file search within bencoded data - LONGBLOB fields by query on JS side - ajax

// AJAX Live File Search - Meta Data - July 15, 2022
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   if (isset($_POST['meta_file_name'])) {
       $matchedfile = $db->query_params('SELECT b.torrent_id, t.name, t.cover1 FROM torrents_blob b LEFT JOIN torrents t ON t.torrent_id = b.torrent_id WHERE b.data LIKE :matched_metafile', array(
           'matched_metafile' => '%' . html_escape(trim($_POST['meta_file_name'])) . '%'
       ));
       $matched     = array();
       foreach ($matchedfile->fetchAll() as $row) {
           $data['torrent_id'] = intval($row['torrent_id']);
           $data['name']       = html_escape(trim($row['name']));
           $data['cover']      = $row['cover1'];
           array_push($matched, $data);
       }
   }
   echo empty($matched) ? json_encode(array(
       'matched' => 'false'
   )) : json_encode($matched, JSON_UNESCAPED_SLASHES);
}
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728