From a879fb7c4f874f406cee264724f273223c64ff98 Mon Sep 17 00:00:00 2001 From: Astrologies Date: Thu, 23 Dec 2021 00:24:14 -0500 Subject: [PATCH] User and Render impl update --- globals/Dependencies/Users/Outfit.php | 3 +- globals/Dependencies/Users/Render.php | 143 ++++++++++++++---------- globals/Dependencies/Users/User.php | 48 ++++++++ globals/functions.php | 70 +----------- html/avatar/changebc.php | 2 +- html_api/user/avatar/updatesettings.php | 9 +- 6 files changed, 139 insertions(+), 136 deletions(-) diff --git a/globals/Dependencies/Users/Outfit.php b/globals/Dependencies/Users/Outfit.php index 616459d..af56c0e 100644 --- a/globals/Dependencies/Users/Outfit.php +++ b/globals/Dependencies/Users/Outfit.php @@ -6,6 +6,7 @@ namespace Alphaland\Users { + use Alphaland\Users\User; use Alphaland\Users\Render; use Exception; use PDO; @@ -93,7 +94,7 @@ namespace Alphaland\Users { $rightleg = (int)$wearingcolors->rl; //currently wearing items - $assets = wearingAssets($userid); + $assets = User::GetWearingAssetsString($userid); //add to db $outfit = $GLOBALS['pdo']->prepare("INSERT INTO user_outfits(userid, assets, name, h, t, la, ra, ll, rl, headshotAngleRight, headshotAngleLeft, ThumbHash, HeadshotThumbHash, whenCreated) VALUES (:uid, :assets, :name, :h, :t, :la, :ra, :ll, :rl, :har, :hal, :th, :hth, UNIX_TIMESTAMP())"); diff --git a/globals/Dependencies/Users/Render.php b/globals/Dependencies/Users/Render.php index 5cc1936..6d4657c 100644 --- a/globals/Dependencies/Users/Render.php +++ b/globals/Dependencies/Users/Render.php @@ -64,84 +64,103 @@ namespace Alphaland\Users { return false; } + private static function SetPlayerRenderStats(int $userid) + { + $setrenderstat = $GLOBALS['pdo']->prepare("UPDATE users SET pendingRender = 1, pendingHeadshotRender = 1, renderCount = renderCount+1, lastRender = UNIX_TIMESTAMP(), lastHeadshotRender = UNIX_TIMESTAMP() WHERE id = :u"); + $setrenderstat->bindParam(":u", $userid, PDO::PARAM_INT); + $setrenderstat->execute(); + if ($setrenderstat->rowCount() > 0) { + return true; + } + return false; + } + public static function RenderPlayerCloseup(int $userid, bool $fork=false) { - if ($fork) + if (Render::SetPlayerRenderStats($userid)) { - $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$userid." avatarcloseup", "r"); //throwaway background process - if ($job !== FALSE); + if ($fork) { - pclose($job); - return true; + $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$userid." avatarcloseup", "r"); //throwaway background process + if ($job !== FALSE); + { + pclose($job); + return true; + } + return false; } - return false; - } - else - { - $script = file_get_contents($GLOBALS['avatarcloseupthumbnailscript']); - - $angleright = userInfo($userid)->headshotAngleRight; - $angleleft = userInfo($userid)->headshotAngleLeft; - - $soap = new RccServiceHelper($GLOBALS['thumbnailArbiter']); - $soap = $soap->BatchJobEx( - $soap->ConstructGenericJob(gen_uuid(), 25, 0, 3, "Render Player Closeup ".$userid, $script, array( - $userid, - "https://www.alphaland.cc/", - "https://api.alphaland.cc/users/avatar-accoutrements?userId=".$userid, - "png", - "840", - "840", - (bool)$angleright, //angleRight - (bool)$angleleft //angleLeft - )) - ); - - if (!is_soap_fault($soap)) { - Render::Update($userid, $soap, true); - return true; - } else { - die(print_r($soap)); + else + { + $script = file_get_contents($GLOBALS['avatarcloseupthumbnailscript']); + + $angleright = userInfo($userid)->headshotAngleRight; + $angleleft = userInfo($userid)->headshotAngleLeft; + + $soap = new RccServiceHelper($GLOBALS['thumbnailArbiter']); + $soap = $soap->BatchJobEx( + $soap->ConstructGenericJob(gen_uuid(), 25, 0, 3, "Render Player Closeup ".$userid, $script, array( + $userid, + "https://www.alphaland.cc/", + "https://api.alphaland.cc/users/avatar-accoutrements?userId=".$userid, + "png", + "840", + "840", + (bool)$angleright, //angleRight + (bool)$angleleft //angleLeft + )) + ); + + if (!is_soap_fault($soap)) { + Render::Update($userid, $soap, true); + return true; + } else { + die(print_r($soap)); + } + return false; } - return false; } + return false; } public static function RenderPlayer(int $userid, bool $fork=false) { - if ($fork) + if (Render::SetPlayerRenderStats($userid)) { - $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$userid." avatar", "r"); //throwaway background process - if ($job !== FALSE); + if ($fork) { - pclose($job); - return true; + $job = popen("cd C:/Webserver/nginx/Alphaland/WebserviceTools/RenderTools && start /B php backgroundRenderJob.php ".$userid." avatar", "r"); //throwaway background process + if ($job !== FALSE); + { + pclose($job); + return true; + } + return false; } - return false; - } - else - { - Render::RenderPlayerCloseup($userid, true); //run in the background so it will *hopefully* finish with this - $script = file_get_contents($GLOBALS['avatarthumbnailscript']); - - $soap = new RccServiceHelper($GLOBALS['thumbnailArbiter']); - $soap = $soap->BatchJobEx( - $soap->ConstructGenericJob(gen_uuid(), 25, 0, 3, "Render Player ".$userid, $script, array( - $userid, - "https://api.alphaland.cc/users/avatar-accoutrements?userId=".$userid, - "https://www.alphaland.cc/", - "png", - "840", - "840" - )) - ); - - if (!is_soap_fault($soap)) { - Render::Update($userid, $soap); - return true; + else + { + Render::RenderPlayerCloseup($userid, true); //run in the background so it will *hopefully* finish with this + $script = file_get_contents($GLOBALS['avatarthumbnailscript']); + + $soap = new RccServiceHelper($GLOBALS['thumbnailArbiter']); + $soap = $soap->BatchJobEx( + $soap->ConstructGenericJob(gen_uuid(), 25, 0, 3, "Render Player ".$userid, $script, array( + $userid, + "https://api.alphaland.cc/users/avatar-accoutrements?userId=".$userid, + "https://www.alphaland.cc/", + "png", + "840", + "840" + )) + ); + + if (!is_soap_fault($soap)) { + Render::Update($userid, $soap); + return true; + } + return false; } - return false; } + return false; } public static function Update(int $userid, $soapobject, $headshot=false) diff --git a/globals/Dependencies/Users/User.php b/globals/Dependencies/Users/User.php index 690e7fc..ce94086 100644 --- a/globals/Dependencies/Users/User.php +++ b/globals/Dependencies/Users/User.php @@ -18,5 +18,53 @@ namespace Alphaland\Users { } return false; } + + public static function SetHeadshotAngleRight(int $userid) + { + $right = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 1, headshotAngleLeft = 0 WHERE id = :uid'); + $right->bindParam(":uid", $userid, PDO::PARAM_INT); + $right->execute(); + if ($right->rowCount() > 0) { + return true; + } + return false; + } + + public static function SetHeadshotAngleLeft(int $userid) + { + $left = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 0, headshotAngleLeft = 1 WHERE id = :uid'); + $left->bindParam(":uid", $userid, PDO::PARAM_INT); + $left->execute(); + if ($left->rowCount() > 0) { + return true; + } + return false; + } + + public static function SetHeadshotAngleCenter(int $userid) + { + $center = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 0, headshotAngleLeft = 0 WHERE id = :uid'); + $center->bindParam(":uid", $userid, PDO::PARAM_INT); + $center->execute(); + if ($center->rowCount() > 0) { + return true; + } + return false; + } + + public static function GetWearingAssetsString(int $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) + $wearingitems->bindParam(":uid", $userid, PDO::PARAM_INT); + $wearingitems->execute(); + + $iter = 0; + $wearingassets = ""; + foreach($wearingitems as $item) { + $iter += 1; + $wearingassets .= ($iter == $wearingitems->rowCount()) ? $item['aid'] : $item['aid'] . ';'; + } + return $wearingassets; + } } } \ No newline at end of file diff --git a/globals/functions.php b/globals/functions.php index a8a3a49..f868846 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -1376,72 +1376,6 @@ function configPermission($groupid) // ... -//render utility functions - -function setHeadshotAngleRight($userid) -{ - $right = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 1, headshotAngleLeft = 0 WHERE id = :uid'); - $right->bindParam(":uid", $userid, PDO::PARAM_INT); - $right->execute(); - if ($right->rowCount() > 0) - { - return true; - } - return false; -} - -function setHeadshotAngleLeft($userid) -{ - $left = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 0, headshotAngleLeft = 1 WHERE id = :uid'); - $left->bindParam(":uid", $userid, PDO::PARAM_INT); - $left->execute(); - if ($left->rowCount() > 0) - { - return true; - } - return false; -} - -function setHeadshotAngleCenter($userid) -{ - $center = $GLOBALS['pdo']->prepare('UPDATE users SET headshotAngleRight = 0, headshotAngleLeft = 0 WHERE id = :uid'); - $center->bindParam(":uid", $userid, PDO::PARAM_INT); - $center->execute(); - if ($center->rowCount() > 0) - { - return true; - } - 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) - $wearingitems->bindParam(":uid", $userid, PDO::PARAM_INT); - $wearingitems->execute(); - - $iter = 0; - $wearingassets = ""; - foreach($wearingitems as $item) - { - $iter += 1; - $wearingassets .= ($iter == $wearingitems->rowCount()) ? $item['aid'] : $item['aid'] . ';'; - } - return $wearingassets; -} - -function rerenderutility() -{ - $localplayer = $GLOBALS['user']->id; - - $setrenderstat = $GLOBALS['pdo']->prepare("UPDATE users SET pendingRender = 1, pendingHeadshotRender = 1, renderCount = renderCount+1, lastRender = UNIX_TIMESTAMP(), lastHeadshotRender = UNIX_TIMESTAMP() WHERE id = :u"); - $setrenderstat->bindParam(":u", $localplayer, PDO::PARAM_INT); - $setrenderstat->execute(); - UsersRender::RenderPlayer($localplayer); -} - -//end local user render utility functions - //asset functions function availableAssetId() { @@ -3181,7 +3115,7 @@ function deequipItem($assetId) $deequip->bindParam(":a", $assetId, PDO::PARAM_INT); $deequip->execute(); - rerenderutility(); + UsersRender::RenderPlayer($localuser); } else { @@ -3243,7 +3177,7 @@ function equipItem($assetId) $equip->bindParam(":a", $assetId, PDO::PARAM_INT); $equip->execute(); - rerenderutility(); + UsersRender::RenderPlayer($localuser); } } else diff --git a/html/avatar/changebc.php b/html/avatar/changebc.php index cca7521..951e19f 100644 --- a/html/avatar/changebc.php +++ b/html/avatar/changebc.php @@ -30,7 +30,7 @@ if(getBC($clr) != "-") $upd->bindParam(":b", $clr, PDO::PARAM_INT); $upd->execute(); - rerenderutility(); + Render::RenderPlayer($localuser); echo "s"; } diff --git a/html_api/user/avatar/updatesettings.php b/html_api/user/avatar/updatesettings.php index 2812e9b..60656a4 100644 --- a/html_api/user/avatar/updatesettings.php +++ b/html_api/user/avatar/updatesettings.php @@ -8,6 +8,7 @@ Alphaland 2021 //headers use Alphaland\Users\Render; +use Alphaland\Users\User; header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); @@ -27,22 +28,22 @@ else if (!Render::PendingRender($user->id)) { if ($angleRight) { - if (setHeadshotAngleRight($user->id)) { + if (User::SetHeadshotAngleRight($user->id)) { $alert = true; } } else if ($angleLeft) { - if (setHeadshotAngleLeft($user->id)) { + if (User::SetHeadshotAngleLeft($user->id)) { $alert = true; } } else { - if (setHeadshotAngleCenter($user->id)) { + if (User::SetHeadshotAngleCenter($user->id)) { $alert = true; } } if ($alert) { if (!Render::RenderCooldown($user->id)) { - rerenderutility(); + Render::RenderPlayer($localuser); } else { $alert = "Slow down!"; }