Revert "Revert "Merge branch 'master' into develop""

This reverts commit fc6d7d2b18.
This commit is contained in:
2021-10-13 01:47:16 +01:00
parent 64d8ffa9d9
commit 427c9d1c57
13 changed files with 2263 additions and 1916 deletions

45
app/Providers/MojangStatusProvider.php Executable file → Normal file
View File

@@ -1,32 +1,13 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Providers;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use Illuminate\Http\Client\ConnectionException;
class MojangStatusProvider extends ServiceProvider
{
@@ -47,16 +28,26 @@ class MojangStatusProvider extends ServiceProvider
*/
public function boot()
{
// TODO: (IMPORTANT) Switch this to Middleware
if (! Cache::has('mojang_status')) {
Log::info('Mojang Status Provider: Mojang Status not found in the cache; Sending new request.');
$unknown_status = '[{"minecraft.net":"red"},{"session.minecraft.net":"red"},{"account.mojang.com":"red"},{"authserver.mojang.com":"red"},{"sessionserver.mojang.com":"red"},{"api.mojang.com":"red"},{"textures.minecraft.net":"red"},{"mojang.com":"red"}]';
try {
// TODO: (IMPORTANT) Switch this to Middleware
if (!Cache::has('mojang_status'))
{
Log::info("Mojang Status Provider: Mojang Status not found in the cache; Sending new request.");
try
{
$mcstatus = Http::get(config('general.urls.mojang.statuscheck'));
Cache::put('mojang_status', base64_encode($mcstatus->body()), now()->addDays(3));
} catch (ConnectException $connectException) {
}
catch(ConnectionException $connectException)
{
// Shorter TTL because mojang status server might have recovered
Cache::put('mojang_status', base64_encode($unknown_status), now()->addMinutes(60));
Log::alert('Writing unknown Mojang status placeholder to cache');
Log::critical('Could not connect to Mojang servers: Cannot check/refresh status', [
'message' => $connectException->getMessage(),
'message' => $connectException->getMessage()
]);
}
}