5 * Client-side functions which perform room operations
17 #include <sys/types.h>
23 #include "citadel_ipc.h"
24 #include "citadel_decls.h"
34 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
37 void sttybbs(int cmd);
38 void hit_any_key(void);
39 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
40 void progress(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');
84 remove_token(listing, 0, '\n');
85 extract(floorlist[extract_int(buf, 0)], buf, 1);
91 void room_tree_list(struct roomlisting *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 roomlisting *r1, struct roomlisting *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 roomlisting *rl = NULL;
172 struct roomlisting *rp;
173 struct roomlisting *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 roomlisting));
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();
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();
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 room *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(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 scr_printf("Enter the name of the directory to save '%s'\n"
726 "to, or press return for the current directory.\n",
728 newprompt("Directory: ", dest, PATH_MAX);
729 if (strlen(dest) == 0) {
734 strcat(dest, supplied_filename);
739 * download() - download a file or files. The argument passed to this
740 * function determines which protocol to use.
741 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
743 void download(CtdlIPC *ipc, int proto)
746 char filename[PATH_MAX];
747 char tempname[PATH_MAX];
748 char transmit_cmd[SIZ];
752 void *file = NULL; /* The downloaded file */
753 size_t filelen = 0L; /* The downloaded file length */
755 if ((room_flags & QR_DOWNLOAD) == 0) {
756 scr_printf("*** You cannot download from this room.\n");
760 newprompt("Enter filename: ", filename, PATH_MAX);
762 /* Save to local disk, for folks with their own copy of the client */
764 destination_directory(tempname, filename);
765 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
767 scr_printf("%s\n", buf);
770 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
775 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
777 scr_printf("%s\n", buf);
780 filelen = extract_unsigned_long(buf, 0);
782 /* Meta-download for public clients */
783 /* scr_printf("Fetching file from Citadel server...\n"); */
784 mkdir(tempdir, 0700);
785 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
786 tpipe = fopen(tempname, "wb");
787 if (fwrite(file, filelen, 1, tpipe) < filelen) {
788 /* FIXME: restart syscall on EINTR */
792 if (file) free(file);
795 /* FIXME: display internally instead */
796 snprintf(transmit_cmd, sizeof transmit_cmd,
797 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
801 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
803 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
805 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
807 /* FIXME: display internally instead */
808 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
812 system(transmit_cmd);
816 /* clean up the temporary directory */
818 ctdl_beep(); /* Beep beep! */
823 * read directory of this room
825 void roomdir(CtdlIPC *ipc)
832 CtdlIPC_putline(ipc, "RDIR");
833 CtdlIPC_getline(ipc, buf);
835 pprintf("%s\n", &buf[4]);
839 extract(comment, &buf[4], 0);
840 extract(flnm, &buf[4], 1);
841 pprintf("\nDirectory of %s on %s\n", flnm, comment);
842 pprintf("-----------------------\n");
843 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
844 extract(flnm, buf, 0);
845 extract(flsz, buf, 1);
846 extract(comment, buf, 2);
847 if (strlen(flnm) <= 14)
848 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
850 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
857 * add a user to a private room
859 void invite(CtdlIPC *ipc)
861 char username[USERNAME_SIZE];
863 int r; /* IPC response code */
865 newprompt("Name of user? ", username, USERNAME_SIZE);
866 if (username[0] == 0)
869 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
870 scr_printf("%s\n", buf);
875 * kick a user out of a room
877 void kickout(CtdlIPC *ipc)
879 char username[USERNAME_SIZE];
881 int r; /* IPC response code */
883 newprompt("Name of user? ", username, USERNAME_SIZE);
884 if (username[0] == 0)
887 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
888 scr_printf("%s\n", buf);
893 * aide command: kill the current room
895 void killroom(CtdlIPC *ipc)
900 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
902 scr_printf("%s\n", aaa);
906 scr_printf("Are you sure you want to kill this room? ");
910 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
911 scr_printf("%s\n", aaa);
914 dotgoto(ipc, "_BASEROOM_", 0, 0);
917 void forget(CtdlIPC *ipc)
918 { /* forget the current room */
921 scr_printf("Are you sure you want to forget this room? ");
925 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
926 scr_printf("%s\n", buf);
930 /* now return to the lobby */
931 dotgoto(ipc, "_BASEROOM_", 0, 0);
938 void entroom(CtdlIPC *ipc)
941 char new_room_name[ROOMNAMELEN];
943 char new_room_pass[10];
946 int r; /* IPC response code */
948 /* Check permission to create room */
949 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
951 scr_printf("%s\n", buf);
955 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
956 if (strlen(new_room_name) == 0) {
959 for (a = 0; a < strlen(new_room_name); ++a) {
960 if (new_room_name[a] == '|') {
961 new_room_name[a] = '_';
965 new_room_floor = select_floor(ipc, (int) curr_floor);
967 IFNEXPERT formout(ipc, "roomaccess");
969 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
970 "<3>Passworded room\n<4>Invitation-only room\n"
972 "Enter room type: ");
975 } while (((b < '1') || (b > '5')) && (b != '?'));
978 formout(ipc, "roomaccess");
980 } while ((b < '1') || (b > '5'));
981 b -= '0'; /* Portable */
982 scr_printf("%d\n", b);
983 new_room_type = b - 1;
984 if (new_room_type == 2) {
985 newprompt("Enter a room password: ", new_room_pass, 9);
986 for (a = 0; a < strlen(new_room_pass); ++a)
987 if (new_room_pass[a] == '|')
988 new_room_pass[a] = '_';
990 strcpy(new_room_pass, "");
993 scr_printf("\042%s\042, a", new_room_name);
995 scr_printf(" public room.");
997 scr_printf(" guess-name room.");
999 scr_printf(" passworded room, password: %s", new_room_pass);
1001 scr_printf("n invitation-only room.");
1003 scr_printf(" personal room.");
1004 scr_printf("\nInstall it? (y/n) : ");
1009 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1010 new_room_pass, new_room_floor, buf);
1012 scr_printf("%s\n", buf);
1016 /* command succeeded... now GO to the new room! */
1017 dotgoto(ipc, new_room_name, 0, 0);
1022 void readinfo(CtdlIPC *ipc)
1023 { /* read info file for current room */
1026 int r; /* IPC response code */
1029 /* Name of currernt room aide */
1030 r = CtdlIPCGetRoomAide(ipc, buf);
1032 safestrncpy(raide, buf, sizeof raide);
1036 if (strlen(raide) > 0)
1037 scr_printf("Room aide is %s.\n\n", raide);
1039 r = CtdlIPCRoomInfo(ipc, &text, buf);
1044 fmout(screenwidth, NULL, text, NULL,
1045 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1046 (*raide) ? 2 : 0, 1);
1053 * <W>ho knows room...
1055 void whoknows(CtdlIPC *ipc)
1058 char *listing = NULL;
1061 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1063 pprintf("%s\n", buf);
1066 while (strlen(listing) > 0) {
1067 extract_token(buf, listing, 0, '\n');
1068 remove_token(listing, 0, '\n');
1070 pprintf("%s\n", buf);
1076 void do_edit(CtdlIPC *ipc,
1077 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1081 int b, cksum, editor_exit;
1083 if (strlen(editor_paths[0]) == 0) {
1084 scr_printf("Do you wish to re-enter %s? ", desc);
1089 fp = fopen(temp, "w");
1092 CtdlIPC_putline(ipc, check_cmd);
1093 CtdlIPC_getline(ipc, cmd);
1094 if (cmd[0] != '2') {
1095 scr_printf("%s\n", &cmd[4]);
1099 if (strlen(editor_paths[0]) > 0) {
1100 CtdlIPC_putline(ipc, read_cmd);
1101 CtdlIPC_getline(ipc, cmd);
1102 if (cmd[0] == '1') {
1103 fp = fopen(temp, "w");
1104 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1105 fprintf(fp, "%s\n", cmd);
1111 cksum = file_checksum(temp);
1113 if (strlen(editor_paths[0]) > 0) {
1116 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1119 sttybbs(SB_RESTORE);
1120 editor_pid = fork();
1121 if (editor_pid == 0) {
1123 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1129 b = ka_wait(&editor_exit);
1130 } while ((b != editor_pid) && (b >= 0));
1132 scr_printf("Executed %s\n", editor_paths[0]);
1136 scr_printf("Entering %s. "
1137 "Press return twice when finished.\n", desc);
1138 fp = fopen(temp, "r+");
1143 if (file_checksum(temp) == cksum) {
1144 scr_printf("*** Aborted.\n");
1148 CtdlIPC_putline(ipc, write_cmd);
1149 CtdlIPC_getline(ipc, cmd);
1150 if (cmd[0] != '4') {
1151 scr_printf("%s\n", &cmd[4]);
1155 fp = fopen(temp, "r");
1156 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1157 cmd[strlen(cmd) - 1] = 0;
1158 CtdlIPC_putline(ipc, cmd);
1161 CtdlIPC_putline(ipc, "000");
1168 void enterinfo(CtdlIPC *ipc)
1169 { /* edit info file for current room */
1170 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1173 void enter_bio(CtdlIPC *ipc)
1176 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1177 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1181 * create a new floor
1183 void create_floor(CtdlIPC *ipc)
1186 char newfloorname[SIZ];
1187 int r; /* IPC response code */
1189 load_floorlist(ipc);
1191 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1192 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1193 scr_printf("%s\n", buf);
1197 newprompt("Name for new floor: ", newfloorname, 255);
1198 if (!*newprompt) return;
1199 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1201 scr_printf("Floor has been created.\n");
1203 scr_printf("%s\n", buf);
1206 load_floorlist(ipc);
1210 * edit the current floor
1212 void edit_floor(CtdlIPC *ipc)
1215 struct ExpirePolicy *ep = NULL;
1216 int r; /* IPC response code */
1218 load_floorlist(ipc);
1220 /* Fetch the expire policy (this will silently fail on old servers,
1221 * resulting in "default" policy)
1223 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1225 /* Interact with the user */
1226 scr_printf("You are editing the floor called \"%s\"\n",
1227 &floorlist[(int) curr_floor][0] );
1228 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1230 /* Angels and demons dancing in my head... */
1232 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1234 ("Floor default message expire policy (? for list)",
1236 if (buf[0] == '?') {
1238 "0. Use the system default\n"
1239 "1. Never automatically expire messages\n"
1240 "2. Expire by message count\n"
1241 "3. Expire by message age\n");
1243 } while ((buf[0] < '0') || (buf[0] > '3'));
1244 ep->expire_mode = buf[0] - '0';
1246 /* ...lunatics and monsters underneath my bed */
1247 if (ep->expire_mode == 2) {
1248 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1249 strprompt("Keep how many messages online?", buf, 10);
1250 ep->expire_value = atol(buf);
1253 if (ep->expire_mode == 3) {
1254 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1255 strprompt("Keep messages for how many days?", buf, 10);
1256 ep->expire_value = atol(buf);
1260 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1261 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1262 scr_printf("%s\n", buf);
1263 load_floorlist(ipc);
1270 * kill the current floor
1272 void kill_floor(CtdlIPC *ipc)
1274 int floornum_to_delete, a;
1277 load_floorlist(ipc);
1279 floornum_to_delete = (-1);
1280 scr_printf("(Press return to abort)\n");
1281 newprompt("Delete which floor? ", buf, 255);
1282 if (strlen(buf) == 0)
1284 for (a = 0; a < 128; ++a)
1285 if (!strcasecmp(&floorlist[a][0], buf))
1286 floornum_to_delete = a;
1287 if (floornum_to_delete < 0) {
1288 scr_printf("No such floor. Select one of:\n");
1289 for (a = 0; a < 128; ++a)
1290 if (floorlist[a][0] != 0)
1291 scr_printf("%s\n", &floorlist[a][0]);
1293 } while (floornum_to_delete < 0);
1294 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1295 scr_printf("%s\n", buf);
1296 load_floorlist(ipc);