2020-05-07 23:24:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-10-21 00:01:41 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2020-10-21 00:29:50 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2021-10-12 21:41:24 +00:00
|
|
|
use Illuminate\Http\Client\ConnectionException;
|
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()
|
|
|
|
{
|
2021-10-12 22:01:15 +00:00
|
|
|
$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"}]';
|
|
|
|
|
2020-05-13 21:47:51 +00:00
|
|
|
// TODO: (IMPORTANT) Switch this to Middleware
|
2020-10-21 00:29:50 +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
|
|
|
|
2020-10-21 00:29:50 +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));
|
2020-10-21 00:29:50 +00:00
|
|
|
}
|
2021-10-12 21:41:24 +00:00
|
|
|
catch(ConnectionException $connectException)
|
2020-10-21 00:29:50 +00:00
|
|
|
{
|
2021-10-12 22:01:15 +00:00
|
|
|
// 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');
|
2020-05-29 23:20:39 +00:00
|
|
|
Log::critical('Could not connect to Mojang servers: Cannot check/refresh status', [
|
2020-10-21 00:29:50 +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));
|
|
|
|
}
|
|
|
|
}
|