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 /* Check for new mail. */
373 WC->new_mail = extract_int(&got[4], 9);
374 WC->wc_view = extract_int(&got[4], 11);
376 svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
377 svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
378 svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
379 svcallback("ROOMPIC", embed_room_graphic);
380 svcallback("ROOMINFO", readinfo);
381 svcallback("YOUHAVEMAIL", embed_newmail_button);
382 svcallback("VIEWOMATIC", embed_view_o_matic);
384 do_template("roombanner");
385 clear_local_substs();
393 * generic routine to take the session to a new room
395 * display_name values: 0 = goto only
396 * 1 = goto and display
399 void gotoroom(char *gname, int display_name)
402 static long ls = (-1L);
407 wprintf("Pragma: no-cache\n");
408 wprintf("Cache-Control: no-store\n");
410 wprintf("<HTML><HEAD>\n"
411 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
412 "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
413 "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
414 "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
416 do_template("background");
418 if (display_name != 2) {
419 /* store ungoto information */
420 strcpy(WC->ugname, WC->wc_roomname);
423 /* move to the new room */
424 serv_printf("GOTO %s", gname);
427 serv_puts("GOTO _BASEROOM_");
432 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
437 extract(WC->wc_roomname, &buf[4], 0);
438 WC->room_flags = extract_int(&buf[4], 4);
439 /* highest_msg_read = extract_int(&buf[4],6);
440 maxmsgnum = extract_int(&buf[4],5);
441 is_mail = (char) extract_int(&buf[4],7); */
442 ls = extract_long(&buf[4], 6);
445 WC->is_room_aide = WC->is_aide;
447 WC->is_room_aide = (char) extract_int(&buf[4], 8);
449 remove_march(WC->wc_roomname);
450 if (!strcasecmp(gname, "_BASEROOM_"))
453 /* Display the room banner */
455 embed_room_banner(buf);
458 strcpy(WC->wc_roomname, WC->wc_roomname);
459 WC->wc_view = extract_int(&buf[4], 11);
464 * Locate the room on the march list which we most want to go to. Each room
465 * is measured given a "weight" of preference based on various factors.
467 char *pop_march(int desired_floor)
469 static char TheRoom[64];
471 int TheOrder = 32767;
474 struct march *mptr = NULL;
476 strcpy(TheRoom, "_BASEROOM_");
477 if (WC->march == NULL)
480 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
482 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
483 weight = weight + 10000;
484 if (mptr->march_floor == desired_floor)
485 weight = weight + 5000;
487 weight = weight + ((128 - (mptr->march_floor)) * 128);
488 weight = weight + (128 - (mptr->march_order));
490 if (weight > TheWeight) {
492 strcpy(TheRoom, mptr->march_name);
493 TheFloor = mptr->march_floor;
494 TheOrder = mptr->march_order;
502 /* Goto next room having unread messages.
503 * We want to skip over rooms that the user has already been to, and take the
504 * user back to the lobby when done. The room we end up in is placed in
505 * newroom - which is set to 0 (the lobby) initially.
506 * We start the search in the current room rather than the beginning to prevent
507 * two or more concurrent users from dragging each other back to the same room.
512 struct march *mptr, *mptr2;
515 /* First check to see if the march-mode list is already allocated.
516 * If it is, pop the first room off the list and go there.
519 if (WC->march == NULL) {
523 while (serv_gets(buf), strcmp(buf, "000")) {
524 mptr = (struct march *) malloc(sizeof(struct march));
526 extract(mptr->march_name, buf, 0);
527 mptr->march_floor = extract_int(buf, 2);
528 mptr->march_order = extract_int(buf, 3);
529 if (WC->march == NULL) {
533 while (mptr2->next != NULL)
538 /* add _BASEROOM_ to the end of the march list, so the user will end up
539 * in the system base room (usually the Lobby>) at the end of the loop
541 mptr = (struct march *) malloc(sizeof(struct march));
543 strcpy(mptr->march_name, "_BASEROOM_");
544 if (WC->march == NULL) {
548 while (mptr2->next != NULL)
553 * ...and remove the room we're currently in, so a <G>oto doesn't make us
554 * walk around in circles
556 remove_march(WC->wc_roomname);
558 if (WC->march != NULL) {
559 strcpy(next_room, pop_march(-1));
561 strcpy(next_room, "_BASEROOM_");
565 smart_goto(next_room);
569 void smart_goto(char *next_room) {
570 gotoroom(next_room, 0);
577 * mark all messages in current room as having been read
579 void slrp_highest(void)
584 serv_puts("SLRP HIGHEST");
587 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
594 * un-goto the previous room
600 if (!strcmp(WC->ugname, "")) {
601 smart_goto(WC->wc_roomname);
604 serv_printf("GOTO %s", WC->ugname);
607 smart_goto(WC->wc_roomname);
610 if (WC->uglsn >= 0L) {
611 serv_printf("SLRP %ld", WC->uglsn);
614 strcpy(buf, WC->ugname);
615 strcpy(WC->ugname, "");
620 * display the form for editing a room
622 void display_editroom(void)
629 char er_password[10];
631 char er_roomaide[26];
637 char *not_shared_with;
640 if (strlen(tab) == 0) tab = "admin";
646 display_error(&buf[4]);
649 extract(er_name, &buf[4], 0);
650 extract(er_password, &buf[4], 1);
651 extract(er_dirname, &buf[4], 2);
652 er_flags = extract_int(&buf[4], 3);
653 er_floor = extract_int(&buf[4], 4);
657 /* print the tabbed dialog */
658 wprintf("<TABLE border=0 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
660 if (!strcmp(tab, "admin")) {
661 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
664 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
666 wprintf("Room administration");
667 if (!strcmp(tab, "admin")) {
668 wprintf("</B></FONT></TD>\n");
671 wprintf("</A></TD>\n");
674 wprintf("<TD> </TD>\n");
676 if (!strcmp(tab, "config")) {
677 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
680 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
682 wprintf("Room configuration");
683 if (!strcmp(tab, "config")) {
684 wprintf("</B></FONT></TD>\n");
687 wprintf("</A></TD>\n");
690 wprintf("<TD> </TD>\n");
692 if (!strcmp(tab, "sharing")) {
693 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
696 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
699 if (!strcmp(tab, "sharing")) {
700 wprintf("</B></FONT></TD>\n");
703 wprintf("</A></TD>\n");
706 wprintf("<TD> </TD>\n");
708 if (!strcmp(tab, "listserv")) {
709 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
712 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
714 wprintf("Mailing list service");
715 if (!strcmp(tab, "listserv")) {
716 wprintf("</B></FONT></TD>\n");
719 wprintf("</A></TD>\n");
722 wprintf("<TD> </TD></TR></TABLE>\n");
724 /* end tabbed dialog */
727 if (!strcmp(tab, "admin")) {
729 "<LI><A HREF=\"/confirm_delete_room\">\n"
730 "Delete this room</A>\n"
731 "<LI><A HREF=\"/display_editroompic\">\n"
732 "Set or change the graphic for this room's banner</A>\n"
733 "<LI><A HREF=\"/display_editinfo\">\n"
734 "Edit this room's Info file</A>\n"
738 if (!strcmp(tab, "config")) {
739 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
741 wprintf("<UL><LI>Name of room: ");
742 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
744 wprintf("<LI>Resides on floor: ");
746 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
747 for (i = 0; i < 128; ++i)
748 if (strlen(floorlist[i]) > 0) {
751 wprintf("SELECTED ");
752 wprintf("VALUE=\"%d\">", i);
753 escputs(floorlist[i]);
754 wprintf("</OPTION>\n");
756 wprintf("</SELECT>\n");
758 wprintf("<LI>Type of room:<UL>\n");
760 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
761 if ((er_flags & QR_PRIVATE) == 0)
763 wprintf("> Public room\n");
765 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
766 if ((er_flags & QR_PRIVATE) &&
767 (er_flags & QR_GUESSNAME))
769 wprintf("> Private - guess name\n");
771 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
772 if ((er_flags & QR_PRIVATE) &&
773 (er_flags & QR_PASSWORDED))
775 wprintf("> Private - require password:\n");
776 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
778 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
779 if ((er_flags & QR_PRIVATE)
780 && ((er_flags & QR_GUESSNAME) == 0)
781 && ((er_flags & QR_PASSWORDED) == 0))
783 wprintf("> Private - invitation only\n");
785 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
786 wprintf("> If private, cause current users to forget room\n");
790 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
791 if (er_flags & QR_PREFONLY)
793 wprintf("> Preferred users only\n");
795 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
796 if (er_flags & QR_READONLY)
798 wprintf("> Read-only room\n");
800 /* directory stuff */
801 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
802 if (er_flags & QR_DIRECTORY)
804 wprintf("> File directory room\n");
806 wprintf("<UL><LI>Directory name: ");
807 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
809 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
810 if (er_flags & QR_UPLOAD)
812 wprintf("> Uploading allowed\n");
814 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
815 if (er_flags & QR_DOWNLOAD)
817 wprintf("> Downloading allowed\n");
819 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
820 if (er_flags & QR_VISDIR)
822 wprintf("> Visible directory</UL>\n");
824 /* end of directory stuff */
826 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
827 if (er_flags & QR_NETWORK)
829 wprintf("> Network shared room\n");
831 /* start of anon options */
833 wprintf("<LI>Anonymous messages<UL>\n");
835 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
836 if (((er_flags & QR_ANONONLY) == 0)
837 && ((er_flags & QR_ANONOPT) == 0))
839 wprintf("> No anonymous messages\n");
841 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
842 if (er_flags & QR_ANONONLY)
844 wprintf("> All messages are anonymous\n");
846 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
847 if (er_flags & QR_ANONOPT)
849 wprintf("> Prompt user when entering messages</UL>\n");
851 /* end of anon options */
853 wprintf("<LI>Room aide: \n");
857 wprintf("<EM>%s</EM>\n", &buf[4]);
859 extract(er_roomaide, &buf[4], 0);
860 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
863 wprintf("</UL><CENTER>\n");
864 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
865 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
866 wprintf("</CENTER>\n");
870 /* Sharing the room with other Citadel nodes... */
871 if (!strcmp(tab, "sharing")) {
873 shared_with = strdup("");
874 not_shared_with = strdup("");
876 /* Learn the current configuration */
877 serv_puts("CONF getsys|application/x-citadel-ignet-config");
879 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
880 extract(node, buf, 0);
881 not_shared_with = realloc(not_shared_with,
882 strlen(not_shared_with) + 32);
883 strcat(not_shared_with, node);
884 strcat(not_shared_with, "|");
889 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
890 extract(cmd, buf, 0);
891 extract(node, buf, 1);
892 if (!strcasecmp(cmd, "ignet_push_share")) {
893 shared_with = realloc(shared_with,
894 strlen(shared_with) + 32);
895 strcat(shared_with, node);
896 strcat(shared_with, "|");
900 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
901 extract(node, shared_with, i);
902 for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
903 extract(cmd, not_shared_with, j);
904 if (!strcasecmp(node, cmd)) {
905 remove_token(not_shared_with, j, '|');
910 /* Display the stuff */
911 wprintf("<CENTER><BR>"
912 "<TABLE border=1 cellpadding=5><TR>"
913 "<TD><B><I>Shared with</I></B></TD>"
914 "<TD><B><I>Not shared with</I></B></TD></TR>\n"
917 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
918 extract(node, shared_with, i);
919 if (strlen(node) > 0) {
920 wprintf("%s ", node);
921 wprintf("<A HREF=\"/netedit&cmd=remove&line="
922 "ignet_push_share|");
924 wprintf("&tab=sharing\">(unshare)</A><BR>");
928 wprintf("</TD><TD>\n");
930 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
931 extract(node, not_shared_with, i);
932 if (strlen(node) > 0) {
933 wprintf("%s ", node);
934 wprintf("<A HREF=\"/netedit&cmd=add&line="
935 "ignet_push_share|");
937 wprintf("&tab=sharing\">(share)</A><BR>");
941 wprintf("</TD></TR></TABLE><BR>\n"
942 "<I><B>Reminder:</B> When sharing a room, "
943 "it must be shared from both ends. Adding a node to "
944 "the 'shared' list sends messages out, but in order to"
945 " receive messages, the other nodes must be configured"
946 " to send messages out to your system as well.</I><BR>"
951 /* Mailing list management */
952 if (!strcmp(tab, "listserv")) {
954 wprintf("<BR><center><i>The contents of this room are being "
955 "mailed to the following list recipients:"
960 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
961 extract(cmd, buf, 0);
962 if (!strcasecmp(cmd, "listrecp")) {
963 extract(recp, buf, 1);
966 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
969 wprintf("&tab=listserv\">(remove)</A><BR>");
973 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
974 "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
975 "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
976 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
977 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
978 wprintf("</FORM><BR></CENTER>\n");
986 * save new parameters for a room
992 char er_password[10];
994 char er_roomaide[26];
1000 if (strcmp(bstr("sc"), "OK")) {
1001 display_error("Cancelled. Changes were not saved.");
1007 if (buf[0] != '2') {
1008 display_error(&buf[4]);
1011 extract(er_name, &buf[4], 0);
1012 extract(er_password, &buf[4], 1);
1013 extract(er_dirname, &buf[4], 2);
1014 er_flags = extract_int(&buf[4], 3);
1016 strcpy(er_roomaide, bstr("er_roomaide"));
1017 if (strlen(er_roomaide) == 0) {
1020 if (buf[0] != '2') {
1021 strcpy(er_roomaide, "");
1023 extract(er_roomaide, &buf[4], 0);
1026 strcpy(buf, bstr("er_name"));
1028 if (strlen(buf) > 0)
1029 strcpy(er_name, buf);
1031 strcpy(buf, bstr("er_password"));
1033 if (strlen(buf) > 0)
1034 strcpy(er_password, buf);
1036 strcpy(buf, bstr("er_dirname"));
1038 if (strlen(buf) > 0)
1039 strcpy(er_dirname, buf);
1041 strcpy(buf, bstr("type"));
1042 er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1044 if (!strcmp(buf, "invonly")) {
1045 er_flags |= (QR_PRIVATE);
1047 if (!strcmp(buf, "guessname")) {
1048 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1050 if (!strcmp(buf, "passworded")) {
1051 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1053 if (!strcmp(bstr("prefonly"), "yes")) {
1054 er_flags |= QR_PREFONLY;
1056 er_flags &= ~QR_PREFONLY;
1059 if (!strcmp(bstr("readonly"), "yes")) {
1060 er_flags |= QR_READONLY;
1062 er_flags &= ~QR_READONLY;
1065 if (!strcmp(bstr("network"), "yes")) {
1066 er_flags |= QR_NETWORK;
1068 er_flags &= ~QR_NETWORK;
1071 if (!strcmp(bstr("directory"), "yes")) {
1072 er_flags |= QR_DIRECTORY;
1074 er_flags &= ~QR_DIRECTORY;
1077 if (!strcmp(bstr("ulallowed"), "yes")) {
1078 er_flags |= QR_UPLOAD;
1080 er_flags &= ~QR_UPLOAD;
1083 if (!strcmp(bstr("dlallowed"), "yes")) {
1084 er_flags |= QR_DOWNLOAD;
1086 er_flags &= ~QR_DOWNLOAD;
1089 if (!strcmp(bstr("visdir"), "yes")) {
1090 er_flags |= QR_VISDIR;
1092 er_flags &= ~QR_VISDIR;
1095 strcpy(buf, bstr("anon"));
1097 er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1098 if (!strcmp(buf, "anononly"))
1099 er_flags |= QR_ANONONLY;
1100 if (!strcmp(buf, "anon2"))
1101 er_flags |= QR_ANONOPT;
1104 if (!strcmp(bstr("bump"), "yes"))
1107 er_floor = atoi(bstr("er_floor"));
1109 sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1110 er_name, er_password, er_dirname, er_flags, bump, er_floor);
1113 if (buf[0] != '2') {
1114 display_error(&buf[4]);
1117 gotoroom(er_name, 0);
1119 if (strlen(er_roomaide) > 0) {
1120 sprintf(buf, "SETA %s", er_roomaide);
1123 if (buf[0] != '2') {
1124 display_error(&buf[4]);
1128 smart_goto(er_name);
1132 * Invite, Kick, and show Who Knows a room
1134 void display_whok(void)
1136 char buf[SIZ], room[SIZ], username[SIZ];
1141 if (buf[0] != '2') {
1142 display_error(&buf[4]);
1145 extract(room, &buf[4], 0);
1147 strcpy(username, bstr("username"));
1151 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1152 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1153 escputs(WC->wc_roomname);
1154 wprintf("</B></FONT></TD></TR></TABLE>\n");
1156 if(!strcmp(bstr("sc"), "Kick")) {
1157 sprintf(buf, "KICK %s", username);
1161 if (buf[0] != '2') {
1162 display_error(&buf[4]);
1165 wprintf("<B><I>User %s kicked out of room %s.</I></B>\n",
1168 } else if(!strcmp(bstr("sc"), "Invite")) {
1169 sprintf(buf, "INVT %s", username);
1173 if (buf[0] != '2') {
1174 display_error(&buf[4]);
1177 wprintf("<B><I>User %s invited to room %s.</I></B>\n",
1184 wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1185 "<TD>The users listed below have access to this room. "
1186 "To remove a user from the access list, select the user "
1187 "name from the list and click 'Kick'.<BR><BR>");
1189 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1190 wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1193 if (buf[0] == '1') {
1194 while (serv_gets(buf), strcmp(buf, "000")) {
1195 extract(username, buf, 0);
1196 wprintf("<OPTION>");
1201 wprintf("</SELECT><BR>\n");
1203 wprintf("<input type=submit name=sc value=\"Kick\">");
1204 wprintf("</FORM></CENTER>\n");
1207 "To grant another user access to this room, enter the "
1208 "user name in the box below and click 'Invite'.<BR><BR>");
1210 wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1211 wprintf("Invite: ");
1212 wprintf("<input type=text name=username><BR>\n"
1213 "<input type=hidden name=sc value=\"Invite\">"
1214 "<input type=submit value=\"Invite\">"
1215 "</FORM></CENTER>\n");
1217 wprintf("</TD></TR></TABLE>\n");
1224 * display the form for entering a new room
1226 void display_entroom(void)
1231 serv_puts("CRE8 0");
1234 if (buf[0] != '2') {
1235 display_error(&buf[4]);
1240 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1241 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1242 wprintf("<B>Enter (create) a new room</B>\n");
1243 wprintf("</FONT></TD></TR></TABLE>\n");
1245 wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1247 wprintf("<UL><LI>Name of room: ");
1248 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1250 wprintf("<LI>Type of room:<UL>\n");
1252 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1253 wprintf("CHECKED > Public room\n");
1255 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1256 wprintf("> Private - guess name\n");
1258 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1259 wprintf("> Private - require password:\n");
1260 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1262 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1263 wprintf("> Private - invitation only\n");
1266 wprintf("<LI>Resides on floor: ");
1268 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1269 for (i = 0; i < 128; ++i)
1270 if (strlen(floorlist[i]) > 0) {
1271 wprintf("<OPTION ");
1272 wprintf("VALUE=\"%d\">", i);
1273 escputs(floorlist[i]);
1274 wprintf("</OPTION>\n");
1276 wprintf("</SELECT>\n");
1280 wprintf("<CENTER>\n");
1281 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1282 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1283 wprintf("</CENTER>\n");
1284 wprintf("</FORM>\n<HR>");
1285 serv_printf("MESG roomaccess");
1287 if (buf[0] == '1') {
1303 char er_password[10];
1307 if (strcmp(bstr("sc"), "OK")) {
1308 display_error("Cancelled. No new room was created.");
1311 strcpy(er_name, bstr("er_name"));
1312 strcpy(er_type, bstr("type"));
1313 strcpy(er_password, bstr("er_password"));
1314 er_floor = atoi(bstr("er_floor"));
1317 if (!strcmp(er_type, "guessname"))
1319 if (!strcmp(er_type, "passworded"))
1321 if (!strcmp(er_type, "invonly"))
1324 sprintf(buf, "CRE8 1|%s|%d|%s|%d",
1325 er_name, er_num_type, er_password, er_floor);
1328 if (buf[0] != '2') {
1329 display_error(&buf[4]);
1332 smart_goto(er_name);
1337 * display the screen to enter a private room
1339 void display_private(char *rname, int req_pass)
1344 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1345 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1346 wprintf("<B>Goto a private room</B>\n");
1347 wprintf("</FONT></TD></TR></TABLE>\n");
1349 wprintf("<CENTER>\n");
1350 wprintf("If you know the name of a hidden (guess-name) or\n");
1351 wprintf("passworded room, you can enter that room by typing\n");
1352 wprintf("its name below. Once you gain access to a private\n");
1353 wprintf("room, it will appear in your regular room listings\n");
1354 wprintf("so you don't have to keep returning here.\n");
1355 wprintf("<BR><BR>");
1357 wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1359 wprintf("<TABLE border><TR><TD>");
1360 wprintf("Enter room name:</TD><TD>");
1361 wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1364 wprintf("</TD></TR><TR><TD>");
1365 wprintf("Enter room password:</TD><TD>");
1366 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1368 wprintf("</TD></TR></TABLE>\n");
1370 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1371 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1372 wprintf("</FORM>\n");
1377 * goto a private room
1379 void goto_private(void)
1384 if (strcasecmp(bstr("sc"), "OK")) {
1385 display_main_menu();
1388 strcpy(hold_rm, WC->wc_roomname);
1389 strcpy(buf, "GOTO ");
1390 strcat(buf, bstr("gr_name"));
1392 strcat(buf, bstr("gr_pass"));
1396 if (buf[0] == '2') {
1397 smart_goto(bstr("gr_name"));
1400 if (!strncmp(buf, "540", 3)) {
1401 display_private(bstr("gr_name"), 1);
1405 wprintf("%s\n", &buf[4]);
1412 * display the screen to zap a room
1414 void display_zap(void)
1418 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1419 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1420 wprintf("<B>Zap (forget) the current room</B>\n");
1421 wprintf("</FONT></TD></TR></TABLE>\n");
1423 wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1424 wprintf("disappear from your room list. Is this what you wish ");
1425 wprintf("to do?<BR>\n");
1427 wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1428 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1429 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1430 wprintf("</FORM>\n");
1441 char final_destination[SIZ];
1443 /* If the forget-room routine fails for any reason, we fall back
1444 * to the current room; otherwise, we go to the Lobby
1446 strcpy(final_destination, WC->wc_roomname);
1448 if (!strcasecmp(bstr("sc"), "OK")) {
1449 serv_printf("GOTO %s", WC->wc_roomname);
1451 if (buf[0] != '2') {
1452 /* ExpressMessageCat(&buf[4]); */
1456 if (buf[0] != '2') {
1457 /* ExpressMessageCat(&buf[4]); */
1459 strcpy(final_destination, "_BASEROOM_");
1463 smart_goto(final_destination);
1470 * Confirm deletion of the current room
1472 void confirm_delete_room(void)
1476 serv_puts("KILL 0");
1478 if (buf[0] != '2') {
1479 display_error(&buf[4]);
1483 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1484 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1485 wprintf("<B>Confirm deletion of room</B>\n");
1486 wprintf("</FONT></TD></TR></TABLE>\n");
1488 wprintf("<CENTER>");
1489 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1491 wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1492 escputs(WC->wc_roomname);
1493 wprintf("</FONT>?<BR>\n");
1495 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1496 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1498 wprintf("</FORM></CENTER>\n");
1504 * Delete the current room
1506 void delete_room(void)
1511 strcpy(sc, bstr("sc"));
1513 if (strcasecmp(sc, "Delete")) {
1514 display_error("Cancelled. This room was not deleted.");
1517 serv_puts("KILL 1");
1519 if (buf[0] != '2') {
1520 display_error(&buf[4]);
1522 smart_goto("_BASEROOM_");
1529 * Perform changes to a room's network configuration
1531 void netedit(void) {
1536 if (strlen(bstr("line"))==0) {
1541 strcpy(line, bstr("prefix"));
1542 strcat(line, bstr("line"));
1543 strcat(line, bstr("suffix"));
1553 if (buf[0] != '1') {
1559 /* This loop works for add *or* remove. Spiffy, eh? */
1560 while (serv_gets(buf), strcmp(buf, "000")) {
1561 if (strcasecmp(buf, line)) {
1562 fprintf(fp, "%s\n", buf);
1569 if (buf[0] != '4') {
1575 while (fgets(buf, sizeof buf, fp) != NULL) {
1576 buf[strlen(buf)-1] = 0;
1580 if (!strcasecmp(bstr("cmd"), "add")) {
1592 * Convert a room name to a folder-ish-looking name.
1594 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1599 * For mailboxes, just do it straight...
1602 sprintf(folder, "My folders|%s", room);
1606 * Otherwise, prefix the floor name as a "public folders" moniker
1609 sprintf(folder, "%s|%s", floorlist[floor], room);
1613 * Replace "/" characters with "|" for pseudo-folder-delimiting
1615 for (i=0; i<strlen(folder); ++i) {
1616 if (folder[i] == '/') folder[i] = '|';
1627 * Change the view for this room
1629 void change_view(void) {
1633 view = atol(bstr("view"));
1635 serv_printf("VIEW %d", view);
1637 smart_goto(WC->wc_roomname);
1642 * Show the room list in "folders" format. (only should get called by
1643 * knrooms() because that's where output_headers() is called from)
1645 void folders(void) {
1648 int levels, oldlevels;
1658 struct folder *fold = NULL;
1660 int max_folders = 0;
1661 int alloc_folders = 0;
1668 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
1669 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
1670 "<B>Folder list</B>\n"
1671 "</TD></TR></TABLE><BR>\n"
1674 /* Start with the mailboxes */
1677 fold = malloc(sizeof(struct folder));
1678 memset(fold, 0, sizeof(struct folder));
1679 strcpy(fold[0].name, "My folders");
1681 /* Then add floors */
1684 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1685 if (max_folders >= alloc_folders) {
1686 alloc_folders = max_folders + 100;
1687 fold = realloc(fold,
1688 alloc_folders * sizeof(struct folder));
1690 memset(&fold[max_folders], 0, sizeof(struct folder));
1691 extract(fold[max_folders].name, buf, 1);
1696 for (p = 0; p < 2; ++p) {
1697 if (p == 0) serv_puts("LKRN");
1698 else if (p == 1) serv_puts("LKRO");
1700 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1701 if (max_folders >= alloc_folders) {
1702 alloc_folders = max_folders + 100;
1703 fold = realloc(fold,
1704 alloc_folders * sizeof(struct folder));
1706 memset(&fold[max_folders], 0, sizeof(struct folder));
1707 extract(fold[max_folders].room, buf, 0);
1708 if (p == 0) fold[max_folders].hasnewmsgs = 1;
1709 flags = extract_int(buf, 1);
1710 floor = extract_int(buf, 2);
1711 if (flags & QR_MAILBOX) {
1712 fold[max_folders].is_mailbox = 1;
1714 room_to_folder(fold[max_folders].name,
1715 fold[max_folders].room,
1717 fold[max_folders].is_mailbox);
1718 fold[max_folders].selectable = 1;
1723 /* Bubble-sort the folder list */
1724 for (i=0; i<max_folders; ++i) {
1725 for (j=0; j<(max_folders-1)-i; ++j) {
1726 if (strcasecmp(fold[j].name, fold[j+1].name) > 0) {
1727 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1728 memcpy(&fold[j], &fold[j+1],
1729 sizeof(struct folder));
1730 memcpy(&fold[j+1], &ftmp,
1731 sizeof(struct folder));
1740 for (i=0; i<max_folders; ++i) {
1742 levels = num_tokens(fold[i].name, '|');
1743 if (levels > oldlevels) {
1744 for (k=0; k<(levels-oldlevels); ++k) {
1749 if (levels < oldlevels) {
1750 for (k=0; k<(oldlevels-levels); ++k) {
1758 if (fold[i].selectable) {
1759 wprintf("<A HREF=\"/dotgoto?room=");
1760 urlescputs(fold[i].room);
1763 if (fold[i].hasnewmsgs) wprintf("<B>");
1764 extract(buf, fold[i].name, levels-1);
1766 if (fold[i].hasnewmsgs) wprintf("</B>");
1767 if (fold[i].selectable) wprintf("</A>\n");
1769 while (nests-- > 0) wprintf("</UL>\n");
1776 /* Do either a known rooms list or a folders list, depending on the
1780 char listviewpref[SIZ];
1785 /* Determine whether the user is trying to change views */
1786 strcpy(listviewpref, "rooms");
1787 if (bstr("view") != NULL) {
1788 set_preference("roomlistview", bstr("view"));
1791 get_preference("roomlistview", listviewpref);
1793 if (!strcasecmp(listviewpref, "folders")) {
1794 strcpy(listviewpref, "rooms");
1797 /* offer the ability to switch views */
1798 wprintf("<FORM NAME=\"roomlistomatic\">\n"
1799 "<SELECT NAME=\"newview\" SIZE=\"1\" "
1800 "OnChange=\"location.href=roomlistomatic.newview.options"
1801 "[selectedIndex].value\">\n");
1803 wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
1806 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
1809 wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
1810 "View as folder list"
1812 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
1815 wprintf("</SELECT></FORM>\n");
1817 /* Display the room list in the user's preferred format */
1818 if (!strcasecmp(listviewpref, "folders")) {
1822 list_all_rooms_by_floor();