Gayngel

Persistent_URL_Redelivery_Terminal_Client

Oct 22nd, 2021
966
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Script by Gayngel of The Script Yard.
  2.  
  3. //Join The Script Yard Group: secondlife:///app/group/4921b4f0-c21e-7866-c0c2-791d10bb5502/about
  4. //Visit The Script Yard Marketplace: https://marketplace.secondlife.com/stores/149734
  5.  
  6. // This is a simple dropbox system.  Redelivery systems will request redeliveries of the object you have stored in it and the drop box will deliver the object to avatar who requested a redelivery.
  7.  
  8. // The drop box saves it's url to a Google Sheet via Google App Script. The redelivery client will request the url of the drop box from the spreadsheet and then request a redeivery from the drop box.
  9.  
  10. // Get the Google App Script from https://pastebin.com/Cc9ZbYyj and follow the instructions in the app script to setup.
  11.  
  12. // Once set up paste the app url below.
  13.  
  14.  
  15.  
  16. string app = "https://script.google.com/macros/s/AKfycbyX-qKC0mpHFSa8iMDMBQyQtKzGQMdtxyICF5-pF2cebpm_HmU/exec"; // place the url of Google App Script here.
  17. string url;
  18. key reqURL;
  19. key server_req;
  20. key app_req;
  21. integer allow =FALSE;
  22. integer wait = FALSE; // if someone is using the terminal the next user must wait their turn
  23. integer listen_chan;
  24. integer listen_handle;
  25. key recipient;
  26.  
  27. default
  28. {
  29.    
  30.     on_rez(integer start_param)
  31.     {
  32.        
  33.      llResetScript();  
  34.        
  35.     }
  36.    
  37.    
  38.     state_entry()
  39.     {
  40.       allow = FALSE;                  // verbosity just in case
  41.       llReleaseURL(url);             // verbosity just in case
  42.       reqURL =llRequestURL();
  43.    
  44.     }
  45.    
  46.    
  47.    http_request(key id, string method, string body)
  48.     {
  49.     if (id == reqURL)
  50.     {
  51.         if (method == URL_REQUEST_DENIED)
  52.         llOwnerSay("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
  53.  
  54.         else if (method == URL_REQUEST_GRANTED)
  55.         {
  56.         url = body;
  57.         if(app != "")
  58.         {
  59.         llOwnerSay("This terminal can now request redeliveries");
  60.         allow = TRUE;
  61.          
  62.          }
  63.        
  64.        
  65.         else
  66.         llOwnerSay("Please add the URL of the Google App Script at the top of the script");
  67.        
  68.        
  69.         }
  70.         }
  71.        
  72.        
  73.         else if(id == server_req)
  74.         {
  75.          
  76.          if(body == "redelivery_ok")
  77.          {
  78.          
  79.           wait = TRUE;  // verbosity just in case
  80.           allow = TRUE; // verbosity just in case
  81.           llListenRemove(listen_handle); // verbosity just in case
  82.          
  83.          }
  84.            
  85.            
  86.         }
  87.        
  88.        
  89.         else if(method == "POST")
  90.         {
  91.             list tmp = llParseString2List(body,["="],[""]);
  92.             string cmd = llToLower(llList2String(tmp,0));
  93.             string ref = llList2String(tmp,1);
  94.            
  95.            
  96.             if(cmd == "server_url")
  97.             {
  98.                
  99.                
  100.                server_req = llHTTPRequest(llUnescapeURL(ref),[HTTP_METHOD,"POST"],"request_redelivery="+(string)recipient);  // instruct server to redeliver object
  101.                llOwnerSay("Requesting redelivery from server please wait...");
  102.               llSetTimerEvent(0.0);
  103.                llSetTimerEvent(10.0);
  104.              
  105.             }
  106.            
  107.            
  108.            
  109.         }
  110.        
  111.        
  112.        
  113.     }
  114.    
  115.     http_response(key id, integer status, list metadata ,string body)
  116.     {
  117.        
  118.         if(body == "redelivery_complete")
  119.         {
  120.          
  121.           llOwnerSay("Delivery successful");
  122.           llSetTimerEvent(0.0);  
  123.          
  124.           // redelivery was successful
  125.           // do other stuff here
  126.            
  127.         }
  128.        
  129.     }
  130.    
  131.     touch_end(integer num)
  132.     {
  133.          key toucher = llDetectedKey(0);
  134.        if(allow == TRUE)
  135.        {
  136.        
  137.        if(wait == FALSE)
  138.        {
  139.         wait = TRUE;  // other users must wait their turn
  140.         llListenRemove(listen_handle);
  141.         listen_chan = ((integer)("0x"+llGetSubString((string)toucher,-8,-1)) - 723) | 0x8000000;
  142.         listen_handle = llListen(listen_chan,"",toucher,"");
  143.        
  144.         llDialog(toucher,"\nSelect redeliver to redeliver your object.",["Redeliver"],listen_chan);
  145.         }
  146.        
  147.         else
  148.         {
  149.            llRegionSayTo(toucher,0,"Someone is already using this terminal, please wait.");    
  150.            
  151.         }
  152.        }
  153.        
  154.        else
  155.        {
  156.            
  157.          llRegionSayTo(toucher,0,"This redelivery terminal is currently offline.");
  158.            
  159.         }
  160.        
  161.        
  162.        
  163.        
  164.     }
  165.    
  166.    
  167.     listen(integer chan, string name, key id, string msg)
  168.     {
  169.        if(chan == listen_chan)
  170.        {
  171.            
  172.           if(msg == "Redeliver")
  173.           {
  174.               llListenRemove(listen_handle);
  175.               wait = FALSE; //allow next user to use the terminal
  176.               allow = TRUE; // verbosity just in case
  177.              
  178.              //http request to google app script to get url of drop box
  179.              recipient = id;
  180.              app_req = llHTTPRequest(app+"?client_url="+url,[HTTP_METHOD,"GET"],"");  // request url of server from spreadsheet database
  181.           }
  182.            
  183.         }
  184.        
  185.        
  186.        
  187.     }
  188.    
  189.   timer()
  190.   {
  191.    
  192.    llSetTimerEvent(0.0);  
  193.    llInstantMessage(recipient,"There was no response from the server. Please try again.");  
  194.      
  195.   }
  196.  
  197.    
  198.    
  199.    
  200.     changed(integer change)
  201.     {
  202.        
  203.       if(change & CHANGED_REGION_START || change & CHANGED_REGION || change & CHANGED_INVENTORY || change & CHANGED_TELEPORT)
  204.       {
  205.        llReleaseURL(url);    // verbosity just in case
  206.       llResetScript();
  207.       }
  208.        
  209.        
  210.     }
  211.    
  212. }
  213.  
RAW Paste Data