Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Door Door_Lock_Script  

Door_Lock_Script

Door Lock Script.lsl

Category: Door
By : JohnG Linden
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Door_Lock_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Door_Lock_Script_1.lsl
1
2 // Door Lock Script -- JohnG Linden
3 // Edited to by Cutter Rubio to make it work with later LSL releases.
4 // Changed to "Table Wing Script" by James Seraph
5
6 // To make this script open/close an actual door, the door should listen
7 // for the following messages on the following chat channel. One lock
8 // can control multiple doors if they all listen on the same channel.
9 //
10 // It is advisable for you to pick your own channel number so other locks
11 // in the area don't inadvertently open/close your door.
12 //
13 integer gLockChannel = 69;
14 string gOpenMsg = "MSG_OPEN";
15 string gCloseMsg = "MSG_CLOSE";
16 //
17 // Final note: if you need to open doors a long way from the lock, look
18 // for the functions door_open_msg() and door_close_msg() below, and
19 // change the llSay() to llShout().
20
21 // who owns this door
22 // this is changed by on_rez to whoever rezzed the door
23 string gAdministrator = "";
24
25 // who's in and who's out
26 // can be changed by the admin at runtime
27 list gAdmittedList =
28 [
29 ];
30 list gBannedList =
31 [
32 ];
33
34 // return values from permissions funcs
35 integer PERM_BANNED = -1;
36 integer PERM_NO = 0;
37 integer PERM_ADMIN = 1;
38 integer PERM_OK = 2;
39
40 // permission given to people not on any list
41 // if you just want to exclude people on the banned list and admit
42 // everyone else, set to PERM_OK
43 integer gDefaultPerm = PERM_OK;
44
45 // Note: this all would be much easier with lists that can contain lists,
46 // as people could have multiple properties hanging on them. Currently
47 // it's better than arrays but is still somewhat broken, because you have
48 // to assume a # of data fields instead of being able to traverse a list
49 // of lists.
50
51 //
52 // Helper functions here
53 // Uncomment as needed to enable some debug output
54 //
55
56 func_debug(string str)
57 {
58 // llSay(0, str);
59 }
60 debug(string str)
61 {
62 // llSay(0, str);
63 }
64 say(string str)
65 {
66 llSay(0, str);
67 }
68
69 // is name on admitted list?
70 integer check_admitted_list (string name)
71 {
72 if( llListFindList(gAdmittedList, [name]) >= 0 )
73 {
74 return TRUE;
75 } else
76 {
77 return FALSE;
78 }
79 }
80
81 // is name on banned list?
82 integer check_banned_list (string name)
83 {
84 if( llListFindList(gBannedList, [name]) >= 0 )
85 {
86 return TRUE;
87 } else
88 {
89 return FALSE;
90 }
91 }
92
93 // does name have perms to open the door?
94 integer check_permission (string name)
95 {
96 say("check_permission: " + name);
97 // admin always wins (and cannot ban themselves)
98 if( name == gAdministrator ) return PERM_ADMIN;
99 // now check the plebeians
100 if( check_banned_list(name) == TRUE ) return PERM_BANNED;
101 if( check_admitted_list(name) == TRUE ) return PERM_OK;
102 // not on any lists, check default
103 return gDefaultPerm;
104 }
105
106 add_to_admitted_list (string name)
107 {
108 func_debug("add_to_allowed_list");
109
110 gAdmittedList = gAdmittedList + name;
111 }
112
113 add_to_banned_list (string name)
114 {
115 func_debug("add_to_banned_list");
116
117 gBannedList = gBannedList + name;
118 }
119
120 integer remove_from_admitted_list (string name)
121 {
122 func_debug("remove_from_admitted_list");
123
124 list lyst;
125
126 debug("admit: looking for " + name);
127
128 // search and destroy
129 integer index = llListFindList(gAdmittedList, [name]);
130 if( index >= 0 )
131 {
132 debug("admit: found " + name);
133
134 // remove entry
135 gAdmittedList = llDeleteSubList(gAdmittedList, index, index);
136 return TRUE;
137 }
138
139 // couldn't find
140 debug("admit: can't find " + name);
141 return FALSE;
142 }
143
144 integer remove_from_banned_list (string name)
145 {
146 func_debug("remove_from_banned_list");
147
148 list lyst;
149
150 debug("ban: looking for " + name);
151
152 // search and destroy
153 integer index = llListFindList(gBannedList, [name]);
154 if( index >= 0 )
155 {
156 debug("ban: found " + name);
157
158 // remove entry
159 gBannedList = llDeleteSubList(gBannedList, index, index);
160 return TRUE;
161 }
162
163 // couldn't find
164 debug("ban: can't find " + name);
165 return FALSE;
166 }
167
168 show_list (list src)
169 {
170 integer i;
171 integer len = llGetListLength(src);
172
173 for ( i = 0; i < len; ++i )
174 {
175 say(llList2String(src, i));
176 }
177 }
178
179 show_admitted_list ()
180 {
181 say("Allowed avatars:");
182 show_list (gAdmittedList);
183 }
184
185 show_banned_list ()
186 {
187 say("Banned avatars:");
188 show_list (gBannedList);
189 }
190
191 // parses incoming messages and does dirty work accordingly
192 parse_and_handle_message (string message)
193 {
194 func_debug("parse_and_handle_message");
195
196 string name;
197
198 // we only listen to admin, so no user check here
199 if( "ban " == llGetSubString(message, 0, 3) )
200 {
201 name = llGetSubString(message, 4, -1);
202 if( name != gAdministrator )
203 {
204 // note: no check for validity of usernames
205 add_to_banned_list (name);
206 remove_from_admitted_list (name);
207 say(name + " has been banned.");
208 } else
209 {
210 // error
211 say("You cannot ban yourself.");
212 }
213 }
214 else if( "admit " == llGetSubString(message, 0, 5) )
215 {
216 name = llGetSubString(message, 6, -1);
217 if( name != gAdministrator )
218 {
219 add_to_admitted_list (name);
220 remove_from_banned_list (name);
221 say(name + " will now be allowed to open and close the table.");
222 } else
223 {
224 // error
225 say("You are already allowed to open and close the table.");
226 }
227 }
228 else if( "forget " == llGetSubString(message, 0, 6) )
229 {
230 name = llGetSubString(message, 7, -1);
231 // remove user from ban and admit lists
232 if( remove_from_banned_list(name) )
233 {
234 say(name + "'s ban has been revoked.");
235 if( gDefaultPerm == PERM_NO )
236 {
237 say("But the current default permissions still do not allow them");
238 say("to open this Table.");
239 }
240 }
241 if( remove_from_admitted_list(name) )
242 {
243 say(name + "'s access has been revoked.");
244 if( gDefaultPerm == PERM_OK )
245 {
246 say("But the current default permissions still allow them");
247 say("to open this Table.");
248 }
249 }
250 }
251 else if( "list" == llGetSubString(message, 0, 3) )
252 {
253 say("Administrator: " + gAdministrator);
254 show_admitted_list();
255 show_banned_list();
256 if( gDefaultPerm == PERM_NO )
257 {
258 say("Anyone not specifically allowed to open the table cannot.");
259 } else
260 {
261 say("Anyone not specifically banned is allowed to open the table.");
262 }
263 say("Type 'help' for full command list.");
264 }
265 else if( "default admit" == llGetSubString(message, 0, 12) )
266 {
267 say("Anyone not specifically banned is now allowed to open the table.");
268 gDefaultPerm = PERM_OK;
269 }
270 else if( "default ban" == llGetSubString(message, 0, 10) )
271 {
272 say("Anyone not specifically allowed is now denied permission to open the table.");
273 gDefaultPerm = PERM_NO;
274 }
275 else if( "help" == llGetSubString(message, 0, 3) )
276 {
277 // list of commands
278 say("Command List:");
279 say("admit [name] -- grants permission to open and close table");
280 say("ban [name] -- revokes permission to open and close table");
281 say("list -- shows admit/ban lists");
282 say("forget [name] -- removes from admit and ban lists");
283 say("default admit -- anyone not specifically banned is allowed to open and close table");
284 say("default ban -- anyone not specifically admitted is allowed to open and close table");
285 say("help -- this text");
286 }
287 }
288
289 // send messages to actual door
290 door_open_msg()
291 {
292 func_debug("door_open_msg");
293 llSay(gLockChannel, gOpenMsg);
294 }
295 door_close_msg()
296 {
297 llSay(gLockChannel, gCloseMsg);
298 }
299
300 //
301 // States
302 //
303
304 default
305 {
306 on_rez(integer param) { llResetScript(); }
307
309 {
310 func_debug("default state_entry");
311 // set the owner to administrator
312 string owner = llKey2Name(llGetOwner());
313 if( owner == "" )
314 {
315 say("FATAL ERROR: no owner!");
316 }
317 gAdministrator = owner;
318 say("Table Admin: " + owner);
319 // listen for the administrator
320 llListen(0, "", "", "");
321 // door starts out closed
322 state closed_state;
323 }
324
326 {
327 }
328 }
329
330 state closed_state
331 {
332 on_rez(integer param) { llResetScript(); }
333
335 {
336 func_debug("closed_state state_entry");
337 llPlaySound("lock_close", 0.7);
338 llListen(0, "", NULL_KEY, "");
339 // tell door to close
340 door_close_msg();
341 }
342
343 touch_start(integer num_touches)
344 {
345 func_debug("closed_state touch_start");
346 // currently we only address the first touch, if multiple
347 integer i = 0;
348 // who touched us?
349 string name = llDetectedName(i);
350 // can they open the door?
351 integer perm = check_permission(name);
352 if( perm == PERM_ADMIN )
353 {
354 // Yes, master. I'd like a call to determine gender so
355 // I can say "mistress" when appropriate
356 say("");
357 state open_state;
358 } else if( perm == PERM_OK )
359 {
360 // yep
361 say("");
362 state open_state;
363 } else if( perm == PERM_BANNED )
364 {
365 // specifically denied
366 say(name + " is specifically prohibited from opening this table.");
367 } else
368 {
369 say(name + " is not permitted to open this table.");
370 }
371 }
372
373 listen(integer channel, string name, key id, string message)
374 {
375 func_debug("closed_state listen");
376 // note: we don't check name because we only listen to our admin
377 parse_and_handle_message (message);
378 }
379
381 {
382 }
383 }
384
385 state open_state
386 {
387 on_rez(integer param) { llResetScript(); }
388
390 {
391 func_debug("open_state state_entry");
392 llPlaySound("lock_open", 0.7);
393 llListen(0, "", NULL_KEY, "");
394 // tell door to open
395 door_open_msg();
396 }
397
398 touch_start(integer num_touches)
399 {
400 func_debug("open_state touch_start");
401 // currently we only address the first touch, if multiple
402 integer i = 0;
403 // who touched us?
404 string name = llDetectedName(i);
405 // can they open the door?
406 integer perm = check_permission(name);
407 if( perm == PERM_ADMIN )
408 {
409 // Yes, master. I'd like a call to determine gender so
410 // I can say "mistress" when appropriate
411 say("Table Open.");
412 state closed_state;
413 } else if( perm == PERM_OK )
414 {
415 // yep
416 say("Table Open for " + name);
417 state closed_state;
418 } else if( perm == PERM_BANNED )
419 {
420 // specifically denied
421 say(name + " is specifically prohibited from closing this table.");
422 } else
423 {
424 say(name + " is not permitted to close this table.");
425 }
426 }
427
428 listen(integer channel, string name, key id, string message)
429 {
430 func_debug("open_state listen");
431 // note: we don't check name because we only listen to our admin
432 parse_and_handle_message (message);
433 }
434
436 {
437 }
438 }
439 // END //

Back to the Best Free Tools in Second Life and OpenSim.