Database Teleporter BRIGADOON-0009
An Open Simulator Teleporter using a central database.
Loading...
Searching...
No Matches
brigadoon_teleporter.osl
Go to the documentation of this file.
1
15
20 string VERSION_STRING = "1.2.0";
21
26string CONFIG_NOTECARD_NAME = "brigadoon_teleporter.config";
27
32string CONFIG_DESTINATIONS_NAME = "teleport_destinations.config";
33
40string COMMENT_PREAMBLE = "//";
41
47
52//string DATABASE_INTERFACE = "DATABASE_INTERFACE";
53
58string LOCATION_NAME = "LOCATION_NAME";
59
67float TIME_TO_DECIDE = 60.0;
68
73float TIMER_OFF = 0.0;
74
87
95
96/* \var list menu_list
97 * \brief This of menu items to be shown
98 *
99 *
100 */
102
109
115
121
127
133
139
146
152
153/* \var integer comms_channel
154 * \brief Communication Channel used for the Menu
155 *
156 */
158
164
165/* \var integer station_base
166 * \brief offset in the destination list to start listing
167 *
168 */
169integer station_base = 0;
170
176
185
191
197integer LOCAL_FLAG = 1;
198
204integer REGION_FLAG = 2;
205
211integer WORLD_FLAG = 4;
212
218integer METAVERSE_FLAG = 8;
219
227string rdLocInfo2String(integer LocationInfo, integer Index)
228{
229 string location_area = "";
230
231 if ((LocationInfo & LOCAL_FLAG) != 0) location_area = destination_group[Index];
232 else if ((LocationInfo & REGION_FLAG) != 0) location_area = destination_region[Index];
233 else if ((LocationInfo & WORLD_FLAG) != 0) location_area = destination_region[Index];
234 else if ((LocationInfo & METAVERSE_FLAG) != 0) location_area = destination_world[Index];
235 return " [" + location_area + "]";
236}
237
246{
247 integer random_value = 0x80000000 | (integer)llFrand(65536) | ((integer)llFrand(65536) << 16);
248 return(random_value);
249}
250
258{
259 list button_list;
260 menu_list = [];
261
262 // Add the back button if necessary
263 if (station_base > 0) button_list += "<<"; else button_list += " ";
264
265 // Add Done Button
266 button_list += "DONE";
267
268 // Add the Forward button, if necessary
269 if (station_list_size > (station_base + DIALOG_STATION_LIMIT)) button_list += ">>"; else button_list += " ";
270
271 // Now select the next (up to) nine (9) locatiions to display on the menu
272 string menu_header = "Destinations Available from " + location_name + "\n";
273 integer index;
274 for (index = 0; index < DIALOG_STATION_LIMIT; ++index)
275 {
276 // Increase the menu number to match the actual number in the destination list, rather than menu number
277 integer station_pos = index + station_base;
278 if (station_pos < station_list_size)
279 {
280 // Get the type of location this destination is
281 integer loc_info = (integer)llList2String(destination_loc_type, station_pos);
282
283 // Get name of the destination and the type of location it is
284 string item_name = llUnescapeURL(llList2String(destination_name, station_pos)) + rdLocInfo2String(loc_info, station_pos);
285 string index_string = (string)(station_pos + 1);
286
287 // Add the Index, Name and location type to the menu header
288 menu_header += "[" + index_string + "] " + item_name + "\n";
289
290 // Add the index to the Buuton List to be displayed
291 button_list += index_string;
292
293 // Add the index to the line that will be scanned to match selections
294 menu_list += index_string;
295 }
296
297 // If there aren't enough destinations to fill the nine (9) spaces use blanks
298 else
299 {
300 // Add to the button list, but not the menu list as we don'r want matches to empty buttons
301 button_list += " ";
302 }
303 }
304
305 // Display the Dialog Menu
306 llDialog(User, menu_header, button_list, comms_channel);
307}
308
316rdDoTeleport(key Agent, integer Index)
317{
318 // Get information about the Destination Location
319 string the_world = llList2String(destination_world, Index);
320 string the_region = llList2String(destination_region, Index);
321 vector the_landing = (vector)llList2String(destination_location, Index);
322 vector the_look_at = (vector)llList2String(destination_look_at, Index);
323
324 // Update the current location of the Teleporter to select correct Teleportation Routine
325 location_region = llGetRegionName();
326 vector location_position = llGetPos();
327
328 // If the Destination is not in this simulator, use a hop command to get there
329 if (location_world != the_world)
330 {
331 osTeleportAgent(Agent, the_world + ":" + the_region, the_landing, the_look_at);
332 }
333
334 // If the Destination is not in this Region, use a Teleport command that specifies the Region
335 else if (location_region != the_region)
336 {
337 osTeleportAgent(Agent, the_region, the_landing, the_look_at);
338 }
339
340 // If the destination is in this region, but not the landing location of this Teleporter us a local Teleport
341 else if (location_position != the_landing)
342 {
343 osTeleportAgent(Agent, the_landing, the_look_at);
344 }
345}
346
352{
353 // Clear the Teleportation Lists
357
358 // Loop though Destination Configuration File
359 integer list_length = osGetNumberOfNotecardLines(CONFIG_DESTINATIONS_NAME);
360 integer index = 0;
361 do
362 {
363 // Get the Line
364 string trimmed_line = llStringTrim(osGetNotecardLine(CONFIG_DESTINATIONS_NAME, index), STRING_TRIM);
365
366 // Skip comment lines and blank lines
367 if ( (llGetSubString(trimmed_line, 0, COMMENT_PREAMBLE_LENGTH - 1) != COMMENT_PREAMBLE) && (trimmed_line != "") )
368 {
369 // Split the Teleportation Destination COmponents out.
370 list destination = llParseString2List(trimmed_line, ["|"], []);
371 destination_name += (string)destination[0];
372 destination_world += (string)destination[1];
373 destination_region += (string)destination[2];
374 destination_location += (string)destination[3];
375 destination_look_at += (string)destination[4];
376 destination_loc_type += (string)destination[5];
377 destination_group += (string)destination[6];
378 }
379 }
380 while (++index < list_length);
381
382 // Set the Size of teh Destination List for the Menu
383 station_list_size = llGetListLength(destination_name);
384}
385
394{
395 // Get the location of the current world
396 location_world = llGetSubString(osGetGridHomeURI(), 7, -1);
397
398 // Get a Communications Channel. This can been overridden in the basic configuration
400
401 // Read the Configuration File into a List of Lines
402 string config = osGetNotecard(CONFIG_NOTECARD_NAME);
403 list config_data = llParseString2List(config, ["\n"], []);
404
405 // Process each line in the Configuration Data
406 integer index = 0;
407 integer list_length = llGetListLength(config_data);
408 for (; index < list_length; ++index)
409 {
410 // Trim line of Leading and Trailing Spaces
411 string trimmed_line = llStringTrim(llList2String(config_data, index), STRING_TRIM);
412
413 // Only Process lines that are not a comment line or blank
414 if ( (llGetSubString(trimmed_line, 0, COMMENT_PREAMBLE_LENGTH - 1) != COMMENT_PREAMBLE) && (trimmed_line != "") )
415 {
416 // Parse Line for a Configuration Field.
417 list key_value = llParseString2List(trimmed_line, ["="], []);
418
419 // Fold the Trimmed Key into upper case, to eliminate errors where the case is wrong in the config file.
420 string key_object = llToUpper(llStringTrim(llList2String(key_value, 0), STRING_TRIM));
421
422 // Trim the Value to remove leading and training spaces
423 string value_object = llStringTrim(llList2String(key_value, 1), STRING_TRIM);
424
425 // Process the Key-Value Pairs to Set Configuration
426 if (key_object == LOCATION_NAME) location_name = value_object;
427 }
428 location_region = llGetRegionName();
429 }
430
431 // Initial Read of the teleportation Destnation List
433}
434
440//default
441{
448 state_entry()
449 {
450 // Configure the Teleporter Script
452 }
453
460 touch_start(integer TotalNumber)
461 {
462 // Remove any listen handlw
463 llListenRemove(listen_handle);
464
465 // Find out who touched this
466 key user = llDetectedKey(0);
467
468 // Get a new listener & show the Menu to the User
469 listen_handle = llListen(comms_channel, "", user, "");
471
472 // Set a time to ensure the menu is onolu active for a short time
473 llSetTimerEvent(TIME_TO_DECIDE);
474 }
475
487 listen(integer Channel, string Name, key Id, string Message)
488 {
489 integer found_index = -1;
490
491 // If this was not the same user as before , reset to the start of the list
492 if (Id != last_user)
493 {
494 station_base = 0;
495 last_user = Id;
496 }
497
498 // Resert the Lilst to the start if the user is bombing out of the destionation selection
499 if ((Message == "DONE") || (Message == "OK") || (Message == " ") || (Message == "Ignore"))
500 {
501 station_base = 0;
502 return;
503 }
504
505 // If the selection is go back a page, reduce the base pointer by the number of items on a page
506 if (Message == "<<")
507 {
510 }
511
512 // If the selection is to go forward a page, increase the base pointer by the number of items on a page
513 else if (Message == ">>")
514 {
517 }
518
519 // Othereise this ia s destination selection, so process it
520 else
521 {
522 // Scan the list for a match
523 integer index;
524 for (index = 0; index < station_list_size; index++)
525 {
526 // Check if there is a match in the list of items displayed
527 if (llList2String(menu_list, index) == Message)
528 {
529 // Get the actual index into the entire list
530 found_index = index + station_base;
531
532 // End the loop by going to the end index
533 index = station_list_size;
534 }
535 }
536
537 // If a Match was found, Teleport the user to the Destination & reset Dialog parameters
538 if (found_index != -1) {rdDoTeleport(Id, found_index); station_base = 0; last_user = NULL_KEY;}
539 }
540 }
541
549 changed(integer Change)
550 {
551 // If the Inventory has changed, assume it will be the configuration notecard and/or destination notecard
552 if (Change == CHANGED_INVENTORY)
553 {
554 // A Full Reset can cause a race condition when accessin the destination file controlled by the heartbeat script.
555 // Give a bit of time to stop the script not being able to see the destination file immediately after it is rewritten.
556 llSleep(0.25);
557
558 // Reest script and reload Destinations
560 }
561 }
562
571 timer()
572 {
573 llListenRemove(comms_channel);
574 llSetTimerEvent(TIMER_OFF);
575 station_base = 0;
576 }
577}
integer REGION_FLAG
Number value of REgion Location flag.
integer COMMENT_PREAMBLE_LENGTH
THe number of characters in the comment preamble.
list destination_look_at
string CONFIG_DESTINATIONS_NAME
The automatically generated list of teleporter destinations.
string location_name
The display name of the current location.
string CONFIG_NOTECARD_NAME
The name of the notecard containing the Teleport's Configuration.
string LOCATION_NAME
THe Key Value for defining hte name of the location in the Config notecard.
integer rdCalcCommsChannel()
find a pseudo random communications channel number
list menu_list
list destination_group
Group to which the Location belongs.
float TIMER_OFF
Settings a Zero Time will turn off the Timer.
list destination_location
integer METAVERSE_FLAG
Number value of Metaverse Location flag.
list destination_region
The list of Teleport region names.
string location_region
Region holding the Teleporter.
integer comms_channel
float TIME_TO_DECIDE
Time a Menu remains active.
integer station_list_size
The total number of Destinations available.
rdInitialiseTeleporter()
Initialise or re-initialise the Teleporter.
string VERSION_STRING
The Current version of the software.
rdShowStationDialog(key User)
Display the Destination Teelport Menu.
integer WORLD_FLAG
Number value of World Location flag.
list destination_world
The list of Teleport world addresses.
rdReadDestinationList()
Read the list of Teleportation Destinations from the Notecard.
string COMMENT_PREAMBLE
Preamble for a comment line in the configuration file.
list destination_name
The list of Teleport location names.
string rdLocInfo2String(integer LocationInfo, integer Index)
integer LOCAL_FLAG
Number value of Local Location flag.
integer listen_handle
rdDoTeleport(key Agent, integer Index)
Select the Correct Teleportation Routine.
key last_user
the last user of the teleport menu
string location_world
The Teleporter Location's World.
integer station_base
integer DIALOG_STATION_LIMIT
The hard maximum number of Destinations on any menu page.
list destination_loc_type
The list of location types.
The Default State of the Script.