Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function announce($passkey = null)
- {
- //Log::info(Input::all());
- $hash = bin2hex(Input::get('info_hash'));
- $peerId = Input::get('peer_id');
- $cryptedPeerid = md5($peerId);
- $torrent = Torrent::where('info_hash', '=', $hash)->firstOrFail();
- $user = User::where('passkey', '=', $passkey)->firstOrFail();
- $client = Peer::where('md5_peer_id', '=', $cryptedPeerid)->first();
- if(! $client)
- {
- // Set the torrent data
- $client = new Peer();
- $client->uploaded = Input::get('uploaded');
- $client->downloaded = Input::get('downloaded');
- }
- $peers = Peer::where('hash', '=', $hash)->take(50)->get()->toArray();
- $torrent->leechers = Peer::whereRaw('`left` > 0 AND torrent_id =' $torrent->id)->count();
- $torrent->seeders = Peer::whereRaw('`left` = 0 AND torrent_id =' $torrent->id)->count();;
- if(Input::get('event') == 'started')
- {
- $client->ip = Request::getClientIp();
- $client->port = Input::get('port');
- $client->left = Input::get('left');
- $client->peer_id = Input::get('peer_id');
- $client->md5_peer_id = md5($client->peer_id);
- $client->uploaded = 0;
- $client->downloaded = 0;
- $client->hash = $hash;
- $client->seeder = ($client->left == 0) ? true : false;
- $client->user_id = $user->id;
- $client->torrent_id = $torrent->id;
- }
- if(Input::get('event') == 'completed')
- {
- $torrent->times_completed++;
- $torrent->save();
- $client->left = 0;
- $client->seeder = true;
- $client->save();
- }
- if(Input::get('event') == 'stopped')
- {
- $client->delete();
- return Response::make('OK', 200, array('Content-Type' => 'text/plain'));
- }
- // Modification de l'upload/download de l'utilisateur pour le ratio
- if(Input::get('uploaded') > $client->uploaded)
- {
- $user->uploaded = $user->uploaded + (Input::get('uploaded') - $client->uploaded);
- }
- if(Input::get('downloaded') > $client->downloaded)
- {
- $user->downloaded = $user->downloaded + (Input::get('downloaded') - $client->downloaded);
- }
- $user->save();
- $client->save();
- $res['interval'] = 600; // Set to 60 for debug
- $res['min interval'] = 300; // Set to 30 for debug
- //$res['tracker_id'] = $client->md5_peer_id; // A string that the client should send back on its next announcements.
- $res['complete'] = $torrent->seeders;
- $res['incomplete'] = $torrent->leechers;
- $res['peers'] = $peers;
- //Log::info($res);
- return Response::make(Bencode::bencode($res), 200, array('Content-Type' => 'text/plain'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement