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 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)
380 char raide[USERNAME_SIZE];
382 struct quickroom *attr = NULL;
383 struct ExpirePolicy *eptr = NULL;
384 int r; /* IPC response code */
386 /* Fetch the existing room config */
387 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
389 scr_printf("%s\n", buf);
392 eptr = &(attr->QRep);
394 /* Fetch the name of the current room aide */
395 r = CtdlIPCGetRoomAide(ipc, buf);
397 safestrncpy(raide, buf, sizeof raide);
401 if (strlen(raide) == 0) {
402 strcpy(raide, "none");
405 /* Fetch the expire policy (this will silently fail on old servers,
406 * resulting in "default" policy)
408 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
410 /* Now interact with the user. */
412 attr->QRfloor = select_floor(ipc, attr->QRfloor);
413 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
414 if (attr->QRflags & QR_PRIVATE) {
415 attr->QRflags = set_room_attr(ipc, attr->QRflags,
416 "Accessible by guessing room name",
420 /* if it's public, clear the privacy classes */
421 if ((attr->QRflags & QR_PRIVATE) == 0) {
422 if (attr->QRflags & QR_GUESSNAME) {
423 attr->QRflags = attr->QRflags - QR_GUESSNAME;
425 if (attr->QRflags & QR_PASSWORDED) {
426 attr->QRflags = attr->QRflags - QR_PASSWORDED;
430 /* if it's private, choose the privacy classes */
431 if ((attr->QRflags & QR_PRIVATE)
432 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
433 attr->QRflags = set_room_attr(ipc, attr->QRflags,
434 "Accessible by entering a password",
437 if ((attr->QRflags & QR_PRIVATE)
438 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
439 strprompt("Room password", attr->QRpasswd, 9);
442 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
443 rbump = boolprompt("Cause current users to forget room", 0);
446 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Preferred users only", QR_PREFONLY);
447 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Read-only room", QR_READONLY);
448 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Directory room", QR_DIRECTORY);
449 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Permanent room", QR_PERMANENT);
450 if (attr->QRflags & QR_DIRECTORY) {
451 strprompt("Directory name", attr->QRdirname, 14);
453 set_room_attr(ipc, attr->QRflags, "Uploading allowed", QR_UPLOAD);
455 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
458 set_room_attr(ipc, attr->QRflags, "Visible directory", QR_VISDIR);
460 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Network shared room", QR_NETWORK);
461 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
462 "Self-service list subscribe/unsubscribe",
464 attr->QRflags = set_room_attr(ipc, attr->QRflags,
465 "Automatically make all messages anonymous",
467 if ((attr->QRflags & QR_ANONONLY) == 0) {
468 attr->QRflags = set_room_attr(ipc, attr->QRflags,
469 "Ask users whether to make messages anonymous",
472 attr->QRorder = intprompt("Listing order", attr->QRorder, 1, 127);
474 /* Ask about the room aide */
476 strprompt("Room aide (or 'none')", raide, 29);
477 if (!strcasecmp(raide, "none")) {
481 r = CtdlIPCQueryUsername(ipc, raide, buf);
483 scr_printf("%s\n", buf);
485 } while (r / 100 != 2);
487 /* FIXME: Duplicate code??? */
488 if (!strcasecmp(raide, "none")) {
492 /* Angels and demons dancing in my head... */
494 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
495 strprompt("Message expire policy (? for list)", buf, 1);
498 "0. Use the default for this floor\n"
499 "1. Never automatically expire messages\n"
500 "2. Expire by message count\n"
501 "3. Expire by message age\n");
503 } while ((buf[0] < 48) || (buf[0] > 51));
504 attr->QRep.expire_mode = buf[0] - 48;
506 /* ...lunatics and monsters underneath my bed */
507 if (attr->QRep.expire_mode == 2) {
508 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
509 strprompt("Keep how many messages online?", buf, 10);
510 attr->QRep.expire_value = atol(buf);
513 if (attr->QRep.expire_mode == 3) {
514 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
515 strprompt("Keep messages for how many days?", buf, 10);
516 attr->QRep.expire_value = atol(buf);
519 /* Give 'em a chance to change their minds */
520 scr_printf("Save changes (y/n)? ");
523 r = CtdlIPCSetRoomAide(ipc, raide, buf);
525 scr_printf("%s\n", buf);
528 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
530 scr_printf("%s\n", buf);
533 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
534 scr_printf("%s\n", buf);
535 strncpy(buf, attr->QRname, ROOMNAMELEN);
538 dotgoto(ipc, buf, 2, 0);
545 * un-goto the previous room
547 void ungoto(CtdlIPC *ipc)
554 snprintf(buf, sizeof buf, "GOTO %s", uglist[uglistsize-1]);
555 CtdlIPC_putline(ipc, buf);
556 CtdlIPC_getline(ipc, buf);
558 scr_printf("%s\n", &buf[4]);
561 snprintf(buf, sizeof buf, "SLRP %ld", uglistlsn[uglistsize-1]);
562 CtdlIPC_putline(ipc, buf);
563 CtdlIPC_getline(ipc, buf);
565 scr_printf("%s\n", &buf[4]);
567 safestrncpy (buf, uglist[uglistsize-1], sizeof(buf));
569 free(uglist[uglistsize]);
570 /* Don't queue ungoto info or we end up in a loop */
571 dotgoto(ipc, buf, 0, 1);
576 * saves filelen bytes from file at pathname
578 int save_buffer(void *file, size_t filelen, const char *pathname)
581 size_t bytes_written = 0;
584 fp = fopen(pathname, "w");
586 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
590 block = fwrite(file + bytes_written, 1,
591 filelen - bytes_written, fp);
592 bytes_written += block;
593 } while (errno == EINTR && bytes_written < filelen);
596 if (bytes_written < filelen) {
597 err_printf("Trouble saving '%s': %s\n", pathname,
606 * Save supplied_filename in dest directory; gets the name only
608 void destination_directory(char *dest, const char *supplied_filename)
610 scr_printf("Enter the name of the directory to save '%s'\n"
611 "to, or press return for the current directory.\n",
613 newprompt("Directory: ", dest, PATH_MAX);
614 if (strlen(dest) == 0) {
619 strcat(dest, supplied_filename);
624 * download() - download a file or files. The argument passed to this
625 * function determines which protocol to use.
626 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
628 void download(CtdlIPC *ipc, int proto)
631 char filename[PATH_MAX];
632 char tempname[PATH_MAX];
633 char transmit_cmd[SIZ];
637 void *file = NULL; /* The downloaded file */
638 size_t filelen = 0L; /* The downloaded file length */
640 if ((room_flags & QR_DOWNLOAD) == 0) {
641 scr_printf("*** You cannot download from this room.\n");
645 newprompt("Enter filename: ", filename, PATH_MAX);
647 /* Save to local disk, for folks with their own copy of the client */
649 destination_directory(tempname, filename);
650 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
652 scr_printf("%s\n", buf);
655 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
660 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
662 scr_printf("%s\n", buf);
665 filelen = extract_unsigned_long(buf, 0);
667 /* Meta-download for public clients */
668 /* scr_printf("Fetching file from Citadel server...\n"); */
669 mkdir(tempdir, 0700);
670 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
671 tpipe = fopen(tempname, "wb");
672 if (fwrite(file, filelen, 1, tpipe) < filelen) {
673 /* FIXME: restart syscall on EINTR */
677 if (file) free(file);
680 /* FIXME: display internally instead */
681 snprintf(transmit_cmd, sizeof transmit_cmd,
682 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
686 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
688 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
690 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
692 /* FIXME: display internally instead */
693 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
697 system(transmit_cmd);
701 /* clean up the temporary directory */
703 scr_putc(7); /* Beep beep! */
708 * read directory of this room
710 void roomdir(CtdlIPC *ipc)
717 CtdlIPC_putline(ipc, "RDIR");
718 CtdlIPC_getline(ipc, buf);
720 pprintf("%s\n", &buf[4]);
724 extract(comment, &buf[4], 0);
725 extract(flnm, &buf[4], 1);
726 pprintf("\nDirectory of %s on %s\n", flnm, comment);
727 pprintf("-----------------------\n");
728 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
729 extract(flnm, buf, 0);
730 extract(flsz, buf, 1);
731 extract(comment, buf, 2);
732 if (strlen(flnm) <= 14)
733 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
735 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
742 * add a user to a private room
744 void invite(CtdlIPC *ipc)
746 char username[USERNAME_SIZE];
748 int r; /* IPC response code */
750 newprompt("Name of user? ", username, USERNAME_SIZE);
751 if (username[0] == 0)
754 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
755 scr_printf("%s\n", buf);
760 * kick a user out of a room
762 void kickout(CtdlIPC *ipc)
764 char username[USERNAME_SIZE];
766 int r; /* IPC response code */
768 newprompt("Name of user? ", username, USERNAME_SIZE);
769 if (username[0] == 0)
772 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
773 scr_printf("%s\n", buf);
778 * aide command: kill the current room
780 void killroom(CtdlIPC *ipc)
785 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
787 scr_printf("%s\n", aaa);
791 scr_printf("Are you sure you want to kill this room? ");
795 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
796 scr_printf("%s\n", aaa);
799 dotgoto(ipc, "_BASEROOM_", 0, 0);
802 void forget(CtdlIPC *ipc)
803 { /* forget the current room */
806 scr_printf("Are you sure you want to forget this room? ");
810 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
811 scr_printf("%s\n", buf);
815 /* now return to the lobby */
816 dotgoto(ipc, "_BASEROOM_", 0, 0);
823 void entroom(CtdlIPC *ipc)
826 char new_room_name[ROOMNAMELEN];
828 char new_room_pass[10];
831 int r; /* IPC response code */
833 /* Check permission to create room */
834 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
836 scr_printf("%s\n", buf);
840 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
841 if (strlen(new_room_name) == 0) {
844 for (a = 0; a < strlen(new_room_name); ++a) {
845 if (new_room_name[a] == '|') {
846 new_room_name[a] = '_';
850 new_room_floor = select_floor(ipc, (int) curr_floor);
852 IFNEXPERT formout(ipc, "roomaccess");
854 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
855 "<3>Passworded room\n<4>Invitation-only room\n"
857 "Enter room type: ");
860 } while (((b < '1') || (b > '5')) && (b != '?'));
863 formout(ipc, "roomaccess");
865 } while ((b < '1') || (b > '5'));
866 b -= '0'; /* Portable */
867 scr_printf("%d\n", b);
868 new_room_type = b - 1;
869 if (new_room_type == 2) {
870 newprompt("Enter a room password: ", new_room_pass, 9);
871 for (a = 0; a < strlen(new_room_pass); ++a)
872 if (new_room_pass[a] == '|')
873 new_room_pass[a] = '_';
875 strcpy(new_room_pass, "");
878 scr_printf("\042%s\042, a", new_room_name);
880 scr_printf(" public room.");
882 scr_printf(" guess-name room.");
884 scr_printf(" passworded room, password: %s", new_room_pass);
886 scr_printf("n invitation-only room.");
888 scr_printf(" personal room.");
889 scr_printf("\nInstall it? (y/n) : ");
894 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
895 new_room_pass, new_room_floor, buf);
897 scr_printf("%s\n", buf);
901 /* command succeeded... now GO to the new room! */
902 dotgoto(ipc, new_room_name, 0, 0);
907 void readinfo(CtdlIPC *ipc)
908 { /* read info file for current room */
911 int r; /* IPC response code */
914 /* Name of currernt room aide */
915 r = CtdlIPCGetRoomAide(ipc, buf);
917 safestrncpy(raide, buf, sizeof raide);
921 if (strlen(raide) > 0)
922 scr_printf("Room aide is %s.\n\n", raide);
924 r = CtdlIPCRoomInfo(ipc, &text, buf);
929 fmout(screenwidth, NULL, text, NULL,
930 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
931 (*raide) ? 2 : 0, 1);
938 * <W>ho knows room...
940 void whoknows(CtdlIPC *ipc)
943 CtdlIPC_putline(ipc, "WHOK");
944 CtdlIPC_getline(ipc, buf);
946 pprintf("%s\n", &buf[4]);
949 while (CtdlIPC_getline(ipc, buf), strncmp(buf, "000", 3)) {
951 pprintf("%s\n", buf);
956 void do_edit(CtdlIPC *ipc,
957 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
961 int b, cksum, editor_exit;
964 if (strlen(editor_path) == 0) {
965 scr_printf("Do you wish to re-enter %s? ", desc);
970 fp = fopen(temp, "w");
973 CtdlIPC_putline(ipc, check_cmd);
974 CtdlIPC_getline(ipc, cmd);
976 scr_printf("%s\n", &cmd[4]);
980 if (strlen(editor_path) > 0) {
981 CtdlIPC_putline(ipc, read_cmd);
982 CtdlIPC_getline(ipc, cmd);
984 fp = fopen(temp, "w");
985 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
986 fprintf(fp, "%s\n", cmd);
992 cksum = file_checksum(temp);
994 if (strlen(editor_path) > 0) {
997 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1000 if (editor_pid == 0) {
1003 sttybbs(SB_RESTORE);
1004 execlp(editor_path, editor_path, temp, NULL);
1010 b = wait(&editor_exit);
1011 } while ((b != editor_pid) && (b >= 0));
1013 scr_printf("Executed %s\n", editor_path);
1017 scr_printf("Entering %s. "
1018 "Press return twice when finished.\n", desc);
1019 fp = fopen(temp, "r+");
1024 if (file_checksum(temp) == cksum) {
1025 scr_printf("*** Aborted.\n");
1029 CtdlIPC_putline(ipc, write_cmd);
1030 CtdlIPC_getline(ipc, cmd);
1031 if (cmd[0] != '4') {
1032 scr_printf("%s\n", &cmd[4]);
1036 fp = fopen(temp, "r");
1037 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1038 cmd[strlen(cmd) - 1] = 0;
1039 CtdlIPC_putline(ipc, cmd);
1042 CtdlIPC_putline(ipc, "000");
1049 void enterinfo(CtdlIPC *ipc)
1050 { /* edit info file for current room */
1051 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1054 void enter_bio(CtdlIPC *ipc)
1057 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1058 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1062 * create a new floor
1064 void create_floor(CtdlIPC *ipc)
1067 char newfloorname[SIZ];
1068 int r; /* IPC response code */
1070 load_floorlist(ipc);
1072 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1074 scr_printf("%s\n", buf);
1078 newprompt("Name for new floor: ", newfloorname, 255);
1079 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1081 scr_printf("Floor has been created.\n");
1083 scr_printf("%s\n", buf);
1086 load_floorlist(ipc);
1090 * edit the current floor
1092 void edit_floor(CtdlIPC *ipc)
1095 struct ExpirePolicy *ep = NULL;
1096 int r; /* IPC response code */
1098 load_floorlist(ipc);
1100 /* Fetch the expire policy (this will silently fail on old servers,
1101 * resulting in "default" policy)
1103 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1105 /* Interact with the user */
1106 scr_printf("You are editing the floor called \"%s\"\n",
1107 &floorlist[(int) curr_floor][0] );
1108 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1110 /* Angels and demons dancing in my head... */
1112 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1114 ("Floor default message expire policy (? for list)",
1116 if (buf[0] == '?') {
1118 "0. Use the system default\n"
1119 "1. Never automatically expire messages\n"
1120 "2. Expire by message count\n"
1121 "3. Expire by message age\n");
1123 } while ((buf[0] < '0') || (buf[0] > '3'));
1124 ep->expire_mode = buf[0] - '0';
1126 /* ...lunatics and monsters underneath my bed */
1127 if (ep->expire_mode == 2) {
1128 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1129 strprompt("Keep how many messages online?", buf, 10);
1130 ep->expire_value = atol(buf);
1133 if (ep->expire_mode == 3) {
1134 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1135 strprompt("Keep messages for how many days?", buf, 10);
1136 ep->expire_value = atol(buf);
1140 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1141 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1142 scr_printf("%s\n", buf);
1143 load_floorlist(ipc);
1150 * kill the current floor
1152 void kill_floor(CtdlIPC *ipc)
1154 int floornum_to_delete, a;
1157 load_floorlist(ipc);
1159 floornum_to_delete = (-1);
1160 scr_printf("(Press return to abort)\n");
1161 newprompt("Delete which floor? ", buf, 255);
1162 if (strlen(buf) == 0)
1164 for (a = 0; a < 128; ++a)
1165 if (!strcasecmp(&floorlist[a][0], buf))
1166 floornum_to_delete = a;
1167 if (floornum_to_delete < 0) {
1168 scr_printf("No such floor. Select one of:\n");
1169 for (a = 0; a < 128; ++a)
1170 if (floorlist[a][0] != 0)
1171 scr_printf("%s\n", &floorlist[a][0]);
1173 } while (floornum_to_delete < 0);
1174 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1175 scr_printf("%s\n", buf);
1176 load_floorlist(ipc);