diff --git a/app/Azuriom.php b/app/Azuriom.php index fc3a70dc6..ab814df6d 100644 --- a/app/Azuriom.php +++ b/app/Azuriom.php @@ -11,7 +11,7 @@ class Azuriom * * @var string */ - private const VERSION = '1.2.8'; + private const VERSION = '1.2.9'; /** * Get the current version of Azuriom CMS. diff --git a/app/Games/HytaleGame.php b/app/Games/HytaleGame.php new file mode 100644 index 000000000..82310936f --- /dev/null +++ b/app/Games/HytaleGame.php @@ -0,0 +1,64 @@ +name}/{$size}.png"; + } + + public function getUserUniqueId(string $name): ?string + { + return Cache::remember('games.minecraft.uuid.'.$name, now()->addMinutes(30), function () use ($name) { + return Http::get(self::PLAYER_LOOKUP.$name) + ->throw() + ->json('data.player.id'); + }); + } + + public function getUserName(User $user): ?string + { + if ($user->game_id === null) { + return $user->name; + } + + $cacheKey = 'games.minecraft.profile.'.$user->game_id; + + return Cache::remember($cacheKey, now()->addMinutes(30), function () use ($user) { + return Http::get(self::PLAYER_LOOKUP.$user->game_id) + ->throw() + ->json('data.player.username'); + }); + } + + public function getSupportedServers() + { + return [ + 'mc-azlink' => AzLink::class, + ]; + } + + public function trans(string $key, array $placeholders = []): string + { + return trans('game.minecraft.'.$key, $placeholders); + } +} diff --git a/app/Http/Controllers/InstallController.php b/app/Http/Controllers/InstallController.php index a24cd2cf6..f983beab8 100644 --- a/app/Http/Controllers/InstallController.php +++ b/app/Http/Controllers/InstallController.php @@ -5,6 +5,7 @@ use Azuriom\Extensions\Plugin\PluginManager; use Azuriom\Extensions\UpdateManager; use Azuriom\Games\FiveMGame; +use Azuriom\Games\HytaleGame; use Azuriom\Games\Minecraft\MinecraftBedrockGame; use Azuriom\Games\Minecraft\MinecraftOnlineGame; use Azuriom\Games\Steam\SteamGame; @@ -63,6 +64,10 @@ class InstallController extends Controller 'name' => 'Minecraft: Bedrock Edition', 'logo' => 'assets/img/games/minecraft.svg', ], + 'hytale' => [ + 'name' => 'Hytale (Early Access)', + 'logo' => 'assets/img/games/hytale.png', + ], 'gmod' => [ 'name' => 'Garry\'s mod', 'logo' => 'assets/img/games/gmod.svg', @@ -228,18 +233,10 @@ public function showGame(string $game) { abort_if(! array_key_exists($game, $this->games), 404); - if ($game === 'minecraft') { + if ($game === 'minecraft' || $game === 'mc-bedrock' || $game === 'hytale') { return view('install.games.minecraft', [ 'game' => $game, - 'gameName' => 'Minecraft', - 'locales' => self::getAvailableLocales(), - ]); - } - - if ($game === 'mc-bedrock') { - return view('install.games.minecraft', [ - 'game' => $game, - 'gameName' => 'Minecraft: Bedrock Edition', + 'gameName' => Arr::get($this->games, $game.'.name', $game), 'locales' => self::getAvailableLocales(), ]); } @@ -273,8 +270,8 @@ public function setupGame(Request $request, string $game) return $this->setupSteamGame($request, $game); } - if ($game === 'minecraft' || $game === 'mc-bedrock') { - return $this->setupMinecraftGame($request, $game); + if ($game === 'minecraft' || $game === 'mc-bedrock' || $game === 'hytale') { + return $this->setupMinecraftOrHytale($request, $game); } if ($game === 'fivem-cfx') { @@ -334,13 +331,13 @@ protected function setupSteamGame(Request $request, string $game) } /** - * Install Azuriom for Minecraft (with register or Microsoft OAuth). + * Install Azuriom for Minecraft (with register or Microsoft OAuth) or Hytale. * * @throws \Illuminate\Validation\ValidationException */ - protected function setupMinecraftGame(Request $request, string $game) + protected function setupMinecraftOrHytale(Request $request, string $game) { - if ($game !== 'mc-bedrock') { + if ($game !== 'mc-bedrock' && $game !== 'hytale') { $game = $request->input('oauth') ? 'mc-online' : 'mc-offline'; } @@ -368,6 +365,12 @@ protected function setupMinecraftGame(Request $request, string $game) if ($name === null) { throw ValidationException::withMessages(['xuid' => 'Invalid Xbox XUID.']); } + } elseif ($game === 'hytale') { + $response = Http::get(HytaleGame::PLAYER_LOOKUP.$request->input('name')); + + if (! $response->successful() || ! ($gameId = $response->json('data.player.id'))) { + throw ValidationException::withMessages(['name' => 'You must enter a valid Hytale username.']); + } } return $this->setupAzuriom($request, $game, $name, $gameId ?? null); @@ -479,7 +482,7 @@ protected function setupAzuriom(Request $request, string $game, ?string $name, ? $user->markEmailAsVerified(); - if ($game !== 'mc-offline') { + if ($game !== 'mc-offline' && $game !== 'hytale') { Setting::updateSettings('register', false); } diff --git a/app/Http/Middleware/VerifyCaptcha.php b/app/Http/Middleware/VerifyCaptcha.php index fdd756382..e1e216a39 100644 --- a/app/Http/Middleware/VerifyCaptcha.php +++ b/app/Http/Middleware/VerifyCaptcha.php @@ -25,9 +25,9 @@ public function handle(Request $request, Closure $next): Response return $next($request); } - $success = $this->verifyCaptcha($captchaType, $request, $secretKey); - - return $success ? $next($request) : $this->sendFailedResponse($request); + return $this->verifyCaptcha($captchaType, $request, $secretKey) + ? $next($request) + : $this->sendFailedResponse($request); } protected function sendFailedResponse(Request $request): Response diff --git a/app/Providers/GameServiceProvider.php b/app/Providers/GameServiceProvider.php index 094690c44..7c8e17c02 100644 --- a/app/Providers/GameServiceProvider.php +++ b/app/Providers/GameServiceProvider.php @@ -4,6 +4,7 @@ use Azuriom\Games\FallbackGame; use Azuriom\Games\FiveMGame; +use Azuriom\Games\HytaleGame; use Azuriom\Games\Minecraft\MinecraftBedrockGame; use Azuriom\Games\Minecraft\MinecraftOfflineGame; use Azuriom\Games\Minecraft\MinecraftOnlineGame; @@ -42,6 +43,7 @@ public function register(): void 'tf2' => SteamGame::forName('tf2', 'Team Fortress 2'), 'unturned' => SteamGame::forName('unturned', 'Unturned'), '7dtd' => SteamGame::forName('7dtd', '7 Days to Die', true), + 'hytale' => HytaleGame::class, ]); } diff --git a/public/assets/img/games/hytale.png b/public/assets/img/games/hytale.png new file mode 100644 index 000000000..3812b6ed3 Binary files /dev/null and b/public/assets/img/games/hytale.png differ diff --git a/resources/views/install/games.blade.php b/resources/views/install/games.blade.php index 78ec3d709..8f5249813 100644 --- a/resources/views/install/games.blade.php +++ b/resources/views/install/games.blade.php @@ -4,6 +4,10 @@

{{ trans('install.game.title') }}

+

+ {{ trans('install.game.warn') }} +

+
@foreach ($games as $key => $game)
@@ -15,9 +19,5 @@
@endforeach
- -

- {{ trans('install.game.warn') }} -

@endsection diff --git a/resources/views/install/games/minecraft.blade.php b/resources/views/install/games/minecraft.blade.php index bd506d160..f062ba5f8 100644 --- a/resources/views/install/games/minecraft.blade.php +++ b/resources/views/install/games/minecraft.blade.php @@ -2,43 +2,45 @@ @section('game') @if($game !== 'mc-bedrock') -
- - - - - @error('oauth') - {{ $message }} - @enderror - -

- {{ trans('install.game.warn') }} -

-
+ @if($game !== 'hytale') +
+ + + + + @error('oauth') + {{ $message }} + @enderror -
-

{{ trans('install.game.user.title') }}

+

+ {{ trans('install.game.warn') }} +

+
-
- +
+

{{ trans('install.game.user.title') }}

- +
+ - @error('uuid') - {{ $message }} - @enderror + + + @error('uuid') + {{ $message }} + @enderror +
-
+ @endif

{{ trans('install.game.user.title') }}