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(CtdlIPC *ipc, enum RoomList variety, int floor)
171 struct march *listing = NULL;
172 struct march *tmp = NULL;
173 struct roomlisting *rl = NULL;
174 struct roomlisting *rp;
175 struct roomlisting *rs;
176 int r; /* IPC response code */
178 /* Ask the server for a room list */
179 r = CtdlIPCKnownRooms(ipc, variety, floor, &listing, buf);
184 rp = malloc(sizeof(struct roomlisting));
185 strncpy(rp->rlname, listing->march_name, ROOMNAMELEN);
186 rp->rlflags = listing->march_flags;
187 rp->rlfloor = listing->march_floor;
188 rp->rlorder = listing->march_order;
201 if (rordercmp(rp, rs) < 0) {
202 if (rs->lnext == NULL) {
209 if (rs->rnext == NULL) {
220 room_tree_list(NULL);
226 void list_other_floors(void)
231 for (a = 0; a < 128; ++a) {
232 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
233 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
237 pprintf("%s: ", floorlist[a]);
238 c = c + strlen(floorlist[a]) + 3;
245 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
246 * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
248 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
254 if (kn_floor_mode == 0) {
256 pprintf("\n Rooms with unread messages:\n");
257 listrms(ipc, SubscribedRoomsWithNewMessages, -1);
259 pprintf("\n\n No unseen messages in:\n");
260 listrms(ipc, SubscribedRoomsWithNoNewMessages, -1);
264 if (kn_floor_mode == 1) {
266 pprintf("\n Rooms with unread messages on %s:\n",
267 floorlist[(int) curr_floor]);
268 listrms(ipc, SubscribedRoomsWithNewMessages, curr_floor);
270 pprintf("\n\n Rooms with no new messages on %s:\n",
271 floorlist[(int) curr_floor]);
272 listrms(ipc, SubscribedRoomsWithNoNewMessages, curr_floor);
274 pprintf("\n\n Other floors:\n");
279 if (kn_floor_mode == 2) {
280 for (a = 0; a < 128; ++a) {
281 if (floorlist[a][0] != 0) {
283 pprintf("\n Rooms on %s:\n",
285 listrms(ipc, AllAccessibleRooms, a);
292 IFNEXPERT hit_any_key();
296 void listzrooms(CtdlIPC *ipc)
297 { /* list public forgotten rooms */
299 pprintf("\n Forgotten public rooms:\n");
300 listrms(ipc, UnsubscribedRooms, -1);
303 IFNEXPERT hit_any_key();
307 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
311 a = boolprompt(prompt, (ibuf & sbit));
312 ibuf = (ibuf | sbit);
314 ibuf = (ibuf ^ sbit);
322 * Select a floor (used in several commands)
323 * The supplied argument is the 'default' floor number.
324 * This function returns the selected floor number.
326 int select_floor(CtdlIPC *ipc, int rfloor)
331 if (floor_mode == 1) {
332 if (floorlist[(int) curr_floor][0] == 0) {
338 safestrncpy(floorstr, floorlist[rfloor],
340 strprompt("Which floor", floorstr, 255);
341 for (a = 0; a < 128; ++a) {
343 (floorstr, &floorlist[a][0]))
348 (floorstr, &floorlist[a][0],
352 && (pattern(&floorlist[a][0], floorstr)
357 scr_printf("\n One of:\n");
358 for (a = 0; a < 128; ++a) {
359 if (floorlist[a][0] != 0) {
365 } while (newfloor < 0);
370 scr_printf("Floor selection bypassed because you have "
371 "floor mode disabled.\n");
381 * .<A>ide <E>dit room
383 void editthisroom(CtdlIPC *ipc)
386 char raide[USERNAME_SIZE];
388 struct quickroom *attr = NULL;
389 struct ExpirePolicy *eptr = NULL;
390 int r; /* IPC response code */
392 /* Fetch the existing room config */
393 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
395 scr_printf("%s\n", buf);
398 eptr = &(attr->QRep);
400 /* Fetch the name of the current room aide */
401 r = CtdlIPCGetRoomAide(ipc, buf);
403 safestrncpy(raide, buf, sizeof raide);
407 if (strlen(raide) == 0) {
408 strcpy(raide, "none");
411 /* Fetch the expire policy (this will silently fail on old servers,
412 * resulting in "default" policy)
414 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
416 /* Now interact with the user. */
418 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
419 attr->QRfloor = select_floor(ipc, attr->QRfloor);
420 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
421 if (attr->QRflags & QR_PRIVATE) {
422 attr->QRflags = set_room_attr(ipc, attr->QRflags,
423 "Accessible by guessing room name",
427 /* if it's public, clear the privacy classes */
428 if ((attr->QRflags & QR_PRIVATE) == 0) {
429 if (attr->QRflags & QR_GUESSNAME) {
430 attr->QRflags = attr->QRflags - QR_GUESSNAME;
432 if (attr->QRflags & QR_PASSWORDED) {
433 attr->QRflags = attr->QRflags - QR_PASSWORDED;
437 /* if it's private, choose the privacy classes */
438 if ((attr->QRflags & QR_PRIVATE)
439 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
440 attr->QRflags = set_room_attr(ipc, attr->QRflags,
441 "Accessible by entering a password",
444 if ((attr->QRflags & QR_PRIVATE)
445 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
446 strprompt("Room password", attr->QRpasswd, 9);
449 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
450 rbump = boolprompt("Cause current users to forget room", 0);
453 attr->QRflags = set_room_attr(ipc, attr->QRflags,
454 "Preferred users only", QR_PREFONLY);
455 attr->QRflags = set_room_attr(ipc, attr->QRflags,
456 "Read-only room", QR_READONLY);
457 attr->QRflags = set_room_attr(ipc, attr->QRflags,
458 "Directory room", QR_DIRECTORY);
459 attr->QRflags = set_room_attr(ipc, attr->QRflags,
460 "Permanent room", QR_PERMANENT);
461 if (attr->QRflags & QR_DIRECTORY) {
462 strprompt("Directory name", attr->QRdirname, 14);
464 set_room_attr(ipc, attr->QRflags,
465 "Uploading allowed", QR_UPLOAD);
467 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
470 set_room_attr(ipc, attr->QRflags,
471 "Visible directory", QR_VISDIR);
473 attr->QRflags = set_room_attr(ipc, attr->QRflags,
474 "Network shared room", QR_NETWORK);
475 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
476 "Self-service list subscribe/unsubscribe",
478 attr->QRflags = set_room_attr(ipc, attr->QRflags,
479 "Automatically make all messages anonymous",
481 if ((attr->QRflags & QR_ANONONLY) == 0) {
482 attr->QRflags = set_room_attr(ipc, attr->QRflags,
483 "Ask users whether to make messages anonymous",
486 attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
488 /* Ask about the room aide */
490 strprompt("Room aide (or 'none')", raide, 29);
491 if (!strcasecmp(raide, "none")) {
495 r = CtdlIPCQueryUsername(ipc, raide, buf);
497 scr_printf("%s\n", buf);
499 } while (r / 100 != 2);
501 /* FIXME: Duplicate code??? */
502 if (!strcasecmp(raide, "none")) {
506 /* Angels and demons dancing in my head... */
508 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
509 strprompt("Message expire policy (? for list)", buf, 1);
512 "0. Use the default for this floor\n"
513 "1. Never automatically expire messages\n"
514 "2. Expire by message count\n"
515 "3. Expire by message age\n");
517 } while ((buf[0] < 48) || (buf[0] > 51));
518 attr->QRep.expire_mode = buf[0] - 48;
520 /* ...lunatics and monsters underneath my bed */
521 if (attr->QRep.expire_mode == 2) {
522 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
523 strprompt("Keep how many messages online?", buf, 10);
524 attr->QRep.expire_value = atol(buf);
527 if (attr->QRep.expire_mode == 3) {
528 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
529 strprompt("Keep messages for how many days?", buf, 10);
530 attr->QRep.expire_value = atol(buf);
533 /* Give 'em a chance to change their minds */
534 scr_printf("Save changes (y/n)? ");
537 r = CtdlIPCSetRoomAide(ipc, raide, buf);
539 scr_printf("%s\n", buf);
542 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
544 scr_printf("%s\n", buf);
547 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
548 scr_printf("%s\n", buf);
549 strncpy(buf, attr->QRname, ROOMNAMELEN);
552 dotgoto(ipc, buf, 2, 0);
559 * un-goto the previous room, or a specified room
561 void dotungoto(CtdlIPC *ipc, char *towhere)
563 /* Find this 'towhere' room in the list ungoto from this room to
564 that at the messagepointer position in that room in our ungoto list.
565 I suppose I could be a real dick and just ungoto that many places
570 struct ctdlipcroom *rret = NULL; /* ignored */
575 scr_printf("No rooms to ungoto.\n");
580 scr_printf("Must specify a room to ungoto.\n");
583 if (strlen(towhere) == 0)
585 scr_printf("Must specify a room to ungoto.\n");
588 for (lp = uglistsize-1; lp >= 0; lp--)
590 if (strcasecmp(towhere, uglist[lp]) == 0)
598 scr_printf("Room: %s not in ungoto list.\n", towhere);
602 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
603 if (rret) free(rret); /* ignored */
605 scr_printf("%s\n", buf);
608 r = CtdlIPCSetLastRead(ipc, uglistlsn[found], buf);
610 scr_printf("%s\n", buf);
612 safestrncpy(buf, uglist[found], sizeof(buf));
613 /* we queue ungoto information here, because we're not really
614 ungotoing, we're really going to a random spot in some arbitrary
616 dotgoto(ipc, buf, 0, 0);
619 void ungoto(CtdlIPC *ipc)
622 struct ctdlipcroom *rret = NULL; /* ignored */
628 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
629 if (rret) free(rret); /* ignored */
631 scr_printf("%s\n", buf);
634 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
636 scr_printf("%s\n", buf);
638 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
640 free(uglist[uglistsize]);
641 /* Don't queue ungoto info or we end up in a loop */
642 dotgoto(ipc, buf, 0, 1);
647 * saves filelen bytes from file at pathname
649 int save_buffer(void *file, size_t filelen, const char *pathname)
652 size_t bytes_written = 0;
655 fp = fopen(pathname, "w");
657 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
661 block = fwrite(file + bytes_written, 1,
662 filelen - bytes_written, fp);
663 bytes_written += block;
664 } while (errno == EINTR && bytes_written < filelen);
667 if (bytes_written < filelen) {
668 err_printf("Trouble saving '%s': %s\n", pathname,
677 * Save supplied_filename in dest directory; gets the name only
679 void destination_directory(char *dest, const char *supplied_filename)
681 scr_printf("Enter the name of the directory to save '%s'\n"
682 "to, or press return for the current directory.\n",
684 newprompt("Directory: ", dest, PATH_MAX);
685 if (strlen(dest) == 0) {
690 strcat(dest, supplied_filename);
695 * download() - download a file or files. The argument passed to this
696 * function determines which protocol to use.
697 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
699 void download(CtdlIPC *ipc, int proto)
702 char filename[PATH_MAX];
703 char tempname[PATH_MAX];
704 char transmit_cmd[SIZ];
708 void *file = NULL; /* The downloaded file */
709 size_t filelen = 0L; /* The downloaded file length */
711 if ((room_flags & QR_DOWNLOAD) == 0) {
712 scr_printf("*** You cannot download from this room.\n");
716 newprompt("Enter filename: ", filename, PATH_MAX);
718 /* Save to local disk, for folks with their own copy of the client */
720 destination_directory(tempname, filename);
721 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
723 scr_printf("%s\n", buf);
726 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
731 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
733 scr_printf("%s\n", buf);
736 filelen = extract_unsigned_long(buf, 0);
738 /* Meta-download for public clients */
739 /* scr_printf("Fetching file from Citadel server...\n"); */
740 mkdir(tempdir, 0700);
741 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
742 tpipe = fopen(tempname, "wb");
743 if (fwrite(file, filelen, 1, tpipe) < filelen) {
744 /* FIXME: restart syscall on EINTR */
748 if (file) free(file);
751 /* FIXME: display internally instead */
752 snprintf(transmit_cmd, sizeof transmit_cmd,
753 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
757 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
759 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
761 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
763 /* FIXME: display internally instead */
764 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
768 system(transmit_cmd);
772 /* clean up the temporary directory */
774 ctdl_beep(); /* Beep beep! */
779 * read directory of this room
781 void roomdir(CtdlIPC *ipc)
788 CtdlIPC_putline(ipc, "RDIR");
789 CtdlIPC_getline(ipc, buf);
791 pprintf("%s\n", &buf[4]);
795 extract(comment, &buf[4], 0);
796 extract(flnm, &buf[4], 1);
797 pprintf("\nDirectory of %s on %s\n", flnm, comment);
798 pprintf("-----------------------\n");
799 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
800 extract(flnm, buf, 0);
801 extract(flsz, buf, 1);
802 extract(comment, buf, 2);
803 if (strlen(flnm) <= 14)
804 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
806 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
813 * add a user to a private room
815 void invite(CtdlIPC *ipc)
817 char username[USERNAME_SIZE];
819 int r; /* IPC response code */
821 newprompt("Name of user? ", username, USERNAME_SIZE);
822 if (username[0] == 0)
825 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
826 scr_printf("%s\n", buf);
831 * kick a user out of a room
833 void kickout(CtdlIPC *ipc)
835 char username[USERNAME_SIZE];
837 int r; /* IPC response code */
839 newprompt("Name of user? ", username, USERNAME_SIZE);
840 if (username[0] == 0)
843 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
844 scr_printf("%s\n", buf);
849 * aide command: kill the current room
851 void killroom(CtdlIPC *ipc)
856 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
858 scr_printf("%s\n", aaa);
862 scr_printf("Are you sure you want to kill this room? ");
866 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
867 scr_printf("%s\n", aaa);
870 dotgoto(ipc, "_BASEROOM_", 0, 0);
873 void forget(CtdlIPC *ipc)
874 { /* forget the current room */
877 scr_printf("Are you sure you want to forget this room? ");
881 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
882 scr_printf("%s\n", buf);
886 /* now return to the lobby */
887 dotgoto(ipc, "_BASEROOM_", 0, 0);
894 void entroom(CtdlIPC *ipc)
897 char new_room_name[ROOMNAMELEN];
899 char new_room_pass[10];
902 int r; /* IPC response code */
904 /* Check permission to create room */
905 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
907 scr_printf("%s\n", buf);
911 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
912 if (strlen(new_room_name) == 0) {
915 for (a = 0; a < strlen(new_room_name); ++a) {
916 if (new_room_name[a] == '|') {
917 new_room_name[a] = '_';
921 new_room_floor = select_floor(ipc, (int) curr_floor);
923 IFNEXPERT formout(ipc, "roomaccess");
925 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
926 "<3>Passworded room\n<4>Invitation-only room\n"
928 "Enter room type: ");
931 } while (((b < '1') || (b > '5')) && (b != '?'));
934 formout(ipc, "roomaccess");
936 } while ((b < '1') || (b > '5'));
937 b -= '0'; /* Portable */
938 scr_printf("%d\n", b);
939 new_room_type = b - 1;
940 if (new_room_type == 2) {
941 newprompt("Enter a room password: ", new_room_pass, 9);
942 for (a = 0; a < strlen(new_room_pass); ++a)
943 if (new_room_pass[a] == '|')
944 new_room_pass[a] = '_';
946 strcpy(new_room_pass, "");
949 scr_printf("\042%s\042, a", new_room_name);
951 scr_printf(" public room.");
953 scr_printf(" guess-name room.");
955 scr_printf(" passworded room, password: %s", new_room_pass);
957 scr_printf("n invitation-only room.");
959 scr_printf(" personal room.");
960 scr_printf("\nInstall it? (y/n) : ");
965 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
966 new_room_pass, new_room_floor, buf);
968 scr_printf("%s\n", buf);
972 /* command succeeded... now GO to the new room! */
973 dotgoto(ipc, new_room_name, 0, 0);
978 void readinfo(CtdlIPC *ipc)
979 { /* read info file for current room */
982 int r; /* IPC response code */
985 /* Name of currernt room aide */
986 r = CtdlIPCGetRoomAide(ipc, buf);
988 safestrncpy(raide, buf, sizeof raide);
992 if (strlen(raide) > 0)
993 scr_printf("Room aide is %s.\n\n", raide);
995 r = CtdlIPCRoomInfo(ipc, &text, buf);
1000 fmout(screenwidth, NULL, text, NULL,
1001 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1002 (*raide) ? 2 : 0, 1);
1009 * <W>ho knows room...
1011 void whoknows(CtdlIPC *ipc)
1014 char *listing = NULL;
1017 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1019 pprintf("%s\n", buf);
1022 while (strlen(listing) > 0) {
1023 extract_token(buf, listing, 0, '\n');
1024 remove_token(listing, 0, '\n');
1026 pprintf("%s\n", buf);
1032 void do_edit(CtdlIPC *ipc,
1033 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1037 int b, cksum, editor_exit;
1039 if (strlen(editor_paths[0]) == 0) {
1040 scr_printf("Do you wish to re-enter %s? ", desc);
1045 fp = fopen(temp, "w");
1048 CtdlIPC_putline(ipc, check_cmd);
1049 CtdlIPC_getline(ipc, cmd);
1050 if (cmd[0] != '2') {
1051 scr_printf("%s\n", &cmd[4]);
1055 if (strlen(editor_paths[0]) > 0) {
1056 CtdlIPC_putline(ipc, read_cmd);
1057 CtdlIPC_getline(ipc, cmd);
1058 if (cmd[0] == '1') {
1059 fp = fopen(temp, "w");
1060 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1061 fprintf(fp, "%s\n", cmd);
1067 cksum = file_checksum(temp);
1069 if (strlen(editor_paths[0]) > 0) {
1072 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1075 sttybbs(SB_RESTORE);
1076 editor_pid = fork();
1077 if (editor_pid == 0) {
1079 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1085 b = ka_wait(&editor_exit);
1086 } while ((b != editor_pid) && (b >= 0));
1088 scr_printf("Executed %s\n", editor_paths[0]);
1092 scr_printf("Entering %s. "
1093 "Press return twice when finished.\n", desc);
1094 fp = fopen(temp, "r+");
1099 if (file_checksum(temp) == cksum) {
1100 scr_printf("*** Aborted.\n");
1104 CtdlIPC_putline(ipc, write_cmd);
1105 CtdlIPC_getline(ipc, cmd);
1106 if (cmd[0] != '4') {
1107 scr_printf("%s\n", &cmd[4]);
1111 fp = fopen(temp, "r");
1112 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1113 cmd[strlen(cmd) - 1] = 0;
1114 CtdlIPC_putline(ipc, cmd);
1117 CtdlIPC_putline(ipc, "000");
1124 void enterinfo(CtdlIPC *ipc)
1125 { /* edit info file for current room */
1126 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1129 void enter_bio(CtdlIPC *ipc)
1132 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1133 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1137 * create a new floor
1139 void create_floor(CtdlIPC *ipc)
1142 char newfloorname[SIZ];
1143 int r; /* IPC response code */
1145 load_floorlist(ipc);
1147 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1149 scr_printf("%s\n", buf);
1153 newprompt("Name for new floor: ", newfloorname, 255);
1154 if (!*newprompt) return;
1155 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1157 scr_printf("Floor has been created.\n");
1159 scr_printf("%s\n", buf);
1162 load_floorlist(ipc);
1166 * edit the current floor
1168 void edit_floor(CtdlIPC *ipc)
1171 struct ExpirePolicy *ep = NULL;
1172 int r; /* IPC response code */
1174 load_floorlist(ipc);
1176 /* Fetch the expire policy (this will silently fail on old servers,
1177 * resulting in "default" policy)
1179 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1181 /* Interact with the user */
1182 scr_printf("You are editing the floor called \"%s\"\n",
1183 &floorlist[(int) curr_floor][0] );
1184 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1186 /* Angels and demons dancing in my head... */
1188 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1190 ("Floor default message expire policy (? for list)",
1192 if (buf[0] == '?') {
1194 "0. Use the system default\n"
1195 "1. Never automatically expire messages\n"
1196 "2. Expire by message count\n"
1197 "3. Expire by message age\n");
1199 } while ((buf[0] < '0') || (buf[0] > '3'));
1200 ep->expire_mode = buf[0] - '0';
1202 /* ...lunatics and monsters underneath my bed */
1203 if (ep->expire_mode == 2) {
1204 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1205 strprompt("Keep how many messages online?", buf, 10);
1206 ep->expire_value = atol(buf);
1209 if (ep->expire_mode == 3) {
1210 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1211 strprompt("Keep messages for how many days?", buf, 10);
1212 ep->expire_value = atol(buf);
1216 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1217 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1218 scr_printf("%s\n", buf);
1219 load_floorlist(ipc);
1226 * kill the current floor
1228 void kill_floor(CtdlIPC *ipc)
1230 int floornum_to_delete, a;
1233 load_floorlist(ipc);
1235 floornum_to_delete = (-1);
1236 scr_printf("(Press return to abort)\n");
1237 newprompt("Delete which floor? ", buf, 255);
1238 if (strlen(buf) == 0)
1240 for (a = 0; a < 128; ++a)
1241 if (!strcasecmp(&floorlist[a][0], buf))
1242 floornum_to_delete = a;
1243 if (floornum_to_delete < 0) {
1244 scr_printf("No such floor. Select one of:\n");
1245 for (a = 0; a < 128; ++a)
1246 if (floorlist[a][0] != 0)
1247 scr_printf("%s\n", &floorlist[a][0]);
1249 } while (floornum_to_delete < 0);
1250 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1251 scr_printf("%s\n", buf);
1252 load_floorlist(ipc);