Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Jan 17, 2023
2 parents 25f75cc + b613ce8 commit 7b5dbb3
Show file tree
Hide file tree
Showing 84 changed files with 3,411 additions and 2,505 deletions.
6 changes: 3 additions & 3 deletions .dev/docker/gdaemon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM knik/gdaemon-build:buster
FROM debian:latest

ARG ROOT_SSH_PASSWORD=password

RUN apt-get -y update && apt-get -y install \
ssh \
gdb \
clang \
curl \
wget \
rsync \
tar \
python \
Expand Down
5 changes: 1 addition & 4 deletions .dev/docker/gdaemon/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ then
sleep 5
fi

service ssh start
service gameap-daemon start

tail -f /var/log/gameap-daemon/output.log
gameap-daemon
20 changes: 10 additions & 10 deletions .dev/docker/php/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ if (getenv('DB_CONNECTION') == 'sqlite') {

system('php artisan migrate --force');

system('php artisan db:seed --class=ClientCertificatesTableSeeder');
system('php artisan db:seed --class=GamesTableSeeder');
system('php artisan db:seed --class=GameModsTableSeeder');
system('php artisan db:seed --class=UsersTableSeeder');
system('php artisan db:seed --class=PermissionsSeeder');
system('php artisan db:seed --class=ClientCertificatesTableSeeder --force');
system('php artisan db:seed --class=GamesTableSeeder --force');
system('php artisan db:seed --class=GameModsTableSeeder --force');
system('php artisan db:seed --class=UsersTableSeeder --force');
system('php artisan db:seed --class=PermissionsSeeder --force');
} else {
system('php artisan migrate --force');
}
Expand Down Expand Up @@ -57,11 +57,11 @@ else if (getenv('DB_CONNECTION') == 'mysql') {
$count = $pdo->query("SELECT COUNT(*) as count FROM users;")->fetch(PDO::FETCH_ASSOC)['count'];

if ($count == 0) {
system('php artisan db:seed --class=ClientCertificatesTableSeeder');
system('php artisan db:seed --class=GamesTableSeeder');
system('php artisan db:seed --class=GameModsTableSeeder');
system('php artisan db:seed --class=UsersTableSeeder');
system('php artisan db:seed --class=PermissionsSeeder');
system('php artisan db:seed --class=ClientCertificatesTableSeeder --force');
system('php artisan db:seed --class=GamesTableSeeder --force');
system('php artisan db:seed --class=GameModsTableSeeder --force');
system('php artisan db:seed --class=UsersTableSeeder --force');
system('php artisan db:seed --class=PermissionsSeeder --force');
}
}

Expand Down
23 changes: 23 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ steps:
- rm -rf storage/logs/*
- rm .env

- name: tests-php-8.2
image: knik/php:8.2-fpm-alpine
failure: ignore
environment:
APP_KEY: base64:QhlU2DzlLyaYVHzlh3RlSipTtBhwb3/5jPKbctx2lP8=
DB_CONNECTION: mysql
DB_HOST: db
DB_PORT: 3306
DB_DATABASE: homestead
DB_USERNAME: homestead
DB_PASSWORD: secret
commands:
- cp .env.example .env
- php artisan migrate:fresh --seed
- vendor/bin/phpunit --verbose
- rm -rf storage/app/certs
- rm -rf storage/framework/cache/data/*
- rm -rf storage/framework/sessions/*
- rm -rf storage/framework/views/*
- rm -rf storage/debugbar/*
- rm -rf storage/logs/*
- rm .env

- name: browser-tests
image: knik/php:7.3-fpm-buster
environment:
Expand Down
14 changes: 13 additions & 1 deletion app/Exceptions/GdaemonAPI/InvalidApiKeyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
namespace Gameap\Exceptions\GdaemonAPI;

use Gameap\Exceptions\GameapException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

class InvalidApiKeyException extends GameapException
class InvalidApiKeyException extends GameapException implements HttpExceptionInterface
{
public function getStatusCode()
{
return Response::HTTP_UNAUTHORIZED;
}

public function getHeaders()
{
return [];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getInitData(DedicatedServer $dedicatedServer)
'script_restart' => $dedicatedServer->script_restart,
'script_status' => $dedicatedServer->script_status,
'script_get_console' => $dedicatedServer->script_get_console,
'script_send_command' => $dedicatedServer->script_get_console,
'script_send_command' => $dedicatedServer->script_send_command,
'script_delete' => $dedicatedServer->script_delete,
];
}
Expand Down
31 changes: 17 additions & 14 deletions app/Http/Controllers/GdaemonAPI/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Gameap\Http\Requests\GdaemonAPI\JsonServerBulkRequest;
use Gameap\Http\Requests\GdaemonAPI\ServerRequest;
use Gameap\Http\Responses\GdaemonAPI\ServerResponse;
use Gameap\Models\DedicatedServer;
use Gameap\Models\Server;
use Gameap\Repositories\ServerRepository;
Expand All @@ -27,24 +28,26 @@ public function __construct(ServerRepository $serverRepository)

public function index(DedicatedServer $dedicatedServer): JsonResponse
{
return response()->json(
QueryBuilder::for(Server::where('ds_id', '=', $dedicatedServer->id))
->allowedFilters('id')
->with('game')
->with('gameMod')
->with('settings')
->get()
);
$servers = QueryBuilder::for(Server::where('ds_id', '=', $dedicatedServer->id))
->allowedFilters('id')
->with('dedicatedServer')
->with('game')
->with('gameMod')
->with('settings')
->get();

$serversResponse = [];

foreach ($servers as $server) {
$serversResponse[] = new ServerResponse($server);
}

return response()->json($serversResponse);
}

public function server(Server $server): JsonResponse
{
// Get Relations
$server->getRelationValue('game');
$server->getRelationValue('gameMod');
$server->getRelationValue('settings');

return response()->json($server);
return response()->json(new ServerResponse($server));
}

public function update(ServerRequest $request, Server $server): JsonResponse
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/Admin/GameModRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function rules()
'name' => 'required|string|max:255',
'game_code' => 'sometimes|string|max:255|exists:games,code',

'default_start_cmd_linux' => 'nullable|string|max:1000',
'default_start_cmd_windows' => 'nullable|string|max:1000',
'start_cmd_linux' => 'nullable|string|max:1000',
'start_cmd_windows' => 'nullable|string|max:1000',

'vars.*.var' => 'max:16',
'vars.*.default' => 'max:64',
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Requests/Admin/GameRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ public function rules()
'name' => 'required|min:2',
'engine' => 'required|min:2',
'engine_version' => 'required',
'steam_app_id' => 'nullable|integer',
'steam_app_id_linux' => 'nullable|integer',
'steam_app_id_windows' => 'nullable|integer',
'steam_app_set_config' => '',
'local_repository' => '',
'remote_repository' => '',
'local_repository_linux' => '',
'local_repository_windows' => '',
'remote_repository_linux' => '',
'remote_repository_windows' => '',
];
}
}
46 changes: 46 additions & 0 deletions app/Http/Responses/GdaemonAPI/GameModResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Gameap\Http\Responses\GdaemonAPI;

class GameModResponse implements \JsonSerializable
{
/** @var \Gameap\Models\GameMod */
private $gameMod;

/** @var string */
private $os;

public function __construct(\Gameap\Models\GameMod $gameMod, string $os = 'linux')
{
$this->gameMod = $gameMod;
$this->os = $os;
}

public function jsonSerialize()
{
$remoteRepository = '';
$localRepository = '';
$defaultStartCmd = '';
if ($this->os === 'linux') {
$remoteRepository = $this->gameMod->remote_repository_linux;
$localRepository = $this->gameMod->local_repository_linux;
$defaultStartCmd = $this->gameMod->start_cmd_linux;
} elseif ($this->os === 'windows') {
$remoteRepository = $this->gameMod->remote_repository_windows;
$localRepository = $this->gameMod->local_repository_windows;
$defaultStartCmd = $this->gameMod->start_cmd_windows;
}

return [
'id' => $this->gameMod->id,
'game_code' => $this->gameMod->game_code,
'name' => $this->gameMod->name,
'vars' => $this->gameMod->vars,
'remote_repository' => $remoteRepository,
'local_repository' => $localRepository,
'default_start_cmd' => $defaultStartCmd,
'default_start_cmd_linux' => $this->gameMod->start_cmd_linux,
'default_start_cmd_windows' => $this->gameMod->start_cmd_windows,
];
}
}
48 changes: 48 additions & 0 deletions app/Http/Responses/GdaemonAPI/GameResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Gameap\Http\Responses\GdaemonAPI;

use Gameap\Models\Game;

class GameResponse implements \JsonSerializable
{
/** @var Game */
private $game;

private $os;

public function __construct(Game $game, string $os = 'linux')
{
$this->game = $game;
$this->os = $os;
}

public function jsonSerialize()
{
$remoteRepository = '';
$localRepository = '';
$steamAppId = '';

if ($this->os === 'linux') {
$remoteRepository = $this->game->remote_repository_linux;
$localRepository = $this->game->local_repository_linux;
$steamAppId = $this->game->steam_app_id_linux;
} elseif ($this->os === 'windows') {
$remoteRepository = $this->game->remote_repository_windows;
$localRepository = $this->game->local_repository_windows;
$steamAppId = $this->game->steam_app_id_windows;
}

return [
'code' => $this->game->code,
'start_code' => $this->game->start_code,
'name' => $this->game->name,
'engine' => $this->game->engine,
'engine_version' => $this->game->engine_version,
'remote_repository' => $remoteRepository,
'local_repository' => $localRepository,
'steam_app_id' => $steamAppId,
'steam_app_set_config' => $this->game->steam_app_set_config,
];
}
}
62 changes: 62 additions & 0 deletions app/Http/Responses/GdaemonAPI/ServerResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Gameap\Http\Responses\GdaemonAPI;

use Gameap\Models\Game;
use Gameap\Models\GameMod;
use Gameap\Models\Server;
use Symfony\Component\Serializer\SerializerInterface;

class ServerResponse implements \JsonSerializable
{
/** @var Server */
private $server;

public function __construct(Server $server)
{
$this->server = $server;
}

public function jsonSerialize()
{
$gameModResponse = new GameModResponse($this->server->gameMod, $this->server->dedicatedServer->os);
$gameResponse = new GameResponse($this->server->game, $this->server->dedicatedServer->os);

return [
'id' => $this->server->id,
'uuid' => $this->server->uuid,
'uuid_short' => $this->server->uuid_short,
'enabled' => $this->server->enabled,
'installed' => $this->server->installed,
'blocked' => $this->server->blocked,
'name' => $this->server->name,
'ds_id' => $this->server->ds_id,
'game_id' => $this->server->game_id,
'game_mod_id' => $this->server->game_mod_id,
'expires' => $this->server->expires,
'server_ip' => $this->server->server_ip,
'server_port' => $this->server->server_port,
'query_port' => $this->server->query_port,
'rcon_port' => $this->server->rcon_port,
'rcon' => $this->server->rcon,
'dir' => $this->server->dir,
'su_user' => $this->server->su_user,
'cpu_limit' => $this->server->cpu_limit,
'ram_limit' => $this->server->ram_limit,
'net_limit' => $this->server->net_limit,
'start_command' => $this->server->start_command,
'stop_command' => $this->server->stop_command,
'force_stop_command' => $this->server->force_stop_command,
'restart_command' => $this->server->restart_command,
'process_active' => $this->server->process_active,
'last_process_check' => $this->server->last_process_check,
'vars' => $this->server->vars,
'created_at' => $this->server->created_at,
'updated_at' => $this->server->updated_at,
'deleted_at' => $this->server->deleted_at,
'settings' => $this->server->settings,
'game' => $gameResponse->jsonSerialize(),
'game_mod' => $gameModResponse->jsonSerialize(),
];
}
}
15 changes: 10 additions & 5 deletions app/Models/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
* @property string $name
* @property string $engine
* @property string $engine_version
* @property integer $steam_app_id
* @property integer $steam_app_id_linux
* @property integer $steam_app_id_windows
* @property string $steam_app_set_config
* @property string $remote_repository
* @property string $local_repository
* @property string $remote_repository_linux
* @property string $remote_repository_windows
* @property string $local_repository_linux
* @property string $local_repository_windows
*/
class Game extends Model
{
Expand Down Expand Up @@ -54,8 +57,10 @@ class Game extends Model
protected $fillable = [
'code', 'start_code', 'name',
'engine', 'engine_version',
'steam_app_id', 'steam_app_set_config',
'local_repository', 'remote_repository',
'steam_app_id_linux', 'steam_app_id_windows',
'steam_app_set_config',
'remote_repository_linux', 'remote_repository_windows',
'local_repository_linux', 'local_repository_windows'
];

/**
Expand Down
Loading

0 comments on commit 7b5dbb3

Please sign in to comment.