Uploaded asset"; } if ($placesuccess) { $alert = ""; } if ($pbssuccess) { $alert = ""; } function uploadCosmetic() { //upload directories $uploadDirectory = $GLOBALS['assetCDNPath']; //directory where the assets are stored $textureUploadDirectory = $GLOBALS['thumbnailCDNPath']; //directory where the textures are stored $xmlTemplatesDirectory = "../../default_xmls/"; //path to default xml directory //allowed image types $types = array('image/png'); //generate new hashes $xmlhash = genAssetHash(16); $texturehash = genAssetHash(16); //post variables $price = (int)$_POST['asset_price']; $image = $_FILES['asset_file']['tmp_name']; $name = $_POST['asset_name']; $description = $_POST['asset_desc']; //variables used for checks $assettype = -1; $minimumprice = 0; $maxwidth = 0; $maxheight = 0; $xmlfile = ""; $isapproved = false; $onsale = false; //time for a lot of checks //onsale if (isset($_POST['onsale_checkbox'])) { $onsale = true; } //chosen asset type if (isset($_POST['tshirt_checkbox'])) { $xmlfile = $xmlTemplatesDirectory . "tshirts"; $minimumprice = 2; $assettype = 2; $maxwidth = 2048; $maxheight = 2048; } elseif (isset($_POST['shirt_checkbox'])) { $xmlfile = $xmlTemplatesDirectory . "shirts"; $minimumprice = 5; $assettype = 11; $maxwidth = 585; $maxheight = 559; } elseif (isset($_POST['pants_checkbox'])) { $xmlfile = $xmlTemplatesDirectory . "pants"; $minimumprice = 5; $assettype = 12; $maxwidth = 585; $maxheight = 559; } else { return "Please choose an asset type"; } //price if ($onsale) { if (!is_int($price)) //price isnt integer { return "Price must be an integer"; } if ($price < $minimumprice) { return "Price too low, must be atleast " . $minimumprice . " Alphabux"; } if ($price < 1) { return "Price cannot be 0"; } } else { $price = 0; } //check if image is posted if (!file_exists($image) || !is_uploaded_file($image)) { return "Please provide an image"; } //verify that its a valid .png or .jpeg via mimetype, if shirt or pants verify the template is valid $type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $image); if (in_array($type, $types)) { //check dimensions $imagedetails = getimagesize($image); $width = $imagedetails[0]; $height = $imagedetails[1]; //verify dimensions of shirts or pants and if png if ($assettype == 11 || $assettype == 12) //11 is shirt, 12 is pants { if ($width != $maxwidth || $height != $maxheight || !in_array($type, array('image/png'))) //invalid template { return "Invalid template provided"; } } else { //check if image is too large if ($width > $maxwidth || $height > $maxheight) //too big { return "Image is too big"; } } } else { return "Invalid image, must be png"; } //name checks if (strlen($name) > 50) { return "Provided name is too long"; } if (strlen($name) < 3) { return "Provided name is too short"; } //description check if (strlen($description) > 1000) { return "Provided description too long"; } //remove currency if (!removeCurrency($minimumprice, "Creation of cosmetic name ".$name)) { return "You don't have enough currency"; } //POINT OF NO RETURN, ALL CHECKS PASSED //setup the new asset in the DB, lock it! $GLOBALS['pdo']->exec("LOCK TABLES assets WRITE"); //lock since this stuff is sensitive $b = $GLOBALS['pdo']->prepare("SELECT * FROM assets"); $b->execute(); //grab auto increment values $autoincrement = $b->rowCount() + 1; //initial auto increment value $autoincrement2 = $autoincrement+1; //initial auto increment value + 1 //add XML (selected type) to assets $m = $GLOBALS['pdo']->prepare("INSERT INTO `assets`(`id`, `AssetTypeId`, `Name`, `Description`, `Created`, `Updated`, `CreatorId`, `TargetId`, `PriceInAlphabux`, `Sales`, `IsNew`, `IsForSale`, `IsPublicDomain`, `IsLimited`, `IsLimitedUnique`, `IsApproved`, `Remaining`, `MinimumMembershipLevel`, `ContentRatingTypeId`, `Favorited`, `Visited`, `MaxPlayers`, `UpVotes`, `DownVotes`, `Hash`) VALUES (:aid,:atid,:aname,:adesc,UNIX_TIMESTAMP(),UNIX_TIMESTAMP(),:oid,:aid2,:price,0,0,:onsale,1,0,0,:ia,0,0,0,0,0,8,0,0,:hash)"); $m->bindParam(":aid", $autoincrement, PDO::PARAM_INT); $m->bindParam(":atid", $assettype, PDO::PARAM_INT); $m->bindParam(":aname", $name, PDO::PARAM_STR); $m->bindParam(":adesc", $description, PDO::PARAM_STR); $m->bindParam(":oid", $GLOBALS['user']->id, PDO::PARAM_STR); $m->bindParam(":aid2", $autoincrement, PDO::PARAM_INT); $m->bindParam(":ia", $isapproved, PDO::PARAM_INT); $m->bindParam(":price", $price, PDO::PARAM_INT); $m->bindParam(":onsale", $onsale, PDO::PARAM_INT); $m->bindParam(":hash", $xmlhash, PDO::PARAM_STR); $m->execute(); //add texture to assets $name = $name . " Texture"; $x = $GLOBALS['pdo']->prepare("INSERT INTO `assets`(`id`, `AssetTypeId`, `Name`, `Description`, `Created`, `Updated`, `CreatorId`, `TargetId`, `PriceInAlphabux`, `Sales`, `IsNew`, `IsForSale`, `IsPublicDomain`, `IsLimited`, `IsLimitedUnique`, `IsApproved`, `Remaining`, `MinimumMembershipLevel`, `ContentRatingTypeId`, `Favorited`, `Visited`, `MaxPlayers`, `UpVotes`, `DownVotes`, `Hash`) VALUES (:aid,1,:aname,'Shirt Image',UNIX_TIMESTAMP(),UNIX_TIMESTAMP(),:oid,:aid2,0,0,0,0,1,0,0,:ia,0,0,0,0,0,8,0,0,:hash)"); $x->bindParam(":aid", $autoincrement2, PDO::PARAM_INT); $x->bindParam(":aname", $name, PDO::PARAM_STR); $x->bindParam(":oid", $GLOBALS['user']->id, PDO::PARAM_INT); $x->bindParam(":aid2", $autoincrement2, PDO::PARAM_INT); $x->bindParam(":ia", $isapproved, PDO::PARAM_INT); $x->bindParam(":hash", $texturehash, PDO::PARAM_STR); $x->execute(); //unlock since we are done with sensitive asset stuff $GLOBALS['pdo']->exec("UNLOCK TABLES"); //give the creator the asset giveItem($GLOBALS['user']->id, $autoincrement); //upload texture and edit xml template, copy to assets move_uploaded_file($image, $textureUploadDirectory . $texturehash); $str = file_get_contents($xmlfile); $str=str_replace("TEXTUREURLPLACEHOLDER", $GLOBALS['url'] . "/asset/?id=" . $autoincrement2, $str); file_put_contents($uploadDirectory . $xmlhash, $str); return true; } function newPlace() { //upload parameters $uploadDirectory = $GLOBALS['assetCDNPath']; //cdn where the game/asset is stored //post variables $name = $_POST['place_name']; $description = $_POST['place_desc']; //how many games the user has if (getAllGames($GLOBALS['user']->id)->rowCount() >= 6 && !$GLOBALS['user']->IsAdmin()) { return "Games limit reached"; } //name checks if (strlen($name) > 50) { return "Provided name is too long"; } if (strlen($name) < 3) { return "Provided name is too short"; } //description check if (strlen($description) > 1000) { return "Provided description too long"; } //POINT OF NO RETURN $newplace = createPlace($GLOBALS['user']->id, $name, $description, 12); WebContextManager::Redirect("/games/config?id=".$newplace); } function newPBSPlace($placetype) { $selectedPlacePath = "../../default_pbs_places/" . $placetype . ".rbxlx"; //post variables $name = $_POST['place_name']; $description = $_POST['place_desc']; //how many games the user has if (getAllGames($GLOBALS['user']->id)->rowCount() > 6 && !$GLOBALS['user']->IsAdmin()) { return "Games limit reached"; } //name checks if (strlen($name) > 50) { return "Provided name is too long"; } if (strlen($name) < 3) { return "Provided name is too short"; } //description check if (strlen($description) > 1000) { return "Provided description too long"; } //POINT OF NO RETURN $newpbs = createPBSPlace($GLOBALS['user']->id, $name, $description, 12, $selectedPlacePath); WebContextManager::Redirect("/games/pbs/config?id=".$newpbs); } if (isset($_POST['SubmitPBSSuperflat'])) { $upload = newPBSPlace("Superflat"); if ($upload !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?pbsSuccess=true'); } } if (isset($_POST['SubmitPBSRugged'])) { $upload = newPBSPlace("Rugged"); if ($upload !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?pbsSuccess=true'); } } if (isset($_POST['SubmitPBSHappyHome'])) { $upload = newPBSPlace("HappyHome"); if ($upload !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?pbsSuccess=true'); } } if (isset($_POST['SubmitPBSBaseplate'])) { $upload = newPBSPlace("Baseplate"); if ($upload !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?pbsSuccess=true'); } } if (isset($_POST['PBSNoSelection'])) { $alert = ""; } if (isset($_POST['SubmitAsset'])) { $upload = uploadCosmetic(); if ($upload !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?cosSuccess=true'); } } if (isset($_POST['SubmitPlace'])) { $place = newPlace(); if ($place !== true) { $alert = ""; } else { WebContextManager::Redirect('/create?placeSuccess=true'); } } $body = << {$alert}
Create
Create Cosmetic
Shirts/Pants costs 5 Alphabux to create, T-Shirts costs 2 Alphabux to create



Cosmetic Type
Create Place
This will create a default place, limit of 6 places
Create Personal Build Place
This will create a Personal Build Game with chosen template, limit of 6 places.
Place will be configurable after creation


EOT; pageHandler(); $ph->pageTitle("Create"); $ph->body = $body; $ph->output();