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(long int curr, long int 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 char editor_path[];
51 extern int screenwidth;
52 extern int screenheight;
53 extern char fullname[];
54 extern char sigcaught;
55 extern char floor_mode;
56 extern char curr_floor;
61 extern char *uglist[];
62 extern long uglistlsn[];
63 extern int uglistsize;
65 extern char floorlist[128][SIZ];
68 void load_floorlist(CtdlIPC *ipc)
73 int r; /* IPC response code */
75 for (a = 0; a < 128; ++a)
78 r = CtdlIPCFloorListing(ipc, &listing, buf);
80 strcpy(floorlist[0], "Main Floor");
83 while (*listing && strlen(listing)) {
84 extract_token(buf, listing, 0, '\n');
85 remove_token(listing, 0, '\n');
86 extract(floorlist[extract_int(buf, 0)], buf, 1);
92 void room_tree_list(struct roomlisting *rp)
95 char rmname[ROOMNAMELEN];
103 if (rp->lnext != NULL) {
104 room_tree_list(rp->lnext);
107 if (sigcaught == 0) {
108 strcpy(rmname, rp->rlname);
110 if ((c + strlen(rmname) + 4) > screenwidth) {
112 /* line break, check the paginator */
116 if (f & QR_MAILBOX) {
117 color(BRIGHT_YELLOW);
118 } else if (f & QR_PRIVATE) {
123 pprintf("%s", rmname);
124 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
126 else if (f & QR_DIRECTORY)
128 else if (f & QR_NETWORK)
132 c = c + strlen(rmname) + 3;
135 if (rp->rnext != NULL) {
136 room_tree_list(rp->rnext);
144 * Room ordering stuff (compare first by floor, then by order)
146 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
148 if ((r1 == NULL) && (r2 == NULL))
154 if (r1->rlfloor < r2->rlfloor)
156 if (r1->rlfloor > r2->rlfloor)
158 if (r1->rlorder < r2->rlorder)
160 if (r1->rlorder > r2->rlorder)
167 * Common code for all room listings
169 void listrms(CtdlIPC *ipc, char *variety)
173 struct roomlisting *rl = NULL;
174 struct roomlisting *rp;
175 struct roomlisting *rs;
178 /* Ask the server for a room list */
179 CtdlIPC_putline(ipc, variety);
180 CtdlIPC_getline(ipc, buf);
184 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
185 rp = malloc(sizeof(struct roomlisting));
186 extract(rp->rlname, buf, 0);
187 rp->rlflags = extract_int(buf, 1);
188 rp->rlfloor = extract_int(buf, 2);
189 rp->rlorder = extract_int(buf, 3);
198 if (rordercmp(rp, rs) < 0) {
199 if (rs->lnext == NULL) {
206 if (rs->rnext == NULL) {
217 room_tree_list(NULL);
223 void list_other_floors(void)
228 for (a = 0; a < 128; ++a) {
229 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
230 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
234 pprintf("%s: ", floorlist[a]);
235 c = c + strlen(floorlist[a]) + 3;
242 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
243 * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
245 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
252 if (kn_floor_mode == 0) {
254 pprintf("\n Rooms with unread messages:\n");
255 listrms(ipc, "LKRN");
257 pprintf("\n\n No unseen messages in:\n");
258 listrms(ipc, "LKRO");
262 if (kn_floor_mode == 1) {
264 pprintf("\n Rooms with unread messages on %s:\n",
265 floorlist[(int) curr_floor]);
266 snprintf(buf, sizeof buf, "LKRN %d", curr_floor);
269 pprintf("\n\n Rooms with no new messages on %s:\n",
270 floorlist[(int) curr_floor]);
271 snprintf(buf, sizeof buf, "LKRO %d", 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 snprintf(buf, sizeof buf, "LKRA %d", a);
293 IFNEXPERT hit_any_key();
297 void listzrooms(CtdlIPC *ipc)
298 { /* list public forgotten rooms */
300 pprintf("\n Forgotten public rooms:\n");
301 listrms(ipc, "LZRM");
304 IFNEXPERT hit_any_key();
308 int set_room_attr(CtdlIPC *ipc, int ibuf, char *prompt, unsigned int sbit)
312 a = boolprompt(prompt, (ibuf & sbit));
313 ibuf = (ibuf | sbit);
315 ibuf = (ibuf ^ sbit);
323 * Select a floor (used in several commands)
324 * The supplied argument is the 'default' floor number.
325 * This function returns the selected floor number.
327 int select_floor(CtdlIPC *ipc, int rfloor)
332 if (floor_mode == 1) {
333 if (floorlist[(int) curr_floor][0] == 0) {
339 safestrncpy(floorstr, floorlist[rfloor],
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);
375 * .<A>ide <E>dit room
377 void editthisroom(CtdlIPC *ipc)
379 char rname[ROOMNAMELEN];
391 int expire_value = 0;
392 int r; /* IPC response code */
394 /* Fetch the existing room config */
395 CtdlIPC_putline(ipc, "GETR");
396 CtdlIPC_getline(ipc, buf);
398 scr_printf("%s\n", &buf[4]);
402 extract(rname, &buf[4], 0);
403 extract(rpass, &buf[4], 1);
404 extract(rdir, &buf[4], 2);
405 rflags = extract_int(&buf[4], 3);
406 rfloor = extract_int(&buf[4], 4);
407 rorder = extract_int(&buf[4], 5);
408 rview = extract_int(&buf[4], 6);
409 rflags2 = extract_int(&buf[4], 7);
412 /* Fetch the name of the current room aide */
413 CtdlIPC_putline(ipc, "GETA");
414 CtdlIPC_getline(ipc, buf);
416 safestrncpy(raide, &buf[4], sizeof raide);
421 if (strlen(raide) == 0) {
422 strcpy(raide, "none");
425 /* Fetch the expire policy (this will silently fail on old servers,
426 * resulting in "default" policy)
428 CtdlIPC_putline(ipc, "GPEX room");
429 CtdlIPC_getline(ipc, buf);
431 expire_mode = extract_int(&buf[4], 0);
432 expire_value = extract_int(&buf[4], 1);
435 /* Now interact with the user. */
437 rfloor = select_floor(ipc, rfloor);
438 rflags = set_room_attr(ipc, rflags, "Private room", QR_PRIVATE);
439 if (rflags & QR_PRIVATE) {
440 rflags = set_room_attr(ipc, rflags,
441 "Accessible by guessing room name",
445 /* if it's public, clear the privacy classes */
446 if ((rflags & QR_PRIVATE) == 0) {
447 if (rflags & QR_GUESSNAME) {
448 rflags = rflags - QR_GUESSNAME;
450 if (rflags & QR_PASSWORDED) {
451 rflags = rflags - QR_PASSWORDED;
455 /* if it's private, choose the privacy classes */
456 if ((rflags & QR_PRIVATE)
457 && ((rflags & QR_GUESSNAME) == 0)) {
458 rflags = set_room_attr(ipc, rflags,
459 "Accessible by entering a password",
462 if ((rflags & QR_PRIVATE)
463 && ((rflags & QR_PASSWORDED) == QR_PASSWORDED)) {
464 strprompt("Room password", rpass, 9);
467 if ((rflags & QR_PRIVATE) == QR_PRIVATE) {
469 boolprompt("Cause current users to forget room", 0);
473 set_room_attr(ipc, rflags, "Preferred users only", QR_PREFONLY);
474 rflags = set_room_attr(ipc, rflags, "Read-only room", QR_READONLY);
475 rflags = set_room_attr(ipc, rflags, "Directory room", QR_DIRECTORY);
476 rflags = set_room_attr(ipc, rflags, "Permanent room", QR_PERMANENT);
477 if (rflags & QR_DIRECTORY) {
478 strprompt("Directory name", rdir, 14);
480 set_room_attr(ipc, rflags, "Uploading allowed", QR_UPLOAD);
482 set_room_attr(ipc, rflags, "Downloading allowed",
485 set_room_attr(ipc, rflags, "Visible directory", QR_VISDIR);
487 rflags = set_room_attr(ipc, rflags, "Network shared room", QR_NETWORK);
488 rflags2 = set_room_attr(ipc, rflags2,
489 "Self-service list subscribe/unsubscribe",
491 rflags = set_room_attr(ipc, rflags,
492 "Automatically make all messages anonymous",
494 if ((rflags & QR_ANONONLY) == 0) {
495 rflags = set_room_attr(ipc, rflags,
496 "Ask users whether to make messages anonymous",
499 rorder = intprompt("Listing order", rorder, 1, 127);
501 /* Ask about the room aide */
503 strprompt("Room aide (or 'none')", raide, 29);
504 if (!strcasecmp(raide, "none")) {
508 r = CtdlIPCQueryUsername(ipc, raide, buf);
510 scr_printf("%s\n", buf);
512 } while (r / 100 != 2);
514 /* FIXME: Duplicate code??? */
515 if (!strcasecmp(raide, "none")) {
519 /* Angels and demons dancing in my head... */
521 snprintf(buf, sizeof buf, "%d", expire_mode);
522 strprompt("Message expire policy (? for list)", buf, 1);
525 "0. Use the default for this floor\n"
526 "1. Never automatically expire messages\n"
527 "2. Expire by message count\n"
528 "3. Expire by message age\n");
530 } while ((buf[0] < 48) || (buf[0] > 51));
531 expire_mode = buf[0] - 48;
533 /* ...lunatics and monsters underneath my bed */
534 if (expire_mode == 2) {
535 snprintf(buf, sizeof buf, "%d", expire_value);
536 strprompt("Keep how many messages online?", buf, 10);
537 expire_value = atol(buf);
540 if (expire_mode == 3) {
541 snprintf(buf, sizeof buf, "%d", expire_value);
542 strprompt("Keep messages for how many days?", buf, 10);
543 expire_value = atol(buf);
546 /* Give 'em a chance to change their minds */
547 scr_printf("Save changes (y/n)? ");
550 r = CtdlIPCSetRoomAide(ipc, raide, buf);
552 scr_printf("%s\n", buf);
555 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, expire_mode,
558 snprintf(buf, sizeof buf, "SETR %s|%s|%s|%d|%d|%d|%d|%d|%d",
559 rname, rpass, rdir, rflags, rbump, rfloor,
560 rorder, rview, rflags2);
561 CtdlIPC_putline(ipc, buf);
562 CtdlIPC_getline(ipc, buf);
563 scr_printf("%s\n", &buf[4]);
565 dotgoto(ipc, rname, 2, 0);
571 * un-goto the previous room
573 void ungoto(CtdlIPC *ipc)
580 snprintf(buf, sizeof buf, "GOTO %s", uglist[uglistsize-1]);
581 CtdlIPC_putline(ipc, buf);
582 CtdlIPC_getline(ipc, buf);
584 scr_printf("%s\n", &buf[4]);
587 snprintf(buf, sizeof buf, "SLRP %ld", uglistlsn[uglistsize-1]);
588 CtdlIPC_putline(ipc, buf);
589 CtdlIPC_getline(ipc, buf);
591 scr_printf("%s\n", &buf[4]);
593 safestrncpy (buf, uglist[uglistsize-1], sizeof(buf));
595 free(uglist[uglistsize]);
596 /* Don't queue ungoto info or we end up in a loop */
597 dotgoto(ipc, buf, 0, 1);
602 * saves filelen bytes from file at pathname
604 int save_buffer(void *file, size_t filelen, const char *pathname)
607 size_t bytes_written = 0;
610 fp = fopen(pathname, "w");
612 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
616 block = fwrite(file + bytes_written, 1,
617 filelen - bytes_written, fp);
618 bytes_written += block;
619 } while (errno == EINTR && bytes_written < filelen);
622 if (bytes_written < filelen) {
623 err_printf("Trouble saving '%s': %s\n", pathname,
632 * Save supplied_filename in dest directory; gets the name only
634 void destination_directory(char *dest, const char *supplied_filename)
636 scr_printf("Enter the name of the directory to save '%s'\n"
637 "to, or press return for the current directory.\n",
639 newprompt("Directory: ", dest, PATH_MAX);
640 if (strlen(dest) == 0) {
645 strcat(dest, supplied_filename);
650 * download() - download a file or files. The argument passed to this
651 * function determines which protocol to use.
652 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
654 void download(CtdlIPC *ipc, int proto)
657 char filename[PATH_MAX];
658 char tempname[PATH_MAX];
659 char transmit_cmd[SIZ];
663 void *file = NULL; /* The downloaded file */
664 long filelen = 0L; /* The downloaded file length */
666 if ((room_flags & QR_DOWNLOAD) == 0) {
667 scr_printf("*** You cannot download from this room.\n");
671 newprompt("Enter filename: ", filename, PATH_MAX);
673 /* Save to local disk, for folks with their own copy of the client */
675 destination_directory(tempname, filename);
676 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
678 scr_printf("%s\n", buf);
681 save_buffer(file, extract_long(buf, 0), tempname);
686 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
688 scr_printf("%s\n", buf);
691 filelen = extract_long(buf, 0);
693 /* Meta-download for public clients */
694 /* scr_printf("Fetching file from Citadel server...\n"); */
695 mkdir(tempdir, 0700);
696 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
697 tpipe = fopen(tempname, "wb");
698 if (fwrite(file, filelen, 1, tpipe) < filelen) {
702 if (file) free(file);
705 /* FIXME: display internally instead */
706 snprintf(transmit_cmd, sizeof transmit_cmd,
707 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
711 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
713 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
715 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
717 /* FIXME: display internally instead */
718 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
722 system(transmit_cmd);
726 /* clean up the temporary directory */
728 scr_putc(7); /* Beep beep! */
733 * read directory of this room
735 void roomdir(CtdlIPC *ipc)
742 CtdlIPC_putline(ipc, "RDIR");
743 CtdlIPC_getline(ipc, buf);
745 pprintf("%s\n", &buf[4]);
749 extract(comment, &buf[4], 0);
750 extract(flnm, &buf[4], 1);
751 pprintf("\nDirectory of %s on %s\n", flnm, comment);
752 pprintf("-----------------------\n");
753 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
754 extract(flnm, buf, 0);
755 extract(flsz, buf, 1);
756 extract(comment, buf, 2);
757 if (strlen(flnm) <= 14)
758 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
760 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
767 * add a user to a private room
769 void invite(CtdlIPC *ipc)
771 char username[USERNAME_SIZE];
773 int r; /* IPC response code */
775 newprompt("Name of user? ", username, USERNAME_SIZE);
776 if (username[0] == 0)
779 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
780 scr_printf("%s\n", buf);
785 * kick a user out of a room
787 void kickout(CtdlIPC *ipc)
789 char username[USERNAME_SIZE];
791 int r; /* IPC response code */
793 newprompt("Name of user? ", username, USERNAME_SIZE);
794 if (username[0] == 0)
797 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
798 scr_printf("%s\n", buf);
803 * aide command: kill the current room
805 void killroom(CtdlIPC *ipc)
810 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
812 scr_printf("%s\n", aaa);
816 scr_printf("Are you sure you want to kill this room? ");
820 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
821 scr_printf("%s\n", aaa);
824 dotgoto(ipc, "_BASEROOM_", 0, 0);
827 void forget(CtdlIPC *ipc)
828 { /* forget the current room */
831 scr_printf("Are you sure you want to forget this room? ");
835 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
836 scr_printf("%s\n", buf);
840 /* now return to the lobby */
841 dotgoto(ipc, "_BASEROOM_", 0, 0);
848 void entroom(CtdlIPC *ipc)
851 char new_room_name[ROOMNAMELEN];
853 char new_room_pass[10];
856 int r; /* IPC response code */
858 /* Check permission to create room */
859 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
861 scr_printf("%s\n", buf);
865 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
866 if (strlen(new_room_name) == 0) {
869 for (a = 0; a < strlen(new_room_name); ++a) {
870 if (new_room_name[a] == '|') {
871 new_room_name[a] = '_';
875 new_room_floor = select_floor(ipc, (int) curr_floor);
877 IFNEXPERT formout(ipc, "roomaccess");
879 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
880 "<3>Passworded room\n<4>Invitation-only room\n"
882 "Enter room type: ");
885 } while (((b < '1') || (b > '5')) && (b != '?'));
888 formout(ipc, "roomaccess");
890 } while ((b < '1') || (b > '5'));
891 b -= '0'; /* Portable */
892 scr_printf("%d\n", b);
893 new_room_type = b - 1;
894 if (new_room_type == 2) {
895 newprompt("Enter a room password: ", new_room_pass, 9);
896 for (a = 0; a < strlen(new_room_pass); ++a)
897 if (new_room_pass[a] == '|')
898 new_room_pass[a] = '_';
900 strcpy(new_room_pass, "");
903 scr_printf("\042%s\042, a", new_room_name);
905 scr_printf(" public room.");
907 scr_printf(" guess-name room.");
909 scr_printf(" passworded room, password: %s", new_room_pass);
911 scr_printf("n invitation-only room.");
913 scr_printf(" personal room.");
914 scr_printf("\nInstall it? (y/n) : ");
919 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
920 new_room_pass, new_room_floor, buf);
922 scr_printf("%s\n", buf);
926 /* command succeeded... now GO to the new room! */
927 dotgoto(ipc, new_room_name, 0, 0);
932 void readinfo(CtdlIPC *ipc)
933 { /* read info file for current room */
936 int r; /* IPC response code */
939 /* Name of currernt room aide */
940 r = CtdlIPCGetRoomAide(ipc, buf);
942 safestrncpy(raide, buf, sizeof raide);
946 if (strlen(raide) > 0)
947 scr_printf("Room aide is %s.\n\n", raide);
949 r = CtdlIPCRoomInfo(ipc, &text, buf);
954 fmout(screenwidth, NULL, text, NULL,
955 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
956 (*raide) ? 2 : 0, 1);
963 * <W>ho knows room...
965 void whoknows(CtdlIPC *ipc)
968 CtdlIPC_putline(ipc, "WHOK");
969 CtdlIPC_getline(ipc, buf);
971 pprintf("%s\n", &buf[4]);
974 while (CtdlIPC_getline(ipc, buf), strncmp(buf, "000", 3)) {
976 pprintf("%s\n", buf);
981 void do_edit(CtdlIPC *ipc,
982 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
986 int b, cksum, editor_exit;
989 if (strlen(editor_path) == 0) {
990 scr_printf("Do you wish to re-enter %s? ", desc);
995 fp = fopen(temp, "w");
998 CtdlIPC_putline(ipc, check_cmd);
999 CtdlIPC_getline(ipc, cmd);
1000 if (cmd[0] != '2') {
1001 scr_printf("%s\n", &cmd[4]);
1005 if (strlen(editor_path) > 0) {
1006 CtdlIPC_putline(ipc, read_cmd);
1007 CtdlIPC_getline(ipc, cmd);
1008 if (cmd[0] == '1') {
1009 fp = fopen(temp, "w");
1010 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1011 fprintf(fp, "%s\n", cmd);
1017 cksum = file_checksum(temp);
1019 if (strlen(editor_path) > 0) {
1022 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1024 editor_pid = fork();
1025 if (editor_pid == 0) {
1028 sttybbs(SB_RESTORE);
1029 execlp(editor_path, editor_path, temp, NULL);
1035 b = wait(&editor_exit);
1036 } while ((b != editor_pid) && (b >= 0));
1038 scr_printf("Executed %s\n", editor_path);
1042 scr_printf("Entering %s. "
1043 "Press return twice when finished.\n", desc);
1044 fp = fopen(temp, "r+");
1049 if (file_checksum(temp) == cksum) {
1050 scr_printf("*** Aborted.\n");
1054 CtdlIPC_putline(ipc, write_cmd);
1055 CtdlIPC_getline(ipc, cmd);
1056 if (cmd[0] != '4') {
1057 scr_printf("%s\n", &cmd[4]);
1061 fp = fopen(temp, "r");
1062 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1063 cmd[strlen(cmd) - 1] = 0;
1064 CtdlIPC_putline(ipc, cmd);
1067 CtdlIPC_putline(ipc, "000");
1074 void enterinfo(CtdlIPC *ipc)
1075 { /* edit info file for current room */
1076 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1079 void enter_bio(CtdlIPC *ipc)
1082 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1083 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1087 * create a new floor
1089 void create_floor(CtdlIPC *ipc)
1092 char newfloorname[SIZ];
1093 int r; /* IPC response code */
1095 load_floorlist(ipc);
1097 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1099 scr_printf("%s\n", buf);
1103 newprompt("Name for new floor: ", newfloorname, 255);
1104 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1106 scr_printf("Floor has been created.\n");
1108 scr_printf("%s\n", buf);
1111 load_floorlist(ipc);
1115 * edit the current floor
1117 void edit_floor(CtdlIPC *ipc)
1120 int expire_mode = 0;
1121 int expire_value = 0;
1122 int r; /* IPC response code */
1124 load_floorlist(ipc);
1126 /* Fetch the expire policy (this will silently fail on old servers,
1127 * resulting in "default" policy)
1129 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, buf);
1131 expire_mode = extract_int(buf, 0);
1132 expire_value = extract_int(buf, 1);
1135 /* Interact with the user */
1136 scr_printf("You are editing the floor called \"%s\"\n",
1137 &floorlist[(int) curr_floor][0] );
1138 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1140 /* Angels and demons dancing in my head... */
1142 snprintf(buf, sizeof buf, "%d", expire_mode);
1144 ("Floor default message expire policy (? for list)",
1146 if (buf[0] == '?') {
1148 "0. Use the system default\n"
1149 "1. Never automatically expire messages\n"
1150 "2. Expire by message count\n"
1151 "3. Expire by message age\n");
1153 } while ((buf[0] < '0') || (buf[0] > '3'));
1154 expire_mode = buf[0] - '0';
1156 /* ...lunatics and monsters underneath my bed */
1157 if (expire_mode == 2) {
1158 snprintf(buf, sizeof buf, "%d", expire_value);
1159 strprompt("Keep how many messages online?", buf, 10);
1160 expire_value = atol(buf);
1163 if (expire_mode == 3) {
1164 snprintf(buf, sizeof buf, "%d", expire_value);
1165 strprompt("Keep messages for how many days?", buf, 10);
1166 expire_value = atol(buf);
1170 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, expire_mode,
1172 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1173 scr_printf("%s\n", buf);
1174 load_floorlist(ipc);
1181 * kill the current floor
1183 void kill_floor(CtdlIPC *ipc)
1185 int floornum_to_delete, a;
1188 load_floorlist(ipc);
1190 floornum_to_delete = (-1);
1191 scr_printf("(Press return to abort)\n");
1192 newprompt("Delete which floor? ", buf, 255);
1193 if (strlen(buf) == 0)
1195 for (a = 0; a < 128; ++a)
1196 if (!strcasecmp(&floorlist[a][0], buf))
1197 floornum_to_delete = a;
1198 if (floornum_to_delete < 0) {
1199 scr_printf("No such floor. Select one of:\n");
1200 for (a = 0; a < 128; ++a)
1201 if (floorlist[a][0] != 0)
1202 scr_printf("%s\n", &floorlist[a][0]);
1204 } while (floornum_to_delete < 0);
1205 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1206 scr_printf("%s\n", buf);
1207 load_floorlist(ipc);