From 984ead4c775d091dd63bf2f9851f4745d159864b Mon Sep 17 00:00:00 2001 From: Astrologies Date: Thu, 16 Dec 2021 01:51:56 -0500 Subject: [PATCH] Assets\Render RenderPlace impl --- .../RenderTools/backgroundRenderJob.php | 2 +- globals/Dependencies/Assets/Render.php | 71 ++++++++++++++--- globals/functions.php | 78 +------------------ html/Studio/Data/UploadData.php | 2 +- html_data/Data/AutoSave.ashx | 4 +- 5 files changed, 67 insertions(+), 90 deletions(-) diff --git a/WebserviceTools/RenderTools/backgroundRenderJob.php b/WebserviceTools/RenderTools/backgroundRenderJob.php index 0f3a9b4..54d2031 100644 --- a/WebserviceTools/RenderTools/backgroundRenderJob.php +++ b/WebserviceTools/RenderTools/backgroundRenderJob.php @@ -41,7 +41,7 @@ switch ($type) AssetRender::RenderHead($assetid); break; case "place": - RenderPlace($assetid); + AssetRender::RenderPlace($assetid); break; case "package": AssetRender::RenderPackage($assetid); diff --git a/globals/Dependencies/Assets/Render.php b/globals/Dependencies/Assets/Render.php index b5396c7..cb75fef 100644 --- a/globals/Dependencies/Assets/Render.php +++ b/globals/Dependencies/Assets/Render.php @@ -339,31 +339,82 @@ namespace Alphaland\Assets { } } - public static function Update(int $assetid, $soapobject) + public static function RenderPlace(int $assetid, bool $fork=false) { + if ($fork) { + $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$assetid." place", "r"); //throwaway background process + if ($job !== FALSE); { + pclose($job); + return true; + } + return false; + } else { + $thumbnailScript = file_get_contents($GLOBALS['placethumbnailscript']); + $soap = new RccServiceHelper($GLOBALS['thumbnailArbiter']); + $soap = $soap->BatchJobEx( + $soap->ConstructGenericJob(gen_uuid(), 25, 0, 3, "Render Place ".$assetid, $thumbnailScript, array( + $assetid, + "https://www.alphaland.cc/asset/?id=".$assetid, + "https://www.alphaland.cc/", + "png", + "768", + "432" + )) + ); + + if (!is_soap_fault($soap)) { + Render::Update($assetid, $soap, true); + return true; + } + logSoapFault($soap, "Render Place ".$assetid." Job", $thumbnailScript); + return false; + } + } + + public static function Update(int $assetid, $soapobject, $placerender=false) + { + $rendersPath = $GLOBALS['renderCDNPath']; $render = base64_decode($soapobject->BatchJobExResult->LuaValue[0]->value); if (ImageHelper::IsBase64PNGImage($render)) //PNG { $newhash = HashingUtiltity::VerifyMD5(md5($render)); - if (!file_get_contents($GLOBALS['renderCDNPath'] . $newhash)) + if (!file_get_contents($rendersPath . $newhash)) { - if (file_put_contents($GLOBALS['renderCDNPath'] . $newhash, $render)) + if (file_put_contents($rendersPath . $newhash, $render)) { + if ($placerender) { + if (getAssetInfo($assetid)->isPersonalServer == 1) { + $render = imagecreatefrompng($rendersPath . $newhash); + $overlay = imagecreatefrompng($GLOBALS['pbsOverlayPath']); + ImageHelper::CopyMergeImageAlpha($render, $overlay, 0, 0, 0, 0, imagesx($render), imagesy($render), 100); + if (!imagepng($render, $rendersPath . $newhash)) { + return false; + } + } + } + //delete old hash $prevhash = $GLOBALS['pdo']->prepare("SELECT * FROM assets WHERE id = :i"); $prevhash->bindParam(":i", $assetid, PDO::PARAM_INT); $prevhash->execute(); $prevhash = $prevhash->fetch(PDO::FETCH_OBJ); $oldhash = $prevhash->ThumbHash; - unlink($GLOBALS['renderCDNPath'] . $oldhash); - - //set new hash - $newthumbhash = $GLOBALS['pdo']->prepare("UPDATE assets SET ThumbHash = :h WHERE id = :i"); - $newthumbhash->bindParam(":h", $newhash, PDO::PARAM_STR); - $newthumbhash->bindParam(":i", $assetid, PDO::PARAM_INT); - $newthumbhash->execute(); + unlink($rendersPath . $oldhash); + if ($placerender) { + //update place thumbhash n details + $c = $GLOBALS['pdo']->prepare("UPDATE assets SET isPlaceRendered = 1, IconImageAssetId = 0, ThumbHash = :n WHERE id = :i"); + $c->bindParam(":n", $newhash, PDO::PARAM_INT); //item price + $c->bindParam(":i", $assetid, PDO::PARAM_INT); //catalog id + $c->execute(); + } else { + //set new hash + $newthumbhash = $GLOBALS['pdo']->prepare("UPDATE assets SET ThumbHash = :h WHERE id = :i"); + $newthumbhash->bindParam(":h", $newhash, PDO::PARAM_STR); + $newthumbhash->bindParam(":i", $assetid, PDO::PARAM_INT); + $newthumbhash->execute(); + } return true; } } diff --git a/globals/functions.php b/globals/functions.php index bf1c715..8e5faa6 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -2094,82 +2094,6 @@ function setHeadshotAngleCenter($userid) return false; } -function RenderPlace($placeid, $fork=false) -{ - if ($fork) - { - $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$placeid." place", "r"); //throwaway background process - if ($job !== FALSE); - { - pclose($job); - return true; - } - return false; - } - else - { - $script = $GLOBALS['placethumbnailscript']; - - $result = soapBatchJobEx($GLOBALS['thumbnailArbiter'], gen_uuid(), 25, "Render Place ".$placeid, file_get_contents($script), array( - $placeid, - "https://www.alphaland.cc/asset/?id=".$placeid, - "https://www.alphaland.cc/", - "png", - "768", - "432" - ) - ); - - if (!is_soap_fault($result)) - { - $render = base64_decode($result->BatchJobExResult->LuaValue[0]->value); //returned by rcc - $path = $GLOBALS['renderCDNPath']; - $pbsoverlaypath = "C:/Webserver/nginx/Alphaland/PersonalServerOverlay.png"; - - if (isbase64png($render)) //PNG - { - $newhash = safeAssetMD5(md5($render)); - if (file_put_contents($path . $newhash, $render)) - { - //handle overlay for personal build servers TODO: FIX THIS SO ITS NOT SO BAD - if (getAssetInfo($placeid)->isPersonalServer == 1) - { - $render = imagecreatefrompng($path . $newhash); - $overlay = imagecreatefrompng($pbsoverlaypath); - imagecopymerge_alpha($render, $overlay, 0, 0, 0, 0, imagesx($render), imagesy($render), 100); - if (!imagepng($render, $path . $newhash)) - { - return false; - } - } - - //delete old thumb - $prevhash = $GLOBALS['pdo']->prepare("SELECT * FROM assets WHERE id = :i"); - $prevhash->bindParam(":i", $placeid, PDO::PARAM_INT); - $prevhash->execute(); - $prevhash = $prevhash->fetch(PDO::FETCH_OBJ); - $oldhash = $prevhash->ThumbHash; - unlink($path . $oldhash); - // ... - - //update place thumbhash n details - $c = $GLOBALS['pdo']->prepare("UPDATE assets SET isPlaceRendered = 1, IconImageAssetId = 0, ThumbHash = :n WHERE id = :i"); - $c->bindParam(":n", $newhash, PDO::PARAM_INT); //item price - $c->bindParam(":i", $placeid, PDO::PARAM_INT); //catalog id - $c->execute(); - - return true; - } - } - } - else - { - logSoapFault($result, "Render Place ".$placeid." Job", $script); - } - return false; - } -} - function wearingAssets($userid) //returns wearing asset list separated by ; { $wearingitems = $GLOBALS['pdo']->prepare('SELECT * FROM wearing_items WHERE uid = :uid ORDER BY aid ASC'); //wearing items from lowest to highest (EZ) @@ -3948,7 +3872,7 @@ function handleRenderPlace($placeid) //we have a 60 second wait, and we verify t if(($lastrender + (60)) < time()) //60 second interval { - if (RenderPlace($placeid)) + if (Render::RenderPlace($placeid)) { $c = $GLOBALS['pdo']->prepare("UPDATE assets SET lastPlaceRender = UNIX_TIMESTAMP() WHERE id = :i"); $c->bindParam(":i", $placeid, PDO::PARAM_INT); //place id diff --git a/html/Studio/Data/UploadData.php b/html/Studio/Data/UploadData.php index c182fd6..e50c6d2 100644 --- a/html/Studio/Data/UploadData.php +++ b/html/Studio/Data/UploadData.php @@ -56,7 +56,7 @@ if($iteminfo !== FALSE) //asset id exists in alphaland db if (isPlaceUsingRender($iteminfo->id)) { - RenderPlace($iteminfo->id); + Render::RenderPlace($iteminfo->id); } } else diff --git a/html_data/Data/AutoSave.ashx b/html_data/Data/AutoSave.ashx index 3919c1b..baffa82 100644 --- a/html_data/Data/AutoSave.ashx +++ b/html_data/Data/AutoSave.ashx @@ -1,4 +1,6 @@ id)) { - RenderPlace($iteminfo->id, true); //we pass true to fork from this session + Render::RenderPlace($iteminfo->id, true); //we pass true to fork from this session } } }