From 57fcc25822ba3b3a58e42b4adfd40deefb802452 Mon Sep 17 00:00:00 2001 From: Graphictoria Date: Fri, 19 Aug 2022 19:48:11 -0400 Subject: [PATCH] A few rendering updates for templating scripts and some admin page stuff. --- web/app/Grid/SoapService.php | 77 +- web/app/Helpers/GridHelper.php | 107 ++- .../Controllers/Api/ThumbnailController.php | 2 +- .../Http/Controllers/Web/AdminController.php | 27 + .../Http/Controllers/Web/TestController.php | 17 +- web/app/Http/Kernel.php | 1 + .../{Administrator.php => Roleset.php} | 9 +- web/app/Jobs/ArbiterRender.php | 74 +- web/app/Models/ArbiterSoapFault.php | 23 + ...64838_create_arbiter_soap_faults_table.php | 35 + .../seeders/WebConfigurationSeeder.php | 10 + web/resources/views/layouts/nav.blade.php | 3 +- web/resources/views/web/admin/diag.blade.php | 35 + .../views/web/admin/diag/picker.blade.php | 9 + web/routes/web.php | 14 + web/storage/app/.gitignore | 1 + web/storage/app/grid/.gitignore | 1 + web/storage/app/grid/RCCService.wsdl | 800 ++++++++++++++++++ web/storage/app/grid/scripts/Avatar.lua | 26 + web/storage/app/grid/scripts/BodyPart.lua | 20 + web/storage/app/grid/scripts/Closeup.lua | 50 ++ web/storage/app/grid/scripts/Decal.lua | 22 + web/storage/app/grid/scripts/Gear.lua | 16 + web/storage/app/grid/scripts/Hat.lua | 16 + web/storage/app/grid/scripts/Head.lua | 31 + web/storage/app/grid/scripts/Mesh.lua | 19 + web/storage/app/grid/scripts/Model.lua | 36 + web/storage/app/grid/scripts/Package.lua | 131 +++ web/storage/app/grid/scripts/Pants.lua | 19 + web/storage/app/grid/scripts/Place.lua | 19 + web/storage/app/grid/scripts/Shirt.lua | 19 + 31 files changed, 1560 insertions(+), 109 deletions(-) create mode 100644 web/app/Http/Controllers/Web/AdminController.php rename web/app/Http/Middleware/{Administrator.php => Roleset.php} (68%) create mode 100644 web/app/Models/ArbiterSoapFault.php create mode 100644 web/database/migrations/2022_08_19_164838_create_arbiter_soap_faults_table.php create mode 100644 web/resources/views/web/admin/diag.blade.php create mode 100644 web/resources/views/web/admin/diag/picker.blade.php create mode 100644 web/storage/app/grid/.gitignore create mode 100644 web/storage/app/grid/RCCService.wsdl create mode 100644 web/storage/app/grid/scripts/Avatar.lua create mode 100644 web/storage/app/grid/scripts/BodyPart.lua create mode 100644 web/storage/app/grid/scripts/Closeup.lua create mode 100644 web/storage/app/grid/scripts/Decal.lua create mode 100644 web/storage/app/grid/scripts/Gear.lua create mode 100644 web/storage/app/grid/scripts/Hat.lua create mode 100644 web/storage/app/grid/scripts/Head.lua create mode 100644 web/storage/app/grid/scripts/Mesh.lua create mode 100644 web/storage/app/grid/scripts/Model.lua create mode 100644 web/storage/app/grid/scripts/Package.lua create mode 100644 web/storage/app/grid/scripts/Pants.lua create mode 100644 web/storage/app/grid/scripts/Place.lua create mode 100644 web/storage/app/grid/scripts/Shirt.lua diff --git a/web/app/Grid/SoapService.php b/web/app/Grid/SoapService.php index 5a678a6..2648707 100644 --- a/web/app/Grid/SoapService.php +++ b/web/app/Grid/SoapService.php @@ -10,6 +10,9 @@ namespace App\Grid; use Illuminate\Support\Facades\Storage; use SoapClient; +use App\Models\ArbiterSoapFault; +use App\Helpers\GridHelper; + class SoapService { /** @@ -27,11 +30,12 @@ class SoapService * @param string $arbiterAddr * @return null */ - public function __construct($arbiterAddr) { + public function __construct($arbiterType) { + $arbiter = GridHelper::{strtolower($arbiterType) . 'Arbiter'}(); $this->Client = new SoapClient( - Storage::path('grid/RCCService.wsdl'), + Storage::path('grid/RCCservice.wsdl'), // Arbiter WCF service WSDL should not be used for RCCService calls. [ - 'location' => $arbiterAddr, + 'location' => $arbiter, 'uri' => 'http://roblox.com/', 'exceptions' => false ] @@ -49,72 +53,17 @@ class SoapService $soapResult = $this->Client->{$name}($args); if(is_soap_fault($soapResult)) { - // TODO: XlXi: log faults + ArbiterSoapFault::create([ + 'function' => $name, + 'code' => $soapResult->getCode(), + 'message' => $soapResult->getMessage(), + 'job_arguments' => json_encode($args) + ]); } return $soapResult; } - /* Job constructors */ - - public static function LuaValue($value) - { - switch ($value) { - case is_bool(json_encode($value)) || $value == 1: - return json_encode($value); - default: - return $value; - } - } - - public static function CastType($value) - { - $luaTypeConversions = [ - 'NULL' => 'LUA_TNIL', - 'boolean' => 'LUA_TBOOLEAN', - 'integer' => 'LUA_TNUMBER', - 'double' => 'LUA_TNUMBER', - 'string' => 'LUA_TSTRING', - 'array' => 'LUA_TTABLE', - 'object' => 'LUA_TNIL' - ]; - return $luaTypeConversions[gettype($value)]; - } - - public static function ToLuaArguments($luaArguments = []) - { - $luaValue = ['LuaValue' => []]; - - foreach ($luaArguments as $argument) { - array_push( - $luaValue['LuaValue'], - [ - 'type' => SoapService::CastType($argument), - 'value' => SoapService::LuaValue($argument) - ] - ); - } - - return $luaValue; - } - - public static function MakeJobJSON($jobID, $expiration, $category, $cores, $scriptName, $script, $scriptArgs = []) - { - return [ - 'job' => [ - 'id' => $jobID, - 'expirationInSeconds' => $expiration, - 'category' => $category, - 'cores' => $cores - ], - 'script' => [ - 'name' => $scriptName, - 'script' => $script, - 'arguments' => SoapService::ToLuaArguments($scriptArgs) - ] - ]; - } - /* Service functions */ public function HelloWorld() diff --git a/web/app/Helpers/GridHelper.php b/web/app/Helpers/GridHelper.php index ac6d2f1..3b9bf30 100644 --- a/web/app/Helpers/GridHelper.php +++ b/web/app/Helpers/GridHelper.php @@ -7,6 +7,7 @@ namespace App\Helpers; +use Illuminate\Support\Facades\Storage; use Illuminate\Http\Request; use App\Models\DynamicWebConfiguration; @@ -31,13 +32,113 @@ class GridHelper public static function hasAllAccess() { if(app()->runningInConsole()) return true; - if(GridHelper::isIpWhitelisted() && GridHelper::isAccessKeyValid()) return true; + if(self::isIpWhitelisted() && self::isAccessKeyValid()) return true; return false; } - public static function createScript($scripts = [], $arguments = []) + public static function LuaValue($value) { - // TODO: XlXi: this when we get the grid working with the site + switch ($value) { + case is_bool(json_encode($value)) || $value == 1: + return json_encode($value); + default: + return $value; + } + } + + public static function CastType($value) + { + $luaTypeConversions = [ + 'NULL' => 'LUA_TNIL', + 'boolean' => 'LUA_TBOOLEAN', + 'integer' => 'LUA_TNUMBER', + 'double' => 'LUA_TNUMBER', + 'string' => 'LUA_TSTRING', + 'array' => 'LUA_TTABLE', + 'object' => 'LUA_TNIL' + ]; + return $luaTypeConversions[gettype($value)]; + } + + public static function ToLuaArguments($luaArguments = []) + { + $luaValue = ['LuaValue' => []]; + + foreach ($luaArguments as $argument) { + array_push( + $luaValue['LuaValue'], + [ + 'type' => self::CastType($argument), + 'value' => self::LuaValue($argument) + ] + ); + } + + return $luaValue; + } + + public static function Job($jobID, $expiration, $category, $cores, $scriptName, $script, $scriptArgs = []) + { + return [ + 'job' => [ + 'id' => $jobID, + 'expirationInSeconds' => $expiration, + 'category' => $category, + 'cores' => $cores + ], + 'script' => [ + 'name' => $scriptName, + 'script' => $script, + 'arguments' => self::ToLuaArguments($scriptArgs) + ] + ]; + } + + public static function JobTemplate($jobID, $expiration, $category, $cores, $scriptName, $templateName, $scriptArgs = []) + { + $disk = Storage::build([ + 'driver' => 'local', + 'root' => storage_path('app/grid/scripts'), + ]); + + $fileName = sprintf('%s.lua', $templateName); + + if(!$disk->exists($fileName)) + throw new Exception('Unable to locate template file.'); + + $job = self::Job($jobID, $expiration, $category, $cores, $scriptName, '', $scriptArgs); + $job['script']['script'] = $disk->get($fileName); + + return $job; + } + + public static function getArbiter($name) + { + $query = DynamicWebConfiguration::where('name', sprintf('%sArbiterIP', $name))->first(); + if(!$query) + throw new Exception('Unknown arbiter.'); + + return $query->value; + } + + public static function gameArbiter() + { + return sprintf('http://%s:64989', self::getArbiter('Game')); + } + + public static function thumbnailArbiter() + { + return sprintf('http://%s:64989', self::getArbiter('Thumbnail')); + } + + public static function gameArbiterMonitor() + { + return sprintf('http://%s:64990', self::getArbiter('Game')); + } + + public static function thumbnailArbiterMonitor() + { + return sprintf('http://%s:64990', self::getArbiter('Thumbnail')); } } diff --git a/web/app/Http/Controllers/Api/ThumbnailController.php b/web/app/Http/Controllers/Api/ThumbnailController.php index 83ff9d1..44bf766 100644 --- a/web/app/Http/Controllers/Api/ThumbnailController.php +++ b/web/app/Http/Controllers/Api/ThumbnailController.php @@ -49,7 +49,7 @@ class ThumbnailController extends Controller $tracker->target = $valid['id']; $tracker->save(); - ArbiterRender::dispatch($tracker, $valid['type'] == '3d'); + ArbiterRender::dispatch($tracker, $valid['type'] == '3d', $asset->typeString(), $asset->id); } return response(['status' => 'loading']); diff --git a/web/app/Http/Controllers/Web/AdminController.php b/web/app/Http/Controllers/Web/AdminController.php new file mode 100644 index 0000000..6de2393 --- /dev/null +++ b/web/app/Http/Controllers/Web/AdminController.php @@ -0,0 +1,27 @@ +with([ + 'title' => sprintf('%s Arbiter Diag', $arbiterType), + 'arbiter' => $arbiterType + ]); + } +} diff --git a/web/app/Http/Controllers/Web/TestController.php b/web/app/Http/Controllers/Web/TestController.php index dcf4be6..e80d0f0 100644 --- a/web/app/Http/Controllers/Web/TestController.php +++ b/web/app/Http/Controllers/Web/TestController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web; use Illuminate\Http\Request; use Illuminate\Support\Str; +use App\Helpers\GridHelper; use App\Http\Controllers\Controller; use App\Grid\SoapService; @@ -15,20 +16,10 @@ class TestController extends Controller */ public function generateThumbnail() { - $testScript = <<OpenJob(SoapService::MakeJobJSON('test', 10, 0, 0, 'test render', $testScript)); + $test = new SoapService('Thumbnail'); + $result = $test->OpenJob(GridHelper::JobTemplate('test', 10, 0, 0, 'test render', 'place', ['http://www.roblox.com/asset/?id=444204653', 'PNG', 1920, 1080, 'https://www.gtoria.local/', 169618721])); return response(base64_decode($result->OpenJobExResult->LuaValue[0]->value)) ->header('Content-Type', 'image/png'); diff --git a/web/app/Http/Kernel.php b/web/app/Http/Kernel.php index 173ca20..f4a9e92 100644 --- a/web/app/Http/Kernel.php +++ b/web/app/Http/Kernel.php @@ -69,6 +69,7 @@ class Kernel extends HttpKernel 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'roleset' => \App\Http\Middleware\Roleset::class, 'banned' => \App\Http\Middleware\CheckBan::class, ]; } diff --git a/web/app/Http/Middleware/Administrator.php b/web/app/Http/Middleware/Roleset.php similarity index 68% rename from web/app/Http/Middleware/Administrator.php rename to web/app/Http/Middleware/Roleset.php index 7d8c80e..68b8b8e 100644 --- a/web/app/Http/Middleware/Administrator.php +++ b/web/app/Http/Middleware/Roleset.php @@ -4,8 +4,9 @@ namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; -class Administrator +class Roleset { /** * Handle an incoming request. @@ -14,11 +15,11 @@ class Administrator * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ - public function handle(Request $request, Closure $next) + public function handle(Request $request, Closure $next, $role) { - if (Auth::user()->isAdmin()) + if (Auth::check() && Auth::user()->hasRoleset($role)) return $next($request); - return abort(403); + return abort(404); } } diff --git a/web/app/Jobs/ArbiterRender.php b/web/app/Jobs/ArbiterRender.php index 9e6e24c..afc62b2 100644 --- a/web/app/Jobs/ArbiterRender.php +++ b/web/app/Jobs/ArbiterRender.php @@ -12,6 +12,7 @@ use Illuminate\Support\Str; use App\Grid\SoapService; use App\Helpers\CdnHelper; +use App\Helpers\GridHelper; use App\Models\RenderTracker; class ArbiterRender implements ShouldQueue @@ -45,16 +46,32 @@ class ArbiterRender implements ShouldQueue * @var bool */ public $is3D; + + /** + * Asset type string based on asset's type id + * + * @var string + */ + public $type; + + /** + * Asset ID to render + * + * @var int + */ + public $assetId; /** * Create a new job instance. * * @return void */ - public function __construct(RenderTracker $tracker, bool $is3D) + public function __construct(RenderTracker $tracker, bool $is3D, string $type, int $assetId) { $this->tracker = $tracker; $this->is3D = $is3D; + $this->type = $type; + $this->assetId = $assetId; } /** @@ -64,28 +81,41 @@ class ArbiterRender implements ShouldQueue */ public function handle() { - $testScript = <<assetId)), // TODO: XlXi: Move url() to route once the route actually exists. + ($this->is3D ? 'OBJ' : 'PNG'), + 840, // Width + 840, // Height + url('/') + ]; + switch($this->type) { + case 'Head': + case 'Shirt': + case 'Pants': + case 'BodyPart': + // TODO: XlXi: Move this to config, as it could be different from prod in a testing environment. Also move this to it's own asset (not loading from roblox). + array_push($arguments, 'https://www.roblox.com/asset/?id=1785197'); // Rig + break; + case 'Package': + // TODO: XlXi: Move these to config, as it could be different from prod in a testing environment. Also move these to their own assets (not loading from roblox). + array_push($arguments, 'https://www.roblox.com/asset/?id=1785197'); // Rig + array_push($arguments, '27113661;25251154'); // Custom Texture URLs (shirt and pands) + break; + case 'Place': + array_push($arguments, '0'); // TODO: XlXi: Universe IDs + break; + } - game:Load("http://gtoria.net/asset/?id=3529"); - for _, Object in pairs(game:GetChildren())do - if Object:IsA("Tool") then - Object.Parent = workspace - end - end - - -- format, width, height, sky, crop - return game:GetService("ThumbnailGenerator"):Click("OBJ", 840, 840, true, true) -TestScript; - - $test = new SoapService('http://192.168.0.3:64989'); - $result = $test->OpenJob(SoapService::MakeJobJSON(Str::uuid()->toString(), 120, 0, 0, sprintf('Render %s %d', $this->tracker->type, $this->tracker->target), $testScript)); + $service = new SoapService('Thumbnail'); + $result = $service->OpenJob(GridHelper::JobTemplate( + Str::uuid()->toString(), // Job ID + 120, // Expiration + 0, // Category ID + 0, // Cores + sprintf('Render %s %d', $this->tracker->type, $this->tracker->target), // Script Name + $this->type, // Script + $arguments // Arguments + )); if(is_soap_fault($result)) $this->fail(sprintf('SOAP Fault: (faultcode: %s, faultstring: %s)', $result->faultcode, $result->faultstring)); diff --git a/web/app/Models/ArbiterSoapFault.php b/web/app/Models/ArbiterSoapFault.php new file mode 100644 index 0000000..c1a70b2 --- /dev/null +++ b/web/app/Models/ArbiterSoapFault.php @@ -0,0 +1,23 @@ +id(); + $table->string('function'); + $table->string('code'); + $table->string('message'); + $table->longText('job_arguments'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('arbiter_soap_faults'); + } +}; diff --git a/web/database/seeders/WebConfigurationSeeder.php b/web/database/seeders/WebConfigurationSeeder.php index c540d6e..7eb8f94 100644 --- a/web/database/seeders/WebConfigurationSeeder.php +++ b/web/database/seeders/WebConfigurationSeeder.php @@ -43,5 +43,15 @@ class WebConfigurationSeeder extends Seeder 'name' => 'VersionCompatibilityHashes', 'value' => 'debughash' // hash1;hash2;hash3 ]); + + DynamicWebConfiguration::create([ + 'name' => 'GameArbiterIP', + 'value' => '127.0.0.1' + ]); + + DynamicWebConfiguration::create([ + 'name' => 'ThumbnailArbiterIP', + 'value' => '127.0.0.1' + ]); } } diff --git a/web/resources/views/layouts/nav.blade.php b/web/resources/views/layouts/nav.blade.php index f784a6e..7cfcce8 100644 --- a/web/resources/views/layouts/nav.blade.php +++ b/web/resources/views/layouts/nav.blade.php @@ -64,8 +64,7 @@ @yield('quick-admin') @admin @endadmin