5 * Client-side functions which perform room operations
17 #include <sys/types.h>
23 #include "citadel_ipc.h"
24 #include "citadel_decls.h"
33 #include "citadel_dirs.h"
35 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
38 void stty_ctdl(int cmd);
39 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
40 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
41 int pattern(char *search, char *patn);
42 int file_checksum(char *filename);
43 int nukedir(char *dirname);
45 extern unsigned room_flags;
46 extern char room_name[];
48 extern char tempdir[];
49 extern int editor_pid;
50 extern int screenwidth;
51 extern int screenheight;
52 extern char fullname[];
53 extern char sigcaught;
54 extern char floor_mode;
55 extern char curr_floor;
60 extern char *uglist[];
61 extern long uglistlsn[];
62 extern int uglistsize;
64 extern char floorlist[128][SIZ];
67 void load_floorlist(CtdlIPC *ipc)
72 int r; /* IPC response code */
74 for (a = 0; a < 128; ++a)
77 r = CtdlIPCFloorListing(ipc, &listing, buf);
79 strcpy(floorlist[0], "Main Floor");
82 while (*listing && strlen(listing)) {
83 extract_token(buf, listing, 0, '\n', sizeof buf);
84 remove_token(listing, 0, '\n');
85 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
91 void room_tree_list(struct ctdlroomlisting *rp)
94 char rmname[ROOMNAMELEN];
102 if (rp->lnext != NULL) {
103 room_tree_list(rp->lnext);
106 if (sigcaught == 0) {
107 strcpy(rmname, rp->rlname);
109 if ((c + strlen(rmname) + 4) > screenwidth) {
111 /* line break, check the paginator */
115 if (f & QR_MAILBOX) {
116 color(BRIGHT_YELLOW);
117 } else if (f & QR_PRIVATE) {
122 pprintf("%s", rmname);
123 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
125 else if (f & QR_DIRECTORY)
127 else if (f & QR_NETWORK)
131 c = c + strlen(rmname) + 3;
134 if (rp->rnext != NULL) {
135 room_tree_list(rp->rnext);
143 * Room ordering stuff (compare first by floor, then by order)
145 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
147 if ((r1 == NULL) && (r2 == NULL))
153 if (r1->rlfloor < r2->rlfloor)
155 if (r1->rlfloor > r2->rlfloor)
157 if (r1->rlorder < r2->rlorder)
159 if (r1->rlorder > r2->rlorder)
166 * Common code for all room listings
168 static void listrms(struct march *listing, int new_only, int floor_only)
171 struct ctdlroomlisting *rl = NULL;
172 struct ctdlroomlisting *rp;
173 struct ctdlroomlisting *rs;
176 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
179 if ( (new_only == LISTRMS_NEW_ONLY)
180 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
183 if ( (new_only == LISTRMS_OLD_ONLY)
184 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
187 if ( (floor_only >= 0)
188 && (mptr->march_floor != floor_only))
192 rp = malloc(sizeof(struct ctdlroomlisting));
193 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
194 rp->rlflags = mptr->march_flags;
195 rp->rlfloor = mptr->march_floor;
196 rp->rlorder = mptr->march_order;
205 if (rordercmp(rp, rs) < 0) {
206 if (rs->lnext == NULL) {
213 if (rs->rnext == NULL) {
225 room_tree_list(NULL);
231 void list_other_floors(void)
236 for (a = 0; a < 128; ++a) {
237 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
238 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
242 pprintf("%s: ", floorlist[a]);
243 c = c + strlen(floorlist[a]) + 3;
250 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
251 * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
253 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
256 struct march *listing = NULL;
258 int r; /* IPC response code */
262 /* Ask the server for a room list */
263 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
271 if (kn_floor_mode == 0) {
273 pprintf("\n Rooms with unread messages:\n");
274 listrms(listing, LISTRMS_NEW_ONLY, -1);
276 pprintf("\n\n No unseen messages in:\n");
277 listrms(listing, LISTRMS_OLD_ONLY, -1);
281 if (kn_floor_mode == 1) {
283 pprintf("\n Rooms with unread messages on %s:\n",
284 floorlist[(int) curr_floor]);
285 listrms(listing, LISTRMS_NEW_ONLY, curr_floor);
287 pprintf("\n\n Rooms with no new messages on %s:\n",
288 floorlist[(int) curr_floor]);
289 listrms(listing, LISTRMS_OLD_ONLY, curr_floor);
291 pprintf("\n\n Other floors:\n");
296 if (kn_floor_mode == 2) {
297 for (a = 0; a < 128; ++a) {
298 if (floorlist[a][0] != 0) {
300 pprintf("\n Rooms on %s:\n",
302 listrms(listing, LISTRMS_ALL, a);
308 /* Free the room list */
310 mptr = listing->next;
316 IFNEXPERT hit_any_key(ipc);
320 void listzrooms(CtdlIPC *ipc)
321 { /* list public forgotten rooms */
322 struct march *listing = NULL;
324 int r; /* IPC response code */
328 /* Ask the server for a room list */
329 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, 1, &listing, buf);
335 pprintf("\n Forgotten public rooms:\n");
336 listrms(listing, LISTRMS_ALL, -1);
339 /* Free the room list */
341 mptr = listing->next;
347 IFNEXPERT hit_any_key(ipc);
351 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
355 a = boolprompt(prompt, (ibuf & sbit));
356 ibuf = (ibuf | sbit);
358 ibuf = (ibuf ^ sbit);
366 * Select a floor (used in several commands)
367 * The supplied argument is the 'default' floor number.
368 * This function returns the selected floor number.
370 int select_floor(CtdlIPC *ipc, int rfloor)
375 if (floor_mode == 1) {
376 if (floorlist[(int) curr_floor][0] == 0) {
382 safestrncpy(floorstr, floorlist[rfloor],
384 strprompt("Which floor", floorstr, 255);
385 for (a = 0; a < 128; ++a) {
387 (floorstr, &floorlist[a][0]))
392 (floorstr, &floorlist[a][0],
396 && (pattern(&floorlist[a][0], floorstr)
401 scr_printf("\n One of:\n");
402 for (a = 0; a < 128; ++a) {
403 if (floorlist[a][0] != 0) {
409 } while (newfloor < 0);
414 scr_printf("Floor selection bypassed because you have "
415 "floor mode disabled.\n");
425 * .<A>ide <E>dit room
427 void editthisroom(CtdlIPC *ipc)
430 char raide[USERNAME_SIZE];
432 struct ctdlroom *attr = NULL;
433 struct ExpirePolicy *eptr = NULL;
434 int r; /* IPC response code */
436 /* Fetch the existing room config */
437 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
439 scr_printf("%s\n", buf);
442 eptr = &(attr->QRep);
444 /* Fetch the name of the current room aide */
445 r = CtdlIPCGetRoomAide(ipc, buf);
447 safestrncpy(raide, buf, sizeof raide);
451 if (strlen(raide) == 0) {
452 strcpy(raide, "none");
455 /* Fetch the expire policy (this will silently fail on old servers,
456 * resulting in "default" policy)
458 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
460 /* Now interact with the user. */
462 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
463 attr->QRfloor = select_floor(ipc, attr->QRfloor);
464 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
465 if (attr->QRflags & QR_PRIVATE) {
466 attr->QRflags = set_room_attr(ipc, attr->QRflags,
467 "Accessible by guessing room name",
471 /* if it's public, clear the privacy classes */
472 if ((attr->QRflags & QR_PRIVATE) == 0) {
473 if (attr->QRflags & QR_GUESSNAME) {
474 attr->QRflags = attr->QRflags - QR_GUESSNAME;
476 if (attr->QRflags & QR_PASSWORDED) {
477 attr->QRflags = attr->QRflags - QR_PASSWORDED;
481 /* if it's private, choose the privacy classes */
482 if ((attr->QRflags & QR_PRIVATE)
483 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
484 attr->QRflags = set_room_attr(ipc, attr->QRflags,
485 "Accessible by entering a password",
488 if ((attr->QRflags & QR_PRIVATE)
489 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
490 strprompt("Room password", attr->QRpasswd, 9);
493 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
494 rbump = boolprompt("Cause current users to forget room", 0);
497 attr->QRflags = set_room_attr(ipc, attr->QRflags,
498 "Preferred users only", QR_PREFONLY);
499 attr->QRflags = set_room_attr(ipc, attr->QRflags,
500 "Read-only room", QR_READONLY);
501 attr->QRflags = set_room_attr(ipc, attr->QRflags,
502 "Directory room", QR_DIRECTORY);
503 attr->QRflags = set_room_attr(ipc, attr->QRflags,
504 "Permanent room", QR_PERMANENT);
505 if (attr->QRflags & QR_DIRECTORY) {
506 strprompt("Directory name", attr->QRdirname, 14);
508 set_room_attr(ipc, attr->QRflags,
509 "Uploading allowed", QR_UPLOAD);
511 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
514 set_room_attr(ipc, attr->QRflags,
515 "Visible directory", QR_VISDIR);
517 attr->QRflags = set_room_attr(ipc, attr->QRflags,
518 "Network shared room", QR_NETWORK);
519 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
520 "Self-service list subscribe/unsubscribe",
522 attr->QRflags = set_room_attr(ipc, attr->QRflags,
523 "Automatically make all messages anonymous",
525 if ((attr->QRflags & QR_ANONONLY) == 0) {
526 attr->QRflags = set_room_attr(ipc, attr->QRflags,
527 "Ask users whether to make messages anonymous",
530 attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
532 /* Ask about the room aide */
534 strprompt("Room aide (or 'none')", raide, 29);
535 if (!strcasecmp(raide, "none")) {
539 r = CtdlIPCQueryUsername(ipc, raide, buf);
541 scr_printf("%s\n", buf);
543 } while (r / 100 != 2);
545 /* FIXME: Duplicate code??? */
546 if (!strcasecmp(raide, "none")) {
550 /* Angels and demons dancing in my head... */
552 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
553 strprompt("Message expire policy (? for list)", buf, 1);
556 "0. Use the default for this floor\n"
557 "1. Never automatically expire messages\n"
558 "2. Expire by message count\n"
559 "3. Expire by message age\n");
561 } while ((buf[0] < 48) || (buf[0] > 51));
562 attr->QRep.expire_mode = buf[0] - 48;
564 /* ...lunatics and monsters underneath my bed */
565 if (attr->QRep.expire_mode == 2) {
566 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
567 strprompt("Keep how many messages online?", buf, 10);
568 attr->QRep.expire_value = atol(buf);
571 if (attr->QRep.expire_mode == 3) {
572 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
573 strprompt("Keep messages for how many days?", buf, 10);
574 attr->QRep.expire_value = atol(buf);
577 /* Give 'em a chance to change their minds */
578 scr_printf("Save changes (y/n)? ");
581 r = CtdlIPCSetRoomAide(ipc, raide, buf);
583 scr_printf("%s\n", buf);
586 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
588 scr_printf("%s\n", buf);
591 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
592 scr_printf("%s\n", buf);
593 strncpy(buf, attr->QRname, ROOMNAMELEN);
596 dotgoto(ipc, buf, 2, 0);
603 * un-goto the previous room, or a specified room
605 void dotungoto(CtdlIPC *ipc, char *towhere)
607 /* Find this 'towhere' room in the list ungoto from this room to
608 that at the messagepointer position in that room in our ungoto list.
609 I suppose I could be a real dick and just ungoto that many places
614 struct ctdlipcroom *rret = NULL; /* ignored */
619 scr_printf("No rooms to ungoto.\n");
624 scr_printf("Must specify a room to ungoto.\n");
627 if (strlen(towhere) == 0)
629 scr_printf("Must specify a room to ungoto.\n");
632 for (lp = uglistsize-1; lp >= 0; lp--)
634 if (strcasecmp(towhere, uglist[lp]) == 0)
642 scr_printf("Room: %s not in ungoto list.\n", towhere);
646 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
647 if (rret) free(rret); /* ignored */
649 scr_printf("%s\n", buf);
652 r = CtdlIPCSetLastRead(ipc, uglistlsn[found], buf);
654 scr_printf("%s\n", buf);
656 safestrncpy(buf, uglist[found], sizeof(buf));
657 /* we queue ungoto information here, because we're not really
658 ungotoing, we're really going to a random spot in some arbitrary
660 dotgoto(ipc, buf, 0, 0);
663 void ungoto(CtdlIPC *ipc)
666 struct ctdlipcroom *rret = NULL; /* ignored */
672 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
673 if (rret) free(rret); /* ignored */
675 scr_printf("%s\n", buf);
678 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
680 scr_printf("%s\n", buf);
682 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
684 free(uglist[uglistsize]);
685 /* Don't queue ungoto info or we end up in a loop */
686 dotgoto(ipc, buf, 0, 1);
691 * saves filelen bytes from file at pathname
693 int save_buffer(void *file, size_t filelen, const char *pathname)
696 size_t bytes_written = 0;
699 fp = fopen(pathname, "w");
701 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
705 block = fwrite((char *)file + bytes_written, 1,
706 filelen - bytes_written, fp);
707 bytes_written += block;
708 } while (errno == EINTR && bytes_written < filelen);
711 if (bytes_written < filelen) {
712 err_printf("Trouble saving '%s': %s\n", pathname,
721 * Save supplied_filename in dest directory; gets the name only
723 void destination_directory(char *dest, const char *supplied_filename)
725 static char save_dir[SIZ] = { 0 };
727 if (strlen(save_dir) == 0) {
728 if (getenv("HOME") == NULL) {
729 strcpy(save_dir, ".");
732 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
733 if (access(save_dir, W_OK) != 0) {
734 sprintf(save_dir, "%s", getenv("HOME"));
735 if (access(save_dir, W_OK) != 0) {
736 sprintf(save_dir, ".");
742 sprintf(dest, "%s/%s", save_dir, supplied_filename);
743 strprompt("Save as", dest, PATH_MAX);
745 /* Remember the directory for next time */
746 strcpy(save_dir, dest);
747 if (strrchr(save_dir, '/') != NULL) {
748 strcpy(strrchr(save_dir, '/'), "");
751 strcpy(save_dir, ".");
757 * download() - download a file or files. The argument passed to this
758 * function determines which protocol to use.
759 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
761 void download(CtdlIPC *ipc, int proto)
764 char filename[PATH_MAX];
765 char tempname[PATH_MAX];
766 char transmit_cmd[SIZ];
770 void *file = NULL; /* The downloaded file */
771 size_t filelen = 0L; /* The downloaded file length */
773 if ((room_flags & QR_DOWNLOAD) == 0) {
774 scr_printf("*** You cannot download from this room.\n");
778 newprompt("Enter filename: ", filename, PATH_MAX);
780 /* Save to local disk, for folks with their own copy of the client */
782 destination_directory(tempname, filename);
783 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
785 scr_printf("%s\n", buf);
788 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
793 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
795 scr_printf("%s\n", buf);
798 filelen = extract_unsigned_long(buf, 0);
800 /* Meta-download for public clients */
801 /* scr_printf("Fetching file from Citadel server...\n"); */
802 mkdir(tempdir, 0700);
803 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
804 tpipe = fopen(tempname, "wb");
805 if (fwrite(file, filelen, 1, tpipe) < filelen) {
806 /* FIXME: restart syscall on EINTR */
810 if (file) free(file);
813 /* FIXME: display internally instead */
814 snprintf(transmit_cmd, sizeof transmit_cmd,
815 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
819 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
821 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
823 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
825 /* FIXME: display internally instead */
826 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
829 stty_ctdl(SB_RESTORE);
830 system(transmit_cmd);
831 stty_ctdl(SB_NO_INTR);
834 /* clean up the temporary directory */
836 ctdl_beep(); /* Beep beep! */
841 * read directory of this room
843 void roomdir(CtdlIPC *ipc)
849 char *listing = NULL; /* Returned directory listing */
852 r = CtdlIPCReadDirectory(ipc, &listing, buf);
854 pprintf("%s\n", buf);
858 extract_token(comment, buf, 0, '|', sizeof comment);
859 extract_token(flnm, buf, 1, '|', sizeof flnm);
860 pprintf("\nDirectory of %s on %s\n", flnm, comment);
861 pprintf("-----------------------\n");
862 while (*listing && strlen(listing)) {
863 extract_token(buf, listing, 0, '\n', sizeof buf);
864 remove_token(listing, 0, '\n');
866 extract_token(flnm, buf, 0, '|', sizeof flnm);
867 extract_token(flsz, buf, 1, '|', sizeof flsz);
868 extract_token(comment, buf, 2, '|', sizeof comment);
869 if (strlen(flnm) <= 14)
870 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
872 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
879 * add a user to a private room
881 void invite(CtdlIPC *ipc)
883 char username[USERNAME_SIZE];
885 int r; /* IPC response code */
887 newprompt("Name of user? ", username, USERNAME_SIZE);
888 if (username[0] == 0)
891 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
892 scr_printf("%s\n", buf);
897 * kick a user out of a room
899 void kickout(CtdlIPC *ipc)
901 char username[USERNAME_SIZE];
903 int r; /* IPC response code */
905 newprompt("Name of user? ", username, USERNAME_SIZE);
906 if (username[0] == 0)
909 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
910 scr_printf("%s\n", buf);
915 * aide command: kill the current room
917 void killroom(CtdlIPC *ipc)
922 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
924 scr_printf("%s\n", aaa);
928 scr_printf("Are you sure you want to kill this room? ");
932 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
933 scr_printf("%s\n", aaa);
936 dotgoto(ipc, "_BASEROOM_", 0, 0);
939 void forget(CtdlIPC *ipc)
940 { /* forget the current room */
943 scr_printf("Are you sure you want to forget this room? ");
947 remove_march(room_name, 0);
948 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
949 scr_printf("%s\n", buf);
953 /* now return to the lobby */
954 dotgoto(ipc, "_BASEROOM_", 0, 0);
961 void entroom(CtdlIPC *ipc)
964 char new_room_name[ROOMNAMELEN];
966 char new_room_pass[10];
969 int r; /* IPC response code */
971 /* Check permission to create room */
972 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
974 scr_printf("%s\n", buf);
978 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
979 if (strlen(new_room_name) == 0) {
982 for (a = 0; a < strlen(new_room_name); ++a) {
983 if (new_room_name[a] == '|') {
984 new_room_name[a] = '_';
988 new_room_floor = select_floor(ipc, (int) curr_floor);
990 IFNEXPERT formout(ipc, "roomaccess");
992 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
993 "<3>Passworded room\n<4>Invitation-only room\n"
995 "Enter room type: ");
998 } while (((b < '1') || (b > '5')) && (b != '?'));
1001 formout(ipc, "roomaccess");
1003 } while ((b < '1') || (b > '5'));
1004 b -= '0'; /* Portable */
1005 scr_printf("%d\n", b);
1006 new_room_type = b - 1;
1007 if (new_room_type == 2) {
1008 newprompt("Enter a room password: ", new_room_pass, 9);
1009 for (a = 0; a < strlen(new_room_pass); ++a)
1010 if (new_room_pass[a] == '|')
1011 new_room_pass[a] = '_';
1013 strcpy(new_room_pass, "");
1016 scr_printf("\042%s\042, a", new_room_name);
1018 scr_printf(" public room.");
1020 scr_printf(" guess-name room.");
1022 scr_printf(" passworded room, password: %s", new_room_pass);
1024 scr_printf("n invitation-only room.");
1026 scr_printf(" personal room.");
1027 scr_printf("\nInstall it? (y/n) : ");
1032 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1033 new_room_pass, new_room_floor, buf);
1035 scr_printf("%s\n", buf);
1039 /* command succeeded... now GO to the new room! */
1040 dotgoto(ipc, new_room_name, 0, 0);
1045 void readinfo(CtdlIPC *ipc)
1046 { /* read info file for current room */
1049 int r; /* IPC response code */
1052 /* Name of currernt room aide */
1053 r = CtdlIPCGetRoomAide(ipc, buf);
1055 safestrncpy(raide, buf, sizeof raide);
1059 if (strlen(raide) > 0)
1060 scr_printf("Room aide is %s.\n\n", raide);
1062 r = CtdlIPCRoomInfo(ipc, &text, buf);
1067 fmout(screenwidth, NULL, text, NULL,
1068 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1069 (*raide) ? 2 : 0, 1);
1076 * <W>ho knows room...
1078 void whoknows(CtdlIPC *ipc)
1081 char *listing = NULL;
1084 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1086 pprintf("%s\n", buf);
1089 while (strlen(listing) > 0) {
1090 extract_token(buf, listing, 0, '\n', sizeof buf);
1091 remove_token(listing, 0, '\n');
1093 pprintf("%s\n", buf);
1099 void do_edit(CtdlIPC *ipc,
1100 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1104 int b, cksum, editor_exit;
1106 if (strlen(editor_paths[0]) == 0) {
1107 scr_printf("Do you wish to re-enter %s? ", desc);
1112 fp = fopen(temp, "w");
1115 CtdlIPC_chat_send(ipc, check_cmd);
1116 CtdlIPC_chat_recv(ipc, cmd);
1117 if (cmd[0] != '2') {
1118 scr_printf("%s\n", &cmd[4]);
1122 if (strlen(editor_paths[0]) > 0) {
1123 CtdlIPC_chat_send(ipc, read_cmd);
1124 CtdlIPC_chat_recv(ipc, cmd);
1125 if (cmd[0] == '1') {
1126 fp = fopen(temp, "w");
1127 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1128 fprintf(fp, "%s\n", cmd);
1134 cksum = file_checksum(temp);
1136 if (strlen(editor_paths[0]) > 0) {
1139 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1142 stty_ctdl(SB_RESTORE);
1143 editor_pid = fork();
1144 if (editor_pid == 0) {
1146 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1152 b = ka_wait(&editor_exit);
1153 } while ((b != editor_pid) && (b >= 0));
1155 scr_printf("Executed %s\n", editor_paths[0]);
1159 scr_printf("Entering %s. "
1160 "Press return twice when finished.\n", desc);
1161 fp = fopen(temp, "r+");
1166 if (file_checksum(temp) == cksum) {
1167 scr_printf("*** Aborted.\n");
1171 CtdlIPC_chat_send(ipc, write_cmd);
1172 CtdlIPC_chat_recv(ipc, cmd);
1173 if (cmd[0] != '4') {
1174 scr_printf("%s\n", &cmd[4]);
1178 fp = fopen(temp, "r");
1179 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1180 cmd[strlen(cmd) - 1] = 0;
1181 CtdlIPC_chat_send(ipc, cmd);
1184 CtdlIPC_chat_send(ipc, "000");
1191 void enterinfo(CtdlIPC *ipc)
1192 { /* edit info file for current room */
1193 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1196 void enter_bio(CtdlIPC *ipc)
1199 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1200 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1204 * create a new floor
1206 void create_floor(CtdlIPC *ipc)
1209 char newfloorname[SIZ];
1210 int r; /* IPC response code */
1212 load_floorlist(ipc);
1214 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1215 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1216 scr_printf("%s\n", buf);
1220 newprompt("Name for new floor: ", newfloorname, 255);
1221 if (!*newfloorname) return;
1222 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1224 scr_printf("Floor has been created.\n");
1226 scr_printf("%s\n", buf);
1229 load_floorlist(ipc);
1233 * edit the current floor
1235 void edit_floor(CtdlIPC *ipc)
1238 struct ExpirePolicy *ep = NULL;
1239 int r; /* IPC response code */
1241 load_floorlist(ipc);
1243 /* Fetch the expire policy (this will silently fail on old servers,
1244 * resulting in "default" policy)
1246 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1248 /* Interact with the user */
1249 scr_printf("You are editing the floor called \"%s\"\n",
1250 &floorlist[(int) curr_floor][0] );
1251 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1253 /* Angels and demons dancing in my head... */
1255 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1257 ("Floor default message expire policy (? for list)",
1259 if (buf[0] == '?') {
1261 "0. Use the system default\n"
1262 "1. Never automatically expire messages\n"
1263 "2. Expire by message count\n"
1264 "3. Expire by message age\n");
1266 } while ((buf[0] < '0') || (buf[0] > '3'));
1267 ep->expire_mode = buf[0] - '0';
1269 /* ...lunatics and monsters underneath my bed */
1270 if (ep->expire_mode == 2) {
1271 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1272 strprompt("Keep how many messages online?", buf, 10);
1273 ep->expire_value = atol(buf);
1276 if (ep->expire_mode == 3) {
1277 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1278 strprompt("Keep messages for how many days?", buf, 10);
1279 ep->expire_value = atol(buf);
1283 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1284 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1285 scr_printf("%s\n", buf);
1286 load_floorlist(ipc);
1293 * kill the current floor
1295 void kill_floor(CtdlIPC *ipc)
1297 int floornum_to_delete, a;
1300 load_floorlist(ipc);
1302 floornum_to_delete = (-1);
1303 scr_printf("(Press return to abort)\n");
1304 newprompt("Delete which floor? ", buf, 255);
1305 if (strlen(buf) == 0)
1307 for (a = 0; a < 128; ++a)
1308 if (!strcasecmp(&floorlist[a][0], buf))
1309 floornum_to_delete = a;
1310 if (floornum_to_delete < 0) {
1311 scr_printf("No such floor. Select one of:\n");
1312 for (a = 0; a < 128; ++a)
1313 if (floorlist[a][0] != 0)
1314 scr_printf("%s\n", &floorlist[a][0]);
1316 } while (floornum_to_delete < 0);
1317 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1318 scr_printf("%s\n", buf);
1319 load_floorlist(ipc);