Gayngel

Basic URL storage to Google Sheet - Client Script

Nov 14th, 2023
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Instructions
  2. // Follow all steps in order beginning from the Google App Script
  3.  
  4. // Step 12: Copy/Paste this script into the client object
  5.  
  6.  
  7. // Step 13: Paste the URL of the Google App script into the Google_URL variable
  8.  
  9. // Step 14: Check in local/nearby chat that url said by the server prim and the url said by the client prim match.
  10.  
  11. string Google_URL = "https://script.google.com/macros/s/AKfycbx-FGVx1X6y7KvlMIw_pIbNqLDL9A29XAtHznLptPH5mlhh2ElIpKrV8V9Zk0eEIwZ9Hw/exec";
  12. string spreadsheet_name = "URL_Spreadsheet"; // The URL of the Google App Script
  13. key reqURL; // The id of the request for a new URL
  14. string client_url;// The URL of the client script
  15. string server_url;  // The URL of the server script
  16. key http_req; // The id of the http request to the Google app script. // May be redundant as the app script creates a new post to the server with its own id.
  17.  
  18. default
  19. {
  20.     state_entry()
  21.     {
  22.        llReleaseURL(client_url); // release all urls assigned to the client_url varaibale
  23.        reqURL = llRequestURL();  // request a new url which will be assigned to the client_url variable
  24.     }
  25.  
  26.     http_request(key id, string method, string body)
  27.     {
  28.    
  29.        
  30.         if(id == reqURL)
  31.         {
  32.         if (method == URL_REQUEST_DENIED)
  33.         {
  34.             llOwnerSay("No free URLs!");  // All URL slots have been used up in the parcel. The number of URLS avaialble in a parcel is the number of allowed prims in the parcel. For example if you have a maximum prim allowance of 100 prims you can only use up 100 URLs. You may never see this message if you dont request URLs in as many scripts as your prim allowance.
  35.         }
  36.         else if (method == URL_REQUEST_GRANTED)
  37.         {
  38.             client_url = body; // assign the url to the server_url variable
  39.        
  40.           if(Google_URL != "")  // if the google appp script url is not blank
  41.         {  
  42.        
  43.    
  44.        
  45.           http_req = llHTTPRequest(Google_URL+"?client_url="+client_url+"&obj_key="+(string)llGetKey(),[HTTP_METHOD,"GET"],"GetURL"); // make a request to the Google App Script get the URL of the server stored in the spreadsheet
  46.         }
  47.         }
  48.        
  49.      
  50.        
  51.      }
  52.      
  53.       list tmp = llParseString2List(body,["="],[""]);  // Parse the body into a command and reference (key/value pair)
  54.        string cmd = llList2String(tmp,0);// command/key
  55.        string ref = llList2String(tmp,1);  // reference/value
  56.        
  57.       if(cmd == "server_url")
  58.         {
  59.          server_url = llUnescapeURL(ref); // assign the reference value to the server_url variable
  60.          llOwnerSay("Server URL is " + server_url);  
  61.            
  62.         }
  63.      
  64.    
  65.      
  66.      
  67.     }
  68.    
  69.    
  70.    
  71.     changed(integer change)
  72.     {
  73.        if(change & CHANGED_REGION || change & CHANGED_REGION_START)
  74.         {
  75.          
  76.          llResetScript();  
  77.            
  78.         }
  79.        
  80.        
  81.     }
  82. }
Add Comment
Please, Sign In to add comment