mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-24 03:59:08 -05:00
(Update) Hit&Run / History System
- add prewarnings - update history table (migration) - I added a check in the announce controller for the completed event sent by client. During that event I added `$history->immune = ($user->group->is_immune == 1) ? 1 : 0; ` which is pretty much saying is the user in a immune group upon download completion. This will solve people in immune groups that download but dont meet 7 days seedtime but then get demoted and banned. As we wont issue warnings for history records marked as immune.
This commit is contained in:
@@ -45,25 +45,40 @@ class AutoPreWarning extends Command
|
||||
if (config('hitrun.enabled') == true) {
|
||||
$current = new Carbon();
|
||||
$prewarn = History::with(['user', 'torrent'])
|
||||
->where('actual_downloaded', '>', 0)
|
||||
->where('active', 0)
|
||||
->where('seedtime', '<=', config('hitrun.seedtime'))
|
||||
->where('updated_at', '<', $current->copy()->subDays(config('hitrun.prewarn'))->toDateTimeString())
|
||||
->get();
|
||||
->where('prewarn', 0)
|
||||
->where('hitrun', 0)
|
||||
->where('immune', 0)
|
||||
->where('actual_downloaded', '>', 0)
|
||||
->where('active', 0)
|
||||
->where('seedtime', '<=', config('hitrun.seedtime'))
|
||||
->where('updated_at', '<', $current->copy()->subDays(config('hitrun.prewarn'))->toDateTimeString())
|
||||
->get();
|
||||
|
||||
foreach ($prewarn as $pre) {
|
||||
if (!$pre->user->group->is_immune) {
|
||||
if ($pre->actual_downloaded > ($pre->torrent->size * (config('hitrun.buffer') / 100))) {
|
||||
$exsist = Warning::where('torrent', $pre->torrent->id)->where('user_id', $pre->user->id)->first();
|
||||
$exsist = Warning::withTrashed()
|
||||
->where('torrent', $pre->torrent->id)
|
||||
->where('user_id', $pre->user->id)
|
||||
->first();
|
||||
|
||||
// Send Pre Warning PM If Actual Warning Doesnt Already Exsist
|
||||
if (!$exsist) {
|
||||
$timeleft = config('hitrun.grace') - config('hitrun.prewarn');
|
||||
|
||||
// Send Prewarning PM To The Offender
|
||||
PrivateMessage::create(['sender_id' => "1", 'reciever_id' => $pre->user->id, 'subject' => "Hit and Run Warning Incoming", 'message' => "You have received a automated [b]PRE-WARNING PM[/b] from the system because [b]you have been disconnected for " . config('hitrun.prewarn') . " days on Torrent " . $pre->torrent->name . "
|
||||
If you fail to seed it within " . $timeleft . " day(s) you will recieve a automated WARNING which will last " . config('hitrun.expire') ." days![/b]
|
||||
[color=red][b] THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]"]);
|
||||
// Send Private Message
|
||||
$pm = new PrivateMessage;
|
||||
$pm->sender_id = 1;
|
||||
$pm->receiver_id = $pre->user->id;
|
||||
$pm->subject = "Hit and Run Warning Incoming";
|
||||
$pm->message = "You have received a automated [b]PRE-WARNING PM[/b] from the system because [b]you have been disconnected for " . config('hitrun.prewarn') . " days on Torrent {$pre->torrent->name}
|
||||
and have not yet met the required seedtime rules set by " . config('other.title') .". If you fail to seed it within {$timeleft} day(s) you will recieve a automated WARNING which will last " . config('hitrun.expire') ." days![/b]
|
||||
[color=red][b] THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]";
|
||||
$pm->save();
|
||||
|
||||
// Set History Prewarn
|
||||
$pre->prewarn = 1;
|
||||
$pre->save();
|
||||
}
|
||||
|
||||
unset($exist);
|
||||
|
||||
@@ -44,16 +44,22 @@ class AutoWarning extends Command
|
||||
if (config('hitrun.enabled') == true) {
|
||||
$current = new Carbon();
|
||||
$hitrun = History::with(['user', 'torrent'])
|
||||
->where('actual_downloaded', '>', 0)
|
||||
->where('active', 0)
|
||||
->where('seedtime', '<=', config('hitrun.seedtime'))
|
||||
->where('updated_at', '<', $current->copy()->subDays(config('hitrun.grace'))->toDateTimeString())
|
||||
->get();
|
||||
->where('actual_downloaded', '>', 0)
|
||||
->where('prewarn', 1)
|
||||
->where('hitrun', 0)
|
||||
->where('immune', 0)
|
||||
->where('active', 0)
|
||||
->where('seedtime', '<=', config('hitrun.seedtime'))
|
||||
->where('updated_at', '<', $current->copy()->subDays(config('hitrun.grace'))->toDateTimeString())
|
||||
->get();
|
||||
|
||||
foreach ($hitrun as $hr) {
|
||||
if (!$hr->user->group->is_immune) {
|
||||
if ($hr->actual_downloaded > ($hr->torrent->size * (config('hitrun.buffer') / 100))) {
|
||||
$exsist = Warning::where('torrent', $hr->torrent->id)->where('user_id', $hr->user->id)->withTrashed()->first();
|
||||
$exsist = Warning::withTrashed()
|
||||
->where('torrent', $hr->torrent->id)
|
||||
->where('user_id', $hr->user->id)
|
||||
->first();
|
||||
|
||||
// Insert Warning Into Warnings Table if doesnt already exsist
|
||||
if (!$exsist) {
|
||||
@@ -78,6 +84,10 @@ class AutoWarning extends Command
|
||||
$pm->message = "You have received a automated [b]WARNING[/b] from the system because [b]you failed to follow the Hit and Run rules in relation to Torrent " . $hr->torrent->name . "[/b]
|
||||
[color=red][b]THIS IS AN AUTOMATED SYSTEM MESSAGE, PLEASE DO NOT REPLY![/b][/color]";
|
||||
$pm->save();
|
||||
|
||||
// Set History Hitrun
|
||||
$hr->hitrun = 1;
|
||||
$hr->save();
|
||||
}
|
||||
|
||||
unset($exist);
|
||||
|
||||
@@ -18,7 +18,7 @@ class Kernel extends ConsoleKernel
|
||||
\App\Console\Commands\AutoNerdStat::class,
|
||||
\App\Console\Commands\AutoBonAllocation::class,
|
||||
\App\Console\Commands\AutoHighspeedTag::class,
|
||||
//\App\Console\Commands\AutoPreWarning::class,
|
||||
\App\Console\Commands\AutoPreWarning::class,
|
||||
\App\Console\Commands\AutoWarning::class,
|
||||
\App\Console\Commands\AutoDeactivateWarning::class,
|
||||
\App\Console\Commands\AutoRevokePermissions::class,
|
||||
@@ -57,8 +57,8 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('auto:nerdstat ')->hourly();
|
||||
$schedule->command('auto:graveyard')->daily();
|
||||
$schedule->command('auto:highspeed_tag')->hourly();
|
||||
//$schedule->command('auto:prewarning')->hourly();
|
||||
$schedule->command('auto:warning')->hourly();
|
||||
$schedule->command('auto:prewarning')->hourly();
|
||||
$schedule->command('auto:warning')->daily();
|
||||
$schedule->command('auto:deactivate_warning')->hourly();
|
||||
$schedule->command('auto:revoke_permissions')->hourly();
|
||||
$schedule->command('auto:ban')->hourly();
|
||||
|
||||
+4
-1
@@ -34,7 +34,10 @@ class History extends Model
|
||||
'seedtime',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'completed_at'
|
||||
'completed_at',
|
||||
'prewarn',
|
||||
'hitrun',
|
||||
'immune'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Group;
|
||||
use App\History;
|
||||
use App\Peer;
|
||||
use App\Torrent;
|
||||
@@ -89,12 +90,22 @@ class AnnounceController extends Controller
|
||||
return response(Bencode::bencode(['failure reason' => 'Passkey is invalid']), 200, ['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
$bannedGroup = Group::where('slug', '=', 'banned')->select('id')->first();
|
||||
$validatingGroup = Group::where('slug', '=', 'validating')->select('id')->first();
|
||||
$disabledGroup = Group::where('slug', '=', 'disabled')->select('id')->first();
|
||||
|
||||
// If User Is Banned Return Error to Client
|
||||
if ($user->group->id == 5) {
|
||||
if ($user->group->id == $bannedGroup->id) {
|
||||
//info('A Banned User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'You are no longer welcome here']), 200, ['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
// If User Is Disabled Return Error to Client
|
||||
if ($user->group->id == $disabledGroup->id) {
|
||||
//info('A Disabled User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'Your account is disabled. Please login.']), 200, ['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
// If User Account Is Unactivated Return Error to Client
|
||||
if ($user->active == 0) {
|
||||
//info('A Unactivated User (' . $user->username . ') Attempted To Announce');
|
||||
@@ -102,16 +113,11 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// If User Is Validating Return Error to Client
|
||||
if ($user->group->id == 1) {
|
||||
if ($user->group->id == $validatingGroup->id) {
|
||||
//info('A Validating User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'Your account is still validating']), 200, ['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
// If User Is Leech Or Download Rights Disabled Return Error to Client
|
||||
/*if ($user->group->id == 15 || $user->can_download == 0) {
|
||||
return response(Bencode::bencode(['failure reason' => 'Your download rights are disabled']), 200, ['Content-Type' => 'text/plain']);
|
||||
}*/
|
||||
|
||||
// Standard Information Fields
|
||||
$event = $request->input('event');
|
||||
$info_hash = bin2hex($request->input('info_hash'));
|
||||
@@ -227,13 +233,13 @@ class AnnounceController extends Controller
|
||||
$personal_freeleech = PersonalFreeleech::where('user_id', $user->id)->first();
|
||||
$freeleech_token = FreeleechToken::where('user_id', $user->id)->where('torrent_id', $torrent->id)->first();
|
||||
|
||||
if (config('other.freeleech') == true || $torrent->free == 1 || $personal_freeleech || $user->group->is_freeleech == 1 || $freeleech_token) {
|
||||
if (config('other.freeleech') == 1 || $torrent->free == 1 || $personal_freeleech || $user->group->is_freeleech == 1 || $freeleech_token) {
|
||||
$mod_downloaded = 0;
|
||||
} else {
|
||||
$mod_downloaded = $downloaded;
|
||||
}
|
||||
|
||||
if (config('other.doubleup') == true || $torrent->doubleup == 1) {
|
||||
if (config('other.doubleup') == 1 || $torrent->doubleup == 1) {
|
||||
$mod_uploaded = $uploaded * 2;
|
||||
} else {
|
||||
$mod_uploaded = $uploaded;
|
||||
@@ -242,8 +248,8 @@ class AnnounceController extends Controller
|
||||
if ($event == 'started') {
|
||||
// Set the torrent data
|
||||
$history->agent = $agent;
|
||||
$history->active = true;
|
||||
$history->seeder = ($left == 0) ? true : false;
|
||||
$history->active = 1;
|
||||
$history->seeder = ($left == 0) ? 1 : 0;
|
||||
$history->uploaded += 0;
|
||||
$history->actual_uploaded += 0;
|
||||
$history->client_uploaded = $real_uploaded;
|
||||
@@ -263,7 +269,7 @@ class AnnounceController extends Controller
|
||||
$client->agent = $agent;
|
||||
$client->uploaded = $real_uploaded;
|
||||
$client->downloaded = $real_downloaded;
|
||||
$client->seeder = ($left == 0) ? true : false;
|
||||
$client->seeder = ($left == 0) ? 1 : 0;
|
||||
$client->left = $left;
|
||||
$client->torrent_id = $torrent->id;
|
||||
$client->user_id = $user->id;
|
||||
@@ -273,8 +279,9 @@ class AnnounceController extends Controller
|
||||
} elseif ($event == 'completed') {
|
||||
// Set the torrent data
|
||||
$history->agent = $agent;
|
||||
$history->active = true;
|
||||
$history->seeder = ($left == 0) ? true : false;
|
||||
$history->active = 1;
|
||||
$history->seeder = ($left == 0) ? 1 : 0;
|
||||
$history->immune = ($user->group->is_immune == 1) ? 1 : 0;
|
||||
$history->uploaded += $mod_uploaded;
|
||||
$history->actual_uploaded += $uploaded;
|
||||
$history->client_uploaded = $real_uploaded;
|
||||
@@ -299,7 +306,7 @@ class AnnounceController extends Controller
|
||||
$client->agent = $agent;
|
||||
$client->uploaded = $real_uploaded;
|
||||
$client->downloaded = $real_downloaded;
|
||||
$client->seeder = true;
|
||||
$client->seeder = 1;
|
||||
$client->left = 0;
|
||||
$client->torrent_id = $torrent->id;
|
||||
$client->user_id = $user->id;
|
||||
@@ -317,8 +324,8 @@ class AnnounceController extends Controller
|
||||
} elseif ($event == 'stopped') {
|
||||
// Set the torrent data
|
||||
$history->agent = $agent;
|
||||
$history->active = false;
|
||||
$history->seeder = ($left == 0) ? true : false;
|
||||
$history->active = 0;
|
||||
$history->seeder = ($left == 0) ? 1 : 0;
|
||||
$history->uploaded += $mod_uploaded;
|
||||
$history->actual_uploaded += $uploaded;
|
||||
$history->client_uploaded = 0;
|
||||
@@ -342,7 +349,7 @@ class AnnounceController extends Controller
|
||||
$client->agent = $agent;
|
||||
$client->uploaded = $real_uploaded;
|
||||
$client->downloaded = $real_downloaded;
|
||||
$client->seeder = ($left == 0) ? true : false;
|
||||
$client->seeder = ($left == 0) ? 1 : 0;
|
||||
$client->left = $left;
|
||||
$client->torrent_id = $torrent->id;
|
||||
$client->user_id = $user->id;
|
||||
@@ -362,8 +369,8 @@ class AnnounceController extends Controller
|
||||
} else {
|
||||
// Set the torrent data
|
||||
$history->agent = $agent;
|
||||
$history->active = true;
|
||||
$history->seeder = ($left == 0) ? true : false;
|
||||
$history->active = 1;
|
||||
$history->seeder = ($left == 0) ? 1 : 0;
|
||||
$history->uploaded += $mod_uploaded;
|
||||
$history->actual_uploaded += $uploaded;
|
||||
$history->client_uploaded = $real_uploaded;
|
||||
@@ -387,7 +394,7 @@ class AnnounceController extends Controller
|
||||
$client->agent = $agent;
|
||||
$client->uploaded = $real_uploaded;
|
||||
$client->downloaded = $real_downloaded;
|
||||
$client->seeder = ($left == 0) ? true : false;
|
||||
$client->seeder = ($left == 0) ? 1 : 0;
|
||||
$client->left = $left;
|
||||
$client->torrent_id = $torrent->id;
|
||||
$client->user_id = $user->id;
|
||||
|
||||
@@ -26,7 +26,7 @@ return [
|
||||
],
|
||||
'numeric' => [
|
||||
'rows' => ['created_at', 'updated_at', 'id', 'seeders', 'leechers', 'times_completed', 'size', 'uploaded', 'downloaded', 'left', 'seeder',
|
||||
'active', 'seedtime', 'updated_at', 'completed_at'],
|
||||
'active', 'seedtime', 'updated_at', 'completed_at', 'hitrun', 'prewarn', 'immune'],
|
||||
'class' => 'fal fa-sort-numeric',
|
||||
],
|
||||
],
|
||||
|
||||
+1
-1
@@ -100,6 +100,6 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'prewarn' => 2,
|
||||
'prewarn' => 1,
|
||||
|
||||
];
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
* @author HDVinnie
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddImmuneToHistoryTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('history', function (Blueprint $table) {
|
||||
$table->boolean('immune')->default(0)->index()->after('seedtime');
|
||||
$table->boolean('hitrun')->default(0)->index()->after('immune');
|
||||
$table->boolean('prewarn')->default(0)->index()->after('hitrun');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('history', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,9 @@ return [
|
||||
'grant' => 'Grant',
|
||||
'greater-than' => 'Greater than',
|
||||
'history' => 'History',
|
||||
'hitrun' => 'H&R?',
|
||||
'hit-and-runs' => 'Hit and Run counts',
|
||||
'immune' => 'Immune?',
|
||||
'info' => 'Info',
|
||||
'last-seed-activity' => 'Last seed activity',
|
||||
'last-seeder' => 'You Are The Last Remaining Seeder! (has been downloaded atleast 3 times)',
|
||||
@@ -77,6 +79,7 @@ return [
|
||||
'pending' => 'Pending',
|
||||
'poster-view' => 'Poster view',
|
||||
'posters' => 'Posters',
|
||||
'prewarn' => 'Prewarned?',
|
||||
'progress' => 'Progress',
|
||||
'quick-comment' => 'Quick Comment',
|
||||
'quick-tip' => 'Quick tip amounts',
|
||||
|
||||
@@ -42,16 +42,17 @@
|
||||
<th>@sortablelink('created_at', trans('torrent.created_at'))</th>
|
||||
<th>@sortablelink('updated_at', trans('torrent.updated_at'))</th>
|
||||
<th>@sortablelink('completed_at', trans('torrent.completed_at'))</th>
|
||||
<th>@sortablelink('prewarn', trans('torrent.prewarn'))</th>
|
||||
<th>@sortablelink('hitrun', trans('torrent.hitrun'))</th>
|
||||
<th>@sortablelink('immune', trans('torrent.immune'))</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($history as $his)
|
||||
<tr>
|
||||
<td>
|
||||
<a class="view-torrent" data-id="{{ $his->torrent_id }}"
|
||||
data-slug="{{ $his->torrent->slug }}"
|
||||
href="{{ route('torrent', ['slug' => $his->torrent->slug, 'id' => $his->torrent->id]) }}"
|
||||
data-toggle="tooltip" title="{{ $his->torrent->name }}"
|
||||
data-original-title="{{ trans('user.moderated-by', ['mod' => App\User::find($his->torrent->moderated_by)->username]) }} {{ $his->torrent->moderated_at->diffForHumans() }}">{{ $his->torrent->name }}</a>
|
||||
<a class="view-torrent" href="{{ route('torrent', ['slug' => $his->torrent->slug, 'id' => $his->torrent->id]) }}">
|
||||
{{ $his->torrent->name }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge-extra text-purple">{{ $his->agent ? $his->agent : trans('common.unknown') }}</span>
|
||||
@@ -84,6 +85,21 @@
|
||||
<td>{{ $his->created_at->diffForHumans() }}</td>
|
||||
<td>{{ $his->updated_at->diffForHumans() }}</td>
|
||||
<td>{{ $his->completed_at ? $his->completed_at->diffForHumans() : "N/A"}}</td>
|
||||
@if ($his->prewarn == 1)
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-check text-green"></i></td>
|
||||
@else
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-times text-red"></i></td>
|
||||
@endif
|
||||
@if ($his->hitrun == 1)
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-check text-green"></i></td>
|
||||
@else
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-times text-red"></i></td>
|
||||
@endif
|
||||
@if ($his->immune == 1)
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-check text-green"></i></td>
|
||||
@else
|
||||
<td><i class="{{ config('other.font-awesome') }} fa-times text-red"></i></td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user