10 #include <sys/types.h>
12 #include <sys/socket.h>
15 #include <netinet/in.h>
32 char floorlist[128][SIZ];
35 * load the list of floors
37 void load_floorlist(void)
42 for (a = 0; a < 128; ++a)
48 strcpy(floorlist[0], "Main Floor");
51 while (serv_gets(buf), strcmp(buf, "000")) {
52 extract(floorlist[extract_int(buf, 0)], buf, 1);
58 * remove a room from the march list
60 void remove_march(char *aaa)
62 struct march *mptr, *mptr2;
64 if (WC->march == NULL)
67 if (!strcasecmp(WC->march->march_name, aaa)) {
68 mptr = WC->march->next;
74 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
75 if (!strcasecmp(mptr->march_name, aaa)) {
76 mptr2->next = mptr->next;
89 void room_tree_list(struct roomlisting *rp)
97 if (rp->lnext != NULL) {
98 room_tree_list(rp->lnext);
100 strcpy(rmname, rp->rlname);
103 wprintf("<A HREF=\"/dotgoto&room=");
108 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
110 else if (f & QR_DIRECTORY)
112 else if (f & QR_NETWORK)
116 wprintf("</A><TT> </TT>\n");
118 if (rp->rnext != NULL) {
119 room_tree_list(rp->rnext);
126 * Room ordering stuff (compare first by floor, then by order)
128 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
130 if ((r1 == NULL) && (r2 == NULL))
136 if (r1->rlfloor < r2->rlfloor)
138 if (r1->rlfloor > r2->rlfloor)
140 if (r1->rlorder < r2->rlorder)
142 if (r1->rlorder > r2->rlorder)
149 * Common code for all room listings
151 void listrms(char *variety)
156 struct roomlisting *rl = NULL;
157 struct roomlisting *rp;
158 struct roomlisting *rs;
161 /* Ask the server for a room list */
168 while (serv_gets(buf), strcmp(buf, "000")) {
170 rp = malloc(sizeof(struct roomlisting));
171 extract(rp->rlname, buf, 0);
172 rp->rlflags = extract_int(buf, 1);
173 rp->rlfloor = extract_int(buf, 2);
174 rp->rlorder = extract_int(buf, 3);
183 if (rordercmp(rp, rs) < 0) {
184 if (rs->lnext == NULL) {
191 if (rs->rnext == NULL) {
203 /* If no rooms were listed, print an nbsp to make the cell
204 * borders show up anyway.
206 if (num_rooms == 0) wprintf(" ");
218 * list all rooms by floor (only should get called from knrooms() because
219 * that's where output_headers() is called from)
221 void list_all_rooms_by_floor(void)
226 wprintf("<TABLE width=100%% border><TR><TH>Floor</TH>");
227 wprintf("<TH>Rooms with new messages</TH>");
228 wprintf("<TH>Rooms with no new messages</TH></TR>\n");
230 for (a = 0; a < 128; ++a)
231 if (floorlist[a][0] != 0) {
233 /* Floor name column */
236 serv_printf("OIMG _floorpic_|%d", a);
241 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
242 a, &floorlist[a][0]);
244 escputs(&floorlist[a][0]);
249 /* Rooms with new messages column */
251 sprintf(buf, "LKRN %d", a);
253 wprintf("</TD>\n<TD>");
255 /* Rooms with old messages column */
256 sprintf(buf, "LKRO %d", a);
258 wprintf("</TD></TR>\n");
260 wprintf("</TABLE>\n");
266 * list all forgotten rooms
268 void zapped_list(void)
271 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
272 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
273 wprintf("<B>Zapped (forgotten) rooms</B>\n");
274 wprintf("</TD></TR></TABLE><BR>\n");
276 wprintf("<BR><BR>\n");
277 wprintf("Click on any room to un-zap it and goto that room.\n");
283 * read this room's info file (set v to 1 for verbose mode)
299 /* Display room graphic. The server doesn't actually
300 * need the room name, but we supply it in order to
301 * keep the browser from using a cached graphic from
304 void embed_room_graphic(void) {
307 serv_puts("OIMG _roompic_");
310 wprintf("<TD BGCOLOR=444455>");
311 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
312 urlescputs(WC->wc_roomname);
321 /* Let the user know if new mail has arrived
323 void embed_newmail_button(void) {
324 if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
326 "<A HREF=\"/dotgoto?room=_MAIL_\">"
327 "<IMG SRC=\"/static/mail.gif\" border=0 "
328 "ALT=\"You have new mail\">"
329 "<BR><FONT SIZE=2 COLOR=FFFFFF>"
330 "%d new mail</FONT></A>", WC->new_mail);
331 WC->remember_new_mail = WC->new_mail;
338 * Display the current view and offer an option to change it
340 void embed_view_o_matic(void) {
343 wprintf("<FORM NAME=\"viewomatic\">\n"
344 "<SELECT NAME=\"newview\" SIZE=\"1\" "
345 "OnChange=\"location.href=viewomatic.newview.options"
346 "[selectedIndex].value\">\n");
348 for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
349 wprintf("<OPTION %s VALUE=\"/changeview?view=%d\">",
350 ((i == WC->wc_view) ? "SELECTED" : ""),
352 escputs(viewdefs[i]);
353 wprintf("</OPTION>\n");
355 wprintf("</SELECT></FORM>\n");
360 void embed_room_banner(char *got) {
363 /* We need to have the information returned by a GOTO server command.
364 * If it isn't supplied, we fake it by issuing our own GOTO.
367 serv_printf("GOTO %s", WC->wc_roomname);
372 /* If the user happens to select the "make this my start page" link,
373 * we want it to remember the URL as a "/dotskip" one instead of
374 * a "skip" or "gotonext" or something like that.
376 snprintf(WC->this_page, sizeof(WC->this_page), "/dotskip&room=%s",
379 /* Check for new mail. */
380 WC->new_mail = extract_int(&got[4], 9);
381 WC->wc_view = extract_int(&got[4], 11);
383 svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
384 svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
385 svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
386 svcallback("ROOMPIC", embed_room_graphic);
387 svcallback("ROOMINFO", readinfo);
388 svcallback("YOUHAVEMAIL", embed_newmail_button);
389 svcallback("VIEWOMATIC", embed_view_o_matic);
390 svcallback("START", offer_start_page);
392 do_template("roombanner");
393 clear_local_substs();
401 * generic routine to take the session to a new room
403 * display_name values: 0 = goto only
404 * 1 = goto and display
407 void gotoroom(char *gname, int display_name)
410 static long ls = (-1L);
415 wprintf("Pragma: no-cache\n");
416 wprintf("Cache-Control: no-store\n");
418 wprintf("<HTML><HEAD>\n"
419 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
420 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
421 "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
422 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
424 do_template("background");
426 if (display_name != 2) {
427 /* store ungoto information */
428 strcpy(WC->ugname, WC->wc_roomname);
431 /* move to the new room */
432 serv_printf("GOTO %s", gname);
435 serv_puts("GOTO _BASEROOM_");
440 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
445 extract(WC->wc_roomname, &buf[4], 0);
446 WC->room_flags = extract_int(&buf[4], 4);
447 /* highest_msg_read = extract_int(&buf[4],6);
448 maxmsgnum = extract_int(&buf[4],5);
449 is_mail = (char) extract_int(&buf[4],7); */
450 ls = extract_long(&buf[4], 6);
453 WC->is_room_aide = WC->is_aide;
455 WC->is_room_aide = (char) extract_int(&buf[4], 8);
457 remove_march(WC->wc_roomname);
458 if (!strcasecmp(gname, "_BASEROOM_"))
461 /* Display the room banner */
463 embed_room_banner(buf);
466 strcpy(WC->wc_roomname, WC->wc_roomname);
467 WC->wc_view = extract_int(&buf[4], 11);
472 * Locate the room on the march list which we most want to go to. Each room
473 * is measured given a "weight" of preference based on various factors.
475 char *pop_march(int desired_floor)
477 static char TheRoom[64];
479 int TheOrder = 32767;
482 struct march *mptr = NULL;
484 strcpy(TheRoom, "_BASEROOM_");
485 if (WC->march == NULL)
488 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
490 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
491 weight = weight + 10000;
492 if (mptr->march_floor == desired_floor)
493 weight = weight + 5000;
495 weight = weight + ((128 - (mptr->march_floor)) * 128);
496 weight = weight + (128 - (mptr->march_order));
498 if (weight > TheWeight) {
500 strcpy(TheRoom, mptr->march_name);
501 TheFloor = mptr->march_floor;
502 TheOrder = mptr->march_order;
510 /* Goto next room having unread messages.
511 * We want to skip over rooms that the user has already been to, and take the
512 * user back to the lobby when done. The room we end up in is placed in
513 * newroom - which is set to 0 (the lobby) initially.
514 * We start the search in the current room rather than the beginning to prevent
515 * two or more concurrent users from dragging each other back to the same room.
520 struct march *mptr, *mptr2;
523 /* First check to see if the march-mode list is already allocated.
524 * If it is, pop the first room off the list and go there.
527 if (WC->march == NULL) {
531 while (serv_gets(buf), strcmp(buf, "000")) {
532 mptr = (struct march *) malloc(sizeof(struct march));
534 extract(mptr->march_name, buf, 0);
535 mptr->march_floor = extract_int(buf, 2);
536 mptr->march_order = extract_int(buf, 3);
537 if (WC->march == NULL) {
541 while (mptr2->next != NULL)
546 /* add _BASEROOM_ to the end of the march list, so the user will end up
547 * in the system base room (usually the Lobby>) at the end of the loop
549 mptr = (struct march *) malloc(sizeof(struct march));
551 strcpy(mptr->march_name, "_BASEROOM_");
552 if (WC->march == NULL) {
556 while (mptr2->next != NULL)
561 * ...and remove the room we're currently in, so a <G>oto doesn't make us
562 * walk around in circles
564 remove_march(WC->wc_roomname);
566 if (WC->march != NULL) {
567 strcpy(next_room, pop_march(-1));
569 strcpy(next_room, "_BASEROOM_");
573 smart_goto(next_room);
577 void smart_goto(char *next_room) {
578 gotoroom(next_room, 0);
585 * mark all messages in current room as having been read
587 void slrp_highest(void)
592 serv_puts("SLRP HIGHEST");
595 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
602 * un-goto the previous room
608 if (!strcmp(WC->ugname, "")) {
609 smart_goto(WC->wc_roomname);
612 serv_printf("GOTO %s", WC->ugname);
615 smart_goto(WC->wc_roomname);
618 if (WC->uglsn >= 0L) {
619 serv_printf("SLRP %ld", WC->uglsn);
622 strcpy(buf, WC->ugname);
623 strcpy(WC->ugname, "");
628 * display the form for editing a room
630 void display_editroom(void)
637 char er_password[10];
639 char er_roomaide[26];
645 char *not_shared_with;
648 if (strlen(tab) == 0) tab = "admin";
654 display_error(&buf[4]);
657 extract(er_name, &buf[4], 0);
658 extract(er_password, &buf[4], 1);
659 extract(er_dirname, &buf[4], 2);
660 er_flags = extract_int(&buf[4], 3);
661 er_floor = extract_int(&buf[4], 4);
665 /* print the tabbed dialog */
666 wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>"
667 "<TR ALIGN=CENTER BGCOLOR=FFFFFF>"
668 "<TD> </TD>\n");
670 if (!strcmp(tab, "admin")) {
671 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
674 wprintf("<TD BGCOLOR=AAAAAA><A HREF=\"/display_editroom&tab=admin\">");
676 wprintf("Room administration");
677 if (!strcmp(tab, "admin")) {
678 wprintf("</B></FONT></TD>\n");
681 wprintf("</A></TD>\n");
684 wprintf("<TD> </TD>\n");
686 if (!strcmp(tab, "config")) {
687 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
690 wprintf("<TD BGCOLOR=AAAAAA><A HREF=\"/display_editroom&tab=config\">");
692 wprintf("Room configuration");
693 if (!strcmp(tab, "config")) {
694 wprintf("</B></FONT></TD>\n");
697 wprintf("</A></TD>\n");
700 wprintf("<TD> </TD>\n");
702 if (!strcmp(tab, "sharing")) {
703 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
706 wprintf("<TD BGCOLOR=AAAAAA><A HREF=\"/display_editroom&tab=sharing\">");
709 if (!strcmp(tab, "sharing")) {
710 wprintf("</B></FONT></TD>\n");
713 wprintf("</A></TD>\n");
716 wprintf("<TD> </TD>\n");
718 if (!strcmp(tab, "listserv")) {
719 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
722 wprintf("<TD BGCOLOR=AAAAAA><A HREF=\"/display_editroom&tab=listserv\">");
724 wprintf("Mailing list service");
725 if (!strcmp(tab, "listserv")) {
726 wprintf("</B></FONT></TD>\n");
729 wprintf("</A></TD>\n");
732 wprintf("<TD> </TD></TR>"
733 "<TR><TD BGCOLOR=000077 COLSPAN=9 HEIGHT=5> </TD></TR>"
736 /* end tabbed dialog */
739 if (!strcmp(tab, "admin")) {
741 "<LI><A HREF=\"/confirm_delete_room\">\n"
742 "Delete this room</A>\n"
743 "<LI><A HREF=\"/display_editroompic\">\n"
744 "Set or change the graphic for this room's banner</A>\n"
745 "<LI><A HREF=\"/display_editinfo\">\n"
746 "Edit this room's Info file</A>\n"
750 if (!strcmp(tab, "config")) {
751 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
753 wprintf("<UL><LI>Name of room: ");
754 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
756 wprintf("<LI>Resides on floor: ");
758 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
759 for (i = 0; i < 128; ++i)
760 if (strlen(floorlist[i]) > 0) {
763 wprintf("SELECTED ");
764 wprintf("VALUE=\"%d\">", i);
765 escputs(floorlist[i]);
766 wprintf("</OPTION>\n");
768 wprintf("</SELECT>\n");
770 wprintf("<LI>Type of room:<UL>\n");
772 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
773 if ((er_flags & QR_PRIVATE) == 0)
775 wprintf("> Public room\n");
777 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
778 if ((er_flags & QR_PRIVATE) &&
779 (er_flags & QR_GUESSNAME))
781 wprintf("> Private - guess name\n");
783 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
784 if ((er_flags & QR_PRIVATE) &&
785 (er_flags & QR_PASSWORDED))
787 wprintf("> Private - require password:\n");
788 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
790 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
791 if ((er_flags & QR_PRIVATE)
792 && ((er_flags & QR_GUESSNAME) == 0)
793 && ((er_flags & QR_PASSWORDED) == 0))
795 wprintf("> Private - invitation only\n");
797 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
798 wprintf("> If private, cause current users to forget room\n");
802 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
803 if (er_flags & QR_PREFONLY)
805 wprintf("> Preferred users only\n");
807 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
808 if (er_flags & QR_READONLY)
810 wprintf("> Read-only room\n");
812 /* directory stuff */
813 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
814 if (er_flags & QR_DIRECTORY)
816 wprintf("> File directory room\n");
818 wprintf("<UL><LI>Directory name: ");
819 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
821 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
822 if (er_flags & QR_UPLOAD)
824 wprintf("> Uploading allowed\n");
826 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
827 if (er_flags & QR_DOWNLOAD)
829 wprintf("> Downloading allowed\n");
831 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
832 if (er_flags & QR_VISDIR)
834 wprintf("> Visible directory</UL>\n");
836 /* end of directory stuff */
838 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
839 if (er_flags & QR_NETWORK)
841 wprintf("> Network shared room\n");
843 /* start of anon options */
845 wprintf("<LI>Anonymous messages<UL>\n");
847 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
848 if (((er_flags & QR_ANONONLY) == 0)
849 && ((er_flags & QR_ANONOPT) == 0))
851 wprintf("> No anonymous messages\n");
853 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
854 if (er_flags & QR_ANONONLY)
856 wprintf("> All messages are anonymous\n");
858 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
859 if (er_flags & QR_ANONOPT)
861 wprintf("> Prompt user when entering messages</UL>\n");
863 /* end of anon options */
865 wprintf("<LI>Room aide: \n");
869 wprintf("<EM>%s</EM>\n", &buf[4]);
871 extract(er_roomaide, &buf[4], 0);
872 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
875 wprintf("</UL><CENTER>\n");
876 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
877 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
878 wprintf("</CENTER>\n");
882 /* Sharing the room with other Citadel nodes... */
883 if (!strcmp(tab, "sharing")) {
885 shared_with = strdup("");
886 not_shared_with = strdup("");
888 /* Learn the current configuration */
889 serv_puts("CONF getsys|application/x-citadel-ignet-config");
891 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
892 extract(node, buf, 0);
893 not_shared_with = realloc(not_shared_with,
894 strlen(not_shared_with) + 32);
895 strcat(not_shared_with, node);
896 strcat(not_shared_with, "|");
901 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
902 extract(cmd, buf, 0);
903 extract(node, buf, 1);
904 if (!strcasecmp(cmd, "ignet_push_share")) {
905 shared_with = realloc(shared_with,
906 strlen(shared_with) + 32);
907 strcat(shared_with, node);
908 strcat(shared_with, "|");
912 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
913 extract(node, shared_with, i);
914 for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
915 extract(cmd, not_shared_with, j);
916 if (!strcasecmp(node, cmd)) {
917 remove_token(not_shared_with, j, '|');
922 /* Display the stuff */
923 wprintf("<CENTER><BR>"
924 "<TABLE border=1 cellpadding=5><TR>"
925 "<TD><B><I>Shared with</I></B></TD>"
926 "<TD><B><I>Not shared with</I></B></TD></TR>\n"
929 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
930 extract(node, shared_with, i);
931 if (strlen(node) > 0) {
932 wprintf("%s ", node);
933 wprintf("<A HREF=\"/netedit&cmd=remove&line="
934 "ignet_push_share|");
936 wprintf("&tab=sharing\">(unshare)</A><BR>");
940 wprintf("</TD><TD>\n");
942 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
943 extract(node, not_shared_with, i);
944 if (strlen(node) > 0) {
945 wprintf("%s ", node);
946 wprintf("<A HREF=\"/netedit&cmd=add&line="
947 "ignet_push_share|");
949 wprintf("&tab=sharing\">(share)</A><BR>");
955 "<I><B>Reminder:</B> When sharing a room, "
956 "it must be shared from both ends. Adding a node to "
957 "the 'shared' list sends messages out, but in order to"
958 " receive messages, the other nodes must be configured"
959 " to send messages out to your system as well.</I><BR>"
964 /* Mailing list management */
965 if (!strcmp(tab, "listserv")) {
967 wprintf("<BR><center><i>The contents of this room are being "
968 "mailed to the following list recipients:"
973 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
974 extract(cmd, buf, 0);
975 if (!strcasecmp(cmd, "listrecp")) {
976 extract(recp, buf, 1);
979 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
982 wprintf("&tab=listserv\">(remove)</A><BR>");
986 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
987 "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
988 "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
989 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
990 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
991 wprintf("</FORM><BR></CENTER>\n");
999 * save new parameters for a room
1005 char er_password[10];
1006 char er_dirname[15];
1007 char er_roomaide[26];
1013 if (strcmp(bstr("sc"), "OK")) {
1014 display_error("Cancelled. Changes were not saved.");
1020 if (buf[0] != '2') {
1021 display_error(&buf[4]);
1024 extract(er_name, &buf[4], 0);
1025 extract(er_password, &buf[4], 1);
1026 extract(er_dirname, &buf[4], 2);
1027 er_flags = extract_int(&buf[4], 3);
1029 strcpy(er_roomaide, bstr("er_roomaide"));
1030 if (strlen(er_roomaide) == 0) {
1033 if (buf[0] != '2') {
1034 strcpy(er_roomaide, "");
1036 extract(er_roomaide, &buf[4], 0);
1039 strcpy(buf, bstr("er_name"));
1041 if (strlen(buf) > 0)
1042 strcpy(er_name, buf);
1044 strcpy(buf, bstr("er_password"));
1046 if (strlen(buf) > 0)
1047 strcpy(er_password, buf);
1049 strcpy(buf, bstr("er_dirname"));
1051 if (strlen(buf) > 0)
1052 strcpy(er_dirname, buf);
1054 strcpy(buf, bstr("type"));
1055 er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1057 if (!strcmp(buf, "invonly")) {
1058 er_flags |= (QR_PRIVATE);
1060 if (!strcmp(buf, "guessname")) {
1061 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1063 if (!strcmp(buf, "passworded")) {
1064 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1066 if (!strcmp(bstr("prefonly"), "yes")) {
1067 er_flags |= QR_PREFONLY;
1069 er_flags &= ~QR_PREFONLY;
1072 if (!strcmp(bstr("readonly"), "yes")) {
1073 er_flags |= QR_READONLY;
1075 er_flags &= ~QR_READONLY;
1078 if (!strcmp(bstr("network"), "yes")) {
1079 er_flags |= QR_NETWORK;
1081 er_flags &= ~QR_NETWORK;
1084 if (!strcmp(bstr("directory"), "yes")) {
1085 er_flags |= QR_DIRECTORY;
1087 er_flags &= ~QR_DIRECTORY;
1090 if (!strcmp(bstr("ulallowed"), "yes")) {
1091 er_flags |= QR_UPLOAD;
1093 er_flags &= ~QR_UPLOAD;
1096 if (!strcmp(bstr("dlallowed"), "yes")) {
1097 er_flags |= QR_DOWNLOAD;
1099 er_flags &= ~QR_DOWNLOAD;
1102 if (!strcmp(bstr("visdir"), "yes")) {
1103 er_flags |= QR_VISDIR;
1105 er_flags &= ~QR_VISDIR;
1108 strcpy(buf, bstr("anon"));
1110 er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1111 if (!strcmp(buf, "anononly"))
1112 er_flags |= QR_ANONONLY;
1113 if (!strcmp(buf, "anon2"))
1114 er_flags |= QR_ANONOPT;
1117 if (!strcmp(bstr("bump"), "yes"))
1120 er_floor = atoi(bstr("er_floor"));
1122 sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1123 er_name, er_password, er_dirname, er_flags, bump, er_floor);
1126 if (buf[0] != '2') {
1127 display_error(&buf[4]);
1130 gotoroom(er_name, 0);
1132 if (strlen(er_roomaide) > 0) {
1133 sprintf(buf, "SETA %s", er_roomaide);
1136 if (buf[0] != '2') {
1137 display_error(&buf[4]);
1141 smart_goto(er_name);
1145 * Invite, Kick, and show Who Knows a room
1147 void display_whok(void)
1149 char buf[SIZ], room[SIZ], username[SIZ];
1154 if (buf[0] != '2') {
1155 display_error(&buf[4]);
1158 extract(room, &buf[4], 0);
1160 strcpy(username, bstr("username"));
1164 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1165 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1166 escputs(WC->wc_roomname);
1167 wprintf("</B></FONT></TD></TR></TABLE>\n");
1169 if(!strcmp(bstr("sc"), "Kick")) {
1170 sprintf(buf, "KICK %s", username);
1174 if (buf[0] != '2') {
1175 display_error(&buf[4]);
1178 wprintf("<B><I>User %s kicked out of room %s.</I></B>\n",
1181 } else if(!strcmp(bstr("sc"), "Invite")) {
1182 sprintf(buf, "INVT %s", username);
1186 if (buf[0] != '2') {
1187 display_error(&buf[4]);
1190 wprintf("<B><I>User %s invited to room %s.</I></B>\n",
1197 wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1198 "<TD>The users listed below have access to this room. "
1199 "To remove a user from the access list, select the user "
1200 "name from the list and click 'Kick'.<BR><BR>");
1202 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1203 wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1206 if (buf[0] == '1') {
1207 while (serv_gets(buf), strcmp(buf, "000")) {
1208 extract(username, buf, 0);
1209 wprintf("<OPTION>");
1214 wprintf("</SELECT><BR>\n");
1216 wprintf("<input type=submit name=sc value=\"Kick\">");
1217 wprintf("</FORM></CENTER>\n");
1220 "To grant another user access to this room, enter the "
1221 "user name in the box below and click 'Invite'.<BR><BR>");
1223 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1224 wprintf("Invite: ");
1225 wprintf("<input type=text name=username><BR>\n"
1226 "<input type=hidden name=sc value=\"Invite\">"
1227 "<input type=submit value=\"Invite\">"
1228 "</FORM></CENTER>\n");
1230 wprintf("</TD></TR></TABLE>\n");
1237 * display the form for entering a new room
1239 void display_entroom(void)
1244 serv_puts("CRE8 0");
1247 if (buf[0] != '2') {
1248 display_error(&buf[4]);
1253 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1254 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1255 wprintf("<B>Enter (create) a new room</B>\n");
1256 wprintf("</FONT></TD></TR></TABLE>\n");
1258 wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1260 wprintf("<UL><LI>Name of room: ");
1261 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1263 wprintf("<LI>Type of room:<UL>\n");
1265 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1266 wprintf("CHECKED > Public room\n");
1268 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1269 wprintf("> Private - guess name\n");
1271 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1272 wprintf("> Private - require password:\n");
1273 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1275 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1276 wprintf("> Private - invitation only\n");
1279 wprintf("<LI>Resides on floor: ");
1281 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1282 for (i = 0; i < 128; ++i)
1283 if (strlen(floorlist[i]) > 0) {
1284 wprintf("<OPTION ");
1285 wprintf("VALUE=\"%d\">", i);
1286 escputs(floorlist[i]);
1287 wprintf("</OPTION>\n");
1289 wprintf("</SELECT>\n");
1293 wprintf("<CENTER>\n");
1294 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1295 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1296 wprintf("</CENTER>\n");
1297 wprintf("</FORM>\n<HR>");
1298 serv_printf("MESG roomaccess");
1300 if (buf[0] == '1') {
1316 char er_password[10];
1320 if (strcmp(bstr("sc"), "OK")) {
1321 display_error("Cancelled. No new room was created.");
1324 strcpy(er_name, bstr("er_name"));
1325 strcpy(er_type, bstr("type"));
1326 strcpy(er_password, bstr("er_password"));
1327 er_floor = atoi(bstr("er_floor"));
1330 if (!strcmp(er_type, "guessname"))
1332 if (!strcmp(er_type, "passworded"))
1334 if (!strcmp(er_type, "invonly"))
1337 sprintf(buf, "CRE8 1|%s|%d|%s|%d",
1338 er_name, er_num_type, er_password, er_floor);
1341 if (buf[0] != '2') {
1342 display_error(&buf[4]);
1345 smart_goto(er_name);
1350 * display the screen to enter a private room
1352 void display_private(char *rname, int req_pass)
1357 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1358 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1359 wprintf("<B>Goto a private room</B>\n");
1360 wprintf("</FONT></TD></TR></TABLE>\n");
1362 wprintf("<CENTER>\n");
1363 wprintf("If you know the name of a hidden (guess-name) or\n");
1364 wprintf("passworded room, you can enter that room by typing\n");
1365 wprintf("its name below. Once you gain access to a private\n");
1366 wprintf("room, it will appear in your regular room listings\n");
1367 wprintf("so you don't have to keep returning here.\n");
1368 wprintf("<BR><BR>");
1370 wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1372 wprintf("<TABLE border><TR><TD>");
1373 wprintf("Enter room name:</TD><TD>");
1374 wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1377 wprintf("</TD></TR><TR><TD>");
1378 wprintf("Enter room password:</TD><TD>");
1379 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1381 wprintf("</TD></TR></TABLE>\n");
1383 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1384 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1385 wprintf("</FORM>\n");
1390 * goto a private room
1392 void goto_private(void)
1397 if (strcasecmp(bstr("sc"), "OK")) {
1398 display_main_menu();
1401 strcpy(hold_rm, WC->wc_roomname);
1402 strcpy(buf, "GOTO ");
1403 strcat(buf, bstr("gr_name"));
1405 strcat(buf, bstr("gr_pass"));
1409 if (buf[0] == '2') {
1410 smart_goto(bstr("gr_name"));
1413 if (!strncmp(buf, "540", 3)) {
1414 display_private(bstr("gr_name"), 1);
1418 wprintf("%s\n", &buf[4]);
1425 * display the screen to zap a room
1427 void display_zap(void)
1431 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1432 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1433 wprintf("<B>Zap (forget) the current room</B>\n");
1434 wprintf("</FONT></TD></TR></TABLE>\n");
1436 wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1437 wprintf("disappear from your room list. Is this what you wish ");
1438 wprintf("to do?<BR>\n");
1440 wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1441 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1442 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1443 wprintf("</FORM>\n");
1454 char final_destination[SIZ];
1456 /* If the forget-room routine fails for any reason, we fall back
1457 * to the current room; otherwise, we go to the Lobby
1459 strcpy(final_destination, WC->wc_roomname);
1461 if (!strcasecmp(bstr("sc"), "OK")) {
1462 serv_printf("GOTO %s", WC->wc_roomname);
1464 if (buf[0] != '2') {
1465 /* ExpressMessageCat(&buf[4]); */
1469 if (buf[0] != '2') {
1470 /* ExpressMessageCat(&buf[4]); */
1472 strcpy(final_destination, "_BASEROOM_");
1476 smart_goto(final_destination);
1483 * Confirm deletion of the current room
1485 void confirm_delete_room(void)
1489 serv_puts("KILL 0");
1491 if (buf[0] != '2') {
1492 display_error(&buf[4]);
1496 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1497 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1498 wprintf("<B>Confirm deletion of room</B>\n");
1499 wprintf("</FONT></TD></TR></TABLE>\n");
1501 wprintf("<CENTER>");
1502 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1504 wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1505 escputs(WC->wc_roomname);
1506 wprintf("</FONT>?<BR>\n");
1508 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1509 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1511 wprintf("</FORM></CENTER>\n");
1517 * Delete the current room
1519 void delete_room(void)
1524 strcpy(sc, bstr("sc"));
1526 if (strcasecmp(sc, "Delete")) {
1527 display_error("Cancelled. This room was not deleted.");
1530 serv_puts("KILL 1");
1532 if (buf[0] != '2') {
1533 display_error(&buf[4]);
1535 smart_goto("_BASEROOM_");
1542 * Perform changes to a room's network configuration
1544 void netedit(void) {
1549 if (strlen(bstr("line"))==0) {
1554 strcpy(line, bstr("prefix"));
1555 strcat(line, bstr("line"));
1556 strcat(line, bstr("suffix"));
1566 if (buf[0] != '1') {
1572 /* This loop works for add *or* remove. Spiffy, eh? */
1573 while (serv_gets(buf), strcmp(buf, "000")) {
1574 if (strcasecmp(buf, line)) {
1575 fprintf(fp, "%s\n", buf);
1582 if (buf[0] != '4') {
1588 while (fgets(buf, sizeof buf, fp) != NULL) {
1589 buf[strlen(buf)-1] = 0;
1593 if (!strcasecmp(bstr("cmd"), "add")) {
1605 * Convert a room name to a folder-ish-looking name.
1607 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1612 * For mailboxes, just do it straight...
1615 sprintf(folder, "My folders|%s", room);
1619 * Otherwise, prefix the floor name as a "public folders" moniker
1622 sprintf(folder, "%s|%s", floorlist[floor], room);
1626 * Replace "/" characters with "|" for pseudo-folder-delimiting
1628 for (i=0; i<strlen(folder); ++i) {
1629 if (folder[i] == '/') folder[i] = '|';
1640 * Change the view for this room
1642 void change_view(void) {
1646 view = atol(bstr("view"));
1648 serv_printf("VIEW %d", view);
1650 smart_goto(WC->wc_roomname);
1655 * Show the room list in "folders" format. (only should get called by
1656 * knrooms() because that's where output_headers() is called from)
1658 void folders(void) {
1661 int levels, oldlevels;
1671 struct folder *fold = NULL;
1673 int max_folders = 0;
1674 int alloc_folders = 0;
1681 /* Start with the mailboxes */
1684 fold = malloc(sizeof(struct folder));
1685 memset(fold, 0, sizeof(struct folder));
1686 strcpy(fold[0].name, "My folders");
1688 /* Then add floors */
1691 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1692 if (max_folders >= alloc_folders) {
1693 alloc_folders = max_folders + 100;
1694 fold = realloc(fold,
1695 alloc_folders * sizeof(struct folder));
1697 memset(&fold[max_folders], 0, sizeof(struct folder));
1698 extract(fold[max_folders].name, buf, 1);
1703 for (p = 0; p < 2; ++p) {
1704 if (p == 0) serv_puts("LKRN");
1705 else if (p == 1) serv_puts("LKRO");
1707 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1708 if (max_folders >= alloc_folders) {
1709 alloc_folders = max_folders + 100;
1710 fold = realloc(fold,
1711 alloc_folders * sizeof(struct folder));
1713 memset(&fold[max_folders], 0, sizeof(struct folder));
1714 extract(fold[max_folders].room, buf, 0);
1715 if (p == 0) fold[max_folders].hasnewmsgs = 1;
1716 flags = extract_int(buf, 1);
1717 floor = extract_int(buf, 2);
1718 if (flags & QR_MAILBOX) {
1719 fold[max_folders].is_mailbox = 1;
1721 room_to_folder(fold[max_folders].name,
1722 fold[max_folders].room,
1724 fold[max_folders].is_mailbox);
1725 fold[max_folders].selectable = 1;
1730 /* Bubble-sort the folder list */
1731 for (i=0; i<max_folders; ++i) {
1732 for (j=0; j<(max_folders-1)-i; ++j) {
1733 if (strcasecmp(fold[j].name, fold[j+1].name) > 0) {
1734 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1735 memcpy(&fold[j], &fold[j+1],
1736 sizeof(struct folder));
1737 memcpy(&fold[j+1], &ftmp,
1738 sizeof(struct folder));
1747 for (i=0; i<max_folders; ++i) {
1749 levels = num_tokens(fold[i].name, '|');
1750 if (levels > oldlevels) {
1751 for (k=0; k<(levels-oldlevels); ++k) {
1756 if (levels < oldlevels) {
1757 for (k=0; k<(oldlevels-levels); ++k) {
1765 if (fold[i].selectable) {
1766 wprintf("<A HREF=\"/dotgoto?room=");
1767 urlescputs(fold[i].room);
1770 if (fold[i].hasnewmsgs) wprintf("<B>");
1771 extract(buf, fold[i].name, levels-1);
1773 if (fold[i].hasnewmsgs) wprintf("</B>");
1774 if (fold[i].selectable) wprintf("</A>\n");
1776 while (nests-- > 0) wprintf("</UL>\n");
1783 /* Do either a known rooms list or a folders list, depending on the
1787 char listviewpref[SIZ];
1792 /* Determine whether the user is trying to change views */
1793 if (bstr("view") != NULL) {
1794 if (strlen(bstr("view")) > 0) {
1795 set_preference("roomlistview", bstr("view"));
1799 get_preference("roomlistview", listviewpref);
1801 if (strcasecmp(listviewpref, "folders")) {
1802 strcpy(listviewpref, "rooms");
1806 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
1807 "<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
1809 if (!strcasecmp(listviewpref, "rooms")) {
1810 wprintf("Room list");
1812 if (!strcasecmp(listviewpref, "folders")) {
1813 wprintf("Folder list");
1815 wprintf("</B></TD>\n");
1818 /* offer the ability to switch views */
1819 wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
1820 "<SELECT NAME=\"newview\" SIZE=\"1\" "
1821 "OnChange=\"location.href=roomlistomatic.newview.options"
1822 "[selectedIndex].value\">\n");
1824 wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
1827 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
1830 wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
1831 "View as folder list"
1833 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
1836 wprintf("</SELECT></FORM></TD><TD>\n");
1838 wprintf("</TD></TR></TABLE><BR>\n");
1840 /* Display the room list in the user's preferred format */
1841 if (!strcasecmp(listviewpref, "folders")) {
1845 list_all_rooms_by_floor();