public function testStoreAsset()
 {
     $headers = array('X-Asset-Creator-Id' => (string) UUID::Random(), 'X-Asset-Id' => UUID::Zero);
     $r = new HttpRequest($this->server_url, HttpRequest::METH_POST);
     $r->addHeaders($headers);
     $r->AddPostFile(UUID::Random(), "eyewhite.tga", "image/tga");
     $r->send();
     $this->AssetSHA = sha1(file_get_contents('eyewhite.tga'));
     $this->assertEquals(201, $r->getResponseCode());
     if (file_exists('test.assetid')) {
         unlink('test.assetid');
     }
     file_put_contents('test.assetid', (string) UUID::Parse($r->getResponseHeader("X-Asset-Id")));
 }
 public function Execute($db, $params)
 {
     $ownerID = null;
     if (!isset($params['OwnerID'], $params['ContentType']) || !UUID::TryParse($params['OwnerID'], $ownerID)) {
         header("Content-Type: application/json", true);
         echo '{ "Message": "Invalid parameters" }';
         exit;
     }
     $contentType = $params['ContentType'];
     $sql = "SELECT * FROM Inventory WHERE OwnerID=:OwnerID AND Type='Folder' AND ContentType=:ContentType LIMIT 1";
     $sth = $db->prepare($sql);
     if ($sth->execute(array('OwnerID' => $ownerID, 'ContentType' => $contentType))) {
         if ($sth->rowCount() > 0) {
             $item = $sth->fetchObject();
             $folder = new InventoryFolder(UUID::Parse($item->ID));
             $folder->ParentID = UUID::Parse($item->ParentID);
             $folder->OwnerID = UUID::Parse($item->OwnerID);
             $folder->Name = $item->Name;
             $folder->ContentType = $item->ContentType;
             $folder->Version = $item->Version;
             $folder->ExtraData = $item->ExtraData;
             header("Content-Type: application/json", true);
             echo sprintf('{ "Success": true, "Folder": %s }', $folder->toOSD());
             exit;
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "Folder not found" }';
             exit;
         }
     } else {
         log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
         log_message('debug', sprintf("Query: %s", $sql));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Database query error" }';
         exit;
     }
 }
 public function __construct($name, $userid)
 {
     /* folder information */
     $Name = $name;
     $RootID = $userid;
     $parent_0 = UUID::Random();
     $parent_1 = UUID::Random();
     $parent_2 = UUID::Random();
     $parent_3 = UUID::Random();
     $parent_4 = UUID::Random();
     $parent_5 = UUID::Random();
     $parent_6 = UUID::Random();
     $parent_7 = UUID::Random();
     $parent_8 = UUID::Random();
     $parent_9 = UUID::Random();
     $parent_10 = UUID::Random();
     $parent_11 = UUID::Random();
     $parent_12 = UUID::Random();
     $parent_13 = UUID::Random();
     $parent_14 = UUID::Random();
     $this->gFolders = array($this->MakeFolder($RootID, UUID::Parse(UUID::Zero), $Name, 'application/vnd.ll.folder'), $this->MakeFolder($parent_0, $RootID, 'Objects', 'application/vnd.ll.primitive'), $this->MakeFolder($parent_1, $RootID, 'Gestures', 'application/vnd.ll.gesture'), $this->MakeFolder($parent_2, $RootID, 'Sounds', 'application/ogg'), $this->MakeFolder($parent_3, $RootID, 'Landmarks', 'application/vnd.ll.landmark'), $this->MakeFolder($parent_4, $RootID, 'Clothing', 'application/vnd.ll.clothing'), $this->MakeFolder($parent_5, $RootID, 'Calling Cards', 'application/vnd.ll.callingcard'), $this->MakeFolder($parent_6, $RootID, 'Photo Album', 'application/vnd.ll.snapshotfolder'), $this->MakeFolder($parent_7, $RootID, 'Scripts', 'application/vnd.ll.lsltext'), $this->MakeFolder($parent_8, $RootID, 'Notecards', 'application/vnd.ll.notecard'), $this->MakeFolder($parent_9, $RootID, 'Textures', 'image/x-j2c'), $this->MakeFolder($parent_10, $RootID, 'Trash', 'application/vnd.ll.trashfolder'), $this->MakeFolder($parent_11, $RootID, 'Lost and Found', 'application/vnd.ll.lostandfoundfolder'), $this->MakeFolder($parent_12, $RootID, 'Body Parts', 'application/vnd.ll.bodypart'), $this->MakeFolder($parent_13, $RootID, 'Animations', 'application/vnd.ll.animation'), $this->MakeFolder($parent_14, $parent_4, 'Default Outfit', 'application/octet-stream'));
     $this->gItems = array($this->MakeItem($parent_14, 'Default Eyes', '78d20332-9b07-44a2-bf74-3b368605f4b5', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'), $this->MakeItem($parent_14, 'Default Shape', '530a2614-052e-49a2-af0e-534bb3c05af0', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'), $this->MakeItem($parent_14, 'Default Shirt', '6a714f37-fe53-4230-b46f-8db384465981', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'), $this->MakeItem($parent_14, 'Default Skin', '5f787f25-f761-4a35-9764-6418ee4774c4', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'), $this->MakeItem($parent_14, 'Default Hair', 'dc675529-7ba5-4976-b91d-dcb9e5e36188', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'), $this->MakeItem($parent_14, 'Default Pants', '3e8ee2d6-4f21-4a55-832d-77daa505edff', 'fd6e9c85-2fc3-478d-ad1b-e9bd382b78a9', '{}'));
     $this->gAppearance = array('serial' => 1, 'height' => 1.8, 'hipoffset' => 0, 'wearables' => array(array($this->MakeWearable($parent_14, 'Default Shape', '530a2614-052e-49a2-af0e-534bb3c05af0')), array($this->MakeWearable($parent_14, 'Default Skin', '5f787f25-f761-4a35-9764-6418ee4774c4')), array($this->MakeWearable($parent_14, 'Default Hair', 'dc675529-7ba5-4976-b91d-dcb9e5e36188')), array($this->MakeWearable($parent_14, 'Default Eyes', '78d20332-9b07-44a2-bf74-3b368605f4b5')), array($this->MakeWearable($parent_14, 'Default Shirt', '6a714f37-fe53-4230-b46f-8db384465981')), array($this->MakeWearable($parent_14, 'Default Pants', '3e8ee2d6-4f21-4a55-832d-77daa505edff')), array(), array(), array(), array(), array(), array(), array(), array(), array()));
 }
 private function GetDescendant($item)
 {
     $descendant = NULL;
     if ($item->Type == 'Folder') {
         $descendant = new InventoryFolder(UUID::Parse($item->ID));
         if (!UUID::TryParse($item->ParentID, $descendant->ParentID)) {
             $descendant->ParentID = UUID::Parse(UUID::Zero);
         }
         $descendant->OwnerID = UUID::Parse($item->OwnerID);
         $descendant->Name = $item->Name;
         $descendant->ContentType = $item->ContentType;
         $descendant->Version = $item->Version;
         $descendant->ExtraData = $item->ExtraData;
     } else {
         $descendant = new InventoryItem(UUID::Parse($item->ID));
         $descendant->AssetID = UUID::Parse($item->AssetID);
         $descendant->ParentID = UUID::Parse($item->ParentID);
         $descendant->OwnerID = UUID::Parse($item->OwnerID);
         $descendant->CreatorID = UUID::Parse($item->CreatorID);
         $descendant->Name = $item->Name;
         $descendant->Description = $item->Description;
         $descendant->ContentType = $item->ContentType;
         $descendant->Version = $item->Version;
         $descendant->ExtraData = $item->ExtraData;
         $descendant->CreationDate = gmdate('U', (int) $item->CreationDate);
     }
     return $descendant;
 }
Example #5
0
 public static function fromOSD($osd)
 {
     if (!isset($osd)) {
         return NULL;
     }
     if (!is_array($osd)) {
         $osd = json_decode($osd, true);
     }
     if (!isset($osd)) {
         return NULL;
     }
     $session = new Session();
     $session->UserID = UUID::Parse($osd['UserID']);
     $session->SessionID = UUID::Parse($osd['SessionID']);
     $session->SecureSessionID = UUID::Parse($osd['SecureSessionID']);
     $session->SceneID = UUID::Parse($osd['SceneID']);
     $session->ScenePosition = Vector3::Parse($osd['ScenePosition']);
     $session->SceneLookAt = Vector3::Parse($osd['SceneLookAt']);
     $session->ExtraData = json_decode($osd['ExtraData']);
     return $session;
 }
 public function Folders()
 {
     $skeleton = array(array('ID' => $this->RootID, 'ParentID' => UUID::Parse(UUID::Zero), 'Name' => $this->Name, 'PreferredContentType' => 'application/vnd.ll.folder'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Animations', 'PreferredContentType' => 'application/vnd.ll.animation'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Body Parts', 'PreferredContentType' => 'application/vnd.ll.bodypart'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Calling Cards', 'PreferredContentType' => 'application/vnd.ll.callingcard'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Gestures', 'PreferredContentType' => 'application/vnd.ll.gesture'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Landmarks', 'PreferredContentType' => 'application/vnd.ll.landmark'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Lost and Found', 'PreferredContentType' => 'application/vnd.ll.lostandfoundfolder'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Notecards', 'PreferredContentType' => 'application/vnd.ll.notecard'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Objects', 'PreferredContentType' => 'application/vnd.ll.primitive'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Photo Album', 'PreferredContentType' => 'application/vnd.ll.snapshotfolder'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Scripts', 'PreferredContentType' => 'application/vnd.ll.lsltext'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Sounds', 'PreferredContentType' => 'application/ogg'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Textures', 'PreferredContentType' => 'image/x-j2c'), array('ID' => UUID::Random(), 'ParentID' => $this->RootID, 'Name' => 'Trash', 'PreferredContentType' => 'application/vnd.ll.trashfolder'), array('ID' => $this->ClothingID, 'ParentID' => $this->RootID, 'Name' => 'Clothing', 'PreferredContentType' => 'application/vnd.ll.clothing'), array('ID' => $this->OutfitID, 'ParentID' => $this->ClothingID, 'Name' => 'Default Outfit', 'PreferredContentType' => 'application/octet-stream'));
     return $skeleton;
 }
 public function Execute($db, $params)
 {
     if (!isset($params["OwnerID"]) || !UUID::TryParse($params["OwnerID"], $this->UserID)) {
         header("Content-Type: application/json", true);
         echo '{ "Message": "Invalid parameters" }';
         exit;
     }
     $this->Inventory = new ALT($db);
     $this->Name = 'My Inventory';
     $avtype = "DefaultAvatar";
     if (isset($params["AvatarType"])) {
         $avtype = $params["AvatarType"];
     }
     log_message('info', "Creating avatar inventory with type {$avtype}");
     try {
         $avtypehandler = AvatarInventoryFolderFactory::Create($avtype, $this->Name, $this->UserID);
     } catch (Exception $ex) {
         log_message('error', sprintf("Error occurred in avcreation %s", $ex));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Failed loading avatar template "' . $avtype . ': ' . $ex->getMessage() . ' }';
         exit;
     }
     if (!$avtypehandler) {
         // Handle error and return
         log_message('error', "Failed to create handler for avatar with type {$avtype}");
         header("Content-Type: application/json", true);
         echo '{ "Message": "Invalid parameters" }';
         exit;
     }
     $skeleton = $avtypehandler->Folders();
     $items = $avtypehandler->Items();
     $db->beginTransaction();
     for ($i = 0; $i < count($skeleton); $i++) {
         try {
             $Folder = new InventoryFolder($skeleton[$i]["ID"]);
             $Folder->ParentID = UUID::Parse($skeleton[$i]["ParentID"]);
             $Folder->OwnerID = $this->UserID;
             $Folder->Name = $skeleton[$i]["Name"];
             $Folder->ContentType = $skeleton[$i]["PreferredContentType"];
             if (!$this->Inventory->InsertNode($Folder)) {
                 $db->rollBack();
                 log_message('error', sprintf("Error occurred during folder creation: %s", $this->Inventory->LastError));
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Inventory creation error" }';
                 exit;
             }
         } catch (Exception $ex) {
             $db->rollBack();
             log_message('error', sprintf("Error occurred during query: %s", $ex));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     }
     for ($i = 0; $i < count($items); $i++) {
         try {
             $item = new InventoryItem($items[$i]['ID']);
             $item->ParentID = UUID::Parse($items[$i]['ParentID']);
             $item->OwnerID = $this->UserID;
             $creatorID = $this->UserID;
             if (array_key_exists('CreatorID', $items[$i])) {
                 $creatorID = UUID::Parse($items[$i]['CreatorID']);
             }
             $item->CreatorID = $creatorID;
             $item->Name = $items[$i]['Name'];
             $item->AssetID = UUID::Parse($items[$i]['AssetID']);
             if (array_key_exists('ExtraData', $items[$i])) {
                 $item->ExtraData = $items[$i]['ExtraData'];
             }
             if (!$this->Inventory->InsertNode($item)) {
                 $db->rollBack();
                 log_message('error', sprintf("Error occurred during item creation: %s", $this->Inventory->LastError));
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Inventory creation error" }';
                 exit;
             }
         } catch (Exception $ex) {
             $db->rollBack();
             log_message('error', sprintf("Error occurred during query: %s", $ex));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     }
     $db->commit();
     // Update this users appearance in the user service
     $appearance = $avtypehandler->Appearance();
     if ($appearance) {
         $response = update_appearance($this->UserID, $appearance);
         if (empty($response['Success'])) {
             header("Content-Type: application/json", true);
             echo sprintf('{ "Message": "%s" }', $response['Message']);
             exit;
         }
     }
     // Add any additional customizations
     $avtypehandler->Configure();
     // And return success
     header("Content-Type: application/json", true);
     echo sprintf('{"Success": true, "FolderID": "%s"}', $this->UserID);
     exit;
 }