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 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 static void listrms(CtdlIPC *ipc, enum RoomList variety, int floor)
172 struct march *listing = NULL;
173 struct march *tmp = NULL;
174 struct roomlisting *rl = NULL;
175 struct roomlisting *rp;
176 struct roomlisting *rs;
177 int r; /* IPC response code */
179 /* Ask the server for a room list */
180 r = CtdlIPCKnownRooms(ipc, variety, floor, &listing, buf);
185 rp = malloc(sizeof(struct roomlisting));
186 strncpy(rp->rlname, listing->march_name, ROOMNAMELEN);
187 rp->rlflags = listing->march_flags;
188 rp->rlfloor = listing->march_floor;
189 rp->rlorder = listing->march_order;
202 if (rordercmp(rp, rs) < 0) {
203 if (rs->lnext == NULL) {
210 if (rs->rnext == NULL) {
221 room_tree_list(NULL);
227 void list_other_floors(void)
232 for (a = 0; a < 128; ++a) {
233 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
234 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
238 pprintf("%s: ", floorlist[a]);
239 c = c + strlen(floorlist[a]) + 3;
246 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
247 * 1 to list rooms on the current floor, or 1 to list rooms on all floors.
249 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
255 if (kn_floor_mode == 0) {
257 pprintf("\n Rooms with unread messages:\n");
258 listrms(ipc, SubscribedRoomsWithNewMessages, -1);
260 pprintf("\n\n No unseen messages in:\n");
261 listrms(ipc, SubscribedRoomsWithNoNewMessages, -1);
265 if (kn_floor_mode == 1) {
267 pprintf("\n Rooms with unread messages on %s:\n",
268 floorlist[(int) curr_floor]);
269 listrms(ipc, SubscribedRoomsWithNewMessages, curr_floor);
271 pprintf("\n\n Rooms with no new messages on %s:\n",
272 floorlist[(int) curr_floor]);
273 listrms(ipc, SubscribedRoomsWithNoNewMessages, curr_floor);
275 pprintf("\n\n Other floors:\n");
280 if (kn_floor_mode == 2) {
281 for (a = 0; a < 128; ++a) {
282 if (floorlist[a][0] != 0) {
284 pprintf("\n Rooms on %s:\n",
286 listrms(ipc, AllAccessibleRooms, 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, UnsubscribedRooms, -1);
304 IFNEXPERT hit_any_key();
308 int set_room_attr(CtdlIPC *ipc, unsigned 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 strprompt("Which floor", floorstr, 255);
342 for (a = 0; a < 128; ++a) {
344 (floorstr, &floorlist[a][0]))
349 (floorstr, &floorlist[a][0],
353 && (pattern(&floorlist[a][0], floorstr)
358 scr_printf("\n One of:\n");
359 for (a = 0; a < 128; ++a) {
360 if (floorlist[a][0] != 0) {
366 } while (newfloor < 0);
371 scr_printf("Floor selection bypassed because you have "
372 "floor mode disabled.\n");
382 * .<A>ide <E>dit room
384 void editthisroom(CtdlIPC *ipc)
387 char raide[USERNAME_SIZE];
389 struct quickroom *attr = NULL;
390 struct ExpirePolicy *eptr = NULL;
391 int r; /* IPC response code */
393 /* Fetch the existing room config */
394 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
396 scr_printf("%s\n", buf);
399 eptr = &(attr->QRep);
401 /* Fetch the name of the current room aide */
402 r = CtdlIPCGetRoomAide(ipc, buf);
404 safestrncpy(raide, buf, sizeof raide);
408 if (strlen(raide) == 0) {
409 strcpy(raide, "none");
412 /* Fetch the expire policy (this will silently fail on old servers,
413 * resulting in "default" policy)
415 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
417 /* Now interact with the user. */
419 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
420 attr->QRfloor = select_floor(ipc, attr->QRfloor);
421 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
422 if (attr->QRflags & QR_PRIVATE) {
423 attr->QRflags = set_room_attr(ipc, attr->QRflags,
424 "Accessible by guessing room name",
428 /* if it's public, clear the privacy classes */
429 if ((attr->QRflags & QR_PRIVATE) == 0) {
430 if (attr->QRflags & QR_GUESSNAME) {
431 attr->QRflags = attr->QRflags - QR_GUESSNAME;
433 if (attr->QRflags & QR_PASSWORDED) {
434 attr->QRflags = attr->QRflags - QR_PASSWORDED;
438 /* if it's private, choose the privacy classes */
439 if ((attr->QRflags & QR_PRIVATE)
440 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
441 attr->QRflags = set_room_attr(ipc, attr->QRflags,
442 "Accessible by entering a password",
445 if ((attr->QRflags & QR_PRIVATE)
446 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
447 strprompt("Room password", attr->QRpasswd, 9);
450 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
451 rbump = boolprompt("Cause current users to forget room", 0);
454 attr->QRflags = set_room_attr(ipc, attr->QRflags,
455 "Preferred users only", QR_PREFONLY);
456 attr->QRflags = set_room_attr(ipc, attr->QRflags,
457 "Read-only room", QR_READONLY);
458 attr->QRflags = set_room_attr(ipc, attr->QRflags,
459 "Directory room", QR_DIRECTORY);
460 attr->QRflags = set_room_attr(ipc, attr->QRflags,
461 "Permanent room", QR_PERMANENT);
462 if (attr->QRflags & QR_DIRECTORY) {
463 strprompt("Directory name", attr->QRdirname, 14);
465 set_room_attr(ipc, attr->QRflags,
466 "Uploading allowed", QR_UPLOAD);
468 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
471 set_room_attr(ipc, attr->QRflags,
472 "Visible directory", QR_VISDIR);
474 attr->QRflags = set_room_attr(ipc, attr->QRflags,
475 "Network shared room", QR_NETWORK);
476 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
477 "Self-service list subscribe/unsubscribe",
479 attr->QRflags = set_room_attr(ipc, attr->QRflags,
480 "Automatically make all messages anonymous",
482 if ((attr->QRflags & QR_ANONONLY) == 0) {
483 attr->QRflags = set_room_attr(ipc, attr->QRflags,
484 "Ask users whether to make messages anonymous",
487 attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
489 /* Ask about the room aide */
491 strprompt("Room aide (or 'none')", raide, 29);
492 if (!strcasecmp(raide, "none")) {
496 r = CtdlIPCQueryUsername(ipc, raide, buf);
498 scr_printf("%s\n", buf);
500 } while (r / 100 != 2);
502 /* FIXME: Duplicate code??? */
503 if (!strcasecmp(raide, "none")) {
507 /* Angels and demons dancing in my head... */
509 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
510 strprompt("Message expire policy (? for list)", buf, 1);
513 "0. Use the default for this floor\n"
514 "1. Never automatically expire messages\n"
515 "2. Expire by message count\n"
516 "3. Expire by message age\n");
518 } while ((buf[0] < 48) || (buf[0] > 51));
519 attr->QRep.expire_mode = buf[0] - 48;
521 /* ...lunatics and monsters underneath my bed */
522 if (attr->QRep.expire_mode == 2) {
523 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
524 strprompt("Keep how many messages online?", buf, 10);
525 attr->QRep.expire_value = atol(buf);
528 if (attr->QRep.expire_mode == 3) {
529 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
530 strprompt("Keep messages for how many days?", buf, 10);
531 attr->QRep.expire_value = atol(buf);
534 /* Give 'em a chance to change their minds */
535 scr_printf("Save changes (y/n)? ");
538 r = CtdlIPCSetRoomAide(ipc, raide, buf);
540 scr_printf("%s\n", buf);
543 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
545 scr_printf("%s\n", buf);
548 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
549 scr_printf("%s\n", buf);
550 strncpy(buf, attr->QRname, ROOMNAMELEN);
553 dotgoto(ipc, buf, 2, 0);
560 * un-goto the previous room
562 void ungoto(CtdlIPC *ipc)
565 struct ctdlipcroom *rret = NULL; /* ignored */
571 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
572 if (rret) free(rret); /* ignored */
574 scr_printf("%s\n", buf);
577 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
579 scr_printf("%s\n", buf);
581 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
583 free(uglist[uglistsize]);
584 /* Don't queue ungoto info or we end up in a loop */
585 dotgoto(ipc, buf, 0, 1);
590 * saves filelen bytes from file at pathname
592 int save_buffer(void *file, size_t filelen, const char *pathname)
595 size_t bytes_written = 0;
598 fp = fopen(pathname, "w");
600 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
604 block = fwrite(file + bytes_written, 1,
605 filelen - bytes_written, fp);
606 bytes_written += block;
607 } while (errno == EINTR && bytes_written < filelen);
610 if (bytes_written < filelen) {
611 err_printf("Trouble saving '%s': %s\n", pathname,
620 * Save supplied_filename in dest directory; gets the name only
622 void destination_directory(char *dest, const char *supplied_filename)
624 scr_printf("Enter the name of the directory to save '%s'\n"
625 "to, or press return for the current directory.\n",
627 newprompt("Directory: ", dest, PATH_MAX);
628 if (strlen(dest) == 0) {
633 strcat(dest, supplied_filename);
638 * download() - download a file or files. The argument passed to this
639 * function determines which protocol to use.
640 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
642 void download(CtdlIPC *ipc, int proto)
645 char filename[PATH_MAX];
646 char tempname[PATH_MAX];
647 char transmit_cmd[SIZ];
651 void *file = NULL; /* The downloaded file */
652 size_t filelen = 0L; /* The downloaded file length */
654 if ((room_flags & QR_DOWNLOAD) == 0) {
655 scr_printf("*** You cannot download from this room.\n");
659 newprompt("Enter filename: ", filename, PATH_MAX);
661 /* Save to local disk, for folks with their own copy of the client */
663 destination_directory(tempname, filename);
664 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
666 scr_printf("%s\n", buf);
669 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
674 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
676 scr_printf("%s\n", buf);
679 filelen = extract_unsigned_long(buf, 0);
681 /* Meta-download for public clients */
682 /* scr_printf("Fetching file from Citadel server...\n"); */
683 mkdir(tempdir, 0700);
684 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
685 tpipe = fopen(tempname, "wb");
686 if (fwrite(file, filelen, 1, tpipe) < filelen) {
687 /* FIXME: restart syscall on EINTR */
691 if (file) free(file);
694 /* FIXME: display internally instead */
695 snprintf(transmit_cmd, sizeof transmit_cmd,
696 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
700 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
702 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
704 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
706 /* FIXME: display internally instead */
707 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
711 system(transmit_cmd);
715 /* clean up the temporary directory */
717 ctdl_beep(); /* Beep beep! */
722 * read directory of this room
724 void roomdir(CtdlIPC *ipc)
731 CtdlIPC_putline(ipc, "RDIR");
732 CtdlIPC_getline(ipc, buf);
734 pprintf("%s\n", &buf[4]);
738 extract(comment, &buf[4], 0);
739 extract(flnm, &buf[4], 1);
740 pprintf("\nDirectory of %s on %s\n", flnm, comment);
741 pprintf("-----------------------\n");
742 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
743 extract(flnm, buf, 0);
744 extract(flsz, buf, 1);
745 extract(comment, buf, 2);
746 if (strlen(flnm) <= 14)
747 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
749 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
756 * add a user to a private room
758 void invite(CtdlIPC *ipc)
760 char username[USERNAME_SIZE];
762 int r; /* IPC response code */
764 newprompt("Name of user? ", username, USERNAME_SIZE);
765 if (username[0] == 0)
768 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
769 scr_printf("%s\n", buf);
774 * kick a user out of a room
776 void kickout(CtdlIPC *ipc)
778 char username[USERNAME_SIZE];
780 int r; /* IPC response code */
782 newprompt("Name of user? ", username, USERNAME_SIZE);
783 if (username[0] == 0)
786 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
787 scr_printf("%s\n", buf);
792 * aide command: kill the current room
794 void killroom(CtdlIPC *ipc)
799 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
801 scr_printf("%s\n", aaa);
805 scr_printf("Are you sure you want to kill this room? ");
809 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
810 scr_printf("%s\n", aaa);
813 dotgoto(ipc, "_BASEROOM_", 0, 0);
816 void forget(CtdlIPC *ipc)
817 { /* forget the current room */
820 scr_printf("Are you sure you want to forget this room? ");
824 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
825 scr_printf("%s\n", buf);
829 /* now return to the lobby */
830 dotgoto(ipc, "_BASEROOM_", 0, 0);
837 void entroom(CtdlIPC *ipc)
840 char new_room_name[ROOMNAMELEN];
842 char new_room_pass[10];
845 int r; /* IPC response code */
847 /* Check permission to create room */
848 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
850 scr_printf("%s\n", buf);
854 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
855 if (strlen(new_room_name) == 0) {
858 for (a = 0; a < strlen(new_room_name); ++a) {
859 if (new_room_name[a] == '|') {
860 new_room_name[a] = '_';
864 new_room_floor = select_floor(ipc, (int) curr_floor);
866 IFNEXPERT formout(ipc, "roomaccess");
868 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
869 "<3>Passworded room\n<4>Invitation-only room\n"
871 "Enter room type: ");
874 } while (((b < '1') || (b > '5')) && (b != '?'));
877 formout(ipc, "roomaccess");
879 } while ((b < '1') || (b > '5'));
880 b -= '0'; /* Portable */
881 scr_printf("%d\n", b);
882 new_room_type = b - 1;
883 if (new_room_type == 2) {
884 newprompt("Enter a room password: ", new_room_pass, 9);
885 for (a = 0; a < strlen(new_room_pass); ++a)
886 if (new_room_pass[a] == '|')
887 new_room_pass[a] = '_';
889 strcpy(new_room_pass, "");
892 scr_printf("\042%s\042, a", new_room_name);
894 scr_printf(" public room.");
896 scr_printf(" guess-name room.");
898 scr_printf(" passworded room, password: %s", new_room_pass);
900 scr_printf("n invitation-only room.");
902 scr_printf(" personal room.");
903 scr_printf("\nInstall it? (y/n) : ");
908 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
909 new_room_pass, new_room_floor, buf);
911 scr_printf("%s\n", buf);
915 /* command succeeded... now GO to the new room! */
916 dotgoto(ipc, new_room_name, 0, 0);
921 void readinfo(CtdlIPC *ipc)
922 { /* read info file for current room */
925 int r; /* IPC response code */
928 /* Name of currernt room aide */
929 r = CtdlIPCGetRoomAide(ipc, buf);
931 safestrncpy(raide, buf, sizeof raide);
935 if (strlen(raide) > 0)
936 scr_printf("Room aide is %s.\n\n", raide);
938 r = CtdlIPCRoomInfo(ipc, &text, buf);
943 fmout(screenwidth, NULL, text, NULL,
944 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
945 (*raide) ? 2 : 0, 1);
952 * <W>ho knows room...
954 void whoknows(CtdlIPC *ipc)
957 char *listing = NULL;
960 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
962 pprintf("%s\n", buf);
965 while (strlen(listing) > 0) {
966 extract_token(buf, listing, 0, '\n');
967 remove_token(listing, 0, '\n');
969 pprintf("%s\n", buf);
975 void do_edit(CtdlIPC *ipc,
976 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
980 int b, cksum, editor_exit;
982 if (strlen(editor_path) == 0) {
983 scr_printf("Do you wish to re-enter %s? ", desc);
988 fp = fopen(temp, "w");
991 CtdlIPC_putline(ipc, check_cmd);
992 CtdlIPC_getline(ipc, cmd);
994 scr_printf("%s\n", &cmd[4]);
998 if (strlen(editor_path) > 0) {
999 CtdlIPC_putline(ipc, read_cmd);
1000 CtdlIPC_getline(ipc, cmd);
1001 if (cmd[0] == '1') {
1002 fp = fopen(temp, "w");
1003 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1004 fprintf(fp, "%s\n", cmd);
1010 cksum = file_checksum(temp);
1012 if (strlen(editor_path) > 0) {
1015 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1018 sttybbs(SB_RESTORE);
1019 editor_pid = fork();
1020 if (editor_pid == 0) {
1022 execlp(editor_path, editor_path, temp, NULL);
1028 b = ka_wait(&editor_exit);
1029 } while ((b != editor_pid) && (b >= 0));
1031 scr_printf("Executed %s\n", editor_path);
1035 scr_printf("Entering %s. "
1036 "Press return twice when finished.\n", desc);
1037 fp = fopen(temp, "r+");
1042 if (file_checksum(temp) == cksum) {
1043 scr_printf("*** Aborted.\n");
1047 CtdlIPC_putline(ipc, write_cmd);
1048 CtdlIPC_getline(ipc, cmd);
1049 if (cmd[0] != '4') {
1050 scr_printf("%s\n", &cmd[4]);
1054 fp = fopen(temp, "r");
1055 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1056 cmd[strlen(cmd) - 1] = 0;
1057 CtdlIPC_putline(ipc, cmd);
1060 CtdlIPC_putline(ipc, "000");
1067 void enterinfo(CtdlIPC *ipc)
1068 { /* edit info file for current room */
1069 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1072 void enter_bio(CtdlIPC *ipc)
1075 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1076 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1080 * create a new floor
1082 void create_floor(CtdlIPC *ipc)
1085 char newfloorname[SIZ];
1086 int r; /* IPC response code */
1088 load_floorlist(ipc);
1090 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1092 scr_printf("%s\n", buf);
1096 newprompt("Name for new floor: ", newfloorname, 255);
1097 if (!*newprompt) return;
1098 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1100 scr_printf("Floor has been created.\n");
1102 scr_printf("%s\n", buf);
1105 load_floorlist(ipc);
1109 * edit the current floor
1111 void edit_floor(CtdlIPC *ipc)
1114 struct ExpirePolicy *ep = NULL;
1115 int r; /* IPC response code */
1117 load_floorlist(ipc);
1119 /* Fetch the expire policy (this will silently fail on old servers,
1120 * resulting in "default" policy)
1122 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1124 /* Interact with the user */
1125 scr_printf("You are editing the floor called \"%s\"\n",
1126 &floorlist[(int) curr_floor][0] );
1127 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1129 /* Angels and demons dancing in my head... */
1131 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1133 ("Floor default message expire policy (? for list)",
1135 if (buf[0] == '?') {
1137 "0. Use the system default\n"
1138 "1. Never automatically expire messages\n"
1139 "2. Expire by message count\n"
1140 "3. Expire by message age\n");
1142 } while ((buf[0] < '0') || (buf[0] > '3'));
1143 ep->expire_mode = buf[0] - '0';
1145 /* ...lunatics and monsters underneath my bed */
1146 if (ep->expire_mode == 2) {
1147 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1148 strprompt("Keep how many messages online?", buf, 10);
1149 ep->expire_value = atol(buf);
1152 if (ep->expire_mode == 3) {
1153 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1154 strprompt("Keep messages for how many days?", buf, 10);
1155 ep->expire_value = atol(buf);
1159 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1160 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1161 scr_printf("%s\n", buf);
1162 load_floorlist(ipc);
1169 * kill the current floor
1171 void kill_floor(CtdlIPC *ipc)
1173 int floornum_to_delete, a;
1176 load_floorlist(ipc);
1178 floornum_to_delete = (-1);
1179 scr_printf("(Press return to abort)\n");
1180 newprompt("Delete which floor? ", buf, 255);
1181 if (strlen(buf) == 0)
1183 for (a = 0; a < 128; ++a)
1184 if (!strcasecmp(&floorlist[a][0], buf))
1185 floornum_to_delete = a;
1186 if (floornum_to_delete < 0) {
1187 scr_printf("No such floor. Select one of:\n");
1188 for (a = 0; a < 128; ++a)
1189 if (floorlist[a][0] != 0)
1190 scr_printf("%s\n", &floorlist[a][0]);
1192 } while (floornum_to_delete < 0);
1193 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1194 scr_printf("%s\n", buf);
1195 load_floorlist(ipc);