Gayngel

Persistent_URL_Drop_Box_Server

Oct 22nd, 2021
814
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. string app_url = "https://script.google.com/macros/s/AKfycbyX-qKC0mpHFSa8iMDMBQyQtKzGQMdtxyICF5-pF2cebpm_HmU/exec"; // place the url of Google App Script here.
  15.  
  16. string spreadsheet = ""; // The Google App Script will create a spreadsheet in your Google Drive to store the url of the drop box. You can write a name here or leave it blank. If you leave the string blank the spreadsheet will automatically be called the "NameOfParcelDropBoxIsOn Dropbox".
  17.  
  18.  
  19. list parceldetails;
  20. string parcelname;
  21.  
  22. string url;
  23. key reqURL;
  24. key http_req;
  25. key sheet_req;
  26. integer allow =FALSE;
  27.  
  28. default
  29. {
  30.    
  31.     on_rez(integer start_param)
  32.     {
  33.       llSetObjectDesc("");    
  34.      llResetScript();  
  35.        
  36.     }
  37.    
  38.    
  39.     state_entry()
  40.     {
  41.       allow = FALSE;                  // verbosity just in case
  42.       llReleaseURL(url);             // verbosity just in case
  43.      
  44.       parceldetails = llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_NAME]);
  45.       parcelname = llList2String(parceldetails,0);
  46.      
  47.       reqURL =llRequestURL();
  48.    
  49.     }
  50.    
  51.    
  52.    http_request(key id, string method, string body)
  53.     {
  54.          
  55.      
  56.     if (id == reqURL)
  57.     {
  58.         if (method == URL_REQUEST_DENIED)
  59.         llOwnerSay("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
  60.  
  61.         else if (method == URL_REQUEST_GRANTED)
  62.         {
  63.         url = body;
  64.        
  65.        
  66.            
  67.         }
  68.        
  69.          if(app_url != "")
  70.         {
  71.            
  72.              http_req = llHTTPRequest(app_url+"?server_url="+url+"&obj_key="+(string)llGetKey(),[HTTP_METHOD,"GET"],"");  // send the server's url to the spreadsheet to be stored.
  73.        
  74.         }
  75.         else
  76.         llOwnerSay("Please add the URL of the Google App Script at the top of the script");
  77.        
  78.        
  79.        
  80.      } //  if (id == reqURL)
  81.        
  82.        
  83.        
  84.          else if (method == "POST")
  85.         {
  86.            
  87.             list tmp = llParseString2List(body,["="],[""]);
  88.             string cmd = llToLower(llList2String(tmp,0));
  89.             string ref = llList2String(tmp,1);
  90.            
  91.            
  92.            
  93.             if(cmd == "url_ok")
  94.          {
  95.          
  96.            
  97.          
  98.            
  99.          string ssID = llGetObjectDesc();
  100.          
  101.          if(ssID == "") // if the spreadsheet doesn't exist create one
  102.          {
  103.          
  104.          
  105.          
  106.          if(spreadsheet == "")
  107.          {
  108.              
  109.            spreadsheet = parcelname + " drop box.";    
  110.              
  111.          }
  112.          
  113.          llOwnerSay("Creating spreadsheet named " + spreadsheet);
  114.          
  115.          
  116.          if(app_url != "")
  117.         sheet_req = llHTTPRequest(app_url+ "?url="+url+"&spreadsheet=" + llEscapeURL(spreadsheet),[HTTP_METHOD,"POST"],"Create");  // instruct the App Script to create a spreadsheet
  118.          }
  119.          
  120.         else if(ssID != "") // if the spreadsheet exists
  121.         {
  122.            
  123.             llOwnerSay("The spreadsheet database is ready.");    
  124.            
  125.            llOwnerSay("This drop box will now allow redeliveries");
  126.            allow = TRUE;
  127.              sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL");   // update the url of the server and store in the spreadsheet
  128.         }
  129.            
  130.          } //if(cmd == "url_ok")
  131.          
  132.          
  133.          else if(cmd == "url_invalid")
  134.          {
  135.              
  136.             llSetObjectDesc("");  
  137.             llOwnerSay("Can not save this server's URL to the spreadsheet as the Google App Script is tied to another server. Please create a new app script and paste it's url at the top of the script.");
  138.              
  139.          }
  140.            
  141.              
  142.            
  143.            
  144.             else if(cmd == "spreadsheetready")
  145.             {
  146.              llSetObjectDesc(ref);
  147.              
  148.              llOwnerSay("The spreadsheet database has been created.");  
  149.              
  150.              
  151.                allow = TRUE;
  152.                 sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL");
  153.                
  154.                 llOwnerSay("This drop box will now allow redeliveries");  
  155.             }
  156.            
  157.             else if(cmd == "url_added")
  158.             {
  159.                
  160.                 llOwnerSay("The url of your server has been updated in the spreadsheet database.");
  161.                
  162.             }
  163.            
  164.             else if(cmd == "request_redelivery")
  165.             {
  166.                
  167.          
  168.                
  169.               key av = (key)ref;
  170.              
  171.              
  172.                
  173.               if(allow == TRUE)  
  174.               {
  175.                  
  176.                  
  177.                  
  178.                   if(llGetInventoryNumber(INVENTORY_OBJECT) > 0) // if the drop box contains an object
  179.                   {
  180.                        llInstantMessage(av,"Redelivering your object.");
  181.                       string obj = llGetInventoryName(INVENTORY_OBJECT,0);
  182.                      
  183.                       llGiveInventory(av,obj);
  184.                      
  185.                       llHTTPResponse(id,200,"redelivery_complete");
  186.                      
  187.                   }
  188.                  
  189.                   else
  190.                   llInstantMessage(av,"Sorry there is nothing to redeliver");
  191.                  
  192.                  
  193.               }
  194.              
  195.              }  //else if(cmd == "request_redelivery")
  196.            
  197.            
  198.                  
  199.         } // method is post
  200.        
  201.        
  202.        
  203.        
  204.     }
  205.    
  206.    
  207.  
  208.    
  209.    
  210.    
  211.     changed(integer change)
  212.     {
  213.        
  214.       if(change & CHANGED_REGION_START || change & CHANGED_REGION || change & CHANGED_INVENTORY || change & CHANGED_TELEPORT)
  215.       {
  216.        llReleaseURL(url);    // verbosity just in case
  217.       llResetScript();
  218.       }
  219.        
  220.        
  221.     }
  222.    
  223. }
  224.  
RAW Paste Data