コード例 #1
0
ファイル: PwAnnounce.php プロジェクト: LastRitter/WindPT
 public static function buildPeerList($torrent, $peer_list, $compact, $no_peer_id)
 {
     $bencode = new PwBencode();
     $string = 'd' . $bencode->doEncodeString('interval') . 'i840e' . $bencode->doEncodeString('min interval') . 'i30e' . $bencode->doEncodeString('complete') . 'i' . $torrent['seeders'] . 'e' . $bencode->doEncodeString('incomplete') . 'i' . $torrent['leechers'] . 'e' . $bencode->doEncodeString('peers');
     $peer_string = '';
     if (is_array($peer_list)) {
         $count = count($peer_list);
         foreach ($peer_list as $peer) {
             if ($compact) {
                 $peer_string .= str_pad(pack('Nn', ip2long($peer['ip']), $peer['port']), 6);
             } elseif ($no_peer_id == 1) {
                 $peer_string .= 'd' . $bencode->doEncodeString('ip') . $bencode->doEncodeString($peer['ip']) . $bencode->doEncodeString('port') . 'i' . $peer['port'] . 'e' . 'e';
             } else {
                 $peer_string .= 'd' . $bencode->doEncodeString('ip') . $bencode->doEncodeString($peer['ip']) . $bencode->doEncodeString('peer id') . $bencode->doEncodeString($peer['peer_id']) . $bencode->doEncodeString('port') . 'i' . $peer['port'] . 'e' . 'e';
             }
         }
     }
     if ($compact) {
         $string .= $bencode->doEncodeString($peer_string);
     } else {
         $string .= 'l' . $peer_string . 'e';
     }
     return $string . 'e';
 }
コード例 #2
0
ファイル: PwPostDoTorrent.php プロジェクト: Going2333/WindPT
 public function addTorrentt($tid)
 {
     $dm = Wekit::load('EXT:torrent.service.dm.PwTorrentDm');
     $dm->setTid($tid)->setInfoHash($this->infohash)->setOwner($this->user->uid)->setVisible('yes')->setAnonymous('yes')->setSize($this->totalength)->setNumfiles(count($this->filelist))->setType($this->type)->setWikilink($this->wikilink)->setFileName($this->filename)->setSaveAs($this->filesavename)->setSpState(1)->setAdded(date('Y-m-d H:i:s'))->setLastAction(date('Y-m-d H:i:s'));
     $result = $this->_getTorrentDS()->addTorrent($dm);
     if ($result instanceof PwError) {
         return $result;
     }
     if (is_array($this->filelist)) {
         $filedm = Wekit::load('EXT:torrent.service.dm.PwTorrentFileDm');
         foreach ($this->filelist as $file) {
             $filedm->setTorrent($result);
             $filedm->setFileName($file[0]);
             $filedm->setSize($file[1]);
             $this->_getTorrentFileDS()->addTorrentFile($filedm);
         }
     }
     if (!is_dir(WEKIT_PATH . '../torrent')) {
         mkdir(WEKIT_PATH . '../torrent', 0755);
     }
     $fp = fopen(WEKIT_PATH . '../torrent/' . $result . '.torrent', 'w');
     if ($fp) {
         $bencode = new PwBencode();
         @fwrite($fp, $bencode->doEncode($this->dictionary));
         fclose($fp);
     }
     return true;
 }