User:SignpostMarv Martin/exec.lsl

From Second Life Wiki
< User:SignpostMarv Martin
Revision as of 16:01, 9 April 2012 by SignpostMarv Martin (talk | contribs) (moving stuff inside comment header)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<lsl>/**

  • @author SignpostMarv Martin
  • @copyright SignpostMarv Martin 2007-09-17 16:19:09
  • @brief Executes arbitrary LSL commands as from string input. This script was originally written 2007-09-17. It's old, not entirely graceful and was only done as an experiment.
  • /

list valid_commands = [ "llOwnerSay", "llInstantMessage", "llWhisper", "llSay", "llShout", "llRegionSay", "llDialog" ];


string identify_command(string input) {

   integer loc = llSubStringIndex(input,":");
   if(loc == -1)
   {
       return "";
   }
   else
   {
       loc = llListFindList(valid_commands,[llGetSubString(input,0,loc - 1)]);
       if(loc == -1)
       {
           return "";   
       }
       else
       {
           return llList2String(valid_commands,loc);
       }
   }

} execute_command(string command,string data) {

   list foo = llCSV2List(data);
   if(command == "llOwnerSay")
   {
       foo = [];
       llOwnerSay(data);
   }
   else if(command == "llInstantMessage")
   {
       llInstantMessage((key)llList2String(foo,0),llList2CSV(llList2List(foo,1,-1)));
   }
   else if(command == "llDialog")
   {
       llDialog(   (key)llList2String(foo,0),
                   llList2String(foo,1),
                   llList2List(foo,3,-1),
                   (integer)llList2String(foo,2)
       );
   }
   else if(command == "llWhisper" || command == "llSay" || command == "llShout" || command == "llRegionSay")
   {
       integer bar = (integer)llList2String(foo,0);
       data = llList2CSV(llList2List(foo,1,-1));
       if(command == "llWhisper")
       {
           llWhisper(bar,data);
       }
       else if(command == "llSay")
       {
           llSay(bar,data);
       }
       else if(command == "llShout")
       {
           llShout(bar,data);
       }
       else if(command == "llRegionSay")
       {
           llRegionSay(bar,data);
       }
   }

} string _data(string payload) {

   return llGetSubString(payload,llSubStringIndex(payload,":") + 1,-1);

} process_payload(string payload,key is_for) {

   string command = identify_command(payload);
   if(command == "")
   {
       llInstantMessage(is_for,"/me recieved invalid payload");
   }
   else
   {
       execute_command(command,_data(payload));
   }
   llOwnerSay((string)llGetFreeMemory());

}

default {

   state_entry()
   {
       string test="llWhisper:0," + (string)llGetOwner() + ",;;faoskf;aoskdfasd,,,, f;asdfoka;eofk";
       process_payload(test,llGetOwner());
   }

}</lsl>