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);
601 /* Here's the code for simply transferring the file to the client,
602 * for folks who have their own clientware. It's a lot simpler than
603 * the [XYZ]modem code below...
604 * (This function assumes that a download file is already open on the server)
606 void download_to_local_disk(CtdlIPC *ipc,
607 char *supplied_filename, long total_bytes)
611 long transmitted_bytes = 0L;
618 strcpy(filename, supplied_filename);
619 if (strlen(filename) == 0) {
620 newprompt("Filename: ", filename, 250);
623 scr_printf("Enter the name of the directory to save '%s'\n"
624 "to, or press return for the current directory.\n", filename);
625 newprompt("Directory: ", dbuf, sizeof dbuf);
626 if (strlen(dbuf) == 0)
629 strcat(dbuf, filename);
631 savefp = fopen(dbuf, "w");
632 if (savefp == NULL) {
633 scr_printf("Cannot open '%s': %s\n", dbuf, strerror(errno));
634 /* close the download file at the server */
635 CtdlIPC_putline(ipc, "CLOS");
636 CtdlIPC_getline(ipc, buf);
638 scr_printf("%s\n", &buf[4]);
642 progress(0, total_bytes);
643 while ((transmitted_bytes < total_bytes) && (broken == 0)) {
644 bb = total_bytes - transmitted_bytes;
645 aa = ((bb < 4096) ? bb : 4096);
646 snprintf(buf, sizeof buf, "READ %ld|%ld", transmitted_bytes, aa);
647 CtdlIPC_putline(ipc, buf);
648 CtdlIPC_getline(ipc, buf);
650 scr_printf("%s\n", &buf[4]);
653 packet = extract_int(&buf[4], 0);
654 serv_read(ipc, dbuf, packet);
655 if (fwrite(dbuf, packet, 1, savefp) < 1)
657 transmitted_bytes = transmitted_bytes + (long) packet;
658 progress(transmitted_bytes, total_bytes);
661 /* close the download file at the server */
662 CtdlIPC_putline(ipc, "CLOS");
663 CtdlIPC_getline(ipc, buf);
665 scr_printf("%s\n", &buf[4]);
672 * download() - download a file or files. The argument passed to this
673 * function determines which protocol to use.
674 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
676 void download(CtdlIPC *ipc, int proto)
681 char transmit_cmd[SIZ];
682 long total_bytes = 0L;
684 long transmitted_bytes = 0L;
690 if ((room_flags & QR_DOWNLOAD) == 0) {
691 scr_printf("*** You cannot download from this room.\n");
695 newprompt("Enter filename: ", filename, 255);
697 snprintf(buf, sizeof buf, "OPEN %s", filename);
698 CtdlIPC_putline(ipc, buf);
699 CtdlIPC_getline(ipc, buf);
701 scr_printf("%s\n", &buf[4]);
704 total_bytes = extract_long(&buf[4], 0);
706 /* Save to local disk, for folks with their own copy of the client */
708 download_to_local_disk(ipc, filename, total_bytes);
712 /* Meta-download for public clients */
713 scr_printf("Fetching file from Citadel server...\n");
714 mkdir(tempdir, 0700);
715 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
716 tpipe = fopen(tempname, "wb");
717 while ((transmitted_bytes < total_bytes) && (broken == 0)) {
718 progress(transmitted_bytes, total_bytes);
719 bb = total_bytes - transmitted_bytes;
720 aa = ((bb < 4096) ? bb : 4096);
721 snprintf(buf, sizeof buf, "READ %ld|%ld", transmitted_bytes, aa);
722 CtdlIPC_putline(ipc, buf);
723 CtdlIPC_getline(ipc, buf);
725 scr_printf("%s\n", &buf[4]);
727 packet = extract_int(&buf[4], 0);
728 serv_read(ipc, dbuf, packet);
729 if (fwrite(dbuf, packet, 1, tpipe) < 1) {
732 transmitted_bytes = transmitted_bytes + (long) packet;
735 progress(transmitted_bytes, total_bytes);
737 /* close the download file at the server */
738 CtdlIPC_putline(ipc, "CLOS");
739 CtdlIPC_getline(ipc, buf);
741 scr_printf("%s\n", &buf[4]);
745 snprintf(transmit_cmd, sizeof transmit_cmd,
746 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
750 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
752 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
754 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
756 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
760 system(transmit_cmd);
764 /* clean up the temporary directory */
771 * read directory of this room
773 void roomdir(CtdlIPC *ipc)
780 CtdlIPC_putline(ipc, "RDIR");
781 CtdlIPC_getline(ipc, buf);
783 pprintf("%s\n", &buf[4]);
787 extract(comment, &buf[4], 0);
788 extract(flnm, &buf[4], 1);
789 pprintf("\nDirectory of %s on %s\n", flnm, comment);
790 pprintf("-----------------------\n");
791 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
792 extract(flnm, buf, 0);
793 extract(flsz, buf, 1);
794 extract(comment, buf, 2);
795 if (strlen(flnm) <= 14)
796 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
798 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
805 * add a user to a private room
807 void invite(CtdlIPC *ipc)
809 char username[USERNAME_SIZE];
811 int r; /* IPC response code */
813 newprompt("Name of user? ", username, USERNAME_SIZE);
814 if (username[0] == 0)
817 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
818 scr_printf("%s\n", buf);
823 * kick a user out of a room
825 void kickout(CtdlIPC *ipc)
827 char username[USERNAME_SIZE];
829 int r; /* IPC response code */
831 newprompt("Name of user? ", username, USERNAME_SIZE);
832 if (username[0] == 0)
835 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
836 scr_printf("%s\n", buf);
841 * aide command: kill the current room
843 void killroom(CtdlIPC *ipc)
848 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
850 scr_printf("%s\n", aaa);
854 scr_printf("Are you sure you want to kill this room? ");
858 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
859 scr_printf("%s\n", aaa);
862 dotgoto(ipc, "_BASEROOM_", 0, 0);
865 void forget(CtdlIPC *ipc)
866 { /* forget the current room */
869 scr_printf("Are you sure you want to forget this room? ");
873 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
874 scr_printf("%s\n", buf);
878 /* now return to the lobby */
879 dotgoto(ipc, "_BASEROOM_", 0, 0);
886 void entroom(CtdlIPC *ipc)
889 char new_room_name[ROOMNAMELEN];
891 char new_room_pass[10];
894 int r; /* IPC response code */
896 /* Check permission to create room */
897 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
899 scr_printf("%s\n", buf);
903 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
904 if (strlen(new_room_name) == 0) {
907 for (a = 0; a < strlen(new_room_name); ++a) {
908 if (new_room_name[a] == '|') {
909 new_room_name[a] = '_';
913 new_room_floor = select_floor(ipc, (int) curr_floor);
915 IFNEXPERT formout(ipc, "roomaccess");
917 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
918 "<3>Passworded room\n<4>Invitation-only room\n"
920 "Enter room type: ");
923 } while (((b < '1') || (b > '5')) && (b != '?'));
926 formout(ipc, "roomaccess");
928 } while ((b < '1') || (b > '5'));
929 b -= '0'; /* Portable */
930 scr_printf("%d\n", b);
931 new_room_type = b - 1;
932 if (new_room_type == 2) {
933 newprompt("Enter a room password: ", new_room_pass, 9);
934 for (a = 0; a < strlen(new_room_pass); ++a)
935 if (new_room_pass[a] == '|')
936 new_room_pass[a] = '_';
938 strcpy(new_room_pass, "");
941 scr_printf("\042%s\042, a", new_room_name);
943 scr_printf(" public room.");
945 scr_printf(" guess-name room.");
947 scr_printf(" passworded room, password: %s", new_room_pass);
949 scr_printf("n invitation-only room.");
951 scr_printf(" personal room.");
952 scr_printf("\nInstall it? (y/n) : ");
957 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
958 new_room_pass, new_room_floor, buf);
960 scr_printf("%s\n", buf);
964 /* command succeeded... now GO to the new room! */
965 dotgoto(ipc, new_room_name, 0, 0);
970 void readinfo(CtdlIPC *ipc)
971 { /* read info file for current room */
974 int r; /* IPC response code */
977 /* Name of currernt room aide */
978 r = CtdlIPCGetRoomAide(ipc, buf);
980 safestrncpy(raide, buf, sizeof raide);
984 if (strlen(raide) > 0)
985 scr_printf("Room aide is %s.\n\n", raide);
987 r = CtdlIPCRoomInfo(ipc, &text, buf);
992 fmout(screenwidth, NULL, text, NULL,
993 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
994 (*raide) ? 2 : 0, 1);
1001 * <W>ho knows room...
1003 void whoknows(CtdlIPC *ipc)
1006 CtdlIPC_putline(ipc, "WHOK");
1007 CtdlIPC_getline(ipc, buf);
1008 if (buf[0] != '1') {
1009 pprintf("%s\n", &buf[4]);
1012 while (CtdlIPC_getline(ipc, buf), strncmp(buf, "000", 3)) {
1014 pprintf("%s\n", buf);
1019 void do_edit(CtdlIPC *ipc,
1020 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1024 int b, cksum, editor_exit;
1027 if (strlen(editor_path) == 0) {
1028 scr_printf("Do you wish to re-enter %s? ", desc);
1033 fp = fopen(temp, "w");
1036 CtdlIPC_putline(ipc, check_cmd);
1037 CtdlIPC_getline(ipc, cmd);
1038 if (cmd[0] != '2') {
1039 scr_printf("%s\n", &cmd[4]);
1043 if (strlen(editor_path) > 0) {
1044 CtdlIPC_putline(ipc, read_cmd);
1045 CtdlIPC_getline(ipc, cmd);
1046 if (cmd[0] == '1') {
1047 fp = fopen(temp, "w");
1048 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1049 fprintf(fp, "%s\n", cmd);
1055 cksum = file_checksum(temp);
1057 if (strlen(editor_path) > 0) {
1060 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1062 editor_pid = fork();
1063 if (editor_pid == 0) {
1066 sttybbs(SB_RESTORE);
1067 execlp(editor_path, editor_path, temp, NULL);
1073 b = wait(&editor_exit);
1074 } while ((b != editor_pid) && (b >= 0));
1076 scr_printf("Executed %s\n", editor_path);
1080 scr_printf("Entering %s. "
1081 "Press return twice when finished.\n", desc);
1082 fp = fopen(temp, "r+");
1087 if (file_checksum(temp) == cksum) {
1088 scr_printf("*** Aborted.\n");
1092 CtdlIPC_putline(ipc, write_cmd);
1093 CtdlIPC_getline(ipc, cmd);
1094 if (cmd[0] != '4') {
1095 scr_printf("%s\n", &cmd[4]);
1099 fp = fopen(temp, "r");
1100 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1101 cmd[strlen(cmd) - 1] = 0;
1102 CtdlIPC_putline(ipc, cmd);
1105 CtdlIPC_putline(ipc, "000");
1112 void enterinfo(CtdlIPC *ipc)
1113 { /* edit info file for current room */
1114 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1117 void enter_bio(CtdlIPC *ipc)
1120 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1121 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1125 * create a new floor
1127 void create_floor(CtdlIPC *ipc)
1130 char newfloorname[SIZ];
1131 int r; /* IPC response code */
1133 load_floorlist(ipc);
1135 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1137 scr_printf("%s\n", buf);
1141 newprompt("Name for new floor: ", newfloorname, 255);
1142 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1144 scr_printf("Floor has been created.\n");
1146 scr_printf("%s\n", buf);
1149 load_floorlist(ipc);
1153 * edit the current floor
1155 void edit_floor(CtdlIPC *ipc)
1158 int expire_mode = 0;
1159 int expire_value = 0;
1160 int r; /* IPC response code */
1162 load_floorlist(ipc);
1164 /* Fetch the expire policy (this will silently fail on old servers,
1165 * resulting in "default" policy)
1167 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, buf);
1169 expire_mode = extract_int(buf, 0);
1170 expire_value = extract_int(buf, 1);
1173 /* Interact with the user */
1174 scr_printf("You are editing the floor called \"%s\"\n",
1175 &floorlist[(int) curr_floor][0] );
1176 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1178 /* Angels and demons dancing in my head... */
1180 snprintf(buf, sizeof buf, "%d", expire_mode);
1182 ("Floor default message expire policy (? for list)",
1184 if (buf[0] == '?') {
1186 "0. Use the system default\n"
1187 "1. Never automatically expire messages\n"
1188 "2. Expire by message count\n"
1189 "3. Expire by message age\n");
1191 } while ((buf[0] < '0') || (buf[0] > '3'));
1192 expire_mode = buf[0] - '0';
1194 /* ...lunatics and monsters underneath my bed */
1195 if (expire_mode == 2) {
1196 snprintf(buf, sizeof buf, "%d", expire_value);
1197 strprompt("Keep how many messages online?", buf, 10);
1198 expire_value = atol(buf);
1201 if (expire_mode == 3) {
1202 snprintf(buf, sizeof buf, "%d", expire_value);
1203 strprompt("Keep messages for how many days?", buf, 10);
1204 expire_value = atol(buf);
1208 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, expire_mode,
1210 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1211 scr_printf("%s\n", buf);
1212 load_floorlist(ipc);
1219 * kill the current floor
1221 void kill_floor(CtdlIPC *ipc)
1223 int floornum_to_delete, a;
1226 load_floorlist(ipc);
1228 floornum_to_delete = (-1);
1229 scr_printf("(Press return to abort)\n");
1230 newprompt("Delete which floor? ", buf, 255);
1231 if (strlen(buf) == 0)
1233 for (a = 0; a < 128; ++a)
1234 if (!strcasecmp(&floorlist[a][0], buf))
1235 floornum_to_delete = a;
1236 if (floornum_to_delete < 0) {
1237 scr_printf("No such floor. Select one of:\n");
1238 for (a = 0; a < 128; ++a)
1239 if (floorlist[a][0] != 0)
1240 scr_printf("%s\n", &floorlist[a][0]);
1242 } while (floornum_to_delete < 0);
1243 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1244 scr_printf("%s\n", buf);
1245 load_floorlist(ipc);