Database Signage BRIGADOON-0012
Update Signage in Open Simulator from Database
Loading...
Searching...
No Matches
signage_heartbeat.osl
Go to the documentation of this file.
1
16
17 string VERSION_STRING = "0.0.1";
18
28
29
36string CONFIG_NOTECARD_NAME = "brigadoon_signage.config";
37
44string COMMENT_PREAMBLE = "//";
45
52
57string DATABASE_INTERFACE = "DATABASE_INTERFACE";
58
63string HEARTBEAT_PERIOD = "HEARTBEAT_PERIOD";
64
65
70float TIMER_OFF = 0.0;
71
79
84float MINIMUM_OFFSET = 0.5;
85
91
97
104
115
124rdProcessFailureMessage(string FailureMessage)
125{
126 string failure_message;
127
128 list status = llParseString2List(FailureMessage, [":"], ["\n"]);
129 string failure_type = llList2String(status, 0);
130
131 // Explain why the Teleporter could not be automatically processed
132 if (failure_type == "BANNED")
133 {
134 failure_message = "Teleporters owned by user " + llList2String(status, 1) + " are not permitted to";
135 failure_message += " add teleporters to the database, update teleporter information or update teleporter destinations.";
136 }
137
138 // Tell the person what to do if there was an error.
139 failure_message += "\n If you wish to report this as an error please send this message to River Drifter with details of what happened and when.\n";
140 llSay(0, failure_message);
141}
142
150integer rdGetVersionNumber(string VersionString)
151{
152 integer version;
153
154 list versions = llParseString2List(VersionString, ["."], []);
155 version = (integer)llList2String(versions,2) + ((integer)llList2String(versions,1) * 100) + ((integer)llList2String(versions,0) * 10000);
156
157 return version;
158}
159
168rdSaveNewTeleportNotecard(list teleport_list)
169{
170 // Add the Preamble Text before the List of Destinations
171 teleport_list = destination_preamble + teleport_list;
172
173 // Delete the Existing Teleporter Destination Notecard, if it exists
174 integer count = llGetInventoryNumber(INVENTORY_NOTECARD);
175 integer index = 0;
176 for (; index < count; ++index)
177 {
178 if (llGetInventoryName(INVENTORY_NOTECARD, index) == CONFIG_DESTINATIONS_NAME)
179 {
180 llRemoveInventory(CONFIG_DESTINATIONS_NAME);
181 index = count; // Ext Loop
182 }
183 }
184
185 // Write the Teleport List to a New Notecard
186 osMakeNotecard(CONFIG_DESTINATIONS_NAME, teleport_list);
187}
188
203{
204 // Do a cursory Check that the configuration has been set up
205 if (database_interface != "")
206 {
207 key messageboard_key = llGetKey();
208 list details = llGetObjectDetails(teleporter_key, [OBJECT_OWNER, OBJECT_GROUP]);
209
210 string heartbeat_message = database_interface + "?command=heartbeat"
211 + "&key=" + messageboard_key
212 + "&owner=" + llList2String(details, 0)
213 + "&group=" + llList2String(details, 1)
214 heartbeat_key = llHTTPRequest(heartbeat_message, [HTTP_BODY_MAXLENGTH,16384], [""]);
215 }
216 else
217 {
218 llSay(DEBUG_CHANNEL, "The database_interface are undefined! Teleporter " + location_name + " has been disabled");
219 llSetScriptState(llGetScriptName(), FALSE);
220 }
221}
222
227default
228{
235 state_entry()
236 {
237 // Read the Configuration File into a List of Lines
238 string config = osGetNotecard(CONFIG_NOTECARD_NAME);
239 list config_data = llParseString2List(config, ["\n"], []);
240
241 // Process each line in the Configuration Data
242 integer index = 0;
243 integer list_length = llGetListLength(config_data);
244 for (; index < list_length; ++index)
245 {
246 // Trim line of Leading and Trailing Spaces
247 string trimmed_line = llStringTrim(llList2String(config_data, index), STRING_TRIM);
248
249 // Only Process lines that are not a comment line or blank
250 if ( (llGetSubString(trimmed_line, 0, COMMENT_PREAMBLE_LENGTH - 1) != COMMENT_PREAMBLE) && (trimmed_line != "") )
251 {
252 // Parse Line for a Configuration Field.
253 list key_value = llParseString2List(trimmed_line, ["="], []);
254
255 // Fold the Trimmed Key into upper case, to eliminate errors where the case is wrong in the config file.
256 string key_object = llToUpper(llStringTrim(llList2String(key_value, 0), STRING_TRIM));
257
258 // Trim the Value to remove leading and training spaces
259 string value_object = llStringTrim(llList2String(key_value, 1), STRING_TRIM);
260
261 // Process the Key-Value Pairs to Set Configuration
262 if (key_object == DATABASE_INTERFACE) database_interface = value_object;
263 else if (key_object == HEARTBEAT_PERIOD) heartbeat_period = (float)value_object * 3600.0; // Convert hours to seconds
264 }
265
266 // Check that the Heartbeat Period is equal to or greater than the Minimum
268 }
269
270 // Send out an Initial Heartbeat Message
272
273 // Start the Heatbeat Timer, but first check that the heartbeat period would no result in flooding of the database.
275 llSetTimerEvent(heartbeat_period);
276 }
277
292 http_response(key RequestId, integer Status, list Metadata, string Body)
293 {
294 list teleport_list;
295
296 // Only respond to the Heartbeat Request
297 if (RequestId == heartbeat_key)
298 {
299 // Check to see if the Reuest was a Success
300 if (Status != 200)
301 {
302 llSay(DEBUG_CHANNEL, "Heartbeat Request Failed with error " + (string)Status);
303 }
304 else
305 {
306 // Split into a list for easier processing
307 list input_list = llParseString2List(Body, ["\n"], []);
308
309 // Step thought the list a line at a time
310 integer index = 0;
311 integer input_list_started = FALSE;
312 integer list_count = llGetListLength(input_list);
313 string line;
314 do
315 {
316 // Extract the Line
317 line = llList2String(input_list, index);
318
319 // Split the Line into its components
320 list line_list = llString2List(llParseString2List(Body, ["="], []);
321 string key_string = llList2String(line_list, 0);
322 string value_string = llList2String(line_list, 1);
323
324 // Process the Key-Value Pairs
325 if (key_string == "")
326 {
327 }
328 else if (key_string == "")
329 {
330 }
331 else if (key_string == "")
332 {
333 }
334 else if (key_string == "")
335 {
336 }
337 }
338 while ( ++index < list_count);
339 }
340 }
341 }
342
348 timer()
349 {
351 }
352}
integer COMMENT_PREAMBLE_LENGTH
THe number of characters in the comment preamble Menu Item = [17:16] Nothing Found!
string database_interface
The address of the database interface.
rdSendHeartbeatMessage()
float MINIMUM_OFFSET
Minimum allowable offset.
string CONFIG_NOTECARD_NAME
Script(s) Configuration Notecard.
rdProcessFailureMessage(string FailureMessage)
Convert error messages into something that is more readable.
float heartbeat_period
Interval in seconds between Heartbeat messages.
float TIMER_OFF
Set the Timer delay to 0.0 which turns off the timer events.
rdSaveNewTeleportNotecard(list teleport_list)
Save the Teleportation Destinations into a Notecard.
key heartbeat_key
The Heatbeat HTTP Requrest Key.
string HEARTBEAT_PERIOD
The Configuration File Identifier for the Heartbeat Period.
string VERSION_STRING
float MINIMUM_HEARTBEAT_INTERVAL
string DATABASE_INTERFACE
The Configuration File Identifier for the Database Interface URL.
string COMMENT_PREAMBLE
Preamble for a comment line in the configuration file.
integer version_number
Version number as integer.
integer rdGetVersionNumber(string VersionString)
Convert Version String into an Integer.
float MINIMUM_HEARTBEAT_PERIOD
The fastest allowable heartbeat.