Esempio n. 1
0
 public function distance($x = 0, $y = 0, $z = 0)
 {
     if ($x instanceof Position and $x->level !== $this->level) {
         return PHP_INT_MAX;
     }
     return parent::distance($x, $y, $z);
 }
 public function PlayerInteractHandler($data, $event)
 {
     if (!isset($data["target"])) {
         return false;
     }
     $target = $this->api->entity->get($data["target"]);
     if (!isset($target)) {
         return false;
     }
     $t = new Vector3($target->x, $target->y, $target->z);
     $s = new Vector3($this->server->spawn->x, $this->server->spawn->y, $this->server->spawn->z);
     $distance = $t->distance($s);
     if ($distance <= $this->server->api->getProperty("spawn-protection")) {
         return false;
     }
     return true;
 }
function handle_vector_parameter($paramName, $params, &$sql, &$dbValues, &$addComma)
{
    $vector = null;
    if (isset($params[$paramName]) && Vector3::TryParse($params[$paramName], $vector)) {
        if ($addComma) {
            $sql .= ",";
        } else {
            $addComma = TRUE;
        }
        $sql .= " {$paramName}=:{$paramName}";
        $dbValues[$paramName] = (string) $vector;
    }
}
 public function Execute($db, $params)
 {
     $sql = "SELECT * FROM Sessions WHERE";
     if (isset($params["UserID"]) && UUID::TryParse($params["UserID"], $this->ID)) {
         $sql .= " UserID=:ID";
     } else {
         if (isset($params["SessionID"]) && UUID::TryParse($params["SessionID"], $this->ID)) {
             $sql .= " SessionID=:ID";
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "Invalid parameters" }';
             exit;
         }
     }
     $sth = $db->prepare($sql);
     if ($sth->execute(array(':ID' => $this->ID))) {
         if ($sth->rowCount() > 0) {
             $obj = $sth->fetchObject();
             $session = new Session();
             $session->UserID = $obj->UserID;
             $session->SessionID = $obj->SessionID;
             $session->SecureSessionID = $obj->SecureSessionID;
             $session->SceneID = $obj->SceneID;
             $session->ScenePosition = Vector3::Parse($obj->ScenePosition);
             $session->SceneLookAt = Vector3::Parse($obj->SceneLookAt);
             $session->LastUpdate = $obj->LastUpdate;
             $session->ExtraData = $obj->ExtraData;
             if (empty($session->ExtraData)) {
                 $session->ExtraData = "{}";
             }
             $output = sprintf('{ "Success": true, "UserID": "%s", "SessionID": "%s", "SecureSessionID": "%s", "SceneID": "%s", "ScenePosition": %s, "SceneLookAt": %s, "ExtraData": %s }', $session->UserID, $session->SessionID, $session->SecureSessionID, $session->SceneID, $session->ScenePosition->toOSD(), $session->SceneLookAt->toOSD(), $session->ExtraData);
             header("Content-Type: application/json", true);
             echo $output;
             exit;
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "Session 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 static function fromOSD($osd)
 {
     if (!isset($osd)) {
         return NULL;
     }
     if (!is_array($osd)) {
         $osd = json_decode($osd, true);
     }
     if (!isset($osd, $osd['SceneID'], $osd['Position'], $osd['LookAt'])) {
         return NULL;
     }
     $location = new SceneLocation();
     $location->SceneID = $osd['SceneID'];
     if (Vector3::TryParse($osd['Position'], $location->Position) && Vector3::TryParse($osd['LookAt'], $location->LookAt)) {
         return $location;
     }
     return null;
 }
 private function HandleQueryResponse($sth)
 {
     $found = array();
     while ($obj = $sth->fetchObject()) {
         $session = new Session();
         $session->UserID = $obj->UserID;
         $session->SessionID = $obj->SessionID;
         $session->SecureSessionID = $obj->SecureSessionID;
         $session->SceneID = $obj->SceneID;
         $session->ScenePosition = Vector3::Parse($obj->ScenePosition);
         $session->SceneLookAt = Vector3::Parse($obj->SceneLookAt);
         $session->LastUpdate = $obj->LastUpdate;
         if (!is_null($obj->ExtraData)) {
             $session->ExtraData = $obj->ExtraData;
         } else {
             $session->ExtraData = "{}";
         }
         $found[] = $session->toOSD();
     }
     log_message('debug', 'returning ' . count($found));
     header("Content-Type: application/json", true);
     echo '{ "Success": true, "Sessions": [' . implode(',', $found) . '] }';
     exit;
 }
Esempio n. 7
0
 /**
  * 
  * @param Vector3 $b
  * @return \Communiverse\Genesis\Maths\Vector3
  */
 public function vectorProduct(Vector3 $b)
 {
     return new Vector3($this->getY() * $b->getZ() - $this->getZ() * $b->getY(), $this->getZ() * $b->getX() - $this->getX() * $b->getZ(), $this->getX() * $b->getY() - $this->getY() * $b->getX());
 }
Esempio n. 8
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;
     }
     $scene = new Scene();
     $scene->SceneID = $osd["SceneID"];
     $scene->Name = $osd["Name"];
     $scene->MinPosition = Vector3::Parse('<' . implode(',', $osd["MinPosition"]) . '>');
     $scene->MaxPosition = Vector3::Parse('<' . implode(',', $osd["MaxPosition"]) . '>');
     $scene->Address = $osd["Address"];
     $scene->Enabled = $osd["Enabled"];
     $scene->ExtraData = $osd["ExtraData"];
     return $scene;
 }
Esempio n. 9
0
function get_home_region($method_name, $params, $user_data)
{
    $response = array();
    $req = $params[0];
    $userID = $req['userID'];
    $response = array();
    log_message('info', "get_home_region called with UserID {$userID}");
    // Fetch the user
    $user = get_user($userID);
    if (empty($user)) {
        log_message('warn', "Unknown UserID {$userID}");
        $response['result'] = 'false';
        return $response;
    }
    $homeLocation = null;
    if (isset($user['HomeLocation'])) {
        $homeLocation = SceneLocation::fromOSD($user['HomeLocation']);
    }
    log_message('debug', "User retrieval success for {$userID}, HomeLocation is {$homeLocation}");
    $scene = null;
    $position = null;
    $lookat = null;
    // If the user's home is set, try to grab info for that scene
    if (isset($homeLocation)) {
        log_message('debug', sprintf("Looking up scene '%s'", $homeLocation->SceneID));
        $scene = lookup_scene_by_id($homeLocation->SceneID);
        if (isset($scene)) {
            $position = $homeLocation->Position;
            $lookat = $homeLocation->LookAt;
        }
    }
    // No home set, last resort lookup for *any* scene in the grid
    if (!isset($scene)) {
        $position = Vector3::Zero();
        log_message('debug', "Looking up scene closest to '{$position}'");
        $scene = lookup_scene_by_position($position, true);
        if (isset($scene)) {
            $position = new Vector3(($scene->MinPosition->X + $scene->MaxPosition->X) / 2 - $scene->MinPosition->X, ($scene->MinPosition->Y + $scene->MaxPosition->Y) / 2 - $scene->MinPosition->Y, 25);
            $lookat = new Vector3(1, 0, 0);
        }
    }
    if (isset($scene)) {
        $response['result'] = 'true';
        $response['uuid'] = $scene->SceneID;
        $response['x'] = $scene->MinPosition->X;
        $response['y'] = $scene->MinPosition->Y;
        $response['region_name'] = $scene->Name;
        $response['hostname'] = $scene->Address;
        $response['http_port'] = $scene->ExtraData['ExternalPort'];
        $response['internal_port'] = $scene->ExtraData['InternalPort'];
        $response['position'] = (string) $position;
        $response['lookAt'] = (string) $lookat;
        log_message('debug', "Returning successful home lookup for {$userID}");
    } else {
        $response['result'] = 'false';
        log_message('warn', "Failed to find a valid home scene for {$userID}, returning failure");
    }
    return $response;
}
 private function HandleQueryResponse($sth)
 {
     $found = array();
     $scenelist = "";
     while ($obj = $sth->fetchObject()) {
         $scene = new Scene();
         $scene->SceneID = $obj->ID;
         $scene->Name = $obj->Name;
         $scene->Enabled = $obj->Enabled;
         $scene->MinPosition = Vector3::Parse($obj->MinPosition);
         $scene->MaxPosition = Vector3::Parse($obj->MaxPosition);
         $scene->Address = $obj->Address;
         $scene->LastUpdate = $obj->LastUpdate;
         if (!is_null($obj->ExtraData)) {
             $scene->ExtraData = $obj->ExtraData;
         } else {
             $scene->ExtraData = "{}";
         }
         $found[] = $scene->toOSD();
         $scenelist = $scenelist . $scene->Name . ",";
     }
     log_message('debug', 'returning ' . count($found) . ' results : ' . $scenelist);
     header("Content-Type: application/json", true);
     echo '{ "Success": true, "Scenes": [' . implode(',', $found) . '] }';
     exit;
 }
Esempio n. 11
0
 public function CheckNearby()
 {
     $py = $this->api->player->online();
     $copy = $py;
     if (count($py) > 1) {
         //at least 2 players in server
         for ($i = 0; $i < count($py); $i++) {
             if ($i == count($py) - 1) {
                 break;
             }
             $p1 = $this->api->player->get($py[$i]);
             array_shift($copy);
             //remove the $p1 from the second array
             for ($e = 0; $e < count($copy); $e++) {
                 $p2 = $this->api->player->get($copy[$e]);
                 $p1vec = new Vector3($p1->entity->x, $p1->entity->y, $p1->entity->z);
                 $p2vec = new Vector3($p2->entity->x, $p2->entity->y, $p2->entity->z);
                 $range = round($p1vec->distance($p2vec));
                 //the number of blocks away from each other
                 $this->FindNearbyPlayers($p1->username, $p2->username);
                 $this->FindNearbyPlayers($p2->username, $p1->username);
                 //guys, my mind messed up here, help me see if im dong the correc tthings here -Junyi00
             }
         }
         $copy = $py;
     }
 }
Esempio n. 12
0
 public function touchingBlock(Vector3 $block, $radius = 0.9)
 {
     $me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
     if (($block->y == (int) $this->y - 1 or $block->y == (int) $this->y or $block->y == (int) $this->y + 1) and $block->maxPlainDistance($me) < $radius) {
         return true;
     }
     return false;
 }
 public function Execute($db, $params)
 {
     $this->Scene = new Scene();
     // Scene enabling
     if (!isset($params["SceneID"], $params["Name"], $params["MinPosition"], $params["MaxPosition"], $params["Address"], $params["Enabled"]) || !UUID::TryParse($params["SceneID"], $this->Scene->ID) || !Vector3::TryParse($params["MinPosition"], $this->Scene->MinPosition) || !Vector3::TryParse($params["MaxPosition"], $this->Scene->MaxPosition)) {
         // This clause should be removed at some point. It is superceded by the EnableScene
         // API and is only provided for backward compatibility with older OpenSim versions
         if (isset($params["SceneID"], $params["Enabled"]) && UUID::TryParse($params["SceneID"], $this->Scene->ID)) {
             // Scene enable/disable
             $sql = "UPDATE Scenes SET Enabled=:Enabled WHERE ID=:ID";
             $sth = $db->prepare($sql);
             if ($sth->execute(array(':ID' => $this->Scene->ID, ':Enabled' => $params["Enabled"]))) {
                 if ($sth->rowCount() > 0) {
                     header("Content-Type: application/json", true);
                     echo '{ "Success": true }';
                     exit;
                 } else {
                     log_message('error', "Failed updating the database (enabling)");
                     header("Content-Type: application/json", true);
                     echo '{ "Message": "Database update failed", "Success":false }';
                     exit;
                 }
             } else {
                 log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database query error", "Success":false }';
                 exit;
             }
         }
         // End of what needs to be removed
         log_message('error', sprintf("AddScene: Unable to parse passed parameters or parameter missing: '%s'", print_r($params, true)));
         header("Content-Type: application/json", true);
         echo '{ "Message": "Invalid parameters", "Success":false }';
         exit;
     }
     $this->Scene->Address = trim($params["Address"]);
     $this->Scene->Name = trim($params["Name"]);
     $this->Scene->Enabled = $params["Enabled"];
     if (isset($params["ExtraData"])) {
         $this->Scene->ExtraData = $params["ExtraData"];
     } else {
         $this->Scene->ExtraData = NULL;
     }
     $sql = "REPLACE INTO Scenes (ID, Name, MinX, MinY, MinZ, MaxX, MaxY, MaxZ, Address, Enabled, ExtraData, XYPlane) \n                    VALUES (:ID, :Name, :MinX, :MinY,  :MinZ, :MaxX, :MaxY, :MaxZ, :Address, :Enabled, :ExtraData, GeomFromText(:XY))";
     $sth = $db->prepare($sql);
     if ($sth->execute(array(':ID' => $this->Scene->ID, ':Name' => $this->Scene->Name, ':MinX' => $this->Scene->MinPosition->X, ':MinY' => $this->Scene->MinPosition->Y, ':MinZ' => $this->Scene->MinPosition->Z, ':MaxX' => $this->Scene->MaxPosition->X, ':MaxY' => $this->Scene->MaxPosition->Y, ':MaxZ' => $this->Scene->MaxPosition->Z, ':Address' => $this->Scene->Address, ':Enabled' => $this->Scene->Enabled, ':ExtraData' => $this->Scene->ExtraData, ':XY' => sprintf("POLYGON((%d %d, %d %d, %d %d, %d %d, %d %d))", $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y)))) {
         if ($sth->rowCount() > 0) {
             header("Content-Type: application/json", true);
             echo '{ "Success": true }';
             exit;
         } else {
             log_message('error', "Failed updating the database (replace)");
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database update failed", "Success":false }';
             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", "Success":false }';
         exit;
     }
 }
Esempio n. 14
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 Execute($db, $params)
 {
     $sql = "";
     if (isset($params["SceneID"]) && UUID::TryParse($params["SceneID"], $this->SceneID)) {
         log_message('debug', "GetScene by SceneID " . $params["SceneID"]);
         $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE ID='" . $this->SceneID . "'";
         if (isset($params["Enabled"]) && $params["Enabled"]) {
             $sql .= " AND Enabled=1";
         }
     } else {
         if (isset($params["Name"])) {
             log_message('debug', "GetScene by Name " . $params["Name"]);
             $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                    CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                    CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                    FROM Scenes WHERE Name='" . $params["Name"] . "'";
             if (isset($params["Enabled"]) && $params["Enabled"]) {
                 $sql .= " AND Enabled=1";
             }
         } else {
             if (isset($params["Position"]) && Vector3::TryParse($params["Position"], $this->Position)) {
                 if (isset($params["FindClosest"]) && $params["FindClosest"]) {
                     log_message('debug', "GetScene (closest) by position " . $this->Position);
                     $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                        CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                        CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition,\n                        GLength(LineString(GeomFromText('POINT(" . $this->Position->X . " " . $this->Position->Y . ")'), Centroid(XYPlane)))\n                        AS dist FROM Scenes";
                     $sql .= " WHERE ExtraData NOT REGEXP :RegExp";
                     if (isset($params["Enabled"]) && $params["Enabled"]) {
                         $sql .= " AND Enabled=1";
                     }
                     $sql .= " ORDER BY dist LIMIT 1";
                 } else {
                     log_message('debug', "GetScene by position " . $this->Position);
                     $sql = "SELECT ID, Name, Address, Enabled, ExtraData, LastUpdate,\n                        CONCAT('<', MinX, ',', MinY, ',', MinZ, '>') AS MinPosition,  \n                        CONCAT('<', MaxX, ',', MaxY, ',', MaxZ, '>') AS MaxPosition\n                        FROM Scenes WHERE MBRContains(XYPlane, GeomFromText('POINT(" . $this->Position->X . " " . $this->Position->Y . ")'))";
                     if (isset($params["Enabled"]) && $params["Enabled"]) {
                         $sql .= " AND Enabled=1";
                     }
                     $sql .= " LIMIT 1";
                 }
             } else {
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Invalid parameters" }';
                 exit;
             }
         }
     }
     log_message('debug', "what {$sql}");
     $sth = $db->prepare($sql);
     if (isset($params["FindClosest"]) && $params["FindClosest"]) {
         $sth->bindValue(':RegExp', '.+\\"HyperGrid\\":true.+');
     }
     if ($sth->execute()) {
         if ($sth->rowCount() > 0) {
             $obj = $sth->fetchObject();
             $scene = new Scene();
             $scene->SceneID = $obj->ID;
             $scene->Name = $obj->Name;
             $scene->Enabled = $obj->Enabled;
             $scene->MinPosition = Vector3::Parse($obj->MinPosition);
             $scene->MaxPosition = Vector3::Parse($obj->MaxPosition);
             $scene->Address = $obj->Address;
             $scene->LastUpdate = $obj->LastUpdate;
             if (!is_null($obj->ExtraData)) {
                 $scene->ExtraData = $obj->ExtraData;
             } else {
                 $scene->ExtraData = "{}";
             }
             $out = $scene->toOSD();
             $out = substr($out, 0, -1);
             $out .= ',"Success":true}';
             log_message('debug', "Found scene " . $scene->Name);
             header("Content-Type: application/json", true);
             echo $out;
             exit;
         } else {
             header("Content-Type: application/json", true);
             echo '{ "Message": "No matching scene 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;
     }
 }
Esempio n. 16
0
function find_start_location($start, $lastLocation, $homeLocation, &$scene, &$startPosition, &$startLookAt)
{
    $config =& get_config();
    $defaultLocation = $config['default_location'];
    $scene = null;
    if (strtolower($start) == "last") {
        if (isset($lastLocation)) {
            log_message('debug', sprintf("Finding start location (last) for '%s'", $lastLocation->SceneID));
            $scene = lookup_scene_by_id($lastLocation->SceneID);
            if (isset($scene)) {
                $startPosition = $lastLocation->Position;
                $startLookAt = $lastLocation->LookAt;
                return true;
            }
        }
    }
    if (strtolower($start) == "home") {
        if (isset($homeLocation)) {
            log_message('debug', sprintf("Finding start location (home) for '%s'", $homeLocation->SceneID));
            $scene = lookup_scene_by_id($homeLocation->SceneID);
            if (isset($scene)) {
                $startPosition = $homeLocation->Position;
                $startLookAt = $homeLocation->LookAt;
                return true;
            }
        }
    }
    if (preg_match('/^uri:([a-zA-Z0-9\\s-_]+)&(\\d+)&(\\d+)&(\\d+)$/', $start, $matches)) {
        log_message('debug', sprintf("Finding start location (custom: %s) for '%s'", $start, $matches[1]));
        $scene = lookup_scene_by_name($matches[1]);
        if (isset($scene)) {
            $startPosition = new Vector3($matches[2], $matches[3], $matches[4]);
            $startLookAt = new Vector3(1, 0, 0);
            return true;
        }
    }
    // Check to see if a valid default location has been set
    if (preg_match('/^([a-zA-Z0-9\\s-_]+)\\/(\\d+)\\/(\\d+)\\/(\\d+)$/', $defaultLocation, $matches)) {
        log_message('debug', sprintf("Finding start location (default: %s) for '%s'", $defaultLocation, $matches[1]));
        $scene = lookup_scene_by_name($matches[1]);
        if (isset($scene)) {
            $startPosition = new Vector3($matches[2], $matches[3], $matches[4]);
            $startLookAt = new Vector3(1, 0, 0);
            return true;
        }
    } else {
        log_message('info', 'No valid default_location set');
    }
    // Last resort lookup
    $position = Vector3::Zero();
    log_message('debug', sprintf("Finding start location (any: %s) for '%s'", $start, $position));
    $scene = lookup_scene_by_position($position, true);
    if (isset($scene)) {
        $startPosition = new Vector3(($scene->MinPosition->X + $scene->MaxPosition->X) / 2 - $scene->MinPosition->X, ($scene->MinPosition->Y + $scene->MaxPosition->Y) / 2 - $scene->MinPosition->Y, 25);
        $startLookAt = new Vector3(1, 0, 0);
        return true;
    }
    return false;
}
Esempio n. 17
0
 public function getSafeSpawn($spawn = false)
 {
     if ($spawn === false) {
         $spawn = $this->getSpawn();
     }
     if ($spawn instanceof Vector3) {
         $x = (int) round($spawn->x);
         $y = (int) round($spawn->y);
         $z = (int) round($spawn->z);
         for (; $y > 0; --$y) {
             $v = new Vector3($x, $y, $z);
             $b = $this->getBlock($v->getSide(0));
             if ($b === false) {
                 return $spawn;
             } elseif (!$b instanceof AirBlock) {
                 break;
             }
         }
         for (; $y < 128; ++$y) {
             $v = new Vector3($x, $y, $z);
             if ($this->getBlock($v->getSide(1)) instanceof AirBlock) {
                 if ($this->getBlock($v) instanceof AirBlock) {
                     return new Position($x, $y, $z, $this);
                 }
             } else {
                 ++$y;
             }
         }
         return new Position($x, $y, $z, $this);
     }
     return false;
 }
Esempio n. 18
0
 public function Execute($db, $params)
 {
     $this->Scene = new Scene();
     if (isset($params["SceneID"], $params["Enabled"]) && !$params["Enabled"] && UUID::TryParse($params["SceneID"], $this->Scene->ID)) {
         // Scene disabling
         $sql = "UPDATE Scenes SET Enabled=0 WHERE ID=:ID";
         $sth = $db->prepare($sql);
         if ($sth->execute(array(':ID' => $this->Scene->ID))) {
             if ($sth->rowCount() > 0) {
                 header("Content-Type: application/json", true);
                 echo '{ "Success": true }';
                 exit;
             } else {
                 log_message('error', "Failed updating the database");
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database update failed" }';
                 exit;
             }
         } else {
             log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     } else {
         // Scene enabling
         if (!isset($params["SceneID"], $params["Name"], $params["MinPosition"], $params["MaxPosition"], $params["Address"], $params["Enabled"]) || !UUID::TryParse($params["SceneID"], $this->Scene->ID) || !Vector3::TryParse($params["MinPosition"], $this->Scene->MinPosition) || !Vector3::TryParse($params["MaxPosition"], $this->Scene->MaxPosition)) {
             log_message('error', sprintf("AddScene: Unable to parse passed parameters or parameter missing: '%s'", print_r($params, true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Invalid parameters" }';
             exit;
         }
         $this->Scene->Address = trim($params["Address"]);
         $this->Scene->Name = trim($params["Name"]);
         $this->Scene->Enabled = $params["Enabled"];
         if (isset($params["ExtraData"])) {
             $this->Scene->ExtraData = $params["ExtraData"];
         } else {
             $this->Scene->ExtraData = NULL;
         }
         $sql = "REPLACE INTO Scenes (ID, Name, MinX, MinY, MinZ, MaxX, MaxY, MaxZ, Address, Enabled, ExtraData, XYPlane) \n                    VALUES (:ID, :Name, :MinX, :MinY,  :MinZ, :MaxX, :MaxY, :MaxZ, :Address, :Enabled, :ExtraData, GeomFromText(:XY))";
         $sth = $db->prepare($sql);
         if ($sth->execute(array(':ID' => $this->Scene->ID, ':Name' => $this->Scene->Name, ':MinX' => $this->Scene->MinPosition->X, ':MinY' => $this->Scene->MinPosition->Y, ':MinZ' => $this->Scene->MinPosition->Z, ':MaxX' => $this->Scene->MaxPosition->X, ':MaxY' => $this->Scene->MaxPosition->Y, ':MaxZ' => $this->Scene->MaxPosition->Z, ':Address' => $this->Scene->Address, ':Enabled' => $this->Scene->Enabled, ':ExtraData' => $this->Scene->ExtraData, ':XY' => sprintf("POLYGON((%d %d, %d %d, %d %d, %d %d, %d %d))", $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MinPosition->Y, $this->Scene->MaxPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MaxPosition->Y, $this->Scene->MinPosition->X, $this->Scene->MinPosition->Y)))) {
             if ($sth->rowCount() > 0) {
                 header("Content-Type: application/json", true);
                 echo '{ "Success": true }';
                 exit;
             } else {
                 log_message('error', "Failed updating the database");
                 header("Content-Type: application/json", true);
                 echo '{ "Message": "Database update failed" }';
                 exit;
             }
         } else {
             log_message('error', sprintf("Error occurred during query: %d %s", $sth->errorCode(), print_r($sth->errorInfo(), true)));
             header("Content-Type: application/json", true);
             echo '{ "Message": "Database query error" }';
             exit;
         }
     }
 }