linker.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Sloodle distributor linker (for Sloodle 0.3).
  4. * Allows a Sloodle Vending Machine to update its inventory and report / get permission to give objects.
  5. *
  6. * @package sloodledistributor
  7. * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. * @contributor Edmund Edgar
  11. * @contributor Peter R. Bloomfield
  12. */
  13. // This script should be called with the following parameters:
  14. // sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  15. // sloodlepwd = the prim password or object-specific session key to authenticate the request
  16. // sloodlemoduleid = ID of a chatroom
  17. // sloodleinventory = a pipe-separated list of names of items in the obect's inventory
  18. // sloodleobject = the UUID of an XMLRPC channel which can be used to request object distribution
  19. //
  20. // The following parameter is optional:
  21. // sloodledebug = if 'true', then Sloodle debugging mode is activated
  22. // The response code that tells us to actually give an object
  23. define('SLOODLE_CHANNEL_DISTRIBUTOR_DO_GIVE_OBJECT', 1639271152);
  24. /** Lets Sloodle know we are in a linker script. */
  25. define('SLOODLE_LINKER_SCRIPT', true);
  26. /** Grab the Sloodle/Moodle configuration. */
  27. require_once('../../init.php');
  28. /** Include the Sloodle PHP API. */
  29. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  30. // Authenticate the request, and load a chat module
  31. $sloodle = new SloodleSession();
  32. $sloodle->authenticate_request();
  33. $sloodle->load_module('distributor', true);
  34. // Fetch the required additional parameters
  35. $sloodleinventory = $sloodle->request->optional_param('sloodleinventory', '');
  36. $sloodlegiveobject = $sloodle->request->optional_param('sloodlegiveobject', '');
  37. $sloodleuuid = $sloodle->request->optional_param('sloodleuuid', '');
  38. if ($sloodleinventory != '') {
  39. // Attempt to update the inventory
  40. $objects = explode('|', $sloodleinventory);
  41. if (!$sloodle->module->set_objects($objects)) {
  42. // Update failed
  43. $sloodle->response->quick_output(-101, 'SYSTEM', 'Failed to update list of objects', false);
  44. exit();
  45. }
  46. // Everything seems fine
  47. $sloodle->response->set_status_code(1);
  48. $sloodle->response->set_status_descriptor('OK');
  49. } else if ($sloodlegiveobject != '') {
  50. $sloodle->validate_user(true);
  51. //$sloodle->validate_requirements();
  52. //$sloodle->process_interaction('default', 1);
  53. // Everything seems fine
  54. $sloodle->response->set_status_code(SLOODLE_CHANNEL_DISTRIBUTOR_DO_GIVE_OBJECT);
  55. $sloodle->response->set_status_descriptor('OK');
  56. // Pass back the line for what we want to give
  57. // That way the object to give and the avatar to give to will both be in the response
  58. // ...and we don't need to preserve state in the script
  59. $sloodle->response->add_data_line($sloodleuuid); // avatar line
  60. $sloodle->response->add_data_line($sloodlegiveobject); // object
  61. }
  62. // Output our response
  63. $sloodle->response->render_to_output();
  64. ?>