Tedmorris |
15th June 2020 20:58 |
Compact mode implementation
How to implement compact mode in announce.php?
Find
PHP Code:
$wantseeds = ""; if ( $seeder == 'yes' ) $wantseeds = "AND seeder = 'no'"; $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT $fields FROM peers WHERE torrent = $torrentid AND connectable = 'yes' $wantseeds $limit" ) or err( 'peers query failure' );
Insert below
PHP Code:
//////////////////// START NEW COMPACT MODE///////////////////////////// if($_GET['compact'] != 1) { $resp = "d" . benc_str("interval") . "i" . $INSTALLER09['announce_interval'] . "e" . benc_str("private") . 'i1e' . benc_str("peers") . "l"; } else { $resp = "d" . benc_str("interval") . "i" . $INSTALLER09['announce_interval'] ."e" . benc_str("private") . 'i1e'. benc_str("min interval") . "i" . 300 ."e5:"."peers" ; }
$peer = array(); $peer_num = 0; while ($row = mysqli_fetch_assoc($res)) { if($_GET['compact'] != 1) { $row["peer_id"] = str_pad($row["peer_id"], 20); if ($row["peer_id"] === $peer_id) { $self = $row; continue; } $resp .= "d" . benc_str("ip") . benc_str($row["ip"]); if (!$_GET['no_peer_id']) { $resp .= benc_str("peer id") . benc_str($row["peer_id"]); } $resp .= benc_str("port") . "i" . $row["port"] . "e" . "e"; } else { $peer_ip = explode('.', $row["ip"]); $peer_ip = pack("C*", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3]); $peer_port = pack("n*", (int)$row["port"]); $time = intval((time() % 7680) / 60); if($_GET['left'] == 0) { $time += 128; } $time = pack("C", $time); $peer[] = $time . $peer_ip . $peer_port; $peer_num++; } } if ($_GET['compact']!=1) $resp .= "ee"; else { $o = ""; for($i=0;$i<$peer_num;$i++) { $o .= substr($peer[$i], 1, 6); } $resp .= strlen($o) . ':' . $o . 'e'; } $selfwhere = "torrent = $torrentid AND " . hash_where("peer_id", $peer_id); ///////////////////////////// END NEW COMPACT MODE////////////////////////////////
But I'm missing something else that needs to be added to another file.
At the moment I have
PHP Code:
$resp = "d" . benc_str("interval") . "i" . $announce_interval . "e" . benc_str("peers") . "l"; unset($self); while ($row = mysql_fetch_assoc($res)) { $row["peer_id"] = hash_pad($row["peer_id"]);
if ($row["peer_id"] === $peer_id) { $userid = $row["userid"]; $self = $row; continue; }
$resp .= "d" . benc_str("ip") . benc_str($row["ip"]) . benc_str("peer id") . benc_str($row["peer_id"]) . benc_str("port") . "i" . $row["port"] . "e" . "e"; }
$resp .= "ee"; $selfwhere = "torrent = $torrentid AND " . hash_where("peer_id", $peer_id);
|