rez_response.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. require_once(SLOODLED_BASE_DIR.'/init.php');
  3. if ( !defined('SLOODLE_MESSAGE_QUEUE_TASK') || !SLOODLE_MESSAGE_QUEUE_TASK) {
  4. echo 'This task should be run by the sloodled daemon';
  5. exit;
  6. }
  7. if ( ($info['http_code']) != 200 ) {
  8. print "http code ".$info['http_code']." was wrong, giving up";
  9. return false;
  10. }
  11. // Response should look like this:
  12. // body = (string)id+"\n"+(string)llGetKey()+"\n"+rez_object_prim_password+"\n"+(string)rez_object_http_in_password+"\n"+rez_object_layout_entry_id;
  13. $result_lines = explode("\n",$result);
  14. $rezzed_object_uuid = array_shift($result_lines);
  15. $rezzeruuid = array_shift($result_lines);
  16. $primpassword = array_shift($result_lines);
  17. $rez_http_in_password = array_shift($result_lines);
  18. $layoutentryid = array_shift($result_lines);
  19. $layoutentry = new SloodleLayoutEntry();
  20. if ( !$layoutentry->load( $layoutentryid ) ) {
  21. if ($verbose) {
  22. print "error loading layout entry :$layoutentryid:\n";
  23. }
  24. return false;
  25. }
  26. if (!$layout = $layoutentry->get_layout()) {
  27. if ($verbose) {
  28. print "error loading layout \n";
  29. }
  30. return false;
  31. }
  32. if (!$controllerid = $layout->controllerid) {
  33. if ($verbose) {
  34. print "error layout lacks controllerid\n";
  35. }
  36. return false;
  37. }
  38. // TODO: Get actual object name via layoutentryid
  39. $objectname = $layoutentry->name;
  40. if ( !$objectname ) {
  41. if ($verbose) {
  42. print "error no objectname\n";
  43. }
  44. return false;
  45. }
  46. $config = SloodleObjectConfig::ForObjectName( $objectname );
  47. $controller = new SloodleController();
  48. if (!$controller->load( $controllerid )) {
  49. print "error loading controller\n";
  50. return false;
  51. }
  52. $rezzer = new SloodleActiveObject();
  53. if ( !$rezzer->loadByUUID($rezzeruuid) ) {
  54. print "error loading rezzer\n";
  55. return false;
  56. }
  57. $sloodleuser = new SloodleUser();
  58. if ( !$authid = $controller->register_object($rezzed_object_uuid, $objectname, $sloodleuser, $primpassword, $rez_http_in_password, $config->type()) ) {
  59. print "error registering\n";
  60. return false;
  61. }
  62. if (!$controller->configure_object_from_layout_entry($authid, $layoutentryid, $rezzer->uuid)) {
  63. print "error configuring\n";
  64. return false;
  65. }
  66. return true;
  67. // The object may have registered itself and its URL before we got here.
  68. // In that case, send it its config.
  69. // TODO: This uses more db hits than it should - it would be better if register_object returned the object, not just its ID.
  70. $ao = new SloodleActiveObject();
  71. if ($ao->loadByUUID($rezzed_object_uuid)) {
  72. if ($ao->httpinurl) {
  73. $extraParams = array('sloodlerezzeruuid' => $rezzer->uuid);
  74. $ao->sendConfig($extraParams, $async = false);
  75. }
  76. }
  77. ?>