1. // XML-RPC example
  2.  
  3. integer gSayRange = 0;
  4. key     gChannel; // my llRemoteData channel
  5. integer     gChangeValue;
  6. integer gListenChannel;
  7.  
  8. integer randBetween(float min, float max)
  9. {
  10.     return llCeil(llFrand(max - min) + min);
  11. }
  12.  
  13. DEBUG(list out) { // output debug info
  14.     llSay(0, llList2CSV(out));
  15. }
  16.  
  17. default { // initialize XML-RPC
  18.     state_entry() {
  19.         llOpenRemoteDataChannel(); // create an XML-RPC channel
  20.         // this will raise remote_data event REMOTE_DATA_CHANNEL when created
  21.     }
  22.  
  23.     remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
  24.         if (type == REMOTE_DATA_CHANNEL) { // channel created
  25.             gChannel = channel;
  26.             llSay(gSayRange, "Ready to receive requests on channel \"" + (string)channel +"\"");
  27.             state go; // start handling requests
  28.         } else DEBUG(["Unexpected event type", type, channel, message_id, sender, ival, sval]);
  29.     }
  30. }
  31.  
  32. state go { // handle requests
  33.  
  34.     state_entry()
  35.     {
  36.         gChangeValue = 0;
  37.         gListenChannel = randBetween(1, 100);
  38.         llListen(gListenChannel, "", "", "");
  39.         llSay(gSayRange, "To talk to me, chat on channel " + (string)gListenChannel);
  40.         llSay(gSayRange, "Change speeds by typing in ff <speed>");
  41.         llSay(gSayRange, "I.e. if you want 100% speed, use the command");
  42.         llSay(gSayRange, "ff 100");
  43.         llSay(gSayRange, "ff -1 to turn off client query and shut down");
  44.     }   
  45.    
  46.     listen(integer channel, string name, key id, string message)
  47.     {
  48.         list sayList = llParseString2List(message, [" "], []);
  49.         if(llList2String(sayList, 0) == "ff" || llList2String(sayList, 1) == "ff")
  50.         {
  51.             gChangeValue = (integer)llList2String(sayList,1);
  52.             llSay(gSayRange, "Changing Vibe Value to " + (string)gChangeValue);
  53.             if(gChangeValue < 0)
  54.             {
  55.                 llSay(gSayRange, "Calling Timer to Exit");
  56.             }
  57.         }
  58.     }
  59.    
  60.     remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) {
  61.         if (type == REMOTE_DATA_REQUEST) { // handle requests sent to us
  62.             // handle request
  63.                 llRemoteDataReply(channel, message_id, "Request Received", gChangeValue);
  64.                 llSay(gSayRange, "Update sent to client with value " + (string)gChangeValue);
  65.             }
  66.         else DEBUG(["Unexpected event type:", type, channel, message_id, sender, ival, sval]);
  67.     }
  68.  
  69.     state_exit() {
  70.         llCloseRemoteDataChannel(gChannel); // clean up when you no longer want to handle requests
  71.         llSay(gSayRange, "Shutting down channel");
  72.     }
  73.    
  74.     on_rez(integer start_param)
  75.     {
  76.         gChangeValue = 0;
  77.         llCloseRemoteDataChannel(gChannel); // clean up when you no longer want to handle requests
  78.         llSay(gSayRange, "Shutting down channel");
  79.         llResetScript();
  80.     }