User:Free Portal/Sandbox/LSL Library/Simple Online Indicater

From Second Life Wiki
Jump to navigation Jump to search

Simple Group Invite

간단한 온라인 오프라인 확인기

주요 기능

온라인 오프라인 표시 및 프로필 사진 보이는 스크립트입니다. 간단한 설명 ownerID 키에 원하는 사람의 uuid 넣으면 알아서 동작합니다. 아무꺼도 않쓰면 자동으로 소유자 아이디로 인식해서 동작하며, messageOn 또는 messageOff 에다가 할말 적어두면 터치 했을때 메시지를 뿌려줍니다. 온라인일때와 오프라인일때의 메시지를 각각 따로 입력 해주셔야 합니다.

본인이 설정한 프로필 사진 말고, 다른 사진을 넣고 싶다면, textureID 에다가 표시 하고 싶은 사진의 자산 uuid를 넣어 주시면 됩니다.

*주의: 검색에서 본인의 프로필이 검색되게 설정 해두지 않으면, 자동으로 프로필 사진을 불러 들일수가 없습니다. 아울러 프로필 사진을 바꾸게되면 적용이 되는데 12시간에서 48시간 정도 걸리는 것도 참고 하시기 바랍니다.

Rules

별다른 라이센스는 없으나 어디에 사용하셔도 좋치만 스크립트를 담아가시거나 다른곳에 게시하거나 공개할때는 출처를 명시 해주시기 바랍니다.

Script Source

<lsl>// Simple Online Indicater // @author Free Portal (thedig@hyouk.net) // ---------------------------------------------------------------------------- // Apr 17, 2010 v1.1 - Fixed running deleay, add get auto profile pic // Dec 25, 2009 v1.0 - Simple Online Indicater, orig code

// ---------------------------------------------------------------------------- string messageOn = "set online custom message"; string messageOff = "set offline custom message"; key ownerID = "set custom agent uuid or empty"; key textureID = "set custom texture";

// ---------------------------------------------------------------------------- // Do not edit after Do not edit after Do not edit after // ----------------------------------------------------------------------------

// ---------------------------------------------------------------------------- // Global Variables: // ---------------------------------------------------------------------------- key httpRequestId; key dbRequestId; string agentName; integer isOnline = 3; integer dbData; float timerHttp; float timerDb;

// ---------------------------------------------------------------------------- // Static // ---------------------------------------------------------------------------- string RESIDENT_URL = "http://world.secondlife.com/resident/"; float MAX_TIME_HTTP = 3600; float MAX_TIME_DB = 60;

// ---------------------------------------------------------------------------- // getAgentData // ---------------------------------------------------------------------------- // @comment: // get agent on/off line data // ---------------------------------------------------------------------------- getAgentData() {

   dbRequestId = llRequestAgentData(ownerID, dbData);

}

// ---------------------------------------------------------------------------- // getAgentProfilePic // ---------------------------------------------------------------------------- // @comment: // get agent profile picture from secondlife homepage // ---------------------------------------------------------------------------- getAgentProfilePic() {

   httpRequestId= llHTTPRequest(RESIDENT_URL + (string)ownerID,[HTTP_METHOD,"GET"],"");   

}

// ---------------------------------------------------------------------------- // getBetweenString // ---------------------------------------------------------------------------- // @param : // string str // // @param : // string pre // // @param : // string suf // // @return : // string // // @comment: // get string of between 2 word // ---------------------------------------------------------------------------- string getBetweenString(string str, string pre, string suf) {

   if ((llSubStringIndex(str, pre) == -1) ||
       (llSubStringIndex(str, suf) == -1))
       return NULL_KEY;
   
   return llGetSubString(
           str,
           llSubStringIndex(str, pre) + llStringLength(pre),
           llSubStringIndex(str, suf)-1);

}

// ---------------------------------------------------------------------------- // showState // ---------------------------------------------------------------------------- // @comment: // set object state // ---------------------------------------------------------------------------- showSate() {

   string msg;
   vector color;
   vector msg_color = <1.0 , 1.0, 1.0>;
   if (isOnline != 3) {
       if (isOnline) {
           msg = agentName + " Online";
           color = <1.0, 1.0, 1.0>;
           msg_color = <0, 1.0, 0>;
       }
       else {
           msg = agentName + " Offline";
           color = <0.392157, 0.392157, 0.392157>;
           msg_color = <1.0, 0, 0>;
       }
   }
   else {
       msg = "Loading...";
       color = <0.392157, 0.392157, 0.392157>;
   }
   llSetColor(color, ALL_SIDES);
   llSetObjectDesc(msg);
   llSetText(msg, msg_color, 1.0);

}

// ---------------------------------------------------------------------------- // isValidUUID // ---------------------------------------------------------------------------- // @param : // key UUID // // @return : // integer // // @comment: // check valid uuid // ---------------------------------------------------------------------------- integer isValidUUID(key UUID) {

   if (llStringLength(UUID) < 1 || llStringLength(UUID) < 36)
       return FALSE;
   else if (llGetListLength(llParseString2List(UUID, ["-"], [])) != 5)
       return FALSE;
   else
       return TRUE;

}

// ---------------------------------------------------------------------------- // run // ---------------------------------------------------------------------------- // @comment: // run timer // ---------------------------------------------------------------------------- run() {

   if (timerHttp++ >= MAX_TIME_HTTP) {
       getAgentProfilePic();
       timerHttp = 0;
   }
   if (timerDb++ >= MAX_TIME_DB) {
       dbData = DATA_ONLINE;
       getAgentData();
       timerDb = 0;
   }

}

// ---------------------------------------------------------------------------- // init // ---------------------------------------------------------------------------- // @comment: // init // ---------------------------------------------------------------------------- init() {

   showSate();
   if (!isValidUUID(ownerID) || ownerID == NULL_KEY) {
       ownerID = llGetOwner();
       agentName = llKey2Name(llGetOwner());
   }
   if (!isValidUUID(textureID))
       textureID = NULL_KEY;
       
   dbData = DATA_NAME;
   getAgentData();
   getAgentProfilePic();
   llSetTimerEvent(1.0);

}

// ---------------------------------------------------------------------------- // script main // ----------------------------------------------------------------------------

// ---------------------------------------------------------------------------- // state default // ---------------------------------------------------------------------------- // @comment: // default // ---------------------------------------------------------------------------- default {

   state_entry () {
       init();
   }
   
   touch_start (integer param) {
       if (isOnline) {
           if (llStringLength(messageOn) > 1)
               llInstantMessage(llDetectedKey(0), messageOn);
       }
       else {
           if (llStringLength(messageOff) > 1)
               llInstantMessage(llDetectedKey(0), messageOff);
       }
   }
   http_response(key request_id, integer status, list metadata, string body) {
       if (httpRequestId == request_id) {
           key tmp;
           tmp = getBetweenString(body,
               "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/",
               "/1\" class=\"parcelimg\" />");
           if (tmp != NULL_KEY) {
               if (textureID == NULL_KEY) {
                   textureID = tmp;
               }
           }            
           if (textureID != NULL_KEY)
               llSetTexture(textureID, 3);
       }
   }
   dataserver(key request_id, string data)
   {
       if (dbRequestId == request_id)
       {
           if (dbData == DATA_NAME) {
               agentName = data;
               if (llStringLength(agentName) < 1) {
                   ownerID = llGetOwner();
                   agentName = llKey2Name(llGetOwner());
               }
               dbData = DATA_ONLINE;
               getAgentData();
           }
           else if (dbData == DATA_ONLINE) {
               isOnline = (integer)data;
               showSate();
           }
       }        
   }
   
   timer () {
       run ();
   }    

}</lsl>