Skip to content

Commit 7f91bb4

Browse files
committed
Add Hytale support
1 parent 85dff16 commit 7f91bb4

8 files changed

Lines changed: 127 additions & 56 deletions

File tree

app/Azuriom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Azuriom
1111
*
1212
* @var string
1313
*/
14-
private const VERSION = '1.2.8';
14+
private const VERSION = '1.2.9';
1515

1616
/**
1717
* Get the current version of Azuriom CMS.

app/Games/HytaleGame.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Azuriom\Games;
4+
5+
use Azuriom\Games\Minecraft\Servers\AzLink;
6+
use Azuriom\Models\User;
7+
use Illuminate\Support\Facades\Cache;
8+
use Illuminate\Support\Facades\Http;
9+
10+
class HytaleGame extends Game
11+
{
12+
public const PLAYER_LOOKUP = 'https://playerdb.co/api/player/hytale/';
13+
14+
public function id(): string
15+
{
16+
return 'hytale';
17+
}
18+
19+
public function name(): string
20+
{
21+
return 'Hytale';
22+
}
23+
24+
public function getAvatarUrl(User $user, int $size = 64): string
25+
{
26+
return "https://crafthead.net/hytale/avatar/{$user->name}/{$size}.png";
27+
}
28+
29+
public function getUserUniqueId(string $name): ?string
30+
{
31+
return Cache::remember('games.minecraft.uuid.'.$name, now()->addMinutes(30), function () use ($name) {
32+
return Http::get(self::PLAYER_LOOKUP.$name)
33+
->throw()
34+
->json('data.player.id');
35+
});
36+
}
37+
38+
public function getUserName(User $user): ?string
39+
{
40+
if ($user->game_id === null) {
41+
return $user->name;
42+
}
43+
44+
$cacheKey = 'games.minecraft.profile.'.$user->game_id;
45+
46+
return Cache::remember($cacheKey, now()->addMinutes(30), function () use ($user) {
47+
return Http::get(self::PLAYER_LOOKUP.$user->game_id)
48+
->throw()
49+
->json('data.player.username');
50+
});
51+
}
52+
53+
public function getSupportedServers()
54+
{
55+
return [
56+
'mc-azlink' => AzLink::class,
57+
];
58+
}
59+
60+
public function trans(string $key, array $placeholders = []): string
61+
{
62+
return trans('game.minecraft.'.$key, $placeholders);
63+
}
64+
}

app/Http/Controllers/InstallController.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Azuriom\Extensions\Plugin\PluginManager;
66
use Azuriom\Extensions\UpdateManager;
77
use Azuriom\Games\FiveMGame;
8+
use Azuriom\Games\HytaleGame;
89
use Azuriom\Games\Minecraft\MinecraftBedrockGame;
910
use Azuriom\Games\Minecraft\MinecraftOnlineGame;
1011
use Azuriom\Games\Steam\SteamGame;
@@ -63,6 +64,10 @@ class InstallController extends Controller
6364
'name' => 'Minecraft: Bedrock Edition',
6465
'logo' => 'assets/img/games/minecraft.svg',
6566
],
67+
'hytale' => [
68+
'name' => 'Hytale (Early Access)',
69+
'logo' => 'assets/img/games/hytale.png',
70+
],
6671
'gmod' => [
6772
'name' => 'Garry\'s mod',
6873
'logo' => 'assets/img/games/gmod.svg',
@@ -228,18 +233,10 @@ public function showGame(string $game)
228233
{
229234
abort_if(! array_key_exists($game, $this->games), 404);
230235

231-
if ($game === 'minecraft') {
236+
if ($game === 'minecraft' || $game === 'mc-bedrock' || $game === 'hytale') {
232237
return view('install.games.minecraft', [
233238
'game' => $game,
234-
'gameName' => 'Minecraft',
235-
'locales' => self::getAvailableLocales(),
236-
]);
237-
}
238-
239-
if ($game === 'mc-bedrock') {
240-
return view('install.games.minecraft', [
241-
'game' => $game,
242-
'gameName' => 'Minecraft: Bedrock Edition',
239+
'gameName' => Arr::get($this->games, $game.'.name', $game),
243240
'locales' => self::getAvailableLocales(),
244241
]);
245242
}
@@ -273,8 +270,8 @@ public function setupGame(Request $request, string $game)
273270
return $this->setupSteamGame($request, $game);
274271
}
275272

276-
if ($game === 'minecraft' || $game === 'mc-bedrock') {
277-
return $this->setupMinecraftGame($request, $game);
273+
if ($game === 'minecraft' || $game === 'mc-bedrock' || $game === 'hytale') {
274+
return $this->setupMinecraftOrHytale($request, $game);
278275
}
279276

280277
if ($game === 'fivem-cfx') {
@@ -334,13 +331,13 @@ protected function setupSteamGame(Request $request, string $game)
334331
}
335332

336333
/**
337-
* Install Azuriom for Minecraft (with register or Microsoft OAuth).
334+
* Install Azuriom for Minecraft (with register or Microsoft OAuth) or Hytale.
338335
*
339336
* @throws \Illuminate\Validation\ValidationException
340337
*/
341-
protected function setupMinecraftGame(Request $request, string $game)
338+
protected function setupMinecraftOrHytale(Request $request, string $game)
342339
{
343-
if ($game !== 'mc-bedrock') {
340+
if ($game !== 'mc-bedrock' && $game !== 'hytale') {
344341
$game = $request->input('oauth') ? 'mc-online' : 'mc-offline';
345342
}
346343

@@ -368,6 +365,12 @@ protected function setupMinecraftGame(Request $request, string $game)
368365
if ($name === null) {
369366
throw ValidationException::withMessages(['xuid' => 'Invalid Xbox XUID.']);
370367
}
368+
} elseif ($game === 'hytale') {
369+
$response = Http::get(HytaleGame::PLAYER_LOOKUP.$request->input('name'));
370+
371+
if (! $response->successful() || ! ($gameId = $response->json('data.player.id'))) {
372+
throw ValidationException::withMessages(['name' => 'You must enter a valid Hytale username.']);
373+
}
371374
}
372375

373376
return $this->setupAzuriom($request, $game, $name, $gameId ?? null);
@@ -479,7 +482,7 @@ protected function setupAzuriom(Request $request, string $game, ?string $name, ?
479482

480483
$user->markEmailAsVerified();
481484

482-
if ($game !== 'mc-offline') {
485+
if ($game !== 'mc-offline' && $game !== 'hytale') {
483486
Setting::updateSettings('register', false);
484487
}
485488

app/Http/Middleware/VerifyCaptcha.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function handle(Request $request, Closure $next): Response
2525
return $next($request);
2626
}
2727

28-
$success = $this->verifyCaptcha($captchaType, $request, $secretKey);
29-
30-
return $success ? $next($request) : $this->sendFailedResponse($request);
28+
return $this->verifyCaptcha($captchaType, $request, $secretKey)
29+
? $next($request)
30+
: $this->sendFailedResponse($request);
3131
}
3232

3333
protected function sendFailedResponse(Request $request): Response

app/Providers/GameServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Azuriom\Games\FallbackGame;
66
use Azuriom\Games\FiveMGame;
7+
use Azuriom\Games\HytaleGame;
78
use Azuriom\Games\Minecraft\MinecraftBedrockGame;
89
use Azuriom\Games\Minecraft\MinecraftOfflineGame;
910
use Azuriom\Games\Minecraft\MinecraftOnlineGame;
@@ -42,6 +43,7 @@ public function register(): void
4243
'tf2' => SteamGame::forName('tf2', 'Team Fortress 2'),
4344
'unturned' => SteamGame::forName('unturned', 'Unturned'),
4445
'7dtd' => SteamGame::forName('7dtd', '7 Days to Die', true),
46+
'hytale' => HytaleGame::class,
4547
]);
4648
}
4749

public/assets/img/games/hytale.png

26.3 KB
Loading

resources/views/install/games.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<div id="gameSelect" class="text-center">
55
<h2 class="mb-3">{{ trans('install.game.title') }}</h2>
66

7+
<p class="text-danger font-weight-bold mb-0">
8+
<i class="bi bi-exclamation-triangle"></i> {{ trans('install.game.warn') }}
9+
</p>
10+
711
<div class="row justify-content-center mb-3">
812
@foreach ($games as $key => $game)
913
<div class="col-md-3">
@@ -15,9 +19,5 @@
1519
</div>
1620
@endforeach
1721
</div>
18-
19-
<p class="text-danger font-weight-bold mb-0">
20-
<i class="bi bi-exclamation-triangle"></i> {{ trans('install.game.warn') }}
21-
</p>
2222
</div>
2323
@endsection

resources/views/install/games/minecraft.blade.php

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,45 @@
22

33
@section('game')
44
@if($game !== 'mc-bedrock')
5-
<div class="mb-3">
6-
<label class="form-label" for="oauth">
7-
{{ trans('install.game.minecraft.premium') }}
8-
</label>
9-
10-
<select name="oauth" class="form-select @error('oauth') is-invalid @enderror" id="oauth" data-toggle-select="oauth" required>
11-
<option value=""></option>
12-
<option value="1" @selected(old('oauth') === '1')>
13-
{{ trans('messages.yes') }}
14-
</option>
15-
<option value="0" @selected(old('oauth') === '0')>
16-
{{ trans('messages.no') }}
17-
</option>
18-
</select>
19-
20-
@error('oauth')
21-
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
22-
@enderror
23-
24-
<p class="form-text text-danger">
25-
<i class="bi bi-exclamation-triangle"></i> {{ trans('install.game.warn') }}
26-
</p>
27-
</div>
5+
@if($game !== 'hytale')
6+
<div class="mb-3">
7+
<label class="form-label" for="oauth">
8+
{{ trans('install.game.minecraft.premium') }}
9+
</label>
10+
11+
<select name="oauth" class="form-select @error('oauth') is-invalid @enderror" id="oauth" data-toggle-select="oauth" required>
12+
<option value=""></option>
13+
<option value="1" @selected(old('oauth') === '1')>
14+
{{ trans('messages.yes') }}
15+
</option>
16+
<option value="0" @selected(old('oauth') === '0')>
17+
{{ trans('messages.no') }}
18+
</option>
19+
</select>
20+
21+
@error('oauth')
22+
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
23+
@enderror
2824

29-
<div data-oauth="1">
30-
<h3>{{ trans('install.game.user.title') }}</h3>
25+
<p class="form-text text-danger">
26+
<i class="bi bi-exclamation-triangle"></i> {{ trans('install.game.warn') }}
27+
</p>
28+
</div>
3129

32-
<div class="mb-3">
33-
<label class="form-label" for="uuid">Minecraft UUID</label>
30+
<div data-oauth="1">
31+
<h3>{{ trans('install.game.user.title') }}</h3>
3432

35-
<input name="uuid" id="uuid" type="text" class="form-control @error('uuid') is-invalid @enderror" value="{{ old('uuid', '') }}">
33+
<div class="mb-3">
34+
<label class="form-label" for="uuid">Minecraft UUID</label>
3635

37-
@error('uuid')
38-
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
39-
@enderror
36+
<input name="uuid" id="uuid" type="text" class="form-control @error('uuid') is-invalid @enderror" value="{{ old('uuid', '') }}">
37+
38+
@error('uuid')
39+
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
40+
@enderror
41+
</div>
4042
</div>
41-
</div>
43+
@endif
4244

4345
<div data-oauth="0">
4446
<h3>{{ trans('install.game.user.title') }}</h3>

0 commit comments

Comments
 (0)