diff --git a/globals/Dependencies/Administration/Maintenance.php b/globals/Dependencies/Administration/Maintenance.php new file mode 100644 index 0000000..5755601 --- /dev/null +++ b/globals/Dependencies/Administration/Maintenance.php @@ -0,0 +1,26 @@ +prepare("UPDATE websettingsdeprecated SET maintenance = 1, maintenance_text = :t"); + $setmaintenance->bindParam(":t", $text, PDO::PARAM_STR); + $setmaintenance->execute(); + + $jobClose = new RccServiceHelper($GLOBALS['gamesArbiter']); + $jobClose->CloseAllJobs(); + } + + public static function Disable() + { + $setmaintenance = $GLOBALS['pdo']->prepare("UPDATE websettingsdeprecated SET maintenance = 0, maintenance_text = ''"); + $setmaintenance->execute(); + } + } +} diff --git a/globals/Dependencies/Assets/Asset.php b/globals/Dependencies/Assets/Asset.php index 94bcf61..26aad05 100644 --- a/globals/Dependencies/Assets/Asset.php +++ b/globals/Dependencies/Assets/Asset.php @@ -5,8 +5,177 @@ */ namespace Alphaland\Assets { - class Asset - { +use Alphaland\Common\HashingUtiltity; +use PDO; + +class Asset + { + private static function GenerateHash(int $len) + { + $hash = ""; + do { + $hash = HashingUtiltity::GenerateByteHash($len); + $tokencheck = $GLOBALS['pdo']->prepare("SELECT COUNT (*) FROM assets WHERE Hash = :t"); + $tokencheck->bindParam(":t", $hash, PDO::PARAM_STR); + $tokencheck->execute(); + } while ($tokencheck->fetchColumn() != 0); + return $hash; + } + + public static function AvailableId() + { + $GLOBALS['pdo']->exec("LOCK TABLES assets WRITE"); + $b = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM assets"); + $b->execute(); + $GLOBALS['pdo']->exec("UNLOCK TABLES"); + return $b->fetchColumn() + 1; + } + + public static function CreateBasicAsset(int $assetid, int $assettypeid, int $targetid, string $producttype, string $name, string $description, int $creatorid, int $price, bool $onsale, bool $ispublicdomain, bool $isapproved, string $hash) + { + $GLOBALS['pdo']->exec("LOCK TABLES assets WRITE"); + + $asset = $GLOBALS['pdo']->prepare("INSERT INTO assets (id, AssetTypeId, TargetId, ProductType, Name, Description, Created, Updated, CreatorId, PriceInAlphabux, IsForSale, isPublicDomain, isApproved, Hash) VALUES(:id, :AssetTypeId, :TargetId, :ProductType, :Name, :Description, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :CreatorId, :PriceInAlphabux, :IsForSale, :isPublicDomain, :isApproved, :Hash)"); + $asset->bindParam(":id", $assetid, PDO::PARAM_INT); + $asset->bindParam(":AssetTypeId", $assettypeid, PDO::PARAM_INT); + $asset->bindParam(":TargetId", $targetid, PDO::PARAM_INT); + $asset->bindParam(":ProductType", $producttype, PDO::PARAM_STR); + $asset->bindParam(":Name", $name, PDO::PARAM_STR); + $asset->bindParam(":Description", $description, PDO::PARAM_STR); + $asset->bindParam(":CreatorId", $creatorid, PDO::PARAM_INT); + $asset->bindParam(":isPublicDomain", $ispublicdomain, PDO::PARAM_INT); + $asset->bindParam(":isApproved", $isapproved, PDO::PARAM_INT); + $asset->bindParam(":PriceInAlphabux", $price, PDO::PARAM_INT); + $asset->bindParam(":IsForSale", $onsale, PDO::PARAM_INT); + $asset->bindParam(":Hash", $hash, PDO::PARAM_STR); + $asset->execute(); + + $GLOBALS['pdo']->exec("UNLOCK TABLES"); + } + + public static function CreateAsset(int $id, int $AssetTypeId, int $IconImageAssetId, int $TargetId, string $ProductType, string $Name, string $Description, $Created, $Updated, $CreatorId, $PriceInAlphabux, $Sales, $isPersonalServer, $IsNew, $IsForSale, $IsPublicDomain, $IsLimited, $IsLimitedUnique, $IsCommentsEnabled, $IsApproved, $IsModerated, $Remaining, $MinimumMembershipLevel, $ContentRatingTypeId, $Favorited, $Visited, $MaxPlayers, $UpVotes, $DownVotes, $Hash, $ThumbHash) + { + //setup the new asset in the DB, lock it! + $GLOBALS['pdo']->exec("LOCK TABLES assets WRITE"); + + //db entry + $m = $GLOBALS['pdo']->prepare("INSERT INTO `assets`(Id, AssetTypeId, IconImageAssetId, TargetId, ProductType, Name, Description, Created, Updated, CreatorId, PriceInAlphabux, Sales, isPersonalServer, IsNew, IsForSale, IsPublicDomain, IsLimited, IsLimitedUnique, IsCommentsEnabled, IsApproved, IsModerated, Remaining, MinimumMembershipLevel, ContentRatingTypeId, Favorited, Visited, MaxPlayers, UpVotes, DownVotes,Hash,ThumbHash) VALUES (:Id, :AssetTypeId, :IconImageAssetId, :TargetId, :ProductType, :Name, :Description, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :CreatorId, :PriceInAlphabux, :Sales, :isPersonalServer, :IsNew, :IsForSale, :IsPublicDomain, :IsLimited, :IsLimitedUnique, :IsCommentsEnabled, :IsApproved, :IsModerated, :Remaining, :MinimumMembershipLevel, :ContentRatingTypeId, :Favorited, :Visited, :MaxPlayers, :UpVotes, :DownVotes, :Hash, :ThumbHash)"); + $m->bindParam(":Id", $id, PDO::PARAM_INT); + $m->bindParam(":AssetTypeId", $AssetTypeId, PDO::PARAM_INT); + $m->bindParam(":IconImageAssetId", $IconImageAssetId, PDO::PARAM_INT); + $m->bindParam(":TargetId", $TargetId, PDO::PARAM_INT); + $m->bindParam(":ProductType", $ProductType, PDO::PARAM_STR); + $m->bindParam(":Name", $Name, PDO::PARAM_STR); + $m->bindParam(":Description", $Description, PDO::PARAM_STR); + $m->bindParam(":CreatorId", $CreatorId, PDO::PARAM_INT); + $m->bindParam(":PriceInAlphabux", $PriceInAlphabux, PDO::PARAM_INT); + $m->bindParam(":Sales", $Sales, PDO::PARAM_INT); + $m->bindParam(":isPersonalServer", $isPersonalServer, PDO::PARAM_INT); + $m->bindParam(":IsNew", $IsNew, PDO::PARAM_INT); + $m->bindParam(":IsForSale", $IsForSale, PDO::PARAM_INT); + $m->bindParam(":IsPublicDomain", $IsPublicDomain, PDO::PARAM_INT); + $m->bindParam(":IsLimited", $IsLimited, PDO::PARAM_INT); + $m->bindParam(":IsLimitedUnique", $IsLimitedUnique, PDO::PARAM_INT); + $m->bindParam(":IsCommentsEnabled", $IsCommentsEnabled, PDO::PARAM_INT); + $m->bindParam(":IsApproved", $IsApproved, PDO::PARAM_INT); + $m->bindParam(":IsModerated", $IsModerated, PDO::PARAM_INT); + $m->bindParam(":Remaining", $Remaining, PDO::PARAM_INT); + $m->bindParam(":MinimumMembershipLevel", $MinimumMembershipLevel, PDO::PARAM_INT); + $m->bindParam(":ContentRatingTypeId", $ContentRatingTypeId, PDO::PARAM_INT); + $m->bindParam(":Favorited", $Favorited, PDO::PARAM_INT); + $m->bindParam(":Visited", $Visited, PDO::PARAM_INT); + $m->bindParam(":MaxPlayers", $MaxPlayers, PDO::PARAM_INT); + $m->bindParam(":UpVotes", $UpVotes, PDO::PARAM_INT); + $m->bindParam(":DownVotes", $DownVotes, PDO::PARAM_INT); + $m->bindParam(":Hash", $Hash, PDO::PARAM_STR); + $m->bindParam(":ThumbHash", $ThumbHash, PDO::PARAM_STR); + $m->execute(); + + $GLOBALS['pdo']->exec("UNLOCK TABLES"); //unlock since we are done with sensitive asset stuff + } + + public static function ConvertAssetUrlToId(int $asseturl) + { + if (strpos($asseturl, "rbxassetid://") !== false) { + return substr($asseturl, strpos($asseturl, "rbxassetid://")+13, strlen($asseturl)); + } else if (strpos($asseturl, "id=") !== false) { + return substr($asseturl, strpos($asseturl, "id=")+3, strlen($asseturl)); + } + return false; + } + + public static function IsMeshSupported(string $meshstr) + { + if (strpos($meshstr, "version 1.00") !== false || strpos($meshstr, "version 1.01") !== false || strpos($meshstr, "version 2.00") !== false) { + return true; + } + return false; + } + + public static function SetAssetModerated(int $id) + { + $moderate = $GLOBALS['pdo']->prepare("UPDATE assets SET IsModerated = 1, IsApproved = 0, IsForSale = 0 WHERE id = :i"); + $moderate->bindParam(":i", $id, PDO::PARAM_INT); + $moderate->execute(); + } + + public static function SetAssetApproved(int $id) + { + $approve = $GLOBALS['pdo']->prepare("UPDATE assets SET IsApproved = 1, IsModerated = 0 WHERE id = :i"); + $approve->bindParam(":i", $id, PDO::PARAM_INT); + $approve->execute(); + } + + public static function IsAssetApproved(int $id) + { + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM assets WHERE id = :i AND IsApproved = 1"); + $check->bindParam(":i", $id, PDO::PARAM_INT); + $check->execute(); + return $check->fetchColumn() > 0; + } + + public static function IsModerated(int $id) + { + $check = $GLOBALS['pdo']->prepare("SELECT COUNT(*) FROM assets WHERE id = :i AND IsModerated = 1"); + $check->bindParam(":i", $id, PDO::PARAM_INT); + $check->execute(); + return $check->fetchColumn() > 0; + } + + public static function GetAssetInfo(int $id) + { + $check = $GLOBALS['pdo']->prepare("SELECT * FROM assets WHERE id = :i"); + $check->bindParam(":i", $id, PDO::PARAM_INT); + $check->execute(); + if($check->rowCount() > 0) { + return $check->fetch(PDO::FETCH_OBJ); + } + return false; + } + + public static function AddSale(int $assetid) + { + $sales = $GLOBALS['pdo']->prepare("UPDATE assets SET Sales = (Sales + 1) WHERE id = :i"); + $sales->bindParam(":i", $assetid, PDO::PARAM_INT); + $sales->execute(); + if ($sales->rowCount() > 0) { + return true; + } + return false; + } + + public static function GiveAsset(int $assetid, int $userid, int $givenby=1) + { + $setitem = $GLOBALS['pdo']->prepare("INSERT INTO owned_assets (uid, aid, when_sold, givenby) VALUES (:d, :a, UNIX_TIMESTAMP(), :b)"); + $setitem->bindParam(":d", $userid, PDO::PARAM_INT); + $setitem->bindParam(":a", $assetid, PDO::PARAM_INT); + $setitem->bindParam(":b", $givenby, PDO::PARAM_INT); + $setitem->execute(); + if ($setitem->rowCount() > 0) { + return true; + } + return false; + } } } diff --git a/globals/Dependencies/Assets/AssetType.php b/globals/Dependencies/Assets/AssetType.php new file mode 100644 index 0000000..186ee98 --- /dev/null +++ b/globals/Dependencies/Assets/AssetType.php @@ -0,0 +1,153 @@ +ConvertToString($assetTypeId); + switch ($string) { + case "Lua": + case "HTML": + case "Text": + case "Group Emblem": + case "App": + case "Code": + return $string; + default: + return $string . "s"; + } + } + + public function TypeToMaxCosmetic(int $assetTypeId): int + { + switch ($assetTypeId) { + case 8: //hat + return 5; + case 2: //tshirt + return 1; + case 11: //shirt + return 1; + case 12: //pants + return 1; + case 18: //face + return 1; + case 19: //gear + return 1; + case 17: //head + return 1; + case 32: //package + return 1; + default: //what? + return 0; + } + } + + public function IsWearable(int $assetTypeId): bool + { + switch ($assetTypeId) { + case 8: + case 2: + case 11: + case 12: + case 18: + case 19: + case 17: + case 32: + return true; + default: + return false; + } + } + } +} diff --git a/globals/Dependencies/Common/ContentDelivery.php b/globals/Dependencies/Common/ContentDelivery.php new file mode 100644 index 0000000..0586437 --- /dev/null +++ b/globals/Dependencies/Common/ContentDelivery.php @@ -0,0 +1,25 @@ +prepare("INSERT INTO transaction_logs (info, amount, userid, whenTransaction) VALUES (:info, :amount, :userid, UNIX_TIMESTAMP())"); @@ -60,5 +64,41 @@ namespace Alphaland\Economy { } return false; } + + public static function PurchaseItem(int $userid, int $assetid) + { + $assetInfo = Asset::GetAssetInfo($assetid); + if (!$assetInfo || + !$assetInfo->IsForSale || + User::OwnsAsset($userid, $assetid) || + Asset::IsModerated($assetid)) { + throw new Exception('Error occurred'); + } else if (!EconomyHelper::HasEnoughAlphabux($assetInfo->PriceInAlphabux, $userid)) { + throw new Exception('You do not have enough Alphabux to purchase this item'); + } else { + $creatorid = $assetInfo->CreatorId; + $price = $assetInfo->PriceInAlphabux; + + if (!EconomyHelper::RemoveAlphabux($price, $userid, "Giving item ".$assetid)) { + throw new Exception(''); + } + + //tax calc + if ($creatorid != 1) { + $price = $price - EconomyHelper::tax * $price; + } + + if (!EconomyHelper::GiveAlphabux($price, $creatorid, "Giving item purchase ".$assetid." Alphabux to creatorid ".$creatorid)) { + throw new Exception(''); + } else if (!Asset::GiveAsset($assetid, $userid, $creatorid)) { + throw new Exception(''); + } + + if (Asset::AddSale($assetid)) { + return true; + } + return false; + } + } } } diff --git a/globals/Dependencies/Games/Game.php b/globals/Dependencies/Games/Game.php index 21d014c..297f97b 100644 --- a/globals/Dependencies/Games/Game.php +++ b/globals/Dependencies/Games/Game.php @@ -234,6 +234,34 @@ namespace Alphaland\Games { return WebsiteSettings::GetSetting("isGameServerAlive"); } + public static function RemovePersonalBuildServerRank(int $placeid, int $userid) + { + $remove = $GLOBALS['pdo']->prepare("DELETE FROM personal_build_ranks WHERE placeid = :pid AND userid = :uid"); + $remove->bindParam(":pid", $placeid, PDO::PARAM_INT); + $remove->bindParam(":uid", $userid, PDO::PARAM_INT); + $remove->execute(); + if ($remove->rowCount() > 0) { + return true; + } + return false; + } + + public static function GetPersonalBuildServerRank(int $placeid, int $userid) + { + if ($userid == Asset::GetAssetInfo($placeid)->CreatorId) { + return 255; + } else { + $rank = $GLOBALS['pdo']->prepare("SELECT * FROM personal_build_ranks WHERE placeid = :pid AND userid = :uid"); + $rank->bindParam(":pid", $placeid, PDO::PARAM_INT); + $rank->bindParam(":uid", $userid, PDO::PARAM_INT); + $rank->execute(); + if ($rank->rowCount() > 0) { + return $rank->fetch(PDO::FETCH_OBJ)->rank; + } + } + return 10; //no rank. consider them Visitor rank + } + public static function PersonalBuildRankToName($rank) { switch ($rank) diff --git a/globals/Dependencies/Moderation/AssetModerationManager.php b/globals/Dependencies/Moderation/AssetModerationManager.php new file mode 100644 index 0000000..a8d2bf0 --- /dev/null +++ b/globals/Dependencies/Moderation/AssetModerationManager.php @@ -0,0 +1,10 @@ +isStaff()) { + if($GLOBALS['user']->IsStaff()) { if (userExists($uid)) { $unban = $GLOBALS['pdo']->prepare("DELETE FROM user_bans WHERE uid = :u"); $unban->bindParam(":u", $uid, PDO::PARAM_INT); @@ -46,7 +46,7 @@ namespace Alphaland\Moderation { // Nikita: TODO: Convert the bantype to a an enum public static function BanUser(int $uid, string $reason, int $banexpiration, int $bantype) { - if($GLOBALS['user']->isStaff()) { + if($GLOBALS['user']->IsStaff()) { if (userExists($uid)) { $isstaffcheck = $GLOBALS['pdo']->prepare("SELECT * FROM `users` WHERE `id` = :i AND `rank` > 0"); $isstaffcheck->bindParam(":i", $uid, PDO::PARAM_INT); diff --git a/globals/Dependencies/Users/ReferralProgram.php b/globals/Dependencies/Users/ReferralProgram.php index 4ec9460..ab4717d 100644 --- a/globals/Dependencies/Users/ReferralProgram.php +++ b/globals/Dependencies/Users/ReferralProgram.php @@ -8,14 +8,14 @@ namespace Alphaland\Users { use Alphaland\Moderation\UserModerationManager; use Alphaland\Common\HashingUtiltity; - use Alphaland\Users\User; + use Alphaland\Groups\Group; use PDO; class ReferralProgram { public static function IsMember(int $userid) { - if (User::IsInGroup($userid, 22)) //id 22 is the official referral program group + if (Group::IsInGroup($userid, 22)) //id 22 is the official referral program group { return true; } diff --git a/globals/config.php b/globals/config.php index f98bfb5..affb3de 100644 --- a/globals/config.php +++ b/globals/config.php @@ -27,7 +27,8 @@ try //PDO $pdoOptions = array( - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //bad for prod? + //PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => true ); @@ -105,9 +106,9 @@ try include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Users/ReferralProgram.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Moderation/UserModerationManager.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Common/HashingUtiltity.php"; - include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/IpRange.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Web/WebContextManager.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Common/System.php"; + include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Assets/Asset.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Games/Game.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Grid/RccServiceHelper.php"; include "C:/Webserver/nginx/Alphaland/globals/Dependencies/Assets/Render.php"; diff --git a/globals/functions.php b/globals/functions.php index 5c66b31..5c57ff7 100644 --- a/globals/functions.php +++ b/globals/functions.php @@ -6,11 +6,11 @@ TODO: clean up a lot of legacy code */ +use Alphaland\Assets\Asset; use Alphaland\Assets\Render; use Alphaland\Games\Game; use Alphaland\Moderation\Filter; use Alphaland\Users\Render as UsersRender; -use Alphaland\Users\User; use Alphaland\Web\WebContextManager; use Alphaland\Web\WebsiteSettings; @@ -252,39 +252,6 @@ function updateBuildServerRank($placeid, $userid, $rank) return "Error occurred"; } -function getBuildServerRank($placeid, $userid) -{ - if ($userid == getAssetInfo($placeid)->CreatorId) - { - return 255; - } - else - { - $rank = $GLOBALS['pdo']->prepare("SELECT * FROM personal_build_ranks WHERE placeid = :pid AND userid = :uid"); - $rank->bindParam(":pid", $placeid, PDO::PARAM_INT); - $rank->bindParam(":uid", $userid, PDO::PARAM_INT); - $rank->execute(); - if ($rank->rowCount() > 0) - { - return $rank->fetch(PDO::FETCH_OBJ)->rank; - } - } - return 10; //no rank. consider them Visitor rank -} - -function removePBSUser($placeid, $userid) -{ - $remove = $GLOBALS['pdo']->prepare("DELETE FROM personal_build_ranks WHERE placeid = :pid AND userid = :uid"); - $remove->bindParam(":pid", $placeid, PDO::PARAM_INT); - $remove->bindParam(":uid", $userid, PDO::PARAM_INT); - $remove->execute(); - if ($remove->rowCount() > 0) - { - return true; - } - return "Error occurred"; -} - function updatePBSGameSettings($placeid, $name, $description, $commentsenabled, $whitelistenabled, $maxplayers) { if (isOwner($placeid) && getAssetInfo($placeid)->isPersonalServer == 1) @@ -560,7 +527,7 @@ function submitRobloxAssetWorker($requestedassetid, $assettypeid, $assetname, $a $newassetid = uploadXML($xml, $assetname, $assetdescription, $price, $onsale, $assettypeid, 1); if ($newassetid !== FALSE) { - giveItem(1, $newassetid); //give the user Alphaland the created asset + Asset::GiveAsset($newassetid, 1); //give the user Alphaland the created asset $assettypeid = getAssetInfo($newassetid)->AssetTypeId; switch ($assettypeid) { @@ -1876,127 +1843,6 @@ function itemSalesCount($id) return $check->Sales; } -function giveCurrency($amount, $userid) -{ - //log the transaction - $info = "Gave user ".$userid." ".$amount; - $log = $GLOBALS['pdo']->prepare("INSERT INTO transaction_logs (info, amount, userid, whenTransaction) VALUES (:info, :amount, :userid, UNIX_TIMESTAMP())"); - $log->bindParam(":info", $info, PDO::PARAM_STR); - $log->bindParam(":amount", $amount, PDO::PARAM_INT); - $log->bindParam(":userid", $userid, PDO::PARAM_INT); - $log->execute(); - - $check = $GLOBALS['pdo']->prepare("UPDATE users SET currency = (currency + :u) WHERE id = :i"); - $check->bindParam(":i", $userid, PDO::PARAM_INT); - $check->bindParam(":u", $amount, PDO::PARAM_INT); - $check->execute(); -} - -function removeCurrency($amount, $info="") -{ - $localuser = $GLOBALS['user']->id; - $playercurrency = $GLOBALS['user']->currency; - - if ($playercurrency >= $amount) //if player currency is greater than or equal to the amount to remove - { - //log the transaction - $log = $GLOBALS['pdo']->prepare("INSERT INTO transaction_logs (info, amount, userid, whenTransaction) VALUES (:info, :amount, :userid, UNIX_TIMESTAMP())"); - $log->bindParam(":info", $info, PDO::PARAM_STR); - $log->bindParam(":amount", $amount, PDO::PARAM_INT); - $log->bindParam(":userid", $localuser, PDO::PARAM_INT); - $log->execute(); - - //remove amount from user - $check = $GLOBALS['pdo']->prepare("UPDATE users SET currency = (currency - :u) WHERE id = :i"); - $check->bindParam(":i", $localuser, PDO::PARAM_INT); - $check->bindParam(":u", $amount, PDO::PARAM_INT); - $check->execute(); - return true; - } - return false; -} - -function giveItem($uid, $id) -{ - //give the user the item - $setitem = $GLOBALS['pdo']->prepare("INSERT INTO owned_assets (uid, aid, when_sold, givenby) VALUES (:d, :a, UNIX_TIMESTAMP(), :b)"); - $setitem->bindParam(":d", $uid, PDO::PARAM_INT); - $setitem->bindParam(":a", $id, PDO::PARAM_INT); - $setitem->bindParam(":b", $GLOBALS['user']->id, PDO::PARAM_INT); - if ($setitem->execute()) - { - return true; - } - // ... - return false; -} - -function buyItem($id) //0 = not enough currency, 1 = already owned, 2 = bought, 3 = error -{ - $localuser = $GLOBALS['user']->id; - $playercurrency = $GLOBALS['user']->currency; - - $iteminfo = getAssetInfo($id); - $itemprice = $iteminfo->PriceInAlphabux; - $itemcreator = $iteminfo->CreatorId; - $onsale = $iteminfo->IsForSale; - - if (!isAssetModerated($id)) - { - if ($onsale == 1) //if asset is onsale - { - if ($playercurrency >= $itemprice) //if the player has greater or equal amount of currency required - { - if (User::OwnsAsset($localuser, $id)) //if player owns the asset - { - return 1; //already owned - } - else //everything passed, do the do - { - $tax = 0.30; //tax percentage - $taxtoremove = 0; - if ($itemcreator != 1) //we dont want to tax the account Alphaland items - { - $taxtoremove = $tax * $itemprice; - } - - removeCurrency($itemprice, "Purchase of asset ".$id); - - //give creator of the item the currency, remove tax depending on the item - $itemprice = $itemprice - $taxtoremove; //remove tax (if any) - - $check = $GLOBALS['pdo']->prepare("UPDATE users SET currency = (currency + :u) WHERE id = :i"); - $check->bindParam(":i", $itemcreator, PDO::PARAM_INT); - $check->bindParam(":u", $itemprice, PDO::PARAM_INT); - $check->execute(); - // ... - - //give the user the item - $setitem = $GLOBALS['pdo']->prepare("INSERT INTO owned_assets (uid, aid, when_sold, givenby) VALUES (:d, :a, UNIX_TIMESTAMP(), :b)"); - $setitem->bindParam(":d", $localuser, PDO::PARAM_INT); - $setitem->bindParam(":a", $id, PDO::PARAM_INT); - $setitem->bindParam(":b", $itemcreator, PDO::PARAM_INT); - $setitem->execute(); - // ... - - //sales + 1 - $sales = $GLOBALS['pdo']->prepare("UPDATE assets SET Sales = (Sales + 1) WHERE id = :i"); - $sales->bindParam(":i", $id, PDO::PARAM_INT); - $sales->execute(); - // ... - - return 2; //bought - } - } - else - { - return 0; //not enough currency - } - } - } - return 3; -} - function isOwner($id, $userid=NULL) { if ($userid === NULL){ diff --git a/html/Game/ClientPresence.php b/html/Game/ClientPresence.php index 80513e6..c4c518b 100644 --- a/html/Game/ClientPresence.php +++ b/html/Game/ClientPresence.php @@ -2,6 +2,7 @@ //the design choice here was to tie in clientpresence with recently played and visits and make it fully server-sided besides the client pings +use Alphaland\Economy\EconomyHelper; use Alphaland\Games\Game; use Alphaland\Web\WebContextManager; @@ -143,7 +144,7 @@ else if ($action == "connect") $setgamevisit->bindParam(":g", $placeid, PDO::PARAM_INT); $setgamevisit->execute(); - giveCurrency(1, $creatorid); + EconomyHelper::GiveAlphabux(1, $creatorid, "Place visit reward, placeid ".$placeid); } // ... } diff --git a/html/Studio/IDE/Publish/uploadnewasset.php b/html/Studio/IDE/Publish/uploadnewasset.php index d9a2d61..bbbe8cd 100644 --- a/html/Studio/IDE/Publish/uploadnewasset.php +++ b/html/Studio/IDE/Publish/uploadnewasset.php @@ -5,6 +5,7 @@ Alphaland 2021 The purpose of this is to upload SolidModels (Unions) from studio, since studio does not serialize the actual Union */ +use Alphaland\Assets\Asset; use Alphaland\Assets\Render; $assetTypeName = $_GET['assetTypeName']; @@ -139,7 +140,7 @@ if ($assetTypeName && $name && $isPublic && $allowComments) { Render::RenderModel($newitem); //if first fail do it again } - giveItem($user->id, $newitem); + Asset::GiveAsset($newitem, $user->id, $user->id); } } } diff --git a/html/catalog/view.php b/html/catalog/view.php index 64a0846..b105a42 100644 --- a/html/catalog/view.php +++ b/html/catalog/view.php @@ -1,5 +1,6 @@ You don't have enough Alphabux"; - } - elseif ($result == 1) - { - $alert = "