Difference between revisions of "Chat Logger (GPL)"

From Second Life Wiki
Jump to navigation Jump to search
m (Attribution of original source)
m (<lsl> tag to <source>)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header|ml=*}}
This code demonstrates several functions in combination. Listens, dialogs, Lists, states, arrays, etc.   
This code demonstrates several functions in combination. Listens, dialogs, Lists, states, arrays, etc.   


Line 8: Line 8:
(You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.  
(You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.  


Change Log:
'''Change Log:'''
January 12, 2007: Text output in HTML, Requests permissions from user before logging chat. (NF/TR)
*March 15, 2008: Fixed memory leaks & cleaned up the whitespace. ([[User:Strife Onizuka|SO]])
*January 12, 2007: Text output in HTML, Requests permissions from user before logging chat. ([[User:Nobody Fugazi|NF]]/TR)




<pre>
<source lang="lsl2">list names;
list names;
list speech;
list speech;
list colours=["002EB8","FF6633","006600","660066","660033","663300","1A9900","FF14B1","001A99","#B88A00"];
list colours=["002EB8","FF6633","006600","660066","660033","663300","1A9900","FF14B1","001A99","B88A00"];
list unique_names;
list unique_names;
list ignore_names;
list ignore_names;
list buffer_await;
list buffer_await;
integer BUFFERSTRIDE = 2;


list ALLOW_MENU = ["sure", "no way"]; // the main menu
list ALLOW_MENU = ["sure", "no way"]; // the main menu
Line 29: Line 28:
     state_entry()
     state_entry()
     {
     {
         llSetText("This is a GPL Chat Logger.\n We request permission before recording.",<0,0,0>,1.0);
         llSetText("This is a GPL Chat Logger.\n We request permission before recording.",<0.0, 0.0, 0.0>, 1.0);
         integer i;
         integer i = 0;
         integer c;
         integer c = llGetListLength(names);
         for (i=0;i<llGetListLength(names);i++)
         for (;i < c;++i)
         {
         {
             c = llListFindList(unique_names,llList2List(names,i,i) );
             llSetObjectName("<font color=#" + llList2String(colours,
            while (c >= llGetListLength(colours)) // dont crash if I run out of colours
                    llListFindList(unique_names, llList2List(names,i,i))
                c -= llGetListLength(colours);
                    % llGetListLength(colours))
            llSetObjectName("<font color=#" + llList2String(colours,c)
                 + ">" + llList2String(names,i) );
                 + ">" + llList2String(names,i) );
             llOwnerSay( llList2String(speech,i) + "</font>" );
             llOwnerSay( llList2String(speech,i) + "</font>" );
         }
         }
         names = [];
         names = speech = unique_names = [];
        speech = [];
        unique_names = [];
         llSetObjectName("GPL ChatLogger 0.1");
         llSetObjectName("GPL ChatLogger 0.1");
     }
     }
Line 79: Line 75:
         // If the dialog is hanging out doing nothing too long, kill the llListen
         // If the dialog is hanging out doing nothing too long, kill the llListen
         llListenRemove(HandleDialogListen);
         llListenRemove(HandleDialogListen);
        buffer_await = [];
     }
     }
      
      
Line 86: Line 83:
         {
         {
             llSay(0, "chat logging now off - replaying log!.");
             llSay(0, "chat logging now off - replaying log!.");
            buffer_await = [];
             state default;
             state default;
         }
         }
Line 92: Line 90:
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
          // Is this a message from the permissions dialog?
        if (llGetOwnerKey(id) == id)//only listen to avatars (they own themselves)
             if ((llListFindList(ALLOW_MENU, [message]) != -1) && (channel==CHANNEL))
        {
            // Is this a message from the permissions dialog?
             list temp_name = (list)name;
            if (channel == CHANNEL)
             {
             {
                 string buffer_temp;
                 if (~llListFindList(ALLOW_MENU, [message]))
                 // we'll need this from the strided list.
                 {
                integer buffer_loc;
                    // we'll need this from the strided list.
                list temp_name;
                    integer buffer_loc;
                temp_name +=name;
                   
                buffer_loc = llListFindList(buffer_await, temp_name);
                    if (~(buffer_loc = llListFindList(ignore_names, temp_name)))
                if (message=="sure")
                    {
                        ignore_names = llDeleteSubList(ignore_names, buffer_loc, buffer_loc);
                    }
                    if (~(buffer_loc = llListFindList(unique_names, temp_name)))
                    {
                        unique_names = llDeleteSubList(unique_names, buffer_loc, buffer_loc);
                    }
                    if (message == "sure")
                     {
                     {
                         unique_names += name;
                         unique_names += name;
                         llListenRemove(HandleDialogListen);
                         while (~(buffer_loc = llListFindList(buffer_await, temp_name)))
                         // buffered message is worthwhile, so add it:
                         {
                        buffer_temp = llList2String(buffer_await, buffer_loc);
                            // buffered message is worthwhile, so add it:
                        names += buffer_temp;
                            names += llList2String(buffer_await, buffer_loc);
                        buffer_loc++;
                            speech += llList2String(buffer_await, buffer_loc + 1);
                        buffer_temp = llList2String(buffer_await, buffer_loc);
                            buffer_await = llDeleteSubList(buffer_await, buffer_loc, buffer_loc + 1);
                        speech += buffer_temp;
                         }
                        buffer_loc--;
                        llDeleteSubList(buffer_await, buffer_loc, BUFFERSTRIDE);
                         return;
                     }
                     }
                else  
                    else  
                     {
                     {
                        // To Be Safe, even if someone hits ignore
                         ignore_names += name;
                         ignore_names += name;
                        while (~(buffer_loc = llListFindList(buffer_await, temp_name)))
                        {
                            buffer_await = llDeleteSubList(buffer_await, buffer_loc, buffer_loc + 1);
                        }
                    }
                    if (buffer_await == [])
                    {
                         llListenRemove(HandleDialogListen);
                         llListenRemove(HandleDialogListen);
                        // We can delete the buffer without adding stuff.
                        llDeleteSubList(buffer_await, buffer_loc, BUFFERSTRIDE);
                        return;
                     }
                     }
                }
             }
             }
         
            else if (!~llListFindList(ignore_names, temp_name))
          if(llListFindList(ignore_names,[name]) != -1)
          {
              return;
            }
            if(llListFindList(unique_names,[name]) == -1)
             {
             {
                 //Check if avatar will give permissions
                 if (!~llListFindList(unique_names, temp_name))
                HandleDialogListen = llListen(CHANNEL, "", NULL_KEY, "");
                {
                llDialog(id, "Hello. This is a chat logger. If you give us permission, your participation will be recorded. May we have your permission?", ALLOW_MENU, CHANNEL);
                    //Check if avatar will give permissions
                // Give people 1.5 minutes to respond,  
                    if (!~llListFindList(buffer_await, temp_name))
                // else kill the llListen in timer()
                    {
                llSetTimerEvent(90);
                        if (buffer_await == [])
                //store in strided buffer in case last message is to be permed.
                        {
                buffer_await +=[name,message];  
                            HandleDialogListen = llListen(CHANNEL, "", NULL_KEY, "");
                 //we're done here (until the user responds to the dialog).
                        }
                 return;
                        llDialog(id, "Hello. This is a chat logger. If you give us permission, your participation will be recorded. May we have your permission?", ALLOW_MENU, CHANNEL);
                        // Give people 1.5 minutes to respond,  
                        // else kill the llListen in timer()
                        llSetTimerEvent(0.0);
                        llSetTimerEvent(90.0);
                    }
                    // store in strided buffer in case last message is to be permed.
                    buffer_await += temp_name + (key)message;  
                 }
                else
                 {
                    names += name;
                    speech += message;
                }
             }
             }
         names += name;
         }   
        speech += message;
           
     }
     }
 
}</source>
}
 
</pre>
[[Category:LSL Library|Chat Logger (GPL)]]
[[Category:LSL Library|Chat Logger (GPL)]]

Latest revision as of 18:33, 24 January 2015

This code demonstrates several functions in combination. Listens, dialogs, Lists, states, arrays, etc.

Preamble: Code adapted from: http://www.simteach.com/wiki/index.php?title=SL_Chat_Logger (by Patch Lamington) which is covered by GNU Free Documentation License (http://www.gnu.org/copyleft/fdl.html) in the spirit of which this script is GPL'd. Copyright (C) 2007 Nobody Fugazi/T. Rampersad

(This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GPL license: [1]

(You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Change Log:

  • March 15, 2008: Fixed memory leaks & cleaned up the whitespace. (SO)
  • January 12, 2007: Text output in HTML, Requests permissions from user before logging chat. (NF/TR)


list names;
list speech;
list colours=["002EB8","FF6633","006600","660066","660033","663300","1A9900","FF14B1","001A99","B88A00"];
list unique_names;
list ignore_names;
list buffer_await;

list ALLOW_MENU = ["sure", "no way"]; // the main menu
integer CHANNEL = 42; // Life, the Universe, and Everything.
integer HandleDialogListen;

default
{
    state_entry()
    {
        llSetText("This is a GPL Chat Logger.\n We request permission before recording.",<0.0, 0.0, 0.0>, 1.0);
        integer i = 0;
        integer c = llGetListLength(names);
        for (;i < c;++i)
        {
            llSetObjectName("<font color=#" + llList2String(colours, 
                    llListFindList(unique_names, llList2List(names,i,i))
                    % llGetListLength(colours))
                + ">" + llList2String(names,i) );
            llOwnerSay( llList2String(speech,i) + "</font>" );
        }
        names = speech = unique_names = [];
        llSetObjectName("GPL ChatLogger 0.1");
    }

    on_rez(integer i)
    {
        llResetScript();
    }
    
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner() )
        {
            llSay(0, "Beginning Chat Logging.");
            state chat_logging;
        }
    }
}

state chat_logging
{
    state_entry()
    {
        llListen(0,"",NULL_KEY,"");
        buffer_await = [];
    }

    on_rez(integer i)
    {
        llOwnerSay("Logging still active! Touch to get playback");
    }
    
    timer()
    {
        // If the dialog is hanging out doing nothing too long, kill the llListen
        llListenRemove(HandleDialogListen);
        buffer_await = [];
    }
    
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner() )
        {
            llSay(0, "chat logging now off - replaying log!.");
            buffer_await = [];
            state default;
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if (llGetOwnerKey(id) == id)//only listen to avatars (they own themselves)
        {
            // Is this a message from the permissions dialog?
            list temp_name = (list)name;
            if (channel == CHANNEL)
            {
                if (~llListFindList(ALLOW_MENU, [message]))
                {
                    // we'll need this from the strided list.
                    integer buffer_loc;
                    
                    if (~(buffer_loc = llListFindList(ignore_names, temp_name)))
                    {
                        ignore_names = llDeleteSubList(ignore_names, buffer_loc, buffer_loc);
                    }
                    if (~(buffer_loc = llListFindList(unique_names, temp_name)))
                    {
                        unique_names = llDeleteSubList(unique_names, buffer_loc, buffer_loc);
                    }
                    if (message == "sure")
                    {
                        unique_names += name;
                        while (~(buffer_loc = llListFindList(buffer_await, temp_name)))
                        {
                            // buffered message is worthwhile, so add it:
                            names += llList2String(buffer_await, buffer_loc);
                            speech += llList2String(buffer_await, buffer_loc + 1);
                            buffer_await = llDeleteSubList(buffer_await, buffer_loc, buffer_loc + 1);
                        }
                    }
                    else 
                    {
                        ignore_names += name;
                        while (~(buffer_loc = llListFindList(buffer_await, temp_name)))
                        {
                            buffer_await = llDeleteSubList(buffer_await, buffer_loc, buffer_loc + 1);
                        }
                    }
                    if (buffer_await == [])
                    {
                        llListenRemove(HandleDialogListen);
                    }
                }
            }
            else if (!~llListFindList(ignore_names, temp_name))
            {
                if (!~llListFindList(unique_names, temp_name))
                {
                    //Check if avatar will give permissions
                    if (!~llListFindList(buffer_await, temp_name))
                    {
                        if (buffer_await == [])
                        {
                            HandleDialogListen = llListen(CHANNEL, "", NULL_KEY, "");
                        }
                        llDialog(id, "Hello. This is a chat logger. If you give us permission, your participation will be recorded. May we have your permission?", ALLOW_MENU, CHANNEL);
                        // Give people 1.5 minutes to respond, 
                        // else kill the llListen in timer()
                        llSetTimerEvent(0.0);
                        llSetTimerEvent(90.0);
                    }
                    // store in strided buffer in case last message is to be permed.
                    buffer_await += temp_name + (key)message; 
                }
                else
                {
                    names += name;
                    speech += message;
                }
            }
        }    
    }
}