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, or a specified room
562 void dotungoto(CtdlIPC *ipc, char *towhere)
564 /* Find this 'towhere' room in the list ungoto from this room to
565 that at the messagepointer position in that room in our ungoto list.
566 I suppose I could be a real dick and just ungoto that many places
571 struct ctdlipcroom *rret = NULL; /* ignored */
576 scr_printf("No rooms to ungoto.\n");
581 scr_printf("Must specify a room to ungoto.\n");
584 if (strlen(towhere) == 0)
586 scr_printf("Must specify a room to ungoto.\n");
589 for (lp = uglistsize-1; lp >= 0; lp--)
591 if (strcasecmp(towhere, uglist[lp]) == 0)
599 scr_printf("Room: %s not in ungoto list.\n", towhere);
603 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
604 if (rret) free(rret); /* ignored */
606 scr_printf("%s\n", buf);
609 r = CtdlIPCSetLastRead(ipc, uglistlsn[found], buf);
611 scr_printf("%s\n", buf);
613 safestrncpy(buf, uglist[found], sizeof(buf));
614 /* we queue ungoto information here, because we're not really
615 ungotoing, we're really going to a random spot in some arbitrary
617 dotgoto(ipc, buf, 0, 0);
620 void ungoto(CtdlIPC *ipc)
623 struct ctdlipcroom *rret = NULL; /* ignored */
629 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
630 if (rret) free(rret); /* ignored */
632 scr_printf("%s\n", buf);
635 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1], buf);
637 scr_printf("%s\n", buf);
639 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
641 free(uglist[uglistsize]);
642 /* Don't queue ungoto info or we end up in a loop */
643 dotgoto(ipc, buf, 0, 1);
648 * saves filelen bytes from file at pathname
650 int save_buffer(void *file, size_t filelen, const char *pathname)
653 size_t bytes_written = 0;
656 fp = fopen(pathname, "w");
658 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
662 block = fwrite(file + bytes_written, 1,
663 filelen - bytes_written, fp);
664 bytes_written += block;
665 } while (errno == EINTR && bytes_written < filelen);
668 if (bytes_written < filelen) {
669 err_printf("Trouble saving '%s': %s\n", pathname,
678 * Save supplied_filename in dest directory; gets the name only
680 void destination_directory(char *dest, const char *supplied_filename)
682 scr_printf("Enter the name of the directory to save '%s'\n"
683 "to, or press return for the current directory.\n",
685 newprompt("Directory: ", dest, PATH_MAX);
686 if (strlen(dest) == 0) {
691 strcat(dest, supplied_filename);
696 * download() - download a file or files. The argument passed to this
697 * function determines which protocol to use.
698 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
700 void download(CtdlIPC *ipc, int proto)
703 char filename[PATH_MAX];
704 char tempname[PATH_MAX];
705 char transmit_cmd[SIZ];
709 void *file = NULL; /* The downloaded file */
710 size_t filelen = 0L; /* The downloaded file length */
712 if ((room_flags & QR_DOWNLOAD) == 0) {
713 scr_printf("*** You cannot download from this room.\n");
717 newprompt("Enter filename: ", filename, PATH_MAX);
719 /* Save to local disk, for folks with their own copy of the client */
721 destination_directory(tempname, filename);
722 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
724 scr_printf("%s\n", buf);
727 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
732 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
734 scr_printf("%s\n", buf);
737 filelen = extract_unsigned_long(buf, 0);
739 /* Meta-download for public clients */
740 /* scr_printf("Fetching file from Citadel server...\n"); */
741 mkdir(tempdir, 0700);
742 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
743 tpipe = fopen(tempname, "wb");
744 if (fwrite(file, filelen, 1, tpipe) < filelen) {
745 /* FIXME: restart syscall on EINTR */
749 if (file) free(file);
752 /* FIXME: display internally instead */
753 snprintf(transmit_cmd, sizeof transmit_cmd,
754 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
758 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
760 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
762 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
764 /* FIXME: display internally instead */
765 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
769 system(transmit_cmd);
773 /* clean up the temporary directory */
775 ctdl_beep(); /* Beep beep! */
780 * read directory of this room
782 void roomdir(CtdlIPC *ipc)
789 CtdlIPC_putline(ipc, "RDIR");
790 CtdlIPC_getline(ipc, buf);
792 pprintf("%s\n", &buf[4]);
796 extract(comment, &buf[4], 0);
797 extract(flnm, &buf[4], 1);
798 pprintf("\nDirectory of %s on %s\n", flnm, comment);
799 pprintf("-----------------------\n");
800 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
801 extract(flnm, buf, 0);
802 extract(flsz, buf, 1);
803 extract(comment, buf, 2);
804 if (strlen(flnm) <= 14)
805 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
807 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
814 * add a user to a private room
816 void invite(CtdlIPC *ipc)
818 char username[USERNAME_SIZE];
820 int r; /* IPC response code */
822 newprompt("Name of user? ", username, USERNAME_SIZE);
823 if (username[0] == 0)
826 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
827 scr_printf("%s\n", buf);
832 * kick a user out of a room
834 void kickout(CtdlIPC *ipc)
836 char username[USERNAME_SIZE];
838 int r; /* IPC response code */
840 newprompt("Name of user? ", username, USERNAME_SIZE);
841 if (username[0] == 0)
844 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
845 scr_printf("%s\n", buf);
850 * aide command: kill the current room
852 void killroom(CtdlIPC *ipc)
857 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
859 scr_printf("%s\n", aaa);
863 scr_printf("Are you sure you want to kill this room? ");
867 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
868 scr_printf("%s\n", aaa);
871 dotgoto(ipc, "_BASEROOM_", 0, 0);
874 void forget(CtdlIPC *ipc)
875 { /* forget the current room */
878 scr_printf("Are you sure you want to forget this room? ");
882 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
883 scr_printf("%s\n", buf);
887 /* now return to the lobby */
888 dotgoto(ipc, "_BASEROOM_", 0, 0);
895 void entroom(CtdlIPC *ipc)
898 char new_room_name[ROOMNAMELEN];
900 char new_room_pass[10];
903 int r; /* IPC response code */
905 /* Check permission to create room */
906 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
908 scr_printf("%s\n", buf);
912 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
913 if (strlen(new_room_name) == 0) {
916 for (a = 0; a < strlen(new_room_name); ++a) {
917 if (new_room_name[a] == '|') {
918 new_room_name[a] = '_';
922 new_room_floor = select_floor(ipc, (int) curr_floor);
924 IFNEXPERT formout(ipc, "roomaccess");
926 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
927 "<3>Passworded room\n<4>Invitation-only room\n"
929 "Enter room type: ");
932 } while (((b < '1') || (b > '5')) && (b != '?'));
935 formout(ipc, "roomaccess");
937 } while ((b < '1') || (b > '5'));
938 b -= '0'; /* Portable */
939 scr_printf("%d\n", b);
940 new_room_type = b - 1;
941 if (new_room_type == 2) {
942 newprompt("Enter a room password: ", new_room_pass, 9);
943 for (a = 0; a < strlen(new_room_pass); ++a)
944 if (new_room_pass[a] == '|')
945 new_room_pass[a] = '_';
947 strcpy(new_room_pass, "");
950 scr_printf("\042%s\042, a", new_room_name);
952 scr_printf(" public room.");
954 scr_printf(" guess-name room.");
956 scr_printf(" passworded room, password: %s", new_room_pass);
958 scr_printf("n invitation-only room.");
960 scr_printf(" personal room.");
961 scr_printf("\nInstall it? (y/n) : ");
966 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
967 new_room_pass, new_room_floor, buf);
969 scr_printf("%s\n", buf);
973 /* command succeeded... now GO to the new room! */
974 dotgoto(ipc, new_room_name, 0, 0);
979 void readinfo(CtdlIPC *ipc)
980 { /* read info file for current room */
983 int r; /* IPC response code */
986 /* Name of currernt room aide */
987 r = CtdlIPCGetRoomAide(ipc, buf);
989 safestrncpy(raide, buf, sizeof raide);
993 if (strlen(raide) > 0)
994 scr_printf("Room aide is %s.\n\n", raide);
996 r = CtdlIPCRoomInfo(ipc, &text, buf);
1001 fmout(screenwidth, NULL, text, NULL,
1002 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1003 (*raide) ? 2 : 0, 1);
1010 * <W>ho knows room...
1012 void whoknows(CtdlIPC *ipc)
1015 char *listing = NULL;
1018 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1020 pprintf("%s\n", buf);
1023 while (strlen(listing) > 0) {
1024 extract_token(buf, listing, 0, '\n');
1025 remove_token(listing, 0, '\n');
1027 pprintf("%s\n", buf);
1033 void do_edit(CtdlIPC *ipc,
1034 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1038 int b, cksum, editor_exit;
1040 if (strlen(editor_path) == 0) {
1041 scr_printf("Do you wish to re-enter %s? ", desc);
1046 fp = fopen(temp, "w");
1049 CtdlIPC_putline(ipc, check_cmd);
1050 CtdlIPC_getline(ipc, cmd);
1051 if (cmd[0] != '2') {
1052 scr_printf("%s\n", &cmd[4]);
1056 if (strlen(editor_path) > 0) {
1057 CtdlIPC_putline(ipc, read_cmd);
1058 CtdlIPC_getline(ipc, cmd);
1059 if (cmd[0] == '1') {
1060 fp = fopen(temp, "w");
1061 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1062 fprintf(fp, "%s\n", cmd);
1068 cksum = file_checksum(temp);
1070 if (strlen(editor_path) > 0) {
1073 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1076 sttybbs(SB_RESTORE);
1077 editor_pid = fork();
1078 if (editor_pid == 0) {
1080 execlp(editor_path, editor_path, temp, NULL);
1086 b = ka_wait(&editor_exit);
1087 } while ((b != editor_pid) && (b >= 0));
1089 scr_printf("Executed %s\n", editor_path);
1093 scr_printf("Entering %s. "
1094 "Press return twice when finished.\n", desc);
1095 fp = fopen(temp, "r+");
1100 if (file_checksum(temp) == cksum) {
1101 scr_printf("*** Aborted.\n");
1105 CtdlIPC_putline(ipc, write_cmd);
1106 CtdlIPC_getline(ipc, cmd);
1107 if (cmd[0] != '4') {
1108 scr_printf("%s\n", &cmd[4]);
1112 fp = fopen(temp, "r");
1113 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1114 cmd[strlen(cmd) - 1] = 0;
1115 CtdlIPC_putline(ipc, cmd);
1118 CtdlIPC_putline(ipc, "000");
1125 void enterinfo(CtdlIPC *ipc)
1126 { /* edit info file for current room */
1127 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1130 void enter_bio(CtdlIPC *ipc)
1133 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1134 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1138 * create a new floor
1140 void create_floor(CtdlIPC *ipc)
1143 char newfloorname[SIZ];
1144 int r; /* IPC response code */
1146 load_floorlist(ipc);
1148 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1150 scr_printf("%s\n", buf);
1154 newprompt("Name for new floor: ", newfloorname, 255);
1155 if (!*newprompt) return;
1156 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1158 scr_printf("Floor has been created.\n");
1160 scr_printf("%s\n", buf);
1163 load_floorlist(ipc);
1167 * edit the current floor
1169 void edit_floor(CtdlIPC *ipc)
1172 struct ExpirePolicy *ep = NULL;
1173 int r; /* IPC response code */
1175 load_floorlist(ipc);
1177 /* Fetch the expire policy (this will silently fail on old servers,
1178 * resulting in "default" policy)
1180 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1182 /* Interact with the user */
1183 scr_printf("You are editing the floor called \"%s\"\n",
1184 &floorlist[(int) curr_floor][0] );
1185 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1187 /* Angels and demons dancing in my head... */
1189 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1191 ("Floor default message expire policy (? for list)",
1193 if (buf[0] == '?') {
1195 "0. Use the system default\n"
1196 "1. Never automatically expire messages\n"
1197 "2. Expire by message count\n"
1198 "3. Expire by message age\n");
1200 } while ((buf[0] < '0') || (buf[0] > '3'));
1201 ep->expire_mode = buf[0] - '0';
1203 /* ...lunatics and monsters underneath my bed */
1204 if (ep->expire_mode == 2) {
1205 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1206 strprompt("Keep how many messages online?", buf, 10);
1207 ep->expire_value = atol(buf);
1210 if (ep->expire_mode == 3) {
1211 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1212 strprompt("Keep messages for how many days?", buf, 10);
1213 ep->expire_value = atol(buf);
1217 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1218 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1219 scr_printf("%s\n", buf);
1220 load_floorlist(ipc);
1227 * kill the current floor
1229 void kill_floor(CtdlIPC *ipc)
1231 int floornum_to_delete, a;
1234 load_floorlist(ipc);
1236 floornum_to_delete = (-1);
1237 scr_printf("(Press return to abort)\n");
1238 newprompt("Delete which floor? ", buf, 255);
1239 if (strlen(buf) == 0)
1241 for (a = 0; a < 128; ++a)
1242 if (!strcasecmp(&floorlist[a][0], buf))
1243 floornum_to_delete = a;
1244 if (floornum_to_delete < 0) {
1245 scr_printf("No such floor. Select one of:\n");
1246 for (a = 0; a < 128; ++a)
1247 if (floorlist[a][0] != 0)
1248 scr_printf("%s\n", &floorlist[a][0]);
1250 } while (floornum_to_delete < 0);
1251 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1252 scr_printf("%s\n", buf);
1253 load_floorlist(ipc);