Skip to content

Commit

Permalink
Improve FiveM/AzLink links and improve default plugin file
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Feb 6, 2022
1 parent aa24cd7 commit eecd309
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
14 changes: 14 additions & 0 deletions app/Console/Commands/PluginCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ private function createComposerJson(string $path, string $id, string $namespace)
"{$namespace}\\" => 'src/',
],
],
'replace' => [
'guzzlehttp/guzzle' => '*',
'guzzlehttp/promises' => '*',
'guzzlehttp/psr7' => '*',
'monolog/monolog' => '*',
'nesbot/carbon' => '*',
'psr/container' => '*',
'psr/event-dispatcher' => '*',
'psr/http-client' => '*',
'psr/http-factory' => '*',
'psr/http-message' => '*',
'psr/log' => '*',
'psr/simple-cache' => '*',
],
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}

Expand Down
7 changes: 1 addition & 6 deletions app/Games/Minecraft/Servers/AzLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use RuntimeException;

class AzLink extends ServerBridge
{
Expand All @@ -29,14 +28,10 @@ public function verifyLink()

public function sendCommands(array $commands, User $user = null, bool $needConnected = false)
{
if ($user === null) {
throw new RuntimeException('Unknown user');
}

foreach ($commands as $command) {
$this->server->commands()->create([
'command' => $command,
'user_id' => $user->id,
'user_id' => optional($user)->id,
'need_online' => $needConnected,
]);
}
Expand Down
38 changes: 23 additions & 15 deletions app/Games/Steam/Servers/FiveMStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,21 @@

class FiveMStatus extends ServerBridge
{
protected const TIMEOUT = 3;
protected const DEFAULT_PORT = 30120;

public function getServerData()
{
try {
$port = $this->server->port ?? self::DEFAULT_PORT;

$players = Http::get("{$this->server->address}:{$port}/players.json")
->throw()
->json();

$maxPlayers = Http::get("{$this->server->address}:{$port}/info.json")
->throw()
->json('vars.sv_maxClients', 64);

return [
'players' => is_array($players) ? count($players) : 0,
'max_players' => $maxPlayers,
];
return $this->getData();
} catch (Exception $e) {
return null;
}
}

public function verifyLink()
{
return $this->getServerData() !== null;
return $this->getData() !== null;
}

public function canExecuteCommand()
Expand All @@ -46,4 +34,24 @@ public function getDefaultPort()
{
return self::DEFAULT_PORT;
}

private function getData()
{
$port = $this->server->port ?? self::DEFAULT_PORT;

$players = Http::timeout(self::TIMEOUT)
->get("{$this->server->address}:{$port}/players.json")
->throw()
->json();

$maxPlayers = Http::timeout(self::TIMEOUT)
->get("{$this->server->address}:{$port}/info.json")
->throw()
->json('vars.sv_maxClients', 64);

return [
'players' => is_array($players) ? count($players) : 0,
'max_players' => $maxPlayers,
];
}
}
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Azuriom\Extensions\UpdateManager;
use Azuriom\Http\Controllers\Controller;
use Azuriom\Models\ActionLog;
use Azuriom\Models\Image;
use Exception;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
Expand Down Expand Up @@ -145,7 +146,10 @@ public function edit(Request $request, string $theme)
return redirect()->route('admin.themes.index')->with('error', trans('admin.themes.status.no-config'));
}

return view()->file($viewPath, ['theme' => $theme]);
return view()->file($viewPath, [
'theme' => $theme,
'images' => Image::all(),
]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/ServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
/**
* @property int $id
* @property int $server_id
* @property int $user_id
* @property int|null $user_id
* @property bool $need_online
* @property string $command
* @property \Azuriom\Models\Server $server
* @property \Azuriom\Models\User|null $user
*/
class ServerCommand extends Model
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
Schema::create('server_commands', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('server_id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('user_id')->nullable();
$table->boolean('need_online')->default(false);
$table->text('command');
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function up()
$command->user_id = $userId;

return (array) $command;
})->filter(function ($command) {
return $command['user_id'] !== null;
})->all();

DB::table('server_commands')->insert($mappedCommands);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/users/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<label for="searchInput" class="sr-only">{{ trans('messages.actions.search') }}</label>

<div class="input-group">
<input type="text" class="form-control" id="searchInput" name="search" value="{{ $search ?? '' }}" placeholder="{{ trans('messages.actions.search') }}">
<input type="search" class="form-control" id="searchInput" name="search" value="{{ $search ?? '' }}" placeholder="{{ trans('messages.actions.search') }}">

<div class="input-group-append">
<button type="submit" class="btn btn-primary">
Expand Down

0 comments on commit eecd309

Please sign in to comment.