Assets\Render RenderPlace impl
This commit is contained in:
parent
73a3c7d339
commit
984ead4c77
|
|
@ -41,7 +41,7 @@ switch ($type)
|
|||
AssetRender::RenderHead($assetid);
|
||||
break;
|
||||
case "place":
|
||||
RenderPlace($assetid);
|
||||
AssetRender::RenderPlace($assetid);
|
||||
break;
|
||||
case "package":
|
||||
AssetRender::RenderPackage($assetid);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Alphaland\Assets\Render;
|
||||
use Alphaland\Web\WebContextManager;
|
||||
|
||||
if (!WebContextManager::VerifyAccessKeyHeader())
|
||||
|
|
@ -56,7 +58,7 @@ if($iteminfo !== FALSE) //asset id exists in alphaland db
|
|||
//epic
|
||||
if (isPlaceUsingRender($iteminfo->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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue