normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / searchbert_menus_v5.2.txt
1 
2 // huffware script: searchbert menus, by fred huffhines.
3 //
4 // manages the menu system for searchbert so the main script is free to do its thing.
5 //
6 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
7 // do not use it in objects without fully realizing you are implicitly accepting that license.
8 //
9
10 //notes
11 // + need to have the searchbert initiate anything here.  this cannot be free range and
12 //   running even if the searchbert isn't in a menuable mode.
13 // + is the above true?
14
15 // global constants...
16
17 string MAIN_MENU_NAME = "main";  // name we use in menu list manager for the main menu.
18 // boilerplate text that's shown at top of main menu.  we'll add the channel info later.
19 string MAIN_MENU_PREFIX = "Quick help: Say '";
20 string MAIN_MENU_MIDDLE = "#find XYZ' in chat to locate nearby objects with 'XYZ' in their names.\nSay '";
21 string MAIN_MENU_SUFFIX = "#reset' to stop showing a previous search.\n\n[Matches] shows recent search results.\n[Configure] changes options.\n[Reset] clears recent results.\n[Help] dispenses an instruction notecard.";
22
23 // main menu items...
24 string HELP_CHOICE = "Help";
25 string CONFIG_CHOICE = "Configure";
26 string MATCHES_CHOICE = "Matches";
27 string RESET_CHOICE = "Reset";
28
29 // configuration menu items...
30 string MAX_MATCHES_CHOICE = "Max Match";
31 string CHAT_CHANNEL_CHOICE = "Channel";
32 string SEARCH_TYPE_CHOICE = "SearchType";
33 string PRESENT_ARMS_CHOICE = "PresentArms";
34
35 // menu indices...
36 integer MAIN_MENU_INDEX = 0;  // we always do main menu as zero.
37 integer CONFIG_MENU_INDEX = 1;  // choices for configurable items.
38 integer MAX_MATCHES_MENU_INDEX = 2;  // changing the number of matches.
39 integer SEARCH_TYPE_CHOICE_INDEX = 3;  // menu for search types.
40 integer PRESENT_ARMS_CHOICE_INDEX = 4;  // menu for searchbert arm styles.
41
42 // searchbert menus API.
43 //////////////
44 // do not redefine these constants.
45 integer SEARCHBERT_MENUS_HUFFWARE_ID = 10034;
46     // the unique id within the huffware system for this script.
47 //////////////
48 string SM_CONFIGURE_INFO = "#sm-info#";
49     // sets important information this script will use, such as (1) the channel for listening.
50 string SM_POP_MAIN_MENU_UP = "#sm-main#";
51     // causes the main menu to be displayed.  this requires an avatar name and avatar key for the
52     // target of the menu.
53 //////////////
54 string SM_EVENT_MENU_CLICK = "#sm-clik#";
55     // the user has requested a particular menu item that this script cannot fulfill.  the
56     // event is generated back to the client of this script for handling.  it will include (1) the
57     // menu name in question, (2) the item clicked, (3) the avatar name, and (4) the avatar key.
58 //////////////
59
60 // imported interfaces...
61
62 // menu list manager link message API.
63 //////////////
64 // do not redefine these constants.
65 integer MENU_LIST_MANAGER_HUFFWARE_ID = 10033;
66     // the unique id within the huffware system for this sensor plugin script.
67 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
68     // this pattern is an uncommon thing to see in text, so we use it to separate
69     // our commands in link messages.
70 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
71     // used to separate lists of items from each other when stored inside a parameter.
72     // this allows lists to be passed as single string parameters if needed.
73 integer REPLY_DISTANCE = 100008;  // offset added to service's huffware id in reply IDs.
74 string MENU_LIST_MGR_RESET = "#ml-reset#";
75     // throws out any current menus and gets ready to load a new set.
76 string MENU_LIST_MGR_ADD_MENU = "#ml-addmenu#";
77     // puts a new menu into our list.  this requires 3 parameters: menu name,
78     // menu title, menu button list.
79 string MENU_LIST_MGR_SHOW_MENU = "#ml-shomenu#";
80     // a request that a particular menu be shown.  the first parameter is the menu index.
81     // the second parameter is the avatar name.  the third parameter is the avatar key.
82 string MENU_LIST_MGR_GIVE_ITEM = "#ml-give#";
83     // brings up a gift giving menu.  parms are avatar name and avatar key.
84 string MENU_LIST_MGR_MODIFY_MENU = "#ml-modmenu#";
85 string MENU_LIST_KEEP_WORD = "KEEP";
86     // replaces a menu already in the list.  this requires 4 parameters: menu index, menu name,
87     // menu title, menu button list.  if a parameter is the MENU_LIST_KEEP_WORD, then that field
88     // is not changed.
89 string MENU_LIST_MGR_CHOICE_MADE_ALERT = "#ml-event-picked";
90     // alerts the driver for this script that the owner has picked a choice.  the
91     // parameters include: the text of the choice, the name of the menu, the avatar name,
92     // the avatar key.
93 //
94 //////////////
95
96 // we snag just enough of this interface to masquerade as it...
97 // card configurator link message API:
98 //////////////
99 // do not redefine these constants.
100 integer CARD_CONFIGURATOR_HUFFWARE_ID = 10042;
101     // the unique id within the huffware system for the card configurator script to
102     // accept commands on.  this is used in llMessageLinked as the num parameter.
103 //////////////
104 string CARD_CONFIG_RECEIVED_ALERT = "#cfg-event-upd#";
105     // this message is sent when the configurator has found some data updates or has finished
106     // reading the configuration file.
107 //////////////
108
109 // global variables...
110
111 integer initialized_menus_yet = FALSE;
112     // records if the menus have been set up.
113
114 // additional information that's provided by the client script.
115 integer TALKY_CHANNEL = 0;
116
117 //////////////
118
119 // sends a new menu to be placed in the menu manager.
120 add_menu(string menu_name, string menu_title, list button_list)
121 {
122     if (llGetListLength(button_list) == 0) {
123         // patch this degenerate list into a bogus one.
124         button_list = [ "none" ];
125     }
126     llMessageLinked(LINK_ROOT, MENU_LIST_MANAGER_HUFFWARE_ID, MENU_LIST_MGR_ADD_MENU,
127         menu_name + HUFFWARE_PARM_SEPARATOR
128         + menu_title + HUFFWARE_PARM_SEPARATOR
129         + wrap_item_list(button_list));
130 }
131
132 // stuffs in a new version of an old menu.
133 replace_menu(integer index, string menu_name, string menu_title, list button_list)
134 {
135     llMessageLinked(LINK_ROOT, MENU_LIST_MANAGER_HUFFWARE_ID, MENU_LIST_MGR_MODIFY_MENU,
136         (string)index + HUFFWARE_PARM_SEPARATOR
137         + menu_name + HUFFWARE_PARM_SEPARATOR
138         + menu_title + HUFFWARE_PARM_SEPARATOR
139         + wrap_item_list(button_list));
140 }
141
142 // sets up the main menu options.  if "new_now" is false, then this replaces
143 // the main menu rather than expecting to add a new one.
144 establish_main_menu(integer new_now)
145 {
146     // menu zero: this is the main menu.
147     string menu_name = "main";
148     string menu_title = MAIN_MENU_PREFIX + channel_string() + MAIN_MENU_MIDDLE
149         + channel_string() + MAIN_MENU_SUFFIX;
150     list menu_button_list = [ MATCHES_CHOICE, CONFIG_CHOICE, RESET_CHOICE, HELP_CHOICE ];
151     if (new_now) {
152         add_menu(menu_name, menu_title, menu_button_list);
153     } else {
154         replace_menu(MAIN_MENU_INDEX, menu_name, menu_title, menu_button_list);
155     }
156 }
157
158 // sets up all of the static menus for searchbert.
159 prepare_all_menus()
160 {
161     establish_main_menu(TRUE);  // set up the main menu as a new menu.
162
163     // configuration menu provides tasty options for changing the way searchbert behaves.
164     string menu_name = CONFIG_CHOICE;  // reusing menu button from main menu for the menu name.
165     string menu_title = "Configurable Options...\n[" + MAX_MATCHES_CHOICE + "] selects number of items to find.\n[" + CHAT_CHANNEL_CHOICE + "] changes listening channel for commands.\n[" + SEARCH_TYPE_CHOICE + "] selects types to find.\n[" + PRESENT_ARMS_CHOICE + "] arm style for pointing";
166     list menu_button_list = [ MAX_MATCHES_CHOICE, CHAT_CHANNEL_CHOICE,
167         SEARCH_TYPE_CHOICE, PRESENT_ARMS_CHOICE ];
168     add_menu(menu_name, menu_title, menu_button_list);
169
170     menu_name = MAX_MATCHES_CHOICE;  // reusing menu button from config menu.
171     menu_title = "Choose a new maximum number of items to find:";
172     menu_button_list = produce_nums(17);  // ultimate number of arms available (magic constant!).
173     add_menu(menu_name, menu_title, menu_button_list);
174
175     menu_name = SEARCH_TYPE_CHOICE;  // reusing type button too.
176     menu_title = "Look for what types?:\n1=Agent, 2=Active,\n3=Agent+Active, 4=Passive,\n5=Agent+Passive, 6=Agent+Passive\n7=Agent+Active+Passive (i.e. anything)";
177     menu_button_list = produce_nums(7);  // max bit pattern to allow.
178     add_menu(menu_name, menu_title, menu_button_list);
179
180     menu_name = PRESENT_ARMS_CHOICE;  // this is becoming a trend.
181     menu_title = "Which arm pointing style should be used?\n0 = arm middles centered\n1 = arm ends at opposite wall\n2 = arm ends at nearest wall\n3 = arm ends centered";
182     menu_button_list = [ "0" ] + produce_nums(3);  // 0, plus 1-3.
183     add_menu(menu_name, menu_title, menu_button_list);
184
185 }
186
187 // if we haven't initialized yet, we'll do it now.
188 maybe_really_setup_menus()
189 {
190     if (!initialized_menus_yet) {
191 //log_it("needed initialization still!");
192         prepare_all_menus();
193         initialized_menus_yet = TRUE;
194         llSetTimerEvent(0);  // stop timer.
195         return;
196     }
197 }
198
199 // deals with the timer elapsing.
200 handle_timer_hit()
201 {
202     // see if this timer is for initialization purposes.
203     maybe_really_setup_menus();
204 }
205
206 // processes a message requesting our services or updating our info.  or ignore it.
207 handle_link_message(integer sender, integer num, string msg, key id)
208 {
209     if ( (num != MENU_LIST_MANAGER_HUFFWARE_ID + REPLY_DISTANCE)
210             && (num != SEARCHBERT_MENUS_HUFFWARE_ID) )
211         return;
212
213     // make sure we're already initialized.
214     maybe_really_setup_menus();
215
216     list parms = llParseStringKeepNulls(id, [HUFFWARE_PARM_SEPARATOR], []);
217
218     if (num == MENU_LIST_MANAGER_HUFFWARE_ID + REPLY_DISTANCE) {
219         if (msg == MENU_LIST_MGR_CHOICE_MADE_ALERT) {
220             // now deal with the implications of the menu they chose.
221             process_menu_choice(llList2String(parms, 1), llList2String(parms, 2),
222                 llList2String(parms, 3), llList2String(parms, 0));
223         }
224         return;
225     }
226     
227     // if we got to here, it must be for our main interface methods.
228 //log_it("got searchbert menu request: " + msg + ".  memory left=" + (string)llGetFreeMemory());
229     if (msg == SM_CONFIGURE_INFO) {
230         TALKY_CHANNEL = (integer)llList2String(parms, 0);
231         establish_main_menu(FALSE);
232     } else if (msg == SM_POP_MAIN_MENU_UP) {
233         // show the main menu for the specified avatar.
234         request_menu_popup(MAIN_MENU_INDEX, llList2String(parms, 0), llList2String(parms, 1));
235     }
236
237 }
238
239 request_menu_popup(integer menu_index, string av_name, string av_key)
240 {
241     llMessageLinked(LINK_ROOT, MENU_LIST_MANAGER_HUFFWARE_ID, MENU_LIST_MGR_SHOW_MENU,
242         wrap_parameters([menu_index, av_name, av_key]));
243 //log_it("sent menu popup to av " + av_name + " with key " + av_key + "...  memory left=" + (string)llGetFreeMemory());
244 }
245
246 // generates a list of numbers up to and including the "max".
247 list produce_nums(integer max)
248 {
249     list to_return;
250     integer indy;
251     for (indy = 1; indy <= max; indy++) {
252         to_return += (string)indy;
253     }
254     return to_return;
255 }
256
257 // returns the appropriate extra text if the channel is not zero for open chat.
258 string channel_string()
259 {
260     string add_in_channel = "";
261     if (TALKY_CHANNEL != 0)
262         add_in_channel = "/" + (string)TALKY_CHANNEL + " ";
263     return add_in_channel;
264 }
265
266 // handles when a menu has been clicked on.
267 process_menu_choice(string menu_name, string av_name, string av_key, string which_choice)
268 {
269 //log_it("into process menu " + menu_name + " for " + av_name + " who chose " + which_choice);
270     if (menu_name == MAIN_MENU_NAME) {
271         if (which_choice == HELP_CHOICE) {
272             // see if we can find a helper notecard.
273             integer indy = find_basename_in_inventory("docs", INVENTORY_NOTECARD);
274             if (indy < 0) {
275                 llSay(0, "We're very sorry, but there do not seem to be any documentation notecards available.  There may be a better version at eepaw shop (osgrid or SL).");
276             } else {
277                 string invname = llGetInventoryName(INVENTORY_NOTECARD, indy);
278                 llGiveInventory(av_key, invname);
279                 llWhisper(0, "Here's a copy of the help file: " + invname);
280             }
281             return;
282         } else if (which_choice == CONFIG_CHOICE) {
283             request_menu_popup(CONFIG_MENU_INDEX, av_name, av_key);
284             return;
285         }
286         // MATCHES_CHOICE falls through for forwarding.
287         // so does RESET_CHOICE.
288     } else if (menu_name == CONFIG_CHOICE) {
289         if (which_choice == MAX_MATCHES_CHOICE) {
290             // let them pick a new maximum number of matches to find.
291             request_menu_popup(MAX_MATCHES_MENU_INDEX, av_name, av_key);
292             return;
293         } else if (which_choice == CHAT_CHANNEL_CHOICE) {
294             llSay(0, "To change the chat channel, say '" + channel_string()
295                 + "#channel N' where N is your new channel number.");
296             return;
297         } else if (which_choice == SEARCH_TYPE_CHOICE) {
298             // ask what types to allow.
299             request_menu_popup(SEARCH_TYPE_CHOICE_INDEX, av_name, av_key);
300             return;
301         } else if (which_choice == PRESENT_ARMS_CHOICE) {
302             // ask them how they want their arms arranged.
303             request_menu_popup(PRESENT_ARMS_CHOICE_INDEX, av_name, av_key);
304             return;
305         }
306     } else if (menu_name == MAX_MATCHES_CHOICE) {
307         integer max = (integer)which_choice;
308         if (max >= 1) {
309             // a new number of search matches has been decided upon.
310             send_data_burst(["max_matches", which_choice]);
311             llSay(0, "Maximum number of matches is now set to " + (string)max + ".");
312             return;
313         }
314     } else if (menu_name == SEARCH_TYPE_CHOICE) {
315         integer type = (integer)which_choice;
316         if (type >= 1) {
317             // set the types to look for during the search.
318             send_data_burst(["search_type", type]);
319             llSay(0, "Search type now set to " + (string)type + ".");
320             return;
321         }
322     } else if (menu_name == PRESENT_ARMS_CHOICE) {
323         integer pas_type = (integer)which_choice;
324         send_data_burst(["present_arms", pas_type]);
325         string arm_type = "middles centered";
326         if (pas_type == 1) arm_type = "opposite wall";
327         else if (pas_type == 2) arm_type = "nearer wall";
328         else if (pas_type == 3) arm_type = "ends centered";
329         llSay(0, "Arm presentation style is now " + arm_type + ".");
330         return;
331     }
332
333     // cases that aren't handled get forwarded to the client script.    
334     llMessageLinked(LINK_ROOT, SEARCHBERT_MENUS_HUFFWARE_ID + REPLY_DISTANCE, SM_EVENT_MENU_CLICK ,
335         wrap_parameters([menu_name, which_choice, av_name, av_key]));
336 }
337
338 // borrowed from card configurator.
339 // sends the currently held data out to whoever requested it.
340 send_data_burst(list to_send)
341 {
342 //log_it("sending " + (string)llGetListLength(to_send) + " items");
343     llMessageLinked(LINK_THIS, CARD_CONFIGURATOR_HUFFWARE_ID + REPLY_DISTANCE, CARD_CONFIG_RECEIVED_ALERT,
344         wrap_parameters(["yo-updated"] + to_send));
345     to_send = [];  // reset any items held.
346 }
347
348 // set up all the parts of the externally configured bits.
349 initialize()
350 {
351 //log_it("initializing.  memory left=" + (string)llGetFreeMemory());
352     llSleep(0.1);  // initial pause before chatting with menu manager.
353
354     // reset the menu manager to get it ready for our new menus.
355     llMessageLinked(LINK_THIS, MENU_LIST_MANAGER_HUFFWARE_ID, MENU_LIST_MGR_RESET, "");
356
357     // snooze a bit to allow our helper to wake up.
358     llSetTimerEvent(0.34);  // snooze until helper is ready.
359     initialized_menus_yet = FALSE;
360 }
361
362 //////////////
363 // from hufflets...
364 //
365 integer debug_num = 0;
366
367 // a debugging output method.  can be disabled entirely in one place.
368 log_it(string to_say)
369 {
370     debug_num++;
371     // tell this to the owner.    
372     llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
373     // say this on open chat, but use an unusual channel.
374 //    llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
375 }
376
377 //////////////
378
379 // joins a list of parameters using the parameter sentinel for the library.
380 string wrap_parameters(list to_flatten)
381 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
382
383 string wrap_item_list(list to_wrap)
384 { return llDumpList2String(to_wrap, HUFFWARE_ITEM_SEPARATOR); }
385
386 //////////////
387
388 // locates the string "text" in the list to "search_in".
389 integer find_in_list(list search_in, string text)
390
391     integer len = llGetListLength(search_in);
392     integer i; 
393     for (i = 0; i < len; i++) { 
394         if (llList2String(search_in, i) == text) 
395             return i; 
396     } 
397     return -1;
398 }
399
400 // returns the index of the first occurrence of "pattern" inside
401 // the "full_string".  if it is not found, then a negative number is returned.
402 integer find_substring(string full_string, string pattern)
403 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
404
405 // returns TRUE if the "prefix" string is the first part of "compare_with".
406 integer is_prefix(string compare_with, string prefix)
407 { return find_substring(compare_with, prefix) == 0; }
408
409 // looks for an inventory item with the same prefix as the "basename_to_seek".
410 integer find_basename_in_inventory(string basename_to_seek, integer inv_type)
411 {
412     integer num_inv = llGetInventoryNumber(inv_type);
413     if (num_inv == 0) return -1;  // nothing there!
414     integer indy;
415     for (indy = 0; indy < num_inv; indy++) {
416         if (is_prefix(llGetInventoryName(inv_type, indy), basename_to_seek))
417             return indy;
418     }
419     return -2;  // failed to find it.
420 }
421
422 //////////////
423 // huffware script: auto-retire, by fred huffhines, version 2.8.
424 // distributed under BSD-like license.
425 //   !!  keep in mind that this code must be *copied* into another
426 //   !!  script that you wish to add auto-retirement capability to.
427 // when a script has auto_retire in it, it can be dropped into an
428 // object and the most recent version of the script will destroy
429 // all older versions.
430 //
431 // the version numbers are embedded into the script names themselves.
432 // the notation for versions uses a letter 'v', followed by two numbers
433 // in the form "major.minor".
434 // major and minor versions are implicitly considered as a floating point
435 // number that increases with each newer version of the script.  thus,
436 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
437 // and "hazmap v3.2" is a more recent version.
438 //
439 // example usage of the auto-retirement script:
440 //     default {
441 //         state_entry() {
442 //            auto_retire();  // make sure newest addition is only version of script.
443 //        }
444 //     }
445 // this script is partly based on the self-upgrading scripts from markov brodsky
446 // and jippen faddoul.
447 //////////////
448 auto_retire() {
449     string self = llGetScriptName();  // the name of this script.
450     list split = compute_basename_and_version(self);
451     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
452     string basename = llList2String(split, 0);  // script name with no version attached.
453     string version_string = llList2String(split, 1);  // the version found.
454     integer posn;
455     // find any scripts that match the basename.  they are variants of this script.
456     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
457         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
458         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
459             // found a basic match at least.
460             list inv_split = compute_basename_and_version(curr_script);
461             if (llGetListLength(inv_split) == 2) {
462                 // see if this script is more ancient.
463                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
464                 // must make sure that the retiring script is completely the identical basename;
465                 // just matching in the front doesn't make it a relative.
466                 if ( (llList2String(inv_split, 0) == basename)
467                     && ((float)inv_version_string < (float)version_string) ) {
468                     // remove script with same name from inventory that has inferior version.
469                     llRemoveInventory(curr_script);
470                 }
471             }
472         }
473     }
474 }
475 //
476 // separates the base script name and version number.  used by auto_retire.
477 list compute_basename_and_version(string to_chop_up)
478 {
479     // minimum script name is 2 characters plus a version.
480     integer space_v_posn;
481     // find the last useful space and 'v' combo.
482     for (space_v_posn = llStringLength(to_chop_up) - 3;
483         (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
484         space_v_posn--) {
485         // look for space and v but do nothing else.
486     }
487     if (space_v_posn < 2) return [];  // no space found.
488     // now we zoom through the stuff after our beloved v character and find any evil
489     // space characters, which are most likely from SL having found a duplicate item
490     // name and not so helpfully renamed it for us.
491     integer indy;
492     for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
493         if (llGetSubString(to_chop_up, indy, indy) == " ") {
494             // found one; zap it.  since we're going backwards we don't need to
495             // adjust the loop at all.
496             to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
497         }
498     }
499     string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
500     // ditch the space character for our numerical check.
501     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
502     // strip out a 'v' if there is one.
503     if (llGetSubString(chop_suffix, 0, 0) == "v")
504         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
505     // if valid floating point number and greater than zero, that works for our version.
506     string basename = to_chop_up;  // script name with no version attached.
507     if ((float)chop_suffix > 0.0) {
508         // this is a big success right here.
509         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
510         return [ basename, chop_suffix ];
511     }
512     // seems like we found nothing useful.
513     return [];
514 }
515 //
516 //////////////
517
518 // end hufflets.
519 //////////////
520
521 default {
522     state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
523     on_rez(integer parm) { state rerun; }
524 }
525 state rerun { state_entry() { state default; } }
526
527 state real_default
528 {
529     state_entry() {
530         auto_retire();
531         initialize();
532     }
533     
534     on_rez(integer parm) { state default; }
535     
536     timer() { handle_timer_hit(); }
537
538     link_message(integer sender, integer num, string msg, key id) {
539         handle_link_message(sender, num, msg, id);
540     }
541
542 }
543