// The Methods here can be applied to many systems.
//
// The Main Purpose is to demonstrate how one can make use of
// Spam-Less Methods to communicate directly with individuals
// and to provide a basic working framework that shows this in action.
//
// NOTE:
// This is part of a considerably larger system I developed, which "chats"
// as it works with people, depending on their access levels/controls.
// I have included a bit of TEST DATA so that you can see how this works
// and some samples that call it and make it work.
//
// Use this or any part herein AS/IS Whereis however you wish.
//
// A Few parts of this code are NOT optimal but for the purposes of this
// example / sample, it should work fine.
//
// chat_out(key av_key, string babble) is the item of most interest in this example
//
// ======================================================================
//
integer counter = 0; // for the sample
//
list auth_list = ["John Doe","Peter Rabbit","Easter Bunny"]; // Authorized Users
list manager = ["Zeus", "Appolo", "Psycho Babbler"]; // Managers
list owner = []; // Owners
//
key avi_key; // changing avi key for passing
string name; // tmp store of name
integer Commanding = 0;
// comms
integer ListenHandle;
integer CHANNEL;
//==== TOOL FUNCTIONS ==== \\
//======================== \\
string FreeMem()
{
//float mempct = (100 * llGetFreeMemory() / (float)(16*1024)); // for non-MONO
float mempct = (100 * llGetFreeMemory() / (float)(64*1024)); // for MONO
string percent = llGetSubString((string)mempct,0,4); // displays 75.25%
string memtmpA = (string)(llGetFreeMemory()/1024)+"k ("+percent+"%)";
return memtmpA;
}
//
chat_out(key av_key, string babble)
{
if(IsInLst(owner, name)) llOwnerSay(babble);
else if(av_key != NULL_KEY) llInstantMessage(av_key,babble);
else llOwnerSay("ERROR: Module Chat_Out, av_key = "+(string)av_key);
return;
}
/// --- NEXT --- Strictly for sample excersize Don't Message anyone with anything
/// that would need this.
//chat_out_LONG(key av_key, string babble)
//{
// // String Checking [OwnerSay & InstantMessage Max Len = 1023 bytes
// integer TooLong = FALSE;
// string SplitA;
// string SplitB;
// integer slen = llStringLength(babble);
// if(slen > 1022) // This is WAY TOO MUCH CHATTER !

// {
// TooLong = TRUE;
// SplitA = llGetSubString(babble,0,1022);
// SplitB = llGetSubString(babble,1023,-1);
// //IF it's longer than this ! NUTZ The Sun Rises in the West!
// } // If trying to send THIS Much, better use a LinkMessage to a Messenger Slave
// //Applet and use a Compression for the data
// if(IsInLst(owner, name))
// {
// if(!TooLong) llOwnerSay(babble);
// else
// {
// llOwnerSay(SplitA);
// llOwnerSay(SplitB);
// }
// }
// else if(av_key != NULL_KEY)
// {
// if(!TooLong) llInstantMessage(av_key,babble);
// else
// {
// llInstantMessage(av_key,SplitA);
// llInstantMessage(av_key,SplitB);
// }
// }
// else llOwnerSay("ERROR: Module Chat_Out, av_key = "+(string)av_key);
// TooLong = FALSE;
// return;
//}
///===== END OF TOO_LONG =====\\\
//
touched(key av_id)
{
string avi_name = llKey2Name(av_id);
if (IsInLst(owner,avi_name)) // always check owners first !
{
chat_out(av_id, "Owner Access Granted"
;Commanding = 1;
authorized(av_id);
}
else if (IsInLst(manager,avi_name)) // Check Managers next
{
avi_key = av_id;
chat_out(av_id, "Manager Command Access Granted"
;Commanding = 2;
authorized(av_id);
}
else if (IsInLst(auth_list,avi_name)) // Check regular users last
{
Commanding = 0;
authorized(av_id);
}
else
{
chat_out(av_id, "Sorry "+avi_name+" Authorization Not Granted, Contact an Owner or Manager to Continue"
;}
return;
}
//
authorized(key av_id)
{
if(Commanding == 1)
{
chat_out(av_id, "\nManagers:"
;ListOut(av_id, manager);
chat_out(av_id, "\nAuthorized Guests:"
;ListOut(av_id, auth_list);
// proceed to Owners Functions
MENU_Owner(av_id);
}
else if(Commanding == 2)
{
chat_out(av_id, "\nAuthorized Guests:"
;ListOut(av_id, auth_list);
// proceed to Managers Functions
MENU_Mgr(av_id);
}
else
{
chat_out(av_id, "Authorized Access Granted, Proceeding"
;MENU_Usr(av_id);
// Procceed to Regular Functions
}
}
//
float ListOut(key av_id,list lst) // Dumps lst contents out clean with a CRLF after each entry
{ // For Large Lists StringLength Checking is warranted to prevent
// data loss. chat_out_LONG example (COMMENTED OUT) provided above
integer iLen = -1;
iLen = llGetListLength(lst);
if(iLen >= 0)
{
if(IsInLst(owner,name))
{
llOwnerSay("\n"+llDumpList2String(lst,"\n"
+"\nFree Memory = "+FreeMem());}
else if(IsInLst(manager,name))
{
llInstantMessage(av_id,"\n"+llDumpList2String(lst,"\n"
+"\nFree Memory = "+FreeMem());}
}
else llOwnerSay("LIST IS EMPTY"
;return TRUE;
}
//
integer IsInLst(list test_list, string test_item) // test_list to verify if item exist
{
if(~llListFindList(test_list, (list)test_item)) return TRUE; // in list
else return FALSE; // not in list
}
//
// == MENU FUNC'S == \\
OpenChannel() // Generate a Random - Channel for Comms
{
CHANNEL = (integer) llFrand(-100000 - 99999999) - 100000; // Menu Channel (random)
ListenHandle = llListen(CHANNEL,"","",""
;llSetTimerEvent(60.0);
}
MENU_Owner(key id)
{
OpenChannel();
llDialog(id,"== Owners Menu ==",["ONE","TWO"],CHANNEL);
}
MENU_Mgr(key id)
{
OpenChannel();
llDialog(id,"== Manager Menu ==",["ONE","TWO"],CHANNEL);
}
MENU_Usr(key id)
{
OpenChannel();
llDialog(id,"== Users Menu ==",["Process"],CHANNEL);
}
//
// ******** CODE ENTRY ********* \\
//===============================\\
default
{
state_entry()
{
name = llKey2Name(llGetOwner());
owner += name;
}
touch_start(integer total_number)
{
// for the SAMPLE PURPOSES
if(counter < 2 && llDetectedName(0) != name) auth_list += llDetectedName(0);
++counter;
// Have a couple of people touch this so their name is entered
touched(llDetectedKey(0));
}
timer()
{
llListenRemove(ListenHandle);
llSetTimerEvent(0.0);
}
listen(integer channel, string name, key id, string msg)
{
// Owner & Manager COMMANDS
if ((IsInLst(owner,name)) || (IsInLst(manager,name)))
{
llListenRemove(ListenHandle);
if(msg == "ONE"

{
chat_out(id, "Processing... Please Wait for Completion.\n ! ADVISORY !\nBackup when Completed"
;//excecute(routine_1);
}
else if(msg == "TWO"

{
chat_out(id, "This can't be undone! Hope you Backed Up!!"
;//excecute(routine_2);
}
}
else if(IsInLst(auth_list,name))
{
llListenRemove(ListenHandle);
if(msg == "Process"

{
chat_out(id, "Processing Request"
;//excecute(routine_A);
}
}
}
}
