mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-04 01:09:58 -05:00
(Update) Announce Controller 🚀
- forever cache system required group checks. - eager load user group relation with only the two specific columns used. - eager load user history
This commit is contained in:
@@ -37,6 +37,12 @@ class AnnounceController extends Controller
|
||||
*/
|
||||
public function announce(Request $request, $passkey)
|
||||
{
|
||||
/*\DB::listen(function($sql) {
|
||||
\Log::info($sql->sql);
|
||||
\Log::info($sql->bindings);
|
||||
\Log::info($sql->time);
|
||||
});*/
|
||||
|
||||
// Check Announce Request Method
|
||||
$method = $request->method();
|
||||
if (! $request->isMethod('get')) {
|
||||
@@ -108,7 +114,7 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// Check Passkey Against Users Table
|
||||
$user = User::where('passkey', '=', $passkey)->first();
|
||||
$user = User::with(['group:is_immune,is_freeleech', 'history'])->where('passkey', '=', $passkey)->first();
|
||||
|
||||
// If Passkey Doesn't Exist Return Error to Client
|
||||
if (! $user) {
|
||||
@@ -116,18 +122,25 @@ class AnnounceController extends Controller
|
||||
return response(Bencode::bencode(['failure reason' => 'Passkey is invalid']))->withHeaders(['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
|
||||
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
|
||||
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();
|
||||
// Caached System Required Groups
|
||||
$banned_group = cache()->rememberForever('banned_group', function () {
|
||||
return Group::where('slug', '=', 'banned')->pluck('id');
|
||||
});
|
||||
$validating_group = cache()->rememberForever('validating_group', function () {
|
||||
return Group::where('slug', '=', 'validating')->pluck('id');
|
||||
});
|
||||
$disabled_group = cache()->rememberForever('disabled_group', function () {
|
||||
return Group::where('slug', '=', 'disabled')->pluck('id');
|
||||
});
|
||||
|
||||
// If User Is Banned Return Error to Client
|
||||
if ($user->group_id == $bannedGroup->id) {
|
||||
if ($user->group_id == $banned_group[0]) {
|
||||
//info('A Banned User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'You are no longer welcome here']))->withHeaders(['Content-Type' => 'text/plain']);
|
||||
}
|
||||
|
||||
// If User Is Disabled Return Error to Client
|
||||
if ($user->group_id == $disabledGroup->id) {
|
||||
if ($user->group_id == $disabled_group[0]) {
|
||||
//info('A Disabled User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'Your account is disabled. Please login.']))->withHeaders(['Content-Type' => 'text/plain']);
|
||||
}
|
||||
@@ -139,7 +152,7 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// If User Is Validating Return Error to Client
|
||||
if ($user->group_id == $validatingGroup->id) {
|
||||
if ($user->group_id == $validating_group[0]) {
|
||||
//info('A Validating User (' . $user->username . ') Attempted To Announce');
|
||||
return response(Bencode::bencode(['failure reason' => 'Your account is still validating']))->withHeaders(['Content-Type' => 'text/plain']);
|
||||
}
|
||||
@@ -243,7 +256,7 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// Get history information
|
||||
$history = History::where('user_id', '=', $user->id)->where('info_hash', '=', $info_hash)->first();
|
||||
$history = $user->history->where('info_hash', '=', $info_hash)->first();
|
||||
|
||||
if (! $history) {
|
||||
$history = new History();
|
||||
@@ -528,4 +541,4 @@ class AnnounceController extends Controller
|
||||
|
||||
return $peers;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user