Advertisement
itoibo

online indicator

Jun 15th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. key owner_key;
  2. key owner_name_query;
  3. string owner_display_name;
  4.  
  5. string username;
  6.  
  7.  
  8.  
  9.  
  10. ////////////////////////////////////////////////////////////////////////////////////////////////
  11. //    Copyright (c) 2008 by Kristy Fanshaw                                                    //
  12. ////////////////////////////////////////////////////////////////////////////////////////////////
  13. //   This program is free software: you can redistribute it and/or modify                     //
  14. //    it under the terms of the GNU General Public License as published by                    //
  15. //    the Free Software Foundation, either version 3 of the License, or                       //
  16. //    (at your option) any later version.                                                     //
  17. //                                                                                            //
  18. //    Online Indicator is distributed in the hope that it will be useful,                     //
  19. //    but WITHOUT ANY WARRANTY; without even the implied warranty of                          //
  20. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                           //
  21. //    GNU General Public License for more details.                                            //
  22. //                                                                                            //
  23. //    To get a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.    //
  24. ////////////////////////////////////////////////////////////////////////////////////////////////
  25.  
  26. key user_key;       // must be agent UUID whose status it will indicate
  27. integer time = 30;                                           // time within the message should be written.
  28. string url = "http://world.secondlife.com/resident/";
  29. key blank = TEXTURE_BLANK;
  30. string name;
  31. key toucher;
  32. string status;
  33.  
  34.  
  35. // VD 2009-11-24 workaround for WEB-1383, use <meta> instead of <img>
  36. // VD 2009-11-25 try <img> if meta tag gets removed in the future
  37. string profile_key_prefix = "<meta name=\"imageid\" content=\"";
  38. string profile_img_prefix = "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/";
  39. integer profile_key_prefix_length; // calculated from profile_key_prefix in state_entry()
  40. integer profile_img_prefix_length; // calculated from profile_img_prefix in state_entry()
  41.  
  42. //string profile_key_prefix = "<meta name=\"imageid\" content=\"";
  43. //integer s1l;
  44.  
  45. default
  46. {
  47.     state_entry()
  48.     {
  49.         user_key = llGetOwner();
  50.         profile_key_prefix_length = llStringLength(profile_key_prefix);
  51.         profile_img_prefix_length = llStringLength(profile_img_prefix);
  52.         llSetText("", <1,0,0>, 1.0);
  53.         llSetTexture(blank, ALL_SIDES);
  54.         //llRequestAgentData( user_key, DATA_NAME);
  55.  
  56.         owner_key = llGetOwner();
  57.         owner_name_query = llRequestDisplayName(owner_key);
  58.     }
  59.     dataserver(key queryid, string data)
  60.     {
  61.         //name = data;
  62.         owner_display_name = data;
  63.  
  64.         llSetObjectName(owner_display_name + "'s Online Detector");
  65.         state show;
  66.     }
  67. }
  68. state show
  69. {  
  70.     state_entry()
  71.     {
  72.         owner_key = llGetOwner();
  73.         owner_name_query = llRequestDisplayName(owner_key);
  74.         llSetTimerEvent(10);
  75.     }
  76.     timer()
  77.     {
  78.         llHTTPRequest( url + (string)user_key,[HTTP_METHOD,"GET"],"");
  79.         llRequestAgentData( user_key, DATA_ONLINE);  
  80.     }
  81.     on_rez(integer start_param)
  82.     {
  83.         llSetText("", <1,0,0>, 1.0);
  84.         llSetTexture(blank, ALL_SIDES);
  85.     }
  86.     http_response(key request_id,integer status, list metadata, string body)
  87.     {
  88.         string profile_pic;
  89.         integer s1 = llSubStringIndex(body, profile_key_prefix);
  90.         integer s1l = profile_key_prefix_length;
  91.         if(s1 == -1)
  92.         { // second try
  93.             s1 = llSubStringIndex(body, profile_img_prefix);
  94.             s1l = profile_img_prefix_length;
  95.         }
  96.  
  97.         if (s1 == -1)
  98.         { // still no match?
  99.             profile_pic = blank;
  100.         }
  101.         else
  102.         {
  103.             profile_pic = llGetSubString(body,s1 + s1l, s1 + s1l + 35);
  104.             if (profile_pic == (string)NULL_KEY)
  105.             {
  106.                 profile_pic = blank;
  107.             }
  108.         }
  109.         llSetTexture(profile_pic, ALL_SIDES);
  110.     }
  111.     dataserver(key queryid, string data)
  112.     {
  113.         if ( data == "1" )
  114.         {
  115.             status = " is online";
  116.  
  117.             llSetText(owner_display_name + status, <0,1,0>, 1.0);
  118.         }
  119.         else if (data == "0")
  120.         {
  121.             status = " is offline";
  122.  
  123.             llSetText(owner_display_name + status, <1,0,0>, 1.0);
  124.         }
  125.  
  126.     }
  127.     touch_start(integer num_detected)
  128.     {
  129.         toucher = llDetectedKey(0);
  130.         state msg;
  131.     }
  132. }
  133. state msg
  134. {
  135.     state_entry()
  136.     {
  137.         owner_key = llGetOwner();
  138.         owner_name_query = llRequestDisplayName(owner_key);
  139.        
  140.         llListen(0,"",toucher,"");
  141.         llInstantMessage(toucher, "write your message to " + owner_display_name +" - you have " +(string)time + " seconds");
  142.         llInstantMessage(toucher, "to see " + owner_display_name +"'s profile, click this link here: secondlife:///app/agent/" + (string)user_key + "/about");
  143.         llSetTimerEvent(time);  
  144.     }
  145.     listen(integer ch, string name, key id, string msg)
  146.     {
  147.         llInstantMessage(user_key, llKey2Name(toucher) + " sent you a message from " + llGetRegionName() + ": " + msg);
  148.         llInstantMessage(toucher, "message is sent.");
  149.         llListenRemove(0);
  150.         state show;
  151.     }
  152.     timer()
  153.     {
  154.         llInstantMessage(toucher, "time is up - touch again to write a message");
  155.         llListenRemove(0);
  156.         state show;
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement