Render impl update

This commit is contained in:
Astrologies 2021-12-20 07:44:39 -05:00
parent cd7229db1b
commit 7cd4f5affc
4 changed files with 63 additions and 28 deletions

View File

@ -13,6 +13,57 @@ namespace Alphaland\Users {
class Render 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) public static function RenderPlayerCloseup(int $userid, bool $fork=false)
{ {
if ($fork) if ($fork)
@ -112,7 +163,7 @@ namespace Alphaland\Users {
if ($headshot) { if ($headshot) {
$oldhash = $prevhash->HeadshotThumbHash; $oldhash = $prevhash->HeadshotThumbHash;
if ($oldhash != $newhash && !isHeadshotThumbHashInOutfit($oldhash)) { if ($oldhash != $newhash && !Outfit::HeadshotThumbHashInOutfit($oldhash)) {
unlink($path . $oldhash); unlink($path . $oldhash);
} }
$newthumbhash = $GLOBALS['pdo']->prepare("UPDATE users SET HeadshotThumbHash = :h, pendingHeadshotRender = 0, renderCount = renderCount-1 WHERE id = :i"); $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(); $newthumbhash->execute();
} else { } else {
$oldhash = $prevhash->ThumbHash; $oldhash = $prevhash->ThumbHash;
if ($oldhash != $newhash && !isThumbHashInOutfit($oldhash)) { if ($oldhash != $newhash && !Outfit::ThumbHashInOutfit($oldhash)) {
unlink($path . $oldhash); unlink($path . $oldhash);
} }
$newthumbhash = $GLOBALS['pdo']->prepare("UPDATE users SET ThumbHash = :h, pendingRender = 0, renderCount = renderCount-1 WHERE id = :i"); $newthumbhash = $GLOBALS['pdo']->prepare("UPDATE users SET ThumbHash = :h, pendingRender = 0, renderCount = renderCount-1 WHERE id = :i");

View File

@ -3973,28 +3973,6 @@ function equippedAssetByType($type) //returns the users last equipped item by ty
return $wearing; 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) function deequipItem($assetId)
{ {
$localuser = $GLOBALS['user']->id; $localuser = $GLOBALS['user']->id;
@ -4006,7 +3984,7 @@ function deequipItem($assetId)
{ {
if (isThumbnailerAlive()) 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 = $GLOBALS['pdo']->prepare("DELETE from wearing_items WHERE uid = :u AND aid = :a"); //delete db key
$deequip->bindParam(":u", $localuser, PDO::PARAM_INT); $deequip->bindParam(":u", $localuser, PDO::PARAM_INT);
@ -4047,7 +4025,7 @@ function equipItem($assetId)
{ {
if (isThumbnailerAlive()) if (isThumbnailerAlive())
{ {
if (!isRenderCooldown($localuser)) if (!UsersRender::RenderCooldown($localuser))
{ {
if (!isAssetModerated($assetId)) if (!isAssetModerated($assetId))
{ {

View File

@ -8,6 +8,9 @@
4 = Left Leg 4 = Left Leg
5 = Right Leg 5 = Right Leg
*/ */
use Alphaland\Users\Render;
$bcdb = array("0" => "h", "1" => "t", "2" => "la", "3" => "ra", "4" => "ll", "5" => "rl"); $bcdb = array("0" => "h", "1" => "t", "2" => "la", "3" => "ra", "4" => "ll", "5" => "rl");
$cbc = (int)$_POST['bct']; $cbc = (int)$_POST['bct'];
$clr = (int)$_POST['clr']; $clr = (int)$_POST['clr'];
@ -20,7 +23,7 @@ if(getBC($clr) != "-")
{ {
if (isThumbnailerAlive()) if (isThumbnailerAlive())
{ {
if (!isRenderCooldown($localuser)) if (!Render::RenderCooldown($user->id))
{ {
$upd = $pdo->prepare("UPDATE body_colours SET {$bcdb[$cbc]} = :b WHERE uid = :u"); $upd = $pdo->prepare("UPDATE body_colours SET {$bcdb[$cbc]} = :b WHERE uid = :u");
$upd->bindParam(":u", $user->id, PDO::PARAM_INT); $upd->bindParam(":u", $user->id, PDO::PARAM_INT);

View File

@ -6,6 +6,9 @@ Alphaland 2021
*/ */
//headers //headers
use Alphaland\Users\Render;
header("Access-Control-Allow-Origin: https://www.alphaland.cc"); header("Access-Control-Allow-Origin: https://www.alphaland.cc");
header("access-control-allow-credentials: true"); header("access-control-allow-credentials: true");
header('Content-Type: application/json'); header('Content-Type: application/json');
@ -38,7 +41,7 @@ else
} }
if ($alert) { if ($alert) {
if (!isRenderCooldown($user->id)) { if (!Render::RenderCooldown($user->id)) {
rerenderutility(); rerenderutility();
} else { } else {
$alert = "Slow down!"; $alert = "Slow down!";