From 7cd4f5affc35ce099690ad737fb4755509ed1930 Mon Sep 17 00:00:00 2001 From: Astrologies Date: Mon, 20 Dec 2021 07:44:39 -0500 Subject: [PATCH] Render impl update --- globals/Dependencies/Users/Render.php | 55 ++++++++++++++++++++++++- globals/functions.php | 26 +----------- html/avatar/changebc.php | 5 ++- html_api/user/avatar/updatesettings.php | 5 ++- 4 files changed, 63 insertions(+), 28 deletions(-) diff --git a/globals/Dependencies/Users/Render.php b/globals/Dependencies/Users/Render.php index b753813..b6caaf4 100644 --- a/globals/Dependencies/Users/Render.php +++ b/globals/Dependencies/Users/Render.php @@ -13,6 +13,57 @@ namespace Alphaland\Users { class Render { + public static function SetRenderCount(int $userid, int $count) + { + $update = $GLOBALS['pdo']->prepare("UPDATE `users` SET `renderCount` = :count WHERE `id` = :userid"); + $update->bindParam(":count", $count, PDO::PARAM_INT); + $update->bindParam(":userid", $userid, PDO::PARAM_INT); + $update->execute(); + } + + public static function RenderCount(int $userid) + { + $userinfo = userInfo($userid); + if (($userinfo->lastRender + 15) < time()) { + Render::SetRenderCount($userid, 0); + } + return $userinfo->renderCount; + } + + public static function RenderCooldown(int $userid) + { + if (Render::RenderCount($userid) > 3) { + return true; + } + return false; + } + + public static function PendingRendering(int $userid) + { + $pending = $GLOBALS['pdo']->prepare("SELECT * FROM users WHERE id = :u"); + $pending->bindParam(":u", $userid, PDO::PARAM_INT); + $pending->execute(); + $pending = $pending->fetch(PDO::FETCH_OBJ); + + if ($pending->pendingRender) { //render pending + if (($pending->lastRender + 15) < time()) { //if the render is stalled after 15 seconds + $update = $GLOBALS['pdo']->prepare("UPDATE users SET pendingRender = 0 WHERE id = :u"); + $update->bindParam(":u", $userid, PDO::PARAM_INT); + $update->execute(); + } + return true; + } + if ($pending->pendingHeadshotRender) { //headshot render pending + if (($pending->lastHeadshotRender + 15) < time()) { //if the render is stalled after 15 seconds + $update = $GLOBALS['pdo']->prepare("UPDATE users SET pendingHeadshotRender = 0 WHERE id = :u"); + $update->bindParam(":u", $userid, PDO::PARAM_INT); + $update->execute(); + } + return true; + } + return false; + } + public static function RenderPlayerCloseup(int $userid, bool $fork=false) { if ($fork) @@ -112,7 +163,7 @@ namespace Alphaland\Users { if ($headshot) { $oldhash = $prevhash->HeadshotThumbHash; - if ($oldhash != $newhash && !isHeadshotThumbHashInOutfit($oldhash)) { + if ($oldhash != $newhash && !Outfit::HeadshotThumbHashInOutfit($oldhash)) { unlink($path . $oldhash); } $newthumbhash = $GLOBALS['pdo']->prepare("UPDATE users SET HeadshotThumbHash = :h, pendingHeadshotRender = 0, renderCount = renderCount-1 WHERE id = :i"); @@ -121,7 +172,7 @@ namespace Alphaland\Users { $newthumbhash->execute(); } else { $oldhash = $prevhash->ThumbHash; - if ($oldhash != $newhash && !isThumbHashInOutfit($oldhash)) { + if ($oldhash != $newhash && !Outfit::ThumbHashInOutfit($oldhash)) { unlink($path . $oldhash); } $newthumbhash = $GLOBALS['pdo']->prepare("UPDATE users SET ThumbHash = :h, pendingRender = 0, renderCount = renderCount-1 WHERE id = :i"); diff --git a/globals/functions.php b/globals/functions.php index 14cd267..90e0a94 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -3973,28 +3973,6 @@ function equippedAssetByType($type) //returns the users last equipped item by ty return $wearing; } -function currentRenderCount($userid) -{ - $userinfo = userInfo($userid); - if (($userinfo->lastRender + 15) < time()) - { - $update = $GLOBALS['pdo']->prepare("UPDATE users SET renderCount = 0 WHERE id = :u"); - $update->bindParam(":u", $userid, PDO::PARAM_INT); - $update->execute(); - } - - return $userinfo->renderCount; -} - -function isRenderCooldown($userid) -{ - if (currentRenderCount($userid) > 3) - { - return true; - } - return false; -} - function deequipItem($assetId) { $localuser = $GLOBALS['user']->id; @@ -4006,7 +3984,7 @@ function deequipItem($assetId) { if (isThumbnailerAlive()) { - if (!isRenderCooldown($localuser)) + if (!UsersRender::RenderCooldown($localuser)) { $deequip = $GLOBALS['pdo']->prepare("DELETE from wearing_items WHERE uid = :u AND aid = :a"); //delete db key $deequip->bindParam(":u", $localuser, PDO::PARAM_INT); @@ -4047,7 +4025,7 @@ function equipItem($assetId) { if (isThumbnailerAlive()) { - if (!isRenderCooldown($localuser)) + if (!UsersRender::RenderCooldown($localuser)) { if (!isAssetModerated($assetId)) { diff --git a/html/avatar/changebc.php b/html/avatar/changebc.php index eaa2611..cca7521 100644 --- a/html/avatar/changebc.php +++ b/html/avatar/changebc.php @@ -8,6 +8,9 @@ 4 = Left Leg 5 = Right Leg */ + +use Alphaland\Users\Render; + $bcdb = array("0" => "h", "1" => "t", "2" => "la", "3" => "ra", "4" => "ll", "5" => "rl"); $cbc = (int)$_POST['bct']; $clr = (int)$_POST['clr']; @@ -20,7 +23,7 @@ if(getBC($clr) != "-") { if (isThumbnailerAlive()) { - if (!isRenderCooldown($localuser)) + if (!Render::RenderCooldown($user->id)) { $upd = $pdo->prepare("UPDATE body_colours SET {$bcdb[$cbc]} = :b WHERE uid = :u"); $upd->bindParam(":u", $user->id, PDO::PARAM_INT); diff --git a/html_api/user/avatar/updatesettings.php b/html_api/user/avatar/updatesettings.php index b35e00f..f79b7c8 100644 --- a/html_api/user/avatar/updatesettings.php +++ b/html_api/user/avatar/updatesettings.php @@ -6,6 +6,9 @@ Alphaland 2021 */ //headers + +use Alphaland\Users\Render; + header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("access-control-allow-credentials: true"); header('Content-Type: application/json'); @@ -38,7 +41,7 @@ else } if ($alert) { - if (!isRenderCooldown($user->id)) { + if (!Render::RenderCooldown($user->id)) { rerenderutility(); } else { $alert = "Slow down!";