Пример #1
0
 /**
  * Info
  * @param type $s
  * @return type
  */
 static function bdec_list($s)
 {
     if ($s[0] != "l") {
         return;
     }
     $sl = strlen($s);
     $i = 1;
     $v = array();
     $ss = "l";
     for (;;) {
         if ($i >= $sl) {
             return;
         }
         if ($s[$i] == "e") {
             break;
         }
         $ret = Bcode::bdec(substr($s, $i));
         if (!isset($ret) || !is_array($ret)) {
             return;
         }
         $v[] = $ret;
         $i += $ret["strlen"];
         $ss .= $ret["string"];
     }
     $ss .= "e";
     return array("type" => "list", "value" => $v, "strlen" => strlen($ss), "string" => $ss);
 }
Пример #2
0
                 throw new Exception("somthing bad happend. and we dont know what.");
             }
             $ffa[] = $ffe["value"];
         }
         if (!count($ffa)) {
             throw new Exception("somthing bad happend. and we dont know what.");
         }
         $ffe = implode("/", $ffa);
         $filelist[] = array($ffe, $ll);
     }
     $type = "multi";
 }
 $dict['value']['info']['value']['private'] = Bcode::bdec('i1e');
 unset($dict['value']['announce-list']);
 unset($dict['value']['nodes']);
 $dict = Bcode::bdec(Bcode::benc($dict));
 list($ann, $info) = Bcode::dict_check($dict, "announce(string):info");
 $infohash = sha1($info["string"]);
 unset($info);
 $db = new DB("torrents");
 $db->select("torrent_save_as = '{$filename}'");
 if ($db->numRows()) {
     throw new Exception("Torrent allready exists");
 }
 $db = new DB("torrents");
 $db->setColPrefix("torrent_");
 $id = uniqid(true);
 $db->id = $id;
 $db->info_hash = $infohash;
 $db->name = $torrentName;
 $db->filename = $filename;