AVsitter/AVsitter2/Plugins/AVcontrol/Xcite!-Sensations/[AV]Xcite!.lsl
Sei Lisa bf8f10bfe6 Fix several calls that had wraparound hazards.
llGetSubString("abc", 3, -1) gives "abc"; llList2List(L, 1, -1) gives L when L has length 1. In general, llGetSubString or llList2List return the whole thing when the starting index is grater than the last element in the list.

There were a number of spots with that hazard, so fix all we found.
2017-11-19 18:38:33 +01:00

199 lines
6.8 KiB
Text

/*
* [AV]Xcite! - Allows working with Xcite!™ and Sensations products
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright © the AVsitter Contributors (http://avsitter.github.io)
* AVsitter™ is a trademark. For trademark use policy see:
* https://avsitter.github.io/TRADEMARK.mediawiki
*
* Please consider supporting continued development of AVsitter and
* receive automatic updates and other benefits! All details and user
* instructions can be found at http://avsitter.github.io
*/
string product = "AVsitter™ Xcite!™";
string version = "1.02";
string notecard_name = "[AV]Xcite_settings";
key notecard_key;
key notecard_query;
integer notecard_line;
integer verbose = 0;
list POSE_AND_SITTER;
list XCITE_COMMANDS;
list XCITE_TILT;
integer TIMER_DEFAULT = 30;
string CURRENT_POSE;
list TIMERS;
list SITTERS;
integer DEBUG;
Out(integer level, string out)
{
if (verbose >= level)
{
llOwnerSay(llGetScriptName() + "[" + version + "]:" + out);
}
}
key key_request;
string parse_text(string say)
{
integer i;
for (i = 0; i < llGetListLength(SITTERS); i++)
{
string sitter_name = llList2String(llParseString2List(llKey2Name(llList2String(SITTERS, i)), [" "], []), 0);
if (sitter_name == "")
{
sitter_name = "(nobody)";
}
say = strReplace(say, "/" + (string)i, sitter_name);
}
return say;
}
string strReplace(string str, string search, string replace)
{
return llDumpList2String(llParseStringKeepNulls(str, [search], []), replace);
}
default
{
state_entry()
{
notecard_key = llGetInventoryKey(notecard_name);
Out(0, "Loading...");
notecard_query = llGetNotecardLine(notecard_name, 0);
}
changed(integer change)
{
if (change & CHANGED_INVENTORY)
{
if (llGetInventoryKey(notecard_name) != notecard_key)
{
llResetScript();
}
}
if (change & CHANGED_LINK)
{
if (llGetAgentSize(llGetLinkKey(llGetNumberOfPrims())) == ZERO_VECTOR)
{
TIMERS = [];
}
}
}
link_message(integer sender, integer num, string msg, key id)
{
if (sender == llGetLinkNumber())
{
if (num == 90045)
{
string name = llKey2Name(id);
if (name != "")
{
integer i = llGetListLength(TIMERS);
while (i > 0)
{
i--;
if (!llSubStringIndex(llList2String(TIMERS, i), name + "|"))
{
TIMERS = llDeleteSubList(TIMERS, i, i);
}
}
llSetTimerEvent(TIMER_DEFAULT);
list data = llParseStringKeepNulls(msg, ["|"], []);
integer script_channel = (integer)llList2String(data, 0);
CURRENT_POSE = llList2String(data, 1);
SITTERS = llParseStringKeepNulls(llList2String(data, 4), ["@"], []);
integer index = llListFindList(POSE_AND_SITTER, [CURRENT_POSE + "|" + (string)script_channel]);
if (index == -1)
{
index = llListFindList(POSE_AND_SITTER, [CURRENT_POSE + "|*"]);
if (index == -1)
{
index = llListFindList(POSE_AND_SITTER, ["*|*"]);
if (index == -1)
{
return;
}
}
}
if (llList2Integer(XCITE_TILT, index) != 0)
{
if (DEBUG)
{
Out(0, "Setting " + name + "'s tilt to " + llList2String(XCITE_TILT, index));
}
llMessageLinked(LINK_SET, 20020, name + "|" + llList2String(XCITE_TILT, index), "");
}
else
{
if (DEBUG)
{
Out(0, "Restoring " + name + "'s tilt.");
}
llMessageLinked(LINK_SET, 20014, name, "");
}
data = llParseStringKeepNulls(llList2String(XCITE_COMMANDS, index), ["|"], []);
TIMERS += [name + "|" + llList2String(data, 0) + "|" + llList2String(data, 1) + "||" + llList2String(data, 3)];
string commands = parse_text(llList2String(XCITE_COMMANDS, index));
llMessageLinked(LINK_SET, 20001, name + "|" + commands, NULL_KEY);
if (DEBUG)
{
Out(0, "Sending xcite commands: " + name + "|" + commands);
}
}
}
}
}
timer()
{
integer i;
for (; i < llGetListLength(TIMERS); i++)
{
llMessageLinked(LINK_SET, 20001, llList2String(TIMERS, i), NULL_KEY);
if (DEBUG)
{
Out(0, "Sending xcite commands: " + llList2String(TIMERS, i));
}
}
}
dataserver(key query_id, string data)
{
if (query_id == notecard_query)
{
if (data == EOF || llStringTrim(llToLower(data), STRING_TRIM) == "end")
{
Out(0, (string)llGetListLength(POSE_AND_SITTER) + " items Ready, Mem=" + (string)llGetFreeMemory());
}
else
{
data = llStringTrim(data, STRING_TRIM);
string command = llGetSubString(data, 0, llSubStringIndex(data, " ") - 1);
list parts = llParseStringKeepNulls(llGetSubString(data, llSubStringIndex(data, " ") + 1, 99999), [" | ", " |", "| ", "|"], []);
if (command == "TIMER")
{
TIMER_DEFAULT = llList2Integer(parts, 0);
}
if (command == "DEBUG")
{
DEBUG = llList2Integer(parts, 0);
}
if (command == "XCITE")
{
POSE_AND_SITTER += [llStringTrim(llList2String(parts, 0), STRING_TRIM) + "|" + llList2String(parts, 1)];
XCITE_COMMANDS += [llList2String(parts, 2) + "|" + llList2String(parts, 3) + "|" + llList2String(parts, 4) + "|" + llList2String(parts, 5)];
XCITE_TILT += llList2Integer(parts, 6);
}
notecard_query = llGetNotecardLine(notecard_name, ++notecard_line);
}
}
}
}