Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key kSelfCheckRequest;
- key kRequestURL;
- key kKVPUpdate;
- key kCustomer;
- string strProduct;
- string strMyURL;
- string strKVPKeyForServer = "CurrentURL:";
- string strMyExperience= "My Experience Name";
- default {
- state_entry() {
- if(llList2String(llGetExperienceDetails(NULL_KEY),0)!=strMyExperience){
- llOwnerSay("Please ensure that "+strMyExperience+" is able to run on this parcel");
- }
- llReleaseURL(strMyURL);
- kRequestURL = llRequestURL();
- }
- timer() {
- kSelfCheckRequest = llHTTPRequest(strMyURL,[HTTP_METHOD, "POST"],"testing");
- }
- changed(integer ) {
- if(change & CHANGED_REGION_START){
- llReleaseURL(strMyURL);
- kRequestURL = llRequestURL();
- }
- }
- dataserver(key queryid, string data) {
- if(kKVPUpdate == queryid){
- integer success = (integer)llGetSubString(data,0,0);
- data = llDeleteSubString(data,0,1);
- if(success){
- llOwnerSay("Successfully updated value of "+strKVPKeyForServer+" to "+data);
- }
- else{
- llOwnerSay("Could not read server url because "+llGetExperienceErrorMessage((integer)data));
- }
- }
- }
- http_response(key request_id, integer status, list metadata, string body)
- {
- if (request_id== kSelfCheckRequest){
- llOwnerSay("response to self-check test -- status is "+(string)status);
- kSelfCheckRequest= NULL_KEY;
- if (status != 200){
- llReleaseURL(strMyURL);
- kRequestURL = llRequestURL();
- }
- }
- }
- http_request(key id, string method, string body){
- if(kRequestURL == id){
- if(URL_REQUEST_DENIED == method){
- llOwnerSay("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
- }
- else if (URL_REQUEST_GRANTED == method){
- strMyURL = body;
- llOwnerSay("updating value held by "+strKVPKeyForServer+ " to "+strMyURL);
- kKVPUpdate = llUpdateKeyValue(strKVPKeyForServer, strMyURL, FALSE, "");
- llSetTimerEvent(300.0);
- }
- }
- else {
- llOwnerSay("body is "+body);
- if("testing"==body){
- llHTTPResponse(id, 200,"OK");
- }
- // string who = (key)llList2String(lIncoming, -1); //for testing
- else {
- list lIncoming = llParseString2List(body, ["~"], []);
- kCustomer = (key) llList2String(lIncoming, 0);
- llOwnerSay("kCustomer is "+(string)kCustomer);
- llOwnerSay("strProduct is "+strProduct);
- if((key)kCustomer){
- llOwnerSay("kCustomer is a key");
- llHTTPResponse(id, 200, "OK");
- //and send the product to the customer
- }
- else{
- llOwnerSay("kCustomer is not a key");
- //dunno what to do here
- }
- }//end strPing == strProduct
- } //end else
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement