2020-05-07 23:24:56 +00:00
|
|
|
<?php
|
|
|
|
|
2021-10-13 00:55:12 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-05-07 23:24:56 +00:00
|
|
|
namespace App\Providers;
|
|
|
|
|
2021-10-13 00:55:12 +00:00
|
|
|
use GuzzleHttp\Exception\ConnectException;
|
2020-05-07 23:24:56 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-10-13 00:47:16 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2021-10-13 00:55:12 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2020-05-07 23:24:56 +00:00
|
|
|
|
|
|
|
class MojangStatusProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2020-05-13 21:47:51 +00:00
|
|
|
// TODO: (IMPORTANT) Switch this to Middleware
|
2021-10-13 00:55:12 +00:00
|
|
|
if (! Cache::has('mojang_status')) {
|
|
|
|
Log::info('Mojang Status Provider: Mojang Status not found in the cache; Sending new request.');
|
2020-05-07 23:24:56 +00:00
|
|
|
|
2021-10-13 00:55:12 +00:00
|
|
|
try {
|
2020-05-29 23:20:39 +00:00
|
|
|
$mcstatus = Http::get(config('general.urls.mojang.statuscheck'));
|
|
|
|
Cache::put('mojang_status', base64_encode($mcstatus->body()), now()->addDays(3));
|
2021-10-13 00:55:12 +00:00
|
|
|
} catch (ConnectException $connectException) {
|
2020-05-29 23:20:39 +00:00
|
|
|
Log::critical('Could not connect to Mojang servers: Cannot check/refresh status', [
|
2021-10-13 00:55:12 +00:00
|
|
|
'message' => $connectException->getMessage(),
|
2020-05-29 23:20:39 +00:00
|
|
|
]);
|
|
|
|
}
|
2020-05-07 23:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
View::share('mcstatus', json_decode(base64_decode(Cache::get('mojang_status')), true));
|
|
|
|
}
|
|
|
|
}
|