Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Instructions
- // Follow all steps in order beginning from the Google App Script
- // Step 12: Copy/Paste this script into the client object
- // Step 13: Paste the URL of the Google App script into the Google_URL variable
- // Step 14: Check in local/nearby chat that url said by the server prim and the url said by the client prim match.
- string Google_URL = "https://script.google.com/macros/s/AKfycbx-FGVx1X6y7KvlMIw_pIbNqLDL9A29XAtHznLptPH5mlhh2ElIpKrV8V9Zk0eEIwZ9Hw/exec";
- string spreadsheet_name = "URL_Spreadsheet"; // The URL of the Google App Script
- key reqURL; // The id of the request for a new URL
- string client_url;// The URL of the client script
- string server_url; // The URL of the server script
- 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.
- default
- {
- state_entry()
- {
- llReleaseURL(client_url); // release all urls assigned to the client_url varaibale
- reqURL = llRequestURL(); // request a new url which will be assigned to the client_url variable
- }
- http_request(key id, string method, string body)
- {
- if(id == reqURL)
- {
- if (method == URL_REQUEST_DENIED)
- {
- 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.
- }
- else if (method == URL_REQUEST_GRANTED)
- {
- client_url = body; // assign the url to the server_url variable
- if(Google_URL != "") // if the google appp script url is not blank
- {
- 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
- }
- }
- }
- list tmp = llParseString2List(body,["="],[""]); // Parse the body into a command and reference (key/value pair)
- string cmd = llList2String(tmp,0);// command/key
- string ref = llList2String(tmp,1); // reference/value
- if(cmd == "server_url")
- {
- server_url = llUnescapeURL(ref); // assign the reference value to the server_url variable
- llOwnerSay("Server URL is " + server_url);
- }
- }
- changed(integer change)
- {
- if(change & CHANGED_REGION || change & CHANGED_REGION_START)
- {
- llResetScript();
- }
- }
- }
Add Comment
Please, Sign In to add comment