Database Teleporter BRIGADOON-0009
An Open Simulator Teleporter using a central database.
Loading...
Searching...
No Matches
teleport_destination_monitor.osl
Go to the documentation of this file.
1
15
20 string VERSION_STRING = "1.0.0";
21
26string CONFIG_NOTECARD_NAME = "teleport_destination_monitor.conf";
27
32string STATUS_NOTECARD_NAME = "teleport_monitor.txt";
33
38string DATABASE_INTERFACE = "DATABASE_INTERFACE";
39
44string MONITOR_INTERVAL = "MONITOR_INTERVAL";
45
50string LIFE_TIME = "LIFE_TIME";
51
56string SCAN_ONLY = "SCAN_ONLY";
57
62string IN_WORLD_ONLY = "IN_WORLD_ONLY";
63
68string COMMENT_PREAMBLE = "//";
69
75
80float SECONDS_PER_HOUR = 3600.0;
81
87 float MINIMUM_INTERVAL = 1800.0; //seconds
88
101 float MINIMUM_LIFETIME = 0.5; //hours
102
107vector WHITE_COLOUR = <1.0, 1.0, 1.0>;
108
113float SOLID_ALPHA = 1.0;
114
126float monitor_interval = 7200; // Seconds
127
135float lifetime = 24; // hours
136
145
153integer in_world_scan_only = FALSE;
154
161
167
168/* \var scan list
169 * \brief The list of responses from the php script
170 *
171 * The entries in the list are divided into status lines that start with a comment string "//"
172 * and teleporter identifications that do not.
173 *
174 */
176
185integer scan_only = TRUE;
186
195{
196 string header_string;
197 list ScanList;
198
199 // Check to see if there already is a Status Notecard
200 integer result = llGetInventoryType(STATUS_NOTECARD_NAME);
201
202 // If there is no Notecard, Start a new one with this Header
203 if (result == INVENTORY_NONE)
204 {
205 header_string = "//###################################################################\n";
206 header_string += "//###################################################################\n";
207 header_string += "//## File: Teleport_Monitor.txt\n";
208 header_string += "//## Author: River Drifter (river_drifter@aussiebroadband.com.au\n";
209 header_string += "//## Contact: river_drifter@aussiebroadband.com.au\n";
210 header_string += "//###################################################################\n";
211 header_string += "//## This notecard contains a list of Teleporters that have\n";
212 header_string += "//## exceeded their LIFE_TIME which indicates that the Teleporter\n";
213 header_string += "//## may have failed and has been removed from the Teleport table.\n";
214 header_string += "//## It the teleporter was restarted, the teleporter will be\n";
215 header_string += "//## restored to the table.\n";
216 header_string += "//## Monitor Version:" + VERSION_STRING + "\n";
217 header_string += "//## Started: " + llGetTimestamp() + "\n";
218 header_string += "//###################################################################\n";
219 header_string += "//###################################################################\n";
220 }
221
222 // Otherwise Read the existing Status Notecard and prepend it to the new list
223 else
224 {
225 // Read the Existing Status Notecard into the Header String
226 header_string = osGetNotecard(STATUS_NOTECARD_NAME);
227
228 // Delete the Existing Notecard
229 llRemoveInventory(STATUS_NOTECARD_NAME);
230 llSleep(0.1);
231 }
232
233 // Prepend the Header to the List of Teleporters
234 ScanList = [header_string] + scan_list;
235
236 // Write the Teleport List to a New Notecard
237 osMakeNotecard(STATUS_NOTECARD_NAME, ScanList);
238}
239
252integer rdConvertTrueFalse(string TrueFalseString)
253{
254 string temp = llToUpper(llStringTrim(TrueFalseString, STRING_TRIM));
255 if (temp == "TRUE") return TRUE; else return FALSE;
256}
257
266{
267 integer random_value = 0x80000000 | (integer)llFrand(65536) | ((integer)llFrand(65536) << 16);
268 return(random_value);
269}
270
278rdReadConfigNotecard(string NotecardName)
279{
280 // Read the Configuration File into a List of Lines
281 string config = osGetNotecard(NotecardName);
282 list config_data = llParseString2List(config, ["\n"], []);
283
284 // Process each line in the Configuration Data
285 integer index = 0;
286 integer list_length = llGetListLength(config_data);
287 for (; index < list_length; ++index)
288 {
289 // Trim line of Leading and Trailing Spaces
290 string trimmed_line = llStringTrim(llList2String(config_data, index), STRING_TRIM);
291
292 // Only Process lines that are not a comment line or blank
293 if ( (llGetSubString(trimmed_line, 0, COMMENT_PREAMBLE_LENGTH - 1) != COMMENT_PREAMBLE) && (trimmed_line != "") )
294 {
295 // Parse Line for a Configuration Field.
296 list key_value = llParseString2List(trimmed_line, ["="], []);
297
298 // Fold the Trimmed Key into upper case, to eliminate errors where the case is wrong in the config file.
299 string key_object = llToUpper(llStringTrim(llList2String(key_value, 0), STRING_TRIM));
300
301 // Trim the Value to remove leading and training spaces
302 string value_object = llStringTrim(llList2String(key_value, 1), STRING_TRIM);
303
304 // Process the Key-Value Pairs to Set Configuration
305 if (key_object == DATABASE_INTERFACE) database_interface = value_object;
306 else if (key_object == MONITOR_INTERVAL) monitor_interval = (float)value_object * SECONDS_PER_HOUR; // Convert hours to seconds
307 else if (key_object == LIFE_TIME) lifetime = (float)value_object; // Time in Hours
308 else if (key_object == SCAN_ONLY) scan_only = rdConvertTrueFalse(value_object);
309 else if (key_object == IN_WORLD_ONLY) in_world_only = rdConvertTrueFalse(value_object);
310 }
311 }
312
313 // Make sure the time is at least 30 minutes
316}
317
335{
336 // If only the world in which this script is located is to be scanned, include the world,
337 // otherwise, show a false world to indicate all teleporters should be included.
338 if (in_world_only == TRUE) world_state = location_world; else world_state = "###";
339
340 // Find out the information about the object requesting a scan from the php script
341 key controller_key = llGetKey();
342 list details = llGetObjectDetails(controller_key, [OBJECT_OWNER, OBJECT_GROUP]);
343
344 // Create the Heartbeat message that this object sends out
345 string heartbeat_message = database_interface + "?command=scan"
346 + "&key=" + controller_key
347 + "&owner=" + llList2String(details, 0)
348 + "&group=" + llList2String(details, 1)
349 + "&onlyscan=" + (string)scan_only
350 + "&lifetime=" + (string)lifetime
351 + "&version=" + VERSION_STRING
352 + "&world=" + world_state;
353
354 // Send the heartbeat message to the php routine on the web server
355 scan_key = llHTTPRequest(heartbeat_message, [], [""]);
356}
357
364{
365 // Get the Name of the World
366 location_world = llGetSubString(osGetGridHomeURI(), 7, -1);
367
368 // Load the Configuration Notecard
370
371 // Trigger a Scan & Purge of the Destinations Database
373
374 // Set the Timer Event to Trigger a check of the Database for expired Teleporters.
375 llSetTimerEvent(monitor_interval);
376}
377
387//default
388{
395 state_entry()
396 {
397 rdStateEntry();
398 }
399
414 http_response(key RequestId, integer Status, list Metadata, string Body)
415 {
416 // Only respond to the Scan Request
417 if (RequestId == scan_key)
418 {
419 // Check to see if the Reuest was a Success
420 if (Status != 200)
421 {
422 llSay(0, "Scan Request Failed with error " + (string)Status);
423 }
424 else
425 {
426 // Split into a list for easier processing
427 list input_list = llParseString2List(llUnescapeURL(Body), ["\n"], []);
428
429 // Step thought the list a line at a time
430 integer index = 0;
431 integer input_list_started = FALSE;
432 integer list_count = llGetListLength(input_list);
433 string line;
434 do
435 {
436 // Extract the Line
437 line = llList2String(input_list, index);
438
439 // Start the Teleport Notecard
440 if (line == "SCAN_LIST=START") input_list_started = TRUE;
441
442 // End if you find the END FLAG by setting index to the end
443 else if (line == "SCAN_LIST=END")
444 {
445 index = list_count;
446 input_list_started = FALSE;
447 }
448
449 // Extract the Data Line & Process
450 else if (input_list_started == TRUE)
451 {
452 scan_list += line + "\n";
453 }
454
455 // Add each deleted entry to the Scan List
456 }
457 while ( ++index < list_count);
458
459 // Save the List of deleted Teleporters & display prompt
460 integer scan_list_length = llGetListLength(scan_list);
461 string message_string;
462 if (scan_list_length != 0)
463 {
464 // Write the List of Returned Teleporters to the Status Notecard
466 scan_list = [];
467
468 message_string = "Examine Status Notecard for retired Teleporters\nBefore touching the Desk\nbecause this will reset the notecard.\n";
469 }
470 else message_string = "";
471
472 llSetText( message_string, WHITE_COLOUR, SOLID_ALPHA);
473 }
474 }
475 }
476
477 /* \fn timer()
478 * \brief Trigger a scan when the timer fires
479 *
480 */
481 timer()
482 {
484 }
485
490 touch(integer TouchCount)
491 {
492 // Remove the Test Prompt, if it is Visible)
493 llSetText( "", WHITE_COLOUR, SOLID_ALPHA);
494 llRemoveInventory(STATUS_NOTECARD_NAME);
495 }
496
497}
integer COMMENT_PREAMBLE_LENGTH
THe number of characters in the comment preamble.
string CONFIG_NOTECARD_NAME
The name of the notecard containing the Teleport's Configuration.
string VERSION_STRING
The Current version of the software.
string COMMENT_PREAMBLE
Preamble for a comment line in the configuration file.
string location_world
The Teleporter Location's World.
The Default State of the Script.
float MINIMUM_INTERVAL
Minimum internval between scans.
float SECONDS_PER_HOUR
The number of seconds in an hour.
string IN_WORLD_ONLY
Configuration Setting Flag.
vector WHITE_COLOUR
The RGB values for the colour white.
rdWriteStatusNotercard()
Write a Scan's results to the Status Notecard.
integer in_world_scan_only
string database_interface
The HTTP address for invoking the php script to do the scanning & deleting.
rdStateEntry()
Routine to call to initialise the Script.
float lifetime
This is maximum time between heartbeats for a working teleporter.
integer rdCalcCommsChannel()
key scan_key
The key to link the HTTP Request to the HTTP Response.
float SOLID_ALPHA
Alhpa valid for non-transparent text.
rdReadConfigNotecard(string NotecardName)
integer rdConvertTrueFalse(string TrueFalseString)
Convert "True/False" string into an integer.
string DATABASE_INTERFACE
The Identifier for the Database Interface URL.
string MONITOR_INTERVAL
The configuration prompt for the monitoring interval.
integer scan_only
A flag to request a scan for dead teleporter but without deleteing them.
string LIFE_TIME
The configuration prompt for the Teleporer LifeTime in the database.
float MINIMUM_LIFETIME
Minimum time before a telepoter is off-line.
string STATUS_NOTECARD_NAME
The name of the notcard holding the results.
float monitor_interval
Interval between scans in seconds.
rdsScanDestinationDatabase()
Scan the Teleporters in the database.
string SCAN_ONLY
The configuratin prompt for the Scan-only or delete if expired flag.