2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
34 #include <libcitadel.h>
36 #include "citadel_ipc.h"
37 #include "citadel_decls.h"
45 #include "citadel_dirs.h"
47 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
50 void stty_ctdl(int cmd);
51 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
52 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
53 int pattern(char *search, char *patn);
54 int file_checksum(char *filename);
55 int nukedir(char *dirname);
57 extern unsigned room_flags;
58 extern char room_name[];
60 extern char tempdir[];
61 extern int editor_pid;
62 extern int screenwidth;
63 extern int screenheight;
64 extern char fullname[];
65 extern char sigcaught;
66 extern char floor_mode;
67 extern char curr_floor;
72 extern char *uglist[];
73 extern long uglistlsn[];
74 extern int uglistsize;
76 extern char floorlist[128][SIZ];
79 void load_floorlist(CtdlIPC *ipc)
84 int r; /* IPC response code */
86 for (a = 0; a < 128; ++a)
89 r = CtdlIPCFloorListing(ipc, &listing, buf);
91 strcpy(floorlist[0], "Main Floor");
94 while (*listing && !IsEmptyStr(listing)) {
95 extract_token(buf, listing, 0, '\n', sizeof buf);
96 remove_token(listing, 0, '\n');
97 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
103 void room_tree_list(struct ctdlroomlisting *rp)
106 char rmname[ROOMNAMELEN];
114 if (rp->lnext != NULL) {
115 room_tree_list(rp->lnext);
118 if (sigcaught == 0) {
119 strcpy(rmname, rp->rlname);
121 if ((c + strlen(rmname) + 4) > screenwidth) {
123 /* line break, check the paginator */
127 if (f & QR_MAILBOX) {
128 color(BRIGHT_YELLOW);
129 } else if (f & QR_PRIVATE) {
134 scr_printf("%s", rmname);
135 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
137 else if (f & QR_DIRECTORY)
139 else if (f & QR_NETWORK)
143 c = c + strlen(rmname) + 3;
146 if (rp->rnext != NULL) {
147 room_tree_list(rp->rnext);
155 * Room ordering stuff (compare first by floor, then by order)
157 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
159 if ((r1 == NULL) && (r2 == NULL))
165 if (r1->rlfloor < r2->rlfloor)
167 if (r1->rlfloor > r2->rlfloor)
169 if (r1->rlorder < r2->rlorder)
171 if (r1->rlorder > r2->rlorder)
178 * Common code for all room listings
180 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
183 struct ctdlroomlisting *rl = NULL;
184 struct ctdlroomlisting *rp;
185 struct ctdlroomlisting *rs;
188 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
191 if ( (new_only == LISTRMS_NEW_ONLY)
192 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
195 if ( (new_only == LISTRMS_OLD_ONLY)
196 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
199 if ( (floor_only >= 0)
200 && (mptr->march_floor != floor_only))
203 if (flags && (mptr->march_flags & flags) == 0)
206 if (match && (pattern(mptr->march_name, match) == -1))
210 rp = malloc(sizeof(struct ctdlroomlisting));
211 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
212 rp->rlflags = mptr->march_flags;
213 rp->rlfloor = mptr->march_floor;
214 rp->rlorder = mptr->march_order;
223 if (rordercmp(rp, rs) < 0) {
224 if (rs->lnext == NULL) {
231 if (rs->rnext == NULL) {
243 room_tree_list(NULL);
249 void list_other_floors(void)
254 for (a = 0; a < 128; ++a) {
255 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
256 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
260 scr_printf("%s: ", floorlist[a]);
261 c = c + strlen(floorlist[a]) + 3;
268 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
269 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
271 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
274 struct march *listing = NULL;
276 int r; /* IPC response code */
280 /* Ask the server for a room list */
281 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
289 if (kn_floor_mode == 0) {
291 scr_printf("\n Rooms with unread messages:\n");
292 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
294 scr_printf("\n\n No unseen messages in:\n");
295 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
299 if (kn_floor_mode == 1) {
301 scr_printf("\n Rooms with unread messages on %s:\n",
302 floorlist[(int) curr_floor]);
303 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
305 scr_printf("\n\n Rooms with no new messages on %s:\n",
306 floorlist[(int) curr_floor]);
307 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
309 scr_printf("\n\n Other floors:\n");
314 if (kn_floor_mode == 2) {
315 for (a = 0; a < 128; ++a) {
316 if (floorlist[a][0] != 0) {
318 scr_printf("\n Rooms on %s:\n",
320 listrms(listing, LISTRMS_ALL, a, 0, NULL);
326 /* Free the room list */
328 mptr = listing->next;
337 void listzrooms(CtdlIPC *ipc)
338 { /* list public forgotten rooms */
339 struct march *listing = NULL;
341 int r; /* IPC response code */
345 /* Ask the server for a room list */
346 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
352 scr_printf("\n Forgotten public rooms:\n");
353 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
356 /* Free the room list */
358 mptr = listing->next;
366 void dotknown(CtdlIPC *ipc, int what, char *match)
367 { /* list rooms according to attribute */
368 struct march *listing = NULL;
370 int r; /* IPC response code */
373 /* Ask the server for a room list */
374 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
383 scr_printf("\n Anonymous rooms:\n");
384 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
388 scr_printf("\n Directory rooms:\n");
389 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
393 scr_printf("\n Matching \"%s\" rooms:\n", match);
394 listrms(listing, LISTRMS_ALL, -1, 0, match);
398 scr_printf("\n Preferred only rooms:\n");
399 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
403 scr_printf("\n Private rooms:\n");
404 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
408 scr_printf("\n Read only rooms:\n");
409 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
413 scr_printf("\n Shared rooms:\n");
414 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
419 /* Free the room list */
421 mptr = listing->next;
430 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
434 a = boolprompt(prompt, (ibuf & sbit));
435 ibuf = (ibuf | sbit);
437 ibuf = (ibuf ^ sbit);
445 * Select a floor (used in several commands)
446 * The supplied argument is the 'default' floor number.
447 * This function returns the selected floor number.
449 int select_floor(CtdlIPC *ipc, int rfloor)
454 if (floor_mode == 1) {
455 if (floorlist[(int) curr_floor][0] == 0) {
461 safestrncpy(floorstr, floorlist[rfloor],
463 strprompt("Which floor", floorstr, 255);
464 for (a = 0; a < 128; ++a) {
466 (floorstr, &floorlist[a][0]))
471 (floorstr, &floorlist[a][0],
475 && (pattern(&floorlist[a][0], floorstr)
480 scr_printf("\n One of:\n");
481 for (a = 0; a < 128; ++a) {
482 if (floorlist[a][0] != 0) {
488 } while (newfloor < 0);
493 scr_printf("Floor selection bypassed because you have "
494 "floor mode disabled.\n");
504 * .<A>ide <E>dit room
506 void editthisroom(CtdlIPC *ipc)
509 char raide[USERNAME_SIZE];
511 struct ctdlroom *attr = NULL;
512 struct ExpirePolicy *eptr = NULL;
513 int r; /* IPC response code */
515 /* Fetch the existing room config */
516 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
518 scr_printf("%s\n", buf);
521 eptr = &(attr->QRep);
523 /* Fetch the name of the current room aide */
524 r = CtdlIPCGetRoomAide(ipc, buf);
526 safestrncpy(raide, buf, sizeof raide);
530 if (IsEmptyStr(raide)) {
531 strcpy(raide, "none");
534 /* Fetch the expire policy (this will silently fail on old servers,
535 * resulting in "default" policy)
537 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
539 /* Now interact with the user. */
541 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
542 attr->QRfloor = select_floor(ipc, attr->QRfloor);
543 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
544 if (attr->QRflags & QR_PRIVATE) {
545 attr->QRflags = set_room_attr(ipc, attr->QRflags,
546 "Hidden room (accessible to anyone who knows the room name)",
550 /* if it's public, clear the privacy classes */
551 if ((attr->QRflags & QR_PRIVATE) == 0) {
552 if (attr->QRflags & QR_GUESSNAME) {
553 attr->QRflags = attr->QRflags - QR_GUESSNAME;
555 if (attr->QRflags & QR_PASSWORDED) {
556 attr->QRflags = attr->QRflags - QR_PASSWORDED;
560 /* if it's private, choose the privacy classes */
561 if ((attr->QRflags & QR_PRIVATE)
562 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
563 attr->QRflags = set_room_attr(ipc, attr->QRflags,
564 "Accessible by entering a password",
567 if ((attr->QRflags & QR_PRIVATE)
568 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
569 strprompt("Room password", attr->QRpasswd, 9);
572 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
573 rbump = boolprompt("Cause current users to forget room", 0);
576 attr->QRflags = set_room_attr(ipc, attr->QRflags,
577 "Preferred users only", QR_PREFONLY);
578 attr->QRflags = set_room_attr(ipc, attr->QRflags,
579 "Read-only room", QR_READONLY);
580 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
581 "Allow message deletion by anyone who can post",
583 attr->QRflags = set_room_attr(ipc, attr->QRflags,
584 "Permanent room", QR_PERMANENT);
585 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
586 "Subject Required (Force "
587 "users to specify a message "
588 "subject)", QR2_SUBJECTREQ);
589 attr->QRflags = set_room_attr(ipc, attr->QRflags,
590 "Directory room", QR_DIRECTORY);
591 if (attr->QRflags & QR_DIRECTORY) {
592 strprompt("Directory name", attr->QRdirname, 14);
594 set_room_attr(ipc, attr->QRflags,
595 "Uploading allowed", QR_UPLOAD);
597 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
600 set_room_attr(ipc, attr->QRflags,
601 "Visible directory", QR_VISDIR);
603 attr->QRflags = set_room_attr(ipc, attr->QRflags,
604 "Network shared room", QR_NETWORK);
605 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
606 "Self-service list subscribe/unsubscribe",
608 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
609 "public posting to this room via room_roomname@yourcitadel.org",
611 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
612 "moderated mailinglist",
614 attr->QRflags = set_room_attr(ipc, attr->QRflags,
615 "Automatically make all messages anonymous",
617 if ((attr->QRflags & QR_ANONONLY) == 0) {
618 attr->QRflags = set_room_attr(ipc, attr->QRflags,
619 "Ask users whether to make messages anonymous",
622 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
624 /* Ask about the room aide */
626 strprompt("Room aide (or 'none')", raide, 29);
627 if (!strcasecmp(raide, "none")) {
631 r = CtdlIPCQueryUsername(ipc, raide, buf);
633 scr_printf("%s\n", buf);
635 } while (r / 100 != 2);
637 /* Angels and demons dancing in my head... */
639 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
640 strprompt("Message expire policy (? for list)", buf, 1);
643 "0. Use the default for this floor\n"
644 "1. Never automatically expire messages\n"
645 "2. Expire by message count\n"
646 "3. Expire by message age\n");
648 } while ((buf[0] < 48) || (buf[0] > 51));
649 attr->QRep.expire_mode = buf[0] - 48;
651 /* ...lunatics and monsters underneath my bed */
652 if (attr->QRep.expire_mode == 2) {
653 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
654 strprompt("Keep how many messages online?", buf, 10);
655 attr->QRep.expire_value = atol(buf);
658 if (attr->QRep.expire_mode == 3) {
659 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
660 strprompt("Keep messages for how many days?", buf, 10);
661 attr->QRep.expire_value = atol(buf);
664 /* Give 'em a chance to change their minds */
665 scr_printf("Save changes (y/n)? ");
668 r = CtdlIPCSetRoomAide(ipc, raide, buf);
670 scr_printf("%s\n", buf);
673 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
675 scr_printf("%s\n", buf);
678 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
679 scr_printf("%s\n", buf);
680 strncpy(buf, attr->QRname, ROOMNAMELEN);
683 dotgoto(ipc, buf, 2, 0);
690 * un-goto the previous room, or a specified room
692 void dotungoto(CtdlIPC *ipc, char *towhere)
694 /* Find this 'towhere' room in the list ungoto from this room to
695 that at the messagepointer position in that room in our ungoto list.
696 I suppose I could be a real dick and just ungoto that many places
701 struct ctdlipcroom *rret = NULL; /* ignored */
706 scr_printf("No rooms to ungoto.\n");
711 scr_printf("Must specify a room to ungoto.\n");
714 if (IsEmptyStr(towhere))
716 scr_printf("Must specify a room to ungoto.\n");
719 for (lp = uglistsize-1; lp >= 0; lp--)
721 if (strcasecmp(towhere, uglist[lp]) == 0)
729 scr_printf("Room: %s not in ungoto list.\n", towhere);
733 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
734 if (rret) free(rret); /* ignored */
736 scr_printf("%s\n", buf);
739 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
741 scr_printf("%s\n", buf);
743 safestrncpy(buf, uglist[found], sizeof(buf));
744 /* we queue ungoto information here, because we're not really
745 ungotoing, we're really going to a random spot in some arbitrary
747 dotgoto(ipc, buf, 0, 0);
750 void ungoto(CtdlIPC *ipc)
753 struct ctdlipcroom *rret = NULL; /* ignored */
759 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
760 if (rret) free(rret); /* ignored */
762 scr_printf("%s\n", buf);
765 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
767 scr_printf("%s\n", buf);
769 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
771 free(uglist[uglistsize]);
772 /* Don't queue ungoto info or we end up in a loop */
773 dotgoto(ipc, buf, 0, 1);
778 * saves filelen bytes from file at pathname
780 int save_buffer(void *file, size_t filelen, const char *pathname)
783 size_t bytes_written = 0;
786 fp = fopen(pathname, "w");
788 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
792 block = fwrite((char *)file + bytes_written, 1,
793 filelen - bytes_written, fp);
794 bytes_written += block;
795 } while (errno == EINTR && bytes_written < filelen);
798 if (bytes_written < filelen) {
799 scr_printf("Trouble saving '%s': %s\n", pathname,
808 * Save supplied_filename in dest directory; gets the name only
810 void destination_directory(char *dest, const char *supplied_filename)
812 static char save_dir[SIZ] = { 0 };
814 if (IsEmptyStr(save_dir)) {
815 if (getenv("HOME") == NULL) {
816 strcpy(save_dir, ".");
819 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
820 if (access(save_dir, W_OK) != 0) {
821 sprintf(save_dir, "%s", getenv("HOME"));
822 if (access(save_dir, W_OK) != 0) {
823 sprintf(save_dir, ".");
829 sprintf(dest, "%s/%s", save_dir, supplied_filename);
830 strprompt("Save as", dest, PATH_MAX);
832 /* Remember the directory for next time */
833 strcpy(save_dir, dest);
834 if (strrchr(save_dir, '/') != NULL) {
835 strcpy(strrchr(save_dir, '/'), "");
838 strcpy(save_dir, ".");
844 * download() - download a file or files. The argument passed to this
845 * function determines which protocol to use.
846 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
848 void download(CtdlIPC *ipc, int proto)
851 char filename[PATH_MAX];
852 char tempname[PATH_MAX];
853 char transmit_cmd[SIZ];
858 void *file = NULL; /* The downloaded file */
859 size_t filelen = 0L; /* The downloaded file length */
861 if ((room_flags & QR_DOWNLOAD) == 0) {
862 scr_printf("*** You cannot download from this room.\n");
866 newprompt("Enter filename: ", filename, PATH_MAX);
868 /* Save to local disk, for folks with their own copy of the client */
870 destination_directory(tempname, filename);
871 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
873 scr_printf("%s\n", buf);
876 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
881 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
883 scr_printf("%s\n", buf);
886 filelen = extract_unsigned_long(buf, 0);
888 /* Meta-download for public clients */
889 /* scr_printf("Fetching file from Citadel server...\n"); */
890 mkdir(tempdir, 0700);
891 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
892 tpipe = fopen(tempname, "wb");
893 if (fwrite(file, filelen, 1, tpipe) < filelen) {
894 /* FIXME: restart syscall on EINTR */
898 if (file) free(file);
901 /* FIXME: display internally instead */
902 snprintf(transmit_cmd, sizeof transmit_cmd,
903 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
907 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
909 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
911 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
913 /* FIXME: display internally instead */
914 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
916 stty_ctdl(SB_RESTORE);
917 rv = system(transmit_cmd);
918 stty_ctdl(SB_NO_INTR);
920 /* clean up the temporary directory */
922 ctdl_beep(); /* Beep beep! */
927 * read directory of this room
929 void roomdir(CtdlIPC *ipc)
936 char *listing = NULL; /* Returned directory listing */
939 r = CtdlIPCReadDirectory(ipc, &listing, buf);
941 scr_printf("%s\n", buf);
945 extract_token(comment, buf, 0, '|', sizeof comment);
946 extract_token(flnm, buf, 1, '|', sizeof flnm);
947 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
948 scr_printf("-----------------------\n");
949 while (listing && *listing && !IsEmptyStr(listing)) {
950 extract_token(buf, listing, 0, '\n', sizeof buf);
951 remove_token(listing, 0, '\n');
953 extract_token(flnm, buf, 0, '|', sizeof flnm);
954 extract_token(flsz, buf, 1, '|', sizeof flsz);
955 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
956 extract_token(comment, buf, 3, '|', sizeof comment);
957 if (strlen(flnm) <= 14)
958 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
960 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
963 if (listing) free(listing);
968 * add a user to a private room
970 void invite(CtdlIPC *ipc)
972 char username[USERNAME_SIZE];
974 int r; /* IPC response code */
976 newprompt("Name of user? ", username, USERNAME_SIZE);
977 if (username[0] == 0)
980 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
981 scr_printf("%s\n", buf);
986 * kick a user out of a room
988 void kickout(CtdlIPC *ipc)
990 char username[USERNAME_SIZE];
992 int r; /* IPC response code */
994 newprompt("Name of user? ", username, USERNAME_SIZE);
995 if (username[0] == 0)
998 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
999 scr_printf("%s\n", buf);
1004 * aide command: kill the current room
1006 void killroom(CtdlIPC *ipc)
1011 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1013 scr_printf("%s\n", aaa);
1017 scr_printf("Are you sure you want to kill this room? ");
1021 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1022 scr_printf("%s\n", aaa);
1025 dotgoto(ipc, "_BASEROOM_", 0, 0);
1028 void forget(CtdlIPC *ipc)
1029 { /* forget the current room */
1032 scr_printf("Are you sure you want to forget this room? ");
1036 remove_march(room_name, 0);
1037 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1038 scr_printf("%s\n", buf);
1042 /* now return to the lobby */
1043 dotgoto(ipc, "_BASEROOM_", 0, 0);
1050 void entroom(CtdlIPC *ipc)
1053 char new_room_name[ROOMNAMELEN];
1055 char new_room_pass[10];
1058 int r; /* IPC response code */
1060 /* Check permission to create room */
1061 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1063 scr_printf("%s\n", buf);
1067 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1068 if (IsEmptyStr(new_room_name)) {
1071 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1072 if (new_room_name[a] == '|') {
1073 new_room_name[a] = '_';
1077 new_room_floor = select_floor(ipc, (int) curr_floor);
1079 IFNEXPERT formout(ipc, "roomaccess");
1081 scr_printf("<?>Help\n"
1082 "<1>Public room (shown to all users by default)\n"
1083 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1084 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1085 "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1086 "<5>Personal room (accessible to you only)\n"
1091 } while (((b < '1') || (b > '5')) && (b != '?'));
1094 formout(ipc, "roomaccess");
1096 } while ((b < '1') || (b > '5'));
1097 b -= '0'; /* Portable */
1098 scr_printf("%d\n", b);
1099 new_room_type = b - 1;
1100 if (new_room_type == 2) {
1101 newprompt("Enter a room password: ", new_room_pass, 9);
1102 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1103 if (new_room_pass[a] == '|')
1104 new_room_pass[a] = '_';
1106 strcpy(new_room_pass, "");
1109 scr_printf("\042%s\042, a", new_room_name);
1111 scr_printf(" public room.");
1113 scr_printf(" hidden room.");
1115 scr_printf(" passworded room, password: %s", new_room_pass);
1117 scr_printf("n invitation-only room.");
1119 scr_printf(" personal room.");
1120 scr_printf("\nInstall it? (y/n) : ");
1125 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1126 new_room_pass, new_room_floor, buf);
1128 scr_printf("%s\n", buf);
1132 /* command succeeded... now GO to the new room! */
1133 dotgoto(ipc, new_room_name, 0, 0);
1138 void readinfo(CtdlIPC *ipc)
1139 { /* read info file for current room */
1142 int r; /* IPC response code */
1145 /* Name of currernt room aide */
1146 r = CtdlIPCGetRoomAide(ipc, buf);
1148 safestrncpy(raide, buf, sizeof raide);
1152 if (!IsEmptyStr(raide))
1153 scr_printf("Room aide is %s.\n\n", raide);
1155 r = CtdlIPCRoomInfo(ipc, &text, buf);
1160 fmout(screenwidth, NULL, text, NULL, 1);
1167 * <W>ho knows room...
1169 void whoknows(CtdlIPC *ipc)
1172 char *listing = NULL;
1175 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1177 scr_printf("%s\n", buf);
1180 while (!IsEmptyStr(listing)) {
1181 extract_token(buf, listing, 0, '\n', sizeof buf);
1182 remove_token(listing, 0, '\n');
1184 scr_printf("%s\n", buf);
1190 void do_edit(CtdlIPC *ipc,
1191 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1195 int b, cksum, editor_exit;
1197 if (IsEmptyStr(editor_paths[0])) {
1198 scr_printf("Do you wish to re-enter %s? ", desc);
1203 fp = fopen(temp, "w");
1206 CtdlIPC_chat_send(ipc, check_cmd);
1207 CtdlIPC_chat_recv(ipc, cmd);
1208 if (cmd[0] != '2') {
1209 scr_printf("%s\n", &cmd[4]);
1213 if (!IsEmptyStr(editor_paths[0])) {
1214 CtdlIPC_chat_send(ipc, read_cmd);
1215 CtdlIPC_chat_recv(ipc, cmd);
1216 if (cmd[0] == '1') {
1217 fp = fopen(temp, "w");
1218 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1219 fprintf(fp, "%s\n", cmd);
1225 cksum = file_checksum(temp);
1227 if (!IsEmptyStr(editor_paths[0])) {
1230 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1232 stty_ctdl(SB_RESTORE);
1233 editor_pid = fork();
1234 if (editor_pid == 0) {
1236 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1242 b = ka_wait(&editor_exit);
1243 } while ((b != editor_pid) && (b >= 0));
1245 scr_printf("Executed %s\n", editor_paths[0]);
1248 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1249 fp = fopen(temp, "r+");
1254 if (file_checksum(temp) == cksum) {
1255 scr_printf("*** Aborted.\n");
1259 CtdlIPC_chat_send(ipc, write_cmd);
1260 CtdlIPC_chat_recv(ipc, cmd);
1261 if (cmd[0] != '4') {
1262 scr_printf("%s\n", &cmd[4]);
1266 fp = fopen(temp, "r");
1267 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1268 cmd[strlen(cmd) - 1] = 0;
1269 CtdlIPC_chat_send(ipc, cmd);
1272 CtdlIPC_chat_send(ipc, "000");
1279 void enterinfo(CtdlIPC *ipc)
1280 { /* edit info file for current room */
1281 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1284 void enter_bio(CtdlIPC *ipc)
1287 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1288 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1292 * create a new floor
1294 void create_floor(CtdlIPC *ipc)
1297 char newfloorname[SIZ];
1298 int r; /* IPC response code */
1300 load_floorlist(ipc);
1302 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1303 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1304 scr_printf("%s\n", buf);
1308 newprompt("Name for new floor: ", newfloorname, 255);
1309 if (!*newfloorname) return;
1310 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1312 scr_printf("Floor has been created.\n");
1314 scr_printf("%s\n", buf);
1317 load_floorlist(ipc);
1321 * edit the current floor
1323 void edit_floor(CtdlIPC *ipc)
1326 struct ExpirePolicy *ep = NULL;
1327 int r; /* IPC response code */
1329 load_floorlist(ipc);
1331 /* Fetch the expire policy (this will silently fail on old servers,
1332 * resulting in "default" policy)
1334 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1336 /* Interact with the user */
1337 scr_printf("You are editing the floor called \"%s\"\n",
1338 &floorlist[(int) curr_floor][0] );
1339 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1341 /* Angels and demons dancing in my head... */
1343 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1345 ("Floor default message expire policy (? for list)",
1347 if (buf[0] == '?') {
1349 "0. Use the system default\n"
1350 "1. Never automatically expire messages\n"
1351 "2. Expire by message count\n"
1352 "3. Expire by message age\n");
1354 } while ((buf[0] < '0') || (buf[0] > '3'));
1355 ep->expire_mode = buf[0] - '0';
1357 /* ...lunatics and monsters underneath my bed */
1358 if (ep->expire_mode == 2) {
1359 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1360 strprompt("Keep how many messages online?", buf, 10);
1361 ep->expire_value = atol(buf);
1364 if (ep->expire_mode == 3) {
1365 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1366 strprompt("Keep messages for how many days?", buf, 10);
1367 ep->expire_value = atol(buf);
1371 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1372 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1373 scr_printf("%s\n", buf);
1374 load_floorlist(ipc);
1381 * kill the current floor
1383 void kill_floor(CtdlIPC *ipc)
1385 int floornum_to_delete, a;
1388 load_floorlist(ipc);
1390 floornum_to_delete = (-1);
1391 scr_printf("(Press return to abort)\n");
1392 newprompt("Delete which floor? ", buf, 255);
1393 if (IsEmptyStr(buf))
1395 for (a = 0; a < 128; ++a)
1396 if (!strcasecmp(&floorlist[a][0], buf))
1397 floornum_to_delete = a;
1398 if (floornum_to_delete < 0) {
1399 scr_printf("No such floor. Select one of:\n");
1400 for (a = 0; a < 128; ++a)
1401 if (floorlist[a][0] != 0)
1402 scr_printf("%s\n", &floorlist[a][0]);
1404 } while (floornum_to_delete < 0);
1405 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1406 scr_printf("%s\n", buf);
1407 load_floorlist(ipc);