-
Notifications
You must be signed in to change notification settings - Fork 1
/
nPose Docardif plugin.lsl
240 lines (228 loc) · 11.6 KB
/
nPose Docardif plugin.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
The nPose scripts are licensed under the GPLv2 (http://www.gnu.org/licenses/gpl-2.0.txt), with the following addendum:
The nPose scripts are free to be copied, modified, and redistributed, subject to the following conditions:
- If you distribute the nPose scripts, you must leave them full perms.
- If you modify the nPose scripts and distribute the modifications, you must also make your modifications full perms.
"Full perms" means having the modify, copy, and transfer permissions enabled in Second Life and/or other virtual world platforms derived from Second Life (such as OpenSim). If the platform should allow more fine-grained permissions, then "full perms" will mean the most permissive possible set of permissions allowed by the platform.
*/
list UserDefinedPermissionsList;
string USER_DEFINED_PERMISSION_TYPE_BOOL = "bool";
list MacroNames;
list MacroValues;
integer UDPBOOL = -804;
integer MACRO = -807;
integer DOCARDIF = -3500;
integer SEAT_UPDATE = 35353;
list Slots;
integer isAllowed(integer mode, string permissions) {
// OPERATORS (listed in order of their precedence)
// ! means a logical NOT
// & means a logical AND
// ~ means a logical OR
// Operators may be surrounded by spaces
permissions=llStringTrim(permissions, STRING_TRIM);
if(permissions=="") {
return TRUE;
}
else {
list permItemsOr=llParseString2List(llToLower(permissions), ["~"], []);
integer indexOr=~llGetListLength(permItemsOr);
integer result;
while(++indexOr && !result) {
list permItemsAnd=llParseString2List(llList2String(permItemsOr, indexOr), ["&"], []);
integer indexAnd=~llGetListLength(permItemsAnd);
result=TRUE;
while(++indexAnd && result) {
integer invert;
string item=llStringTrim(llList2String(permItemsAnd, indexAnd), STRING_TRIM);
if(llGetSubString(item, 0, 0)=="!") {
invert=TRUE;
item=llStringTrim(llDeleteSubString(item, 0, 0), STRING_TRIM);
}
if(llGetSubString(item, 0, 0)=="@") {
integer macroIndex=llListFindList(MacroNames, [llDeleteSubString(item, 0, 0)]);
if(~macroIndex) {
result=logicalXor(invert, isAllowed(mode, llList2String(MacroValues, macroIndex)));
}
else {
//unknown Macro: assume that it is set to ""
result=invert;
}
}
else {
//maybe a user defined permission
integer udpIndex=llListFindList(UserDefinedPermissionsList, [item]);
if(~udpIndex) {
//plugin permission
string pluginPermissionType=llList2String(UserDefinedPermissionsList, udpIndex+1);
if(pluginPermissionType==USER_DEFINED_PERMISSION_TYPE_BOOL) {
result=logicalXor(invert, (integer)llList2String(UserDefinedPermissionsList, udpIndex+2));
}
else {
//error unknown plugin permission type
result=invert;
}
}
else {
//maybe the plugin has not registered itself right now. So assume a blank list or a 0 as value
result=invert;
}
/*
The nPose scripts are licensed under the GPLv2 (http://www.gnu.org/licenses/gpl-2.0.txt), with the following addendum:
The nPose scripts are free to be copied, modified, and redistributed, subject to the following conditions:
- If you distribute the nPose scripts, you must leave them full perms.
- If you modify the nPose scripts and distribute the modifications, you must also make your modifications full perms.
"Full perms" means having the modify, copy, and transfer permissions enabled in Second Life and/or other virtual world platforms derived from Second Life (such as OpenSim). If the platform should allow more fine-grained permissions, then "full perms" will mean the most permissive possible set of permissions allowed by the platform.
*/
list UserDefinedPermissionsList;
string USER_DEFINED_PERMISSION_TYPE_BOOL = "bool";
list MacroNames;
list MacroValues;
integer UDPBOOL = -804;
integer MACRO = -807;
integer DOCARDIF = -3500;
integer SEAT_UPDATE = 35353;
list Slots;
integer isAllowed(integer mode, string permissions) {
// OPERATORS (listed in order of their precedence)
// ! means a logical NOT
// & means a logical AND
// ~ means a logical OR
// Operators may be surrounded by spaces
permissions=llStringTrim(permissions, STRING_TRIM);
if(permissions=="") {
return TRUE;
}
else {
list permItemsOr=llParseString2List(llToLower(permissions), ["~"], []);
integer indexOr=~llGetListLength(permItemsOr);
integer result;
while(++indexOr && !result) {
list permItemsAnd=llParseString2List(llList2String(permItemsOr, indexOr), ["&"], []);
integer indexAnd=~llGetListLength(permItemsAnd);
result=TRUE;
while(++indexAnd && result) {
integer invert;
string item=llStringTrim(llList2String(permItemsAnd, indexAnd), STRING_TRIM);
if(llGetSubString(item, 0, 0)=="!") {
invert=TRUE;
item=llStringTrim(llDeleteSubString(item, 0, 0), STRING_TRIM);
}
if(llGetSubString(item, 0, 0)=="@") {
integer macroIndex=llListFindList(MacroNames, [llDeleteSubString(item, 0, 0)]);
if(~macroIndex) {
result=logicalXor(invert, isAllowed(mode, llList2String(MacroValues, macroIndex)));
}
else {
//unknown Macro: assume that it is set to ""
result=invert;
}
}
else {
//maybe a user defined permission
integer udpIndex=llListFindList(UserDefinedPermissionsList, [item]);
if(~udpIndex) {
//plugin permission
string pluginPermissionType=llList2String(UserDefinedPermissionsList, udpIndex+1);
if(pluginPermissionType==USER_DEFINED_PERMISSION_TYPE_BOOL) {
result=logicalXor(invert, (integer)llList2String(UserDefinedPermissionsList, udpIndex+2));
}
else {
//error unknown plugin permission type
result=invert;
}
}
else {
//maybe the plugin has not registered itself right now. So assume a blank list or a 0 as value
result=invert;
}
}
}
}
return result;
}
}
integer logicalXor(integer conditionA, integer conditionB) {
//lsl do only know a bitwise XOR :(
return(conditionA && !conditionB) || (!conditionA && conditionB);
}
default {
//catch UPD updates as they occur and save values in ths script
link_message(integer sender, integer num, string str, key id) {
if(num == MACRO || num == UDPBOOL) {
//save new option(s) or macro(s) or userdefined permissions from LINKMSG
list optionsToSet = llParseStringKeepNulls(str, ["|"], []);
integer length = llGetListLength(optionsToSet);
integer index;
for(index=0; index<length; ++index) {
list optionsItems = llParseString2List(llList2String(optionsToSet, index), ["="], []);
string optionItem = llToLower(llStringTrim(llList2String(optionsItems, 0), STRING_TRIM));
string optionString = llList2String(optionsItems, 1);
string optionSetting = llToLower(llStringTrim(optionString, STRING_TRIM));
integer optionSettingFlag = optionSetting=="on" || (integer)optionSetting;
if(num==MACRO) {
integer macroIndex=llListFindList(MacroNames, [optionItem]);
if(~macroIndex) {
MacroNames=llDeleteSubList(MacroNames, macroIndex, macroIndex);
MacroValues=llDeleteSubList(MacroValues, macroIndex, macroIndex);
}
MacroNames+=[optionItem];
MacroValues+=[optionString];
}
else if(num==UDPBOOL) {
integer udpIndex=llListFindList(UserDefinedPermissionsList, [optionItem]);
if(~udpIndex) {
UserDefinedPermissionsList=llDeleteSubList(UserDefinedPermissionsList, udpIndex, udpIndex+2);
}
if(num==UDPBOOL) {
UserDefinedPermissionsList+=[optionItem, USER_DEFINED_PERMISSION_TYPE_BOOL, optionSettingFlag];
}
}
}
}
else if(num == SEAT_UPDATE) {
/*
This script is going to set up a udpbool for each seat where occupied=1 and not occupied=0. The UDPBOOLs will be broadcasted to other scripts.
((The udpbool names for seats will be "seatfilled" + "1" as "seatfilled1", and "seatfilled" + "2" for seatfilled2, etc.))
There is no need to build your own as these are done and maintained in this script and would cause unexpected results.
An example might be where we have a sofa with 2 couples seats available.
When both sitters of a couple stand, we'd like to set their poses back to something that resempbles the default pose set but not disturb the other couple.
We could also have some singles poses available and would really not like to have a singles AV forced into a couples pose when they sit.
To get up-to-date sitter info, we'll grab that info from the seat update broadcast.
syntax examples
DOCARDIF|!seatfilled1 & !seatfilled2|Cpl1BaseCard[|RunIfFalse]
DOCARDIF|seatfilled1 & !seatfilled2 & seatfilled3|Cpl1BaseCard[|RunIfFalse]
*/
list seatsavailable = llParseStringKeepNulls(str, ["^"], []);
str = "";
integer Seatcount;
integer stop = llGetListLength(seatsavailable)/8;
list udps;
for(Seatcount = 0; Seatcount < stop; ++Seatcount) {
integer occupiedFlag = 0;
if (llList2Key(seatsavailable, Seatcount * 8 + 4)) {
occupiedFlag = 1;
}
udps+=["seatfilled" + (string)(Seatcount+1) + "=" + (string)occupiedFlag];
}
llMessageLinked(LINK_SET, 220, "UDPBOOL|" + llDumpList2String(udps, "|"), "");
}
else if (num == DOCARDIF) {
/*
examples
DOCARDIF|is2|SET:TrueCardToRun[|FalseCardToRun]
DOCARDIF|is2&!onT|TestCardTrue[|TestCardFalse]
*/
list TempList = llParseString2List(str, ["|"], []);
string Permissions = llList2String(TempList, 0);
string TrueCardName = llList2String(TempList, 1);
string FalseCardName = llList2String(TempList, 2);
if (isAllowed(0, Permissions)) {
llMessageLinked(LINK_SET, 200,TrueCardName, NULL_KEY);
}
else if (FalseCardName != "") {
llMessageLinked(LINK_SET, 200,FalseCardName, NULL_KEY);
}
}
}
}