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 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
668 if (!strcmp(tab, "admin")) {
669 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
672 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
674 wprintf("Room administration");
675 if (!strcmp(tab, "admin")) {
676 wprintf("</B></FONT></TD>\n");
679 wprintf("</A></TD>\n");
682 wprintf("<TD> </TD>\n");
684 if (!strcmp(tab, "config")) {
685 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
688 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
690 wprintf("Room configuration");
691 if (!strcmp(tab, "config")) {
692 wprintf("</B></FONT></TD>\n");
695 wprintf("</A></TD>\n");
698 wprintf("<TD> </TD>\n");
700 if (!strcmp(tab, "sharing")) {
701 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
704 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
707 if (!strcmp(tab, "sharing")) {
708 wprintf("</B></FONT></TD>\n");
711 wprintf("</A></TD>\n");
714 wprintf("<TD> </TD>\n");
716 if (!strcmp(tab, "listserv")) {
717 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
720 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
722 wprintf("Mailing list service");
723 if (!strcmp(tab, "listserv")) {
724 wprintf("</B></FONT></TD>\n");
727 wprintf("</A></TD>\n");
730 wprintf("<TD> </TD></TR></TABLE>\n");
732 /* end tabbed dialog */
735 if (!strcmp(tab, "admin")) {
737 "<LI><A HREF=\"/confirm_delete_room\">\n"
738 "Delete this room</A>\n"
739 "<LI><A HREF=\"/display_editroompic\">\n"
740 "Set or change the graphic for this room's banner</A>\n"
741 "<LI><A HREF=\"/display_editinfo\">\n"
742 "Edit this room's Info file</A>\n"
746 if (!strcmp(tab, "config")) {
747 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
749 wprintf("<UL><LI>Name of room: ");
750 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
752 wprintf("<LI>Resides on floor: ");
754 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
755 for (i = 0; i < 128; ++i)
756 if (strlen(floorlist[i]) > 0) {
759 wprintf("SELECTED ");
760 wprintf("VALUE=\"%d\">", i);
761 escputs(floorlist[i]);
762 wprintf("</OPTION>\n");
764 wprintf("</SELECT>\n");
766 wprintf("<LI>Type of room:<UL>\n");
768 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
769 if ((er_flags & QR_PRIVATE) == 0)
771 wprintf("> Public room\n");
773 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
774 if ((er_flags & QR_PRIVATE) &&
775 (er_flags & QR_GUESSNAME))
777 wprintf("> Private - guess name\n");
779 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
780 if ((er_flags & QR_PRIVATE) &&
781 (er_flags & QR_PASSWORDED))
783 wprintf("> Private - require password:\n");
784 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
786 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
787 if ((er_flags & QR_PRIVATE)
788 && ((er_flags & QR_GUESSNAME) == 0)
789 && ((er_flags & QR_PASSWORDED) == 0))
791 wprintf("> Private - invitation only\n");
793 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
794 wprintf("> If private, cause current users to forget room\n");
798 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
799 if (er_flags & QR_PREFONLY)
801 wprintf("> Preferred users only\n");
803 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
804 if (er_flags & QR_READONLY)
806 wprintf("> Read-only room\n");
808 /* directory stuff */
809 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
810 if (er_flags & QR_DIRECTORY)
812 wprintf("> File directory room\n");
814 wprintf("<UL><LI>Directory name: ");
815 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
817 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
818 if (er_flags & QR_UPLOAD)
820 wprintf("> Uploading allowed\n");
822 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
823 if (er_flags & QR_DOWNLOAD)
825 wprintf("> Downloading allowed\n");
827 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
828 if (er_flags & QR_VISDIR)
830 wprintf("> Visible directory</UL>\n");
832 /* end of directory stuff */
834 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
835 if (er_flags & QR_NETWORK)
837 wprintf("> Network shared room\n");
839 /* start of anon options */
841 wprintf("<LI>Anonymous messages<UL>\n");
843 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
844 if (((er_flags & QR_ANONONLY) == 0)
845 && ((er_flags & QR_ANONOPT) == 0))
847 wprintf("> No anonymous messages\n");
849 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
850 if (er_flags & QR_ANONONLY)
852 wprintf("> All messages are anonymous\n");
854 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
855 if (er_flags & QR_ANONOPT)
857 wprintf("> Prompt user when entering messages</UL>\n");
859 /* end of anon options */
861 wprintf("<LI>Room aide: \n");
865 wprintf("<EM>%s</EM>\n", &buf[4]);
867 extract(er_roomaide, &buf[4], 0);
868 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
871 wprintf("</UL><CENTER>\n");
872 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
873 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
874 wprintf("</CENTER>\n");
878 /* Sharing the room with other Citadel nodes... */
879 if (!strcmp(tab, "sharing")) {
881 shared_with = strdup("");
882 not_shared_with = strdup("");
884 /* Learn the current configuration */
885 serv_puts("CONF getsys|application/x-citadel-ignet-config");
887 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
888 extract(node, buf, 0);
889 not_shared_with = realloc(not_shared_with,
890 strlen(not_shared_with) + 32);
891 strcat(not_shared_with, node);
892 strcat(not_shared_with, "|");
897 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
898 extract(cmd, buf, 0);
899 extract(node, buf, 1);
900 if (!strcasecmp(cmd, "ignet_push_share")) {
901 shared_with = realloc(shared_with,
902 strlen(shared_with) + 32);
903 strcat(shared_with, node);
904 strcat(shared_with, "|");
908 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
909 extract(node, shared_with, i);
910 for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
911 extract(cmd, not_shared_with, j);
912 if (!strcasecmp(node, cmd)) {
913 remove_token(not_shared_with, j, '|');
918 /* Display the stuff */
919 wprintf("<CENTER><BR>"
920 "<TABLE border=1 cellpadding=5><TR>"
921 "<TD><B><I>Shared with</I></B></TD>"
922 "<TD><B><I>Not shared with</I></B></TD></TR>\n"
925 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
926 extract(node, shared_with, i);
927 if (strlen(node) > 0) {
928 wprintf("%s ", node);
929 wprintf("<A HREF=\"/netedit&cmd=remove&line="
930 "ignet_push_share|");
932 wprintf("&tab=sharing\">(unshare)</A><BR>");
936 wprintf("</TD><TD>\n");
938 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
939 extract(node, not_shared_with, i);
940 if (strlen(node) > 0) {
941 wprintf("%s ", node);
942 wprintf("<A HREF=\"/netedit&cmd=add&line="
943 "ignet_push_share|");
945 wprintf("&tab=sharing\">(share)</A><BR>");
949 wprintf("</TD></TR></TABLE><BR>\n"
950 "<I><B>Reminder:</B> When sharing a room, "
951 "it must be shared from both ends. Adding a node to "
952 "the 'shared' list sends messages out, but in order to"
953 " receive messages, the other nodes must be configured"
954 " to send messages out to your system as well.</I><BR>"
959 /* Mailing list management */
960 if (!strcmp(tab, "listserv")) {
962 wprintf("<BR><center><i>The contents of this room are being "
963 "mailed to the following list recipients:"
968 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
969 extract(cmd, buf, 0);
970 if (!strcasecmp(cmd, "listrecp")) {
971 extract(recp, buf, 1);
974 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
977 wprintf("&tab=listserv\">(remove)</A><BR>");
981 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
982 "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
983 "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
984 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
985 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
986 wprintf("</FORM><BR></CENTER>\n");
994 * save new parameters for a room
1000 char er_password[10];
1001 char er_dirname[15];
1002 char er_roomaide[26];
1008 if (strcmp(bstr("sc"), "OK")) {
1009 display_error("Cancelled. Changes were not saved.");
1015 if (buf[0] != '2') {
1016 display_error(&buf[4]);
1019 extract(er_name, &buf[4], 0);
1020 extract(er_password, &buf[4], 1);
1021 extract(er_dirname, &buf[4], 2);
1022 er_flags = extract_int(&buf[4], 3);
1024 strcpy(er_roomaide, bstr("er_roomaide"));
1025 if (strlen(er_roomaide) == 0) {
1028 if (buf[0] != '2') {
1029 strcpy(er_roomaide, "");
1031 extract(er_roomaide, &buf[4], 0);
1034 strcpy(buf, bstr("er_name"));
1036 if (strlen(buf) > 0)
1037 strcpy(er_name, buf);
1039 strcpy(buf, bstr("er_password"));
1041 if (strlen(buf) > 0)
1042 strcpy(er_password, buf);
1044 strcpy(buf, bstr("er_dirname"));
1046 if (strlen(buf) > 0)
1047 strcpy(er_dirname, buf);
1049 strcpy(buf, bstr("type"));
1050 er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1052 if (!strcmp(buf, "invonly")) {
1053 er_flags |= (QR_PRIVATE);
1055 if (!strcmp(buf, "guessname")) {
1056 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1058 if (!strcmp(buf, "passworded")) {
1059 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1061 if (!strcmp(bstr("prefonly"), "yes")) {
1062 er_flags |= QR_PREFONLY;
1064 er_flags &= ~QR_PREFONLY;
1067 if (!strcmp(bstr("readonly"), "yes")) {
1068 er_flags |= QR_READONLY;
1070 er_flags &= ~QR_READONLY;
1073 if (!strcmp(bstr("network"), "yes")) {
1074 er_flags |= QR_NETWORK;
1076 er_flags &= ~QR_NETWORK;
1079 if (!strcmp(bstr("directory"), "yes")) {
1080 er_flags |= QR_DIRECTORY;
1082 er_flags &= ~QR_DIRECTORY;
1085 if (!strcmp(bstr("ulallowed"), "yes")) {
1086 er_flags |= QR_UPLOAD;
1088 er_flags &= ~QR_UPLOAD;
1091 if (!strcmp(bstr("dlallowed"), "yes")) {
1092 er_flags |= QR_DOWNLOAD;
1094 er_flags &= ~QR_DOWNLOAD;
1097 if (!strcmp(bstr("visdir"), "yes")) {
1098 er_flags |= QR_VISDIR;
1100 er_flags &= ~QR_VISDIR;
1103 strcpy(buf, bstr("anon"));
1105 er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1106 if (!strcmp(buf, "anononly"))
1107 er_flags |= QR_ANONONLY;
1108 if (!strcmp(buf, "anon2"))
1109 er_flags |= QR_ANONOPT;
1112 if (!strcmp(bstr("bump"), "yes"))
1115 er_floor = atoi(bstr("er_floor"));
1117 sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1118 er_name, er_password, er_dirname, er_flags, bump, er_floor);
1121 if (buf[0] != '2') {
1122 display_error(&buf[4]);
1125 gotoroom(er_name, 0);
1127 if (strlen(er_roomaide) > 0) {
1128 sprintf(buf, "SETA %s", er_roomaide);
1131 if (buf[0] != '2') {
1132 display_error(&buf[4]);
1136 smart_goto(er_name);
1140 * Invite, Kick, and show Who Knows a room
1142 void display_whok(void)
1144 char buf[SIZ], room[SIZ], username[SIZ];
1149 if (buf[0] != '2') {
1150 display_error(&buf[4]);
1153 extract(room, &buf[4], 0);
1155 strcpy(username, bstr("username"));
1159 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1160 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1161 escputs(WC->wc_roomname);
1162 wprintf("</B></FONT></TD></TR></TABLE>\n");
1164 if(!strcmp(bstr("sc"), "Kick")) {
1165 sprintf(buf, "KICK %s", username);
1169 if (buf[0] != '2') {
1170 display_error(&buf[4]);
1173 wprintf("<B><I>User %s kicked out of room %s.</I></B>\n",
1176 } else if(!strcmp(bstr("sc"), "Invite")) {
1177 sprintf(buf, "INVT %s", username);
1181 if (buf[0] != '2') {
1182 display_error(&buf[4]);
1185 wprintf("<B><I>User %s invited to room %s.</I></B>\n",
1192 wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1193 "<TD>The users listed below have access to this room. "
1194 "To remove a user from the access list, select the user "
1195 "name from the list and click 'Kick'.<BR><BR>");
1197 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1198 wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1201 if (buf[0] == '1') {
1202 while (serv_gets(buf), strcmp(buf, "000")) {
1203 extract(username, buf, 0);
1204 wprintf("<OPTION>");
1209 wprintf("</SELECT><BR>\n");
1211 wprintf("<input type=submit name=sc value=\"Kick\">");
1212 wprintf("</FORM></CENTER>\n");
1215 "To grant another user access to this room, enter the "
1216 "user name in the box below and click 'Invite'.<BR><BR>");
1218 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1219 wprintf("Invite: ");
1220 wprintf("<input type=text name=username><BR>\n"
1221 "<input type=hidden name=sc value=\"Invite\">"
1222 "<input type=submit value=\"Invite\">"
1223 "</FORM></CENTER>\n");
1225 wprintf("</TD></TR></TABLE>\n");
1232 * display the form for entering a new room
1234 void display_entroom(void)
1239 serv_puts("CRE8 0");
1242 if (buf[0] != '2') {
1243 display_error(&buf[4]);
1248 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1249 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1250 wprintf("<B>Enter (create) a new room</B>\n");
1251 wprintf("</FONT></TD></TR></TABLE>\n");
1253 wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1255 wprintf("<UL><LI>Name of room: ");
1256 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1258 wprintf("<LI>Type of room:<UL>\n");
1260 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1261 wprintf("CHECKED > Public room\n");
1263 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1264 wprintf("> Private - guess name\n");
1266 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1267 wprintf("> Private - require password:\n");
1268 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1270 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1271 wprintf("> Private - invitation only\n");
1274 wprintf("<LI>Resides on floor: ");
1276 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1277 for (i = 0; i < 128; ++i)
1278 if (strlen(floorlist[i]) > 0) {
1279 wprintf("<OPTION ");
1280 wprintf("VALUE=\"%d\">", i);
1281 escputs(floorlist[i]);
1282 wprintf("</OPTION>\n");
1284 wprintf("</SELECT>\n");
1288 wprintf("<CENTER>\n");
1289 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1290 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1291 wprintf("</CENTER>\n");
1292 wprintf("</FORM>\n<HR>");
1293 serv_printf("MESG roomaccess");
1295 if (buf[0] == '1') {
1311 char er_password[10];
1315 if (strcmp(bstr("sc"), "OK")) {
1316 display_error("Cancelled. No new room was created.");
1319 strcpy(er_name, bstr("er_name"));
1320 strcpy(er_type, bstr("type"));
1321 strcpy(er_password, bstr("er_password"));
1322 er_floor = atoi(bstr("er_floor"));
1325 if (!strcmp(er_type, "guessname"))
1327 if (!strcmp(er_type, "passworded"))
1329 if (!strcmp(er_type, "invonly"))
1332 sprintf(buf, "CRE8 1|%s|%d|%s|%d",
1333 er_name, er_num_type, er_password, er_floor);
1336 if (buf[0] != '2') {
1337 display_error(&buf[4]);
1340 smart_goto(er_name);
1345 * display the screen to enter a private room
1347 void display_private(char *rname, int req_pass)
1352 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1353 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1354 wprintf("<B>Goto a private room</B>\n");
1355 wprintf("</FONT></TD></TR></TABLE>\n");
1357 wprintf("<CENTER>\n");
1358 wprintf("If you know the name of a hidden (guess-name) or\n");
1359 wprintf("passworded room, you can enter that room by typing\n");
1360 wprintf("its name below. Once you gain access to a private\n");
1361 wprintf("room, it will appear in your regular room listings\n");
1362 wprintf("so you don't have to keep returning here.\n");
1363 wprintf("<BR><BR>");
1365 wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1367 wprintf("<TABLE border><TR><TD>");
1368 wprintf("Enter room name:</TD><TD>");
1369 wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1372 wprintf("</TD></TR><TR><TD>");
1373 wprintf("Enter room password:</TD><TD>");
1374 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1376 wprintf("</TD></TR></TABLE>\n");
1378 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1379 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1380 wprintf("</FORM>\n");
1385 * goto a private room
1387 void goto_private(void)
1392 if (strcasecmp(bstr("sc"), "OK")) {
1393 display_main_menu();
1396 strcpy(hold_rm, WC->wc_roomname);
1397 strcpy(buf, "GOTO ");
1398 strcat(buf, bstr("gr_name"));
1400 strcat(buf, bstr("gr_pass"));
1404 if (buf[0] == '2') {
1405 smart_goto(bstr("gr_name"));
1408 if (!strncmp(buf, "540", 3)) {
1409 display_private(bstr("gr_name"), 1);
1413 wprintf("%s\n", &buf[4]);
1420 * display the screen to zap a room
1422 void display_zap(void)
1426 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1427 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1428 wprintf("<B>Zap (forget) the current room</B>\n");
1429 wprintf("</FONT></TD></TR></TABLE>\n");
1431 wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1432 wprintf("disappear from your room list. Is this what you wish ");
1433 wprintf("to do?<BR>\n");
1435 wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1436 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1437 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1438 wprintf("</FORM>\n");
1449 char final_destination[SIZ];
1451 /* If the forget-room routine fails for any reason, we fall back
1452 * to the current room; otherwise, we go to the Lobby
1454 strcpy(final_destination, WC->wc_roomname);
1456 if (!strcasecmp(bstr("sc"), "OK")) {
1457 serv_printf("GOTO %s", WC->wc_roomname);
1459 if (buf[0] != '2') {
1460 /* ExpressMessageCat(&buf[4]); */
1464 if (buf[0] != '2') {
1465 /* ExpressMessageCat(&buf[4]); */
1467 strcpy(final_destination, "_BASEROOM_");
1471 smart_goto(final_destination);
1478 * Confirm deletion of the current room
1480 void confirm_delete_room(void)
1484 serv_puts("KILL 0");
1486 if (buf[0] != '2') {
1487 display_error(&buf[4]);
1491 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1492 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1493 wprintf("<B>Confirm deletion of room</B>\n");
1494 wprintf("</FONT></TD></TR></TABLE>\n");
1496 wprintf("<CENTER>");
1497 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1499 wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1500 escputs(WC->wc_roomname);
1501 wprintf("</FONT>?<BR>\n");
1503 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1504 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1506 wprintf("</FORM></CENTER>\n");
1512 * Delete the current room
1514 void delete_room(void)
1519 strcpy(sc, bstr("sc"));
1521 if (strcasecmp(sc, "Delete")) {
1522 display_error("Cancelled. This room was not deleted.");
1525 serv_puts("KILL 1");
1527 if (buf[0] != '2') {
1528 display_error(&buf[4]);
1530 smart_goto("_BASEROOM_");
1537 * Perform changes to a room's network configuration
1539 void netedit(void) {
1544 if (strlen(bstr("line"))==0) {
1549 strcpy(line, bstr("prefix"));
1550 strcat(line, bstr("line"));
1551 strcat(line, bstr("suffix"));
1561 if (buf[0] != '1') {
1567 /* This loop works for add *or* remove. Spiffy, eh? */
1568 while (serv_gets(buf), strcmp(buf, "000")) {
1569 if (strcasecmp(buf, line)) {
1570 fprintf(fp, "%s\n", buf);
1577 if (buf[0] != '4') {
1583 while (fgets(buf, sizeof buf, fp) != NULL) {
1584 buf[strlen(buf)-1] = 0;
1588 if (!strcasecmp(bstr("cmd"), "add")) {
1600 * Convert a room name to a folder-ish-looking name.
1602 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1607 * For mailboxes, just do it straight...
1610 sprintf(folder, "My folders|%s", room);
1614 * Otherwise, prefix the floor name as a "public folders" moniker
1617 sprintf(folder, "%s|%s", floorlist[floor], room);
1621 * Replace "/" characters with "|" for pseudo-folder-delimiting
1623 for (i=0; i<strlen(folder); ++i) {
1624 if (folder[i] == '/') folder[i] = '|';
1635 * Change the view for this room
1637 void change_view(void) {
1641 view = atol(bstr("view"));
1643 serv_printf("VIEW %d", view);
1645 smart_goto(WC->wc_roomname);
1650 * Show the room list in "folders" format. (only should get called by
1651 * knrooms() because that's where output_headers() is called from)
1653 void folders(void) {
1656 int levels, oldlevels;
1666 struct folder *fold = NULL;
1668 int max_folders = 0;
1669 int alloc_folders = 0;
1676 /* Start with the mailboxes */
1679 fold = malloc(sizeof(struct folder));
1680 memset(fold, 0, sizeof(struct folder));
1681 strcpy(fold[0].name, "My folders");
1683 /* Then add floors */
1686 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1687 if (max_folders >= alloc_folders) {
1688 alloc_folders = max_folders + 100;
1689 fold = realloc(fold,
1690 alloc_folders * sizeof(struct folder));
1692 memset(&fold[max_folders], 0, sizeof(struct folder));
1693 extract(fold[max_folders].name, buf, 1);
1698 for (p = 0; p < 2; ++p) {
1699 if (p == 0) serv_puts("LKRN");
1700 else if (p == 1) serv_puts("LKRO");
1702 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1703 if (max_folders >= alloc_folders) {
1704 alloc_folders = max_folders + 100;
1705 fold = realloc(fold,
1706 alloc_folders * sizeof(struct folder));
1708 memset(&fold[max_folders], 0, sizeof(struct folder));
1709 extract(fold[max_folders].room, buf, 0);
1710 if (p == 0) fold[max_folders].hasnewmsgs = 1;
1711 flags = extract_int(buf, 1);
1712 floor = extract_int(buf, 2);
1713 if (flags & QR_MAILBOX) {
1714 fold[max_folders].is_mailbox = 1;
1716 room_to_folder(fold[max_folders].name,
1717 fold[max_folders].room,
1719 fold[max_folders].is_mailbox);
1720 fold[max_folders].selectable = 1;
1725 /* Bubble-sort the folder list */
1726 for (i=0; i<max_folders; ++i) {
1727 for (j=0; j<(max_folders-1)-i; ++j) {
1728 if (strcasecmp(fold[j].name, fold[j+1].name) > 0) {
1729 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1730 memcpy(&fold[j], &fold[j+1],
1731 sizeof(struct folder));
1732 memcpy(&fold[j+1], &ftmp,
1733 sizeof(struct folder));
1742 for (i=0; i<max_folders; ++i) {
1744 levels = num_tokens(fold[i].name, '|');
1745 if (levels > oldlevels) {
1746 for (k=0; k<(levels-oldlevels); ++k) {
1751 if (levels < oldlevels) {
1752 for (k=0; k<(oldlevels-levels); ++k) {
1760 if (fold[i].selectable) {
1761 wprintf("<A HREF=\"/dotgoto?room=");
1762 urlescputs(fold[i].room);
1765 if (fold[i].hasnewmsgs) wprintf("<B>");
1766 extract(buf, fold[i].name, levels-1);
1768 if (fold[i].hasnewmsgs) wprintf("</B>");
1769 if (fold[i].selectable) wprintf("</A>\n");
1771 while (nests-- > 0) wprintf("</UL>\n");
1778 /* Do either a known rooms list or a folders list, depending on the
1782 char listviewpref[SIZ];
1787 /* Determine whether the user is trying to change views */
1788 if (bstr("view") != NULL) {
1789 if (strlen(bstr("view")) > 0) {
1790 set_preference("roomlistview", bstr("view"));
1794 get_preference("roomlistview", listviewpref);
1796 if (strcasecmp(listviewpref, "folders")) {
1797 strcpy(listviewpref, "rooms");
1801 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
1802 "<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
1804 if (!strcasecmp(listviewpref, "rooms")) {
1805 wprintf("Room list");
1807 if (!strcasecmp(listviewpref, "folders")) {
1808 wprintf("Folder list");
1810 wprintf("</B></TD>\n");
1813 /* offer the ability to switch views */
1814 wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
1815 "<SELECT NAME=\"newview\" SIZE=\"1\" "
1816 "OnChange=\"location.href=roomlistomatic.newview.options"
1817 "[selectedIndex].value\">\n");
1819 wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
1822 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
1825 wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
1826 "View as folder list"
1828 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
1831 wprintf("</SELECT></FORM></TD><TD>\n");
1833 wprintf("</TD></TR></TABLE><BR>\n");
1835 /* Display the room list in the user's preferred format */
1836 if (!strcasecmp(listviewpref, "folders")) {
1840 list_all_rooms_by_floor();