Repositories | Polyback | Log in to see private repositories
2,378 bytes | parent directory
<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';
// MarketplaceService:GetProductInfo(id) and PlayerOwnsAsset(player, id). Anybody may look.
// ?id=1 (&type=Product) -> the table the API returns ?id=1&owner=5 -> {"success":true,"owns":true}
// ?id=1&type=Product&owner=5 -> whether they bought that product and it wasn't taken back
// (GamePassService:PlayerHasPass; games ask when somebody joins)
use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\Catalog;
header("content-type: application/json");
function fail($message) { die(json_encode(["success" => false, "message" => $message])); }
$id = (int) ($_GET["id"] ?? 0);
if (isset($_GET["owner"]) && ($_GET["type"] ?? "") === "Product")
{
$owns = Database::singleton()->run(
"SELECT 1 FROM GamePurchases WHERE ProductID = :id AND UserID = :u AND Revoked = 0 LIMIT 1",
[":id" => $id, ":u" => (int) $_GET["owner"]]
)->fetchColumn();
die(json_encode(["success" => true, "owns" => (bool) $owns]));
}
if (isset($_GET["owner"])) die(json_encode(["success" => true, "owns" => (bool) Catalog::OwnsAsset((int) $_GET["owner"], $id)]));
if (($_GET["type"] ?? "") === "Product")
{
$p = Database::singleton()->run(
"SELECT p.*, a.creator, u.username FROM PlaceProducts p JOIN assets a ON a.id = p.PlaceID JOIN users u ON u.id = a.creator WHERE p.ID = :id", [":id" => $id]
)->fetch(PDO::FETCH_OBJ);
if (!$p) fail("There's no product with that id");
die(json_encode(["success" => true, "info" => ["ProductId" => (int) $p->ID, "AssetId" => 0, "Name" => $p->Name, "Description" => $p->Description,
"PriceInRobux" => (int) $p->Price, "IsForSale" => (bool) $p->Active, "Sales" => (int) $p->Sales, "AssetTypeId" => 0,
"Creator" => ["Id" => (int) $p->creator, "Name" => $p->username, "CreatorType" => "User", "CreatorTargetId" => (int) $p->creator]]]));
}
$a = Catalog::GetAssetInfo($id);
if (!$a) fail("There's no item with that id");
die(json_encode(["success" => true, "info" => ["AssetId" => (int) $a->id, "ProductId" => 0, "Name" => $a->name, "Description" => (string) $a->description,
"PriceInRobux" => $a->sale ? (int) $a->price : null, "IsForSale" => (bool) $a->sale, "Sales" => (int) ($a->Sales ?? 0), "AssetTypeId" => (int) $a->type,
"Creator" => ["Id" => (int) $a->creator, "Name" => $a->username, "CreatorType" => "User", "CreatorTargetId" => (int) $a->creator]]]));