Repositories | Polyback | Log in to see private repositories
1,884 bytes | parent directory
<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';
// Create a place owned by the signed-in user (its file comes with the first publish).
// POST JSON {"name", "description", "era", "maxPlayers"} -> {"success", "id"}
use pizzaboxer\ProjectPolygon\API;
use pizzaboxer\ProjectPolygon\Catalog;
use pizzaboxer\ProjectPolygon\ClientVersions;
use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\Studio;
API::initialize(["method" => "POST"]);
$user = Studio::RequireUser();
$body = Studio::Body();
$name = trim((string) ($body["name"] ?? ""));
$description = (string) ($body["description"] ?? "");
$era = ClientVersions::Normalize($body["era"] ?? "") ?? "";
$maxPlayers = (int) ($body["maxPlayers"] ?? 12);
if ($err = Studio::ValidateName($name)) API::respond(400, false, $err);
if ($err = Studio::ValidateDescription($description)) API::respond(400, false, $err);
if (!in_array($era, ClientVersions::ALL, true)) API::respond(400, false, "Unknown era");
if ($maxPlayers < 1 || $maxPlayers > 20) API::respond(400, false, "Players must be between 1 and 20");
$count = Database::singleton()->run("SELECT COUNT(*) FROM assets WHERE creator = :u AND type = 9", [":u" => $user->id])->fetchColumn();
if ($count >= (int) ($user->PlaceSlots ?? 0) && !Studio::IsAdmin($user)) API::respond(403, false, "You've used all your place slots. Publish over one of your places instead.");
$id = Catalog::CreateAsset([
"type" => 9,
"creator" => $user->id,
"name" => $name,
"description" => $description,
"comments" => 1,
"PublicDomain" => 0,
"ServerRunning" => 0,
"MaxPlayers" => $maxPlayers,
"Access" => "Everyone",
"ActivePlayers" => 0,
"Visits" => 0,
"Version" => $era,
"ChatType" => "Classic",
"gear_attributes" => json_encode(Catalog::$GearAttributes),
"approved" => 1,
]);
API::respondCustom(["status" => 200, "success" => true, "id" => (int) $id]);