Ejemplo n.º 1
0
 public function actionAnnounce()
 {
     Yii::$app->response->headers->add("Content-Type", "text/plain");
     Yii::trace(print_r(Yii::$app->request->get(), true));
     $form = new QueryPeersForm();
     $form->attributes = Yii::$app->request->get();
     Yii::info($form->ip);
     $peer_list = null;
     if ($form->validate()) {
         $peer = $form->peer;
         $peer->real_up = $form->uploaded;
         $peer->real_down = $form->downloaded;
         if ($peer->user_id == $form->seed->publisher_user_id) {
             $peer->up_coef = 200;
             //做种者两倍上传
         }
         $peer->save();
         //处理event
         switch ($form->event) {
             case 'regular':
                 break;
             case 'started':
                 //do nothing?
                 break;
             case 'stopped':
                 $peer->delete();
                 break;
             case 'completed':
                 $event = new SeedEvent();
                 $event->seed_id = $form->seed->seed_id;
                 $event->user_id = Yii::$app->user->identity->getId();
                 $event->event_type = 'Completed';
                 $event->insert();
                 $form->seed->completed_count++;
                 $form->seed->save();
                 break;
             default:
                 Yii::warning("Unknown event", static::className());
         }
         if ($form->numwant == 0) {
             $form->numwant = 100;
         }
         //Seeder会排到前面
         $peer_list = Peer::find()->where(['seed_id' => $form->seed->seed_id])->orderBy(['status' => SORT_ASC, 'update_time' => SORT_DESC])->limit(min(300, intval($form->numwant)))->all();
     } else {
         $errors = $form->errors;
         Yii::warning($errors);
     }
     return $this->renderPartial("queryPeerList", ['peer_list' => $peer_list, 'form' => $form]);
 }
Ejemplo n.º 2
0
 public function actionDownload($seed_id)
 {
     $seed = Seed::findOne($seed_id);
     if (empty($seed)) {
         return ['result' => 'failed', 'extra' => 'no such seed'];
     }
     $main_tracker = "http://10.254.36.2:8080/announce.php?";
     //鉴于announce_list实际上是扩展,经过实验,如果有announce_list,
     //announce就不再起作用,所以把main_tracker放到list的第一个
     $secondary_tracker = [$main_tracker, "http://10.254.36.2:9001/announce.php?", "http://tracker1.bevip.xyz:8081/announce.php?", "http://tracker2.bevip.xyz:8082/announce.php?", "http://tracker3.bevip.xyz:8083/announce.php?", "http://tracker4.bevip.xyz:8084/announce.php?"];
     $info_path = getcwd() . "/torrents/" . $seed['info_hash'] . '.info';
     $torrent = TorrentFileTool::buildTorrentFile($info_path, $main_tracker, $secondary_tracker);
     $event = new SeedEvent();
     $event->seed_id = $seed_id;
     $event->user_id = Yii::$app->user->identity->getId();
     $event->event_type = 'Downloaded';
     $event->insert();
     return Yii::$app->response->sendContentAsFile($torrent, '[NGPT]' . $seed['torrent_name'] . '.torrent');
 }
Ejemplo n.º 3
0
 public function getInfo($detail = false)
 {
     $ret = $this->attributes;
     if ($detail) {
         $ret = array_merge($ret, $this->getPeerStat());
         $res = SeedEvent::getUserCounter($this->user_id);
         $ret = array_merge($ret, $res);
         $ret['published_seed'] = count($this->publishedSeed);
     }
     Yii::info($ret);
     return $ret;
 }
Ejemplo n.º 4
0
    public function actionHistory()
    {
        History::deleteAll();
        SeedEvent::deleteAll();
        $offset = 0;
        $limit = 1000;
        QUERY:
        $sql = <<<SQL
        SELECT * FROM `ngpt_ngpt_history` LIMIT {$limit} OFFSET {$offset};
SQL;
        $res = $this->fdb->createCommand($sql)->queryAll();
        foreach ($res as $ohis) {
            $his = new History();
            $his->record_date = $this->date($ohis['lastupdate']);
            /** @var User $user */
            $user = User::findOne(['discuz_user_id' => $ohis['uid']]);
            /** @var Seed $seed */
            $seed = Seed::findOne(['info_hash' => strtoupper($ohis['infohash'])]);
            if (!$seed) {
                continue;
            }
            $his->user_id = $user->user_id;
            $his->seed_id = $seed->seed_id;
            $his->stat_up = $ohis['uploaded'];
            $his->stat_down = $ohis['downloaded'];
            $his->real_up = $ohis['realup'];
            $his->real_down = $ohis['realdown'];
            $seed_event = new SeedEvent();
            $seed_event->user_id = $user->user_id;
            $seed_event->seed_id = $seed->seed_id;
            $seed_event->event_type = 'Downloaded';
            $res = $his->insert() && $seed_event->insert();
            if (!$res) {
                var_dump($his->errors);
                var_dump($seed_event->errors);
                return;
            }
            var_dump($his->attributes);
            var_dump($seed_event->attributes);
        }
        if (count($res)) {
            $offset += $limit;
            goto QUERY;
        }
        return;
    }