This commit is contained in:
Github Enterprise 2021-12-31 09:30:36 +00:00
commit 87dbe20c7e
18 changed files with 488 additions and 184 deletions

View File

@ -0,0 +1,26 @@
<?php
namespace Alphaland\Administration {
use Alphaland\Grid\RccServiceHelper;
use PDO;
class Maintenance
{
public static function Enable($text = "Alphaland is currently under maintenance, check back later.")
{
$setmaintenance = $GLOBALS['pdo']->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();
}
}
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,153 @@
<?php
/*
Alphaland 2021
*/
namespace Alphaland\Assets {
class AssetType
{
public function IsPurchasable($id)
{
switch ($id) {
}
}
public function ConvertToString(int $assetTypeId): string
{
switch ($assetTypeId) {
case 0:
return "Product";
case 1:
return "Image";
case 2:
return "T-Shirt";
case 3:
return "Audio";
case 4:
return "Mesh";
case 5:
return "Lua";
case 6:
return "HTML";
case 7:
return "Text";
case 8:
return "Hat";
case 9:
return "Place";
case 10:
return "Model";
case 11:
return "Shirt";
case 12:
return "Pants";
case 13:
return "Decal";
case 16:
return "Avatar";
case 17:
return "Head";
case 18:
return "Face";
case 19:
return "Gear";
case 21:
return "Badge";
case 22:
return "Group Emblem";
case 24:
return "Animation";
case 25:
return "Arms";
case 26:
return "Legs";
case 27:
return "Torso";
case 28:
return "Right Arm";
case 29:
return "Left Arm";
case 30:
return "Left Leg";
case 31:
return "Right Leg";
case 32:
return "Package";
case 33:
return "YouTube Video";
case 34:
return "Game Pass";
case 35:
return "App";
case 37:
return "Code";
case 38:
return "Plugin";
case 39:
return "SolidModel";
case 40:
return "MeshPart";
default:
return "Asset";
}
}
public function ConvertToStringPlural(int $assetTypeId): string
{
$string = $this->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;
}
}
}
}

View File

@ -0,0 +1,25 @@
<?php
/*
Alphaland 2021
*/
namespace Alphaland\Common {
class ContentDelivery
{
public static function ConstructRenderHashUrl(string $hash)
{
return $GLOBALS['renderCDN']."/".$hash;
}
public static function ConstructThumbnailHashUrl(string $hash)
{
return $GLOBALS['thumbnailCDN']."/".$hash;
}
public static function ConstructAssetHashUrl(string $hash)
{
return $GLOBALS['assetCDN']."/".$hash;
}
}
}

View File

@ -6,11 +6,15 @@
namespace Alphaland\Economy {
use Alphaland\Assets\Asset;
use PDO;
use Alphaland\Users\User;
use Exception;
class EconomyHelper
class EconomyHelper
{
const tax = 0.30;
public static function LogTransaction(int $amount, int $userid, string $description)
{
$log = $GLOBALS['pdo']->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;
}
}
}
}

View File

@ -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)

View File

@ -0,0 +1,10 @@
<?php
namespace Alphaland\Moderation {
use PDO;
class AssetModerationManager
{
}
}

View File

@ -29,7 +29,7 @@ namespace Alphaland\Moderation {
public static function UnbanUser(int $uid)
{
if($GLOBALS['user']->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);

View File

@ -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;
}

View File

@ -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";

View File

@ -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){

View File

@ -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);
}
// ...
}

View File

@ -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);
}
}
}

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Economy\EconomyHelper;
use Alphaland\Users\User;
use Alphaland\Web\WebContextManager;
@ -13,18 +14,12 @@ if(isset($_GET['id']))
//handle purchasing items
if(isset($_POST['buyitem']))
{
$result = buyItem($id);
if ($result == 0)
{
$alert = "<div class='alert alert-danger' role='alert'>You don't have enough Alphabux</div>";
}
elseif ($result == 1)
{
$alert = "<div class='alert alert-danger' role='alert'>You already own this item</div>";
}
elseif ($result == 2)
{
WebContextManager::Redirect("/catalog/view?id=". $id . "");
try {
if (EconomyHelper::PurchaseItem($user->id, $id)) {
WebContextManager::Redirect("/catalog/view?id=". $id . "");
}
} catch (Exception $e) {
$alert = "<div class='alert alert-danger' role='alert'>".$e->getMessage()."</div>";
}
}
// ...

View File

@ -4,6 +4,8 @@
Alphaland 2021
*/
use Alphaland\Assets\Asset;
use Alphaland\Economy\EconomyHelper;
use Alphaland\Web\WebContextManager;
$body = '';
@ -171,7 +173,7 @@ function uploadCosmetic()
}
//remove currency
if (!removeCurrency($minimumprice, "Creation of cosmetic name ".$name))
if (!EconomyHelper::RemoveAlphabux($minimumprice, $GLOBALS['user']->id, "Creation of cosmetic name ".$name))
{
return "You don't have enough currency";
}
@ -217,7 +219,7 @@ function uploadCosmetic()
$GLOBALS['pdo']->exec("UNLOCK TABLES");
//give the creator the asset
giveItem($GLOBALS['user']->id, $autoincrement);
Asset::GiveAsset($autoincrement, $GLOBALS['user']->id, $GLOBALS['user']->id);
//upload texture and edit xml template, copy to assets
move_uploaded_file($image, $textureUploadDirectory . $texturehash);

View File

@ -1,5 +1,6 @@
<?php
use Alphaland\Assets\Asset;
use Alphaland\Web\WebContextManager;
WebContextManager::ForceHttpsCloudflare();
@ -52,7 +53,7 @@ if(isset($_POST['submitgiveasset']))
}
else
{
if (giveItem($userid, $catalogid))
if (Asset::GiveAsset($catalogid, $userid, $user->id))
{
$alert = "<div class='alert alert-success' role='alert'>Successfully gave user the item</div>";
}

View File

@ -6,6 +6,9 @@ Alphaland 2021
*/
//headers
use Alphaland\Games\Game;
header("Access-Control-Allow-Origin: https://www.alphaland.cc");
header("access-control-allow-credentials: true");
@ -21,7 +24,7 @@ $userid = $_GET['userId'];
$userInfo = array(
"data" => array(
"Rank" => getBuildServerRank($placeid, $userid),
"Rank" => Game::GetPersonalBuildServerRank($placeid, $userid),
)
);

View File

@ -64,7 +64,10 @@ else
else if ($removeuser)
{
$userid = $data->userid;
$message = removePBSUser($assetid, $userid);
$message = null;
if (Game::RemovePersonalBuildServerRank($assetid, $userid)) {
$message = true;
}
}
else if ($whitelistuser)
{