5 * Client-side functions which perform room operations
17 #include <sys/types.h>
23 #include "citadel_ipc.h"
24 #include "citadel_decls.h"
33 #include "citadel_dirs.h"
35 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
38 void stty_ctdl(int cmd);
39 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
40 void progress(CtdlIPC* ipc, 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 int screenwidth;
51 extern int screenheight;
52 extern char fullname[];
53 extern char sigcaught;
54 extern char floor_mode;
55 extern char curr_floor;
60 extern char *uglist[];
61 extern long uglistlsn[];
62 extern int uglistsize;
64 extern char floorlist[128][SIZ];
67 void load_floorlist(CtdlIPC *ipc)
72 int r; /* IPC response code */
74 for (a = 0; a < 128; ++a)
77 r = CtdlIPCFloorListing(ipc, &listing, buf);
79 strcpy(floorlist[0], "Main Floor");
82 while (*listing && strlen(listing)) {
83 extract_token(buf, listing, 0, '\n', sizeof buf);
84 remove_token(listing, 0, '\n');
85 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
91 void room_tree_list(struct ctdlroomlisting *rp)
94 char rmname[ROOMNAMELEN];
102 if (rp->lnext != NULL) {
103 room_tree_list(rp->lnext);
106 if (sigcaught == 0) {
107 strcpy(rmname, rp->rlname);
109 if ((c + strlen(rmname) + 4) > screenwidth) {
111 /* line break, check the paginator */
115 if (f & QR_MAILBOX) {
116 color(BRIGHT_YELLOW);
117 } else if (f & QR_PRIVATE) {
122 pprintf("%s", rmname);
123 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
125 else if (f & QR_DIRECTORY)
127 else if (f & QR_NETWORK)
131 c = c + strlen(rmname) + 3;
134 if (rp->rnext != NULL) {
135 room_tree_list(rp->rnext);
143 * Room ordering stuff (compare first by floor, then by order)
145 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
147 if ((r1 == NULL) && (r2 == NULL))
153 if (r1->rlfloor < r2->rlfloor)
155 if (r1->rlfloor > r2->rlfloor)
157 if (r1->rlorder < r2->rlorder)
159 if (r1->rlorder > r2->rlorder)
166 * Common code for all room listings
168 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
171 struct ctdlroomlisting *rl = NULL;
172 struct ctdlroomlisting *rp;
173 struct ctdlroomlisting *rs;
176 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
179 if ( (new_only == LISTRMS_NEW_ONLY)
180 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
183 if ( (new_only == LISTRMS_OLD_ONLY)
184 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
187 if ( (floor_only >= 0)
188 && (mptr->march_floor != floor_only))
191 if (flags && (mptr->march_flags & flags) == 0)
194 if (match && (pattern(mptr->march_name, match) == -1))
198 rp = malloc(sizeof(struct ctdlroomlisting));
199 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
200 rp->rlflags = mptr->march_flags;
201 rp->rlfloor = mptr->march_floor;
202 rp->rlorder = mptr->march_order;
211 if (rordercmp(rp, rs) < 0) {
212 if (rs->lnext == NULL) {
219 if (rs->rnext == NULL) {
231 room_tree_list(NULL);
237 void list_other_floors(void)
242 for (a = 0; a < 128; ++a) {
243 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
244 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
248 pprintf("%s: ", floorlist[a]);
249 c = c + strlen(floorlist[a]) + 3;
256 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
257 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
259 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
262 struct march *listing = NULL;
264 int r; /* IPC response code */
268 /* Ask the server for a room list */
269 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
277 if (kn_floor_mode == 0) {
279 pprintf("\n Rooms with unread messages:\n");
280 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
282 pprintf("\n\n No unseen messages in:\n");
283 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
287 if (kn_floor_mode == 1) {
289 pprintf("\n Rooms with unread messages on %s:\n",
290 floorlist[(int) curr_floor]);
291 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
293 pprintf("\n\n Rooms with no new messages on %s:\n",
294 floorlist[(int) curr_floor]);
295 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
297 pprintf("\n\n Other floors:\n");
302 if (kn_floor_mode == 2) {
303 for (a = 0; a < 128; ++a) {
304 if (floorlist[a][0] != 0) {
306 pprintf("\n Rooms on %s:\n",
308 listrms(listing, LISTRMS_ALL, a, 0, NULL);
314 /* Free the room list */
316 mptr = listing->next;
322 IFNEXPERT hit_any_key(ipc);
326 void listzrooms(CtdlIPC *ipc)
327 { /* list public forgotten rooms */
328 struct march *listing = NULL;
330 int r; /* IPC response code */
334 /* Ask the server for a room list */
335 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
341 pprintf("\n Forgotten public rooms:\n");
342 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
345 /* Free the room list */
347 mptr = listing->next;
353 IFNEXPERT hit_any_key(ipc);
356 void dotknown(CtdlIPC *ipc, int what, char *match)
357 { /* list rooms according to attribute */
358 struct march *listing = NULL;
360 int r; /* IPC response code */
363 /* Ask the server for a room list */
364 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
373 pprintf("\n Anonymous rooms:\n");
374 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
378 pprintf("\n Directory rooms:\n");
379 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
383 pprintf("\n Matching \"%s\" rooms:\n", match);
384 listrms(listing, LISTRMS_ALL, -1, 0, match);
388 pprintf("\n Preferred only rooms:\n");
389 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
393 pprintf("\n Private rooms:\n");
394 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
398 pprintf("\n Read only rooms:\n");
399 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
403 pprintf("\n Shared rooms:\n");
404 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
409 /* Free the room list */
411 mptr = listing->next;
417 IFNEXPERT hit_any_key(ipc);
421 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
425 a = boolprompt(prompt, (ibuf & sbit));
426 ibuf = (ibuf | sbit);
428 ibuf = (ibuf ^ sbit);
436 * Select a floor (used in several commands)
437 * The supplied argument is the 'default' floor number.
438 * This function returns the selected floor number.
440 int select_floor(CtdlIPC *ipc, int rfloor)
445 if (floor_mode == 1) {
446 if (floorlist[(int) curr_floor][0] == 0) {
452 safestrncpy(floorstr, floorlist[rfloor],
454 strprompt("Which floor", floorstr, 255);
455 for (a = 0; a < 128; ++a) {
457 (floorstr, &floorlist[a][0]))
462 (floorstr, &floorlist[a][0],
466 && (pattern(&floorlist[a][0], floorstr)
471 scr_printf("\n One of:\n");
472 for (a = 0; a < 128; ++a) {
473 if (floorlist[a][0] != 0) {
479 } while (newfloor < 0);
484 scr_printf("Floor selection bypassed because you have "
485 "floor mode disabled.\n");
495 * .<A>ide <E>dit room
497 void editthisroom(CtdlIPC *ipc)
500 char raide[USERNAME_SIZE];
502 struct ctdlroom *attr = NULL;
503 struct ExpirePolicy *eptr = NULL;
504 int r; /* IPC response code */
506 /* Fetch the existing room config */
507 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
509 scr_printf("%s\n", buf);
512 eptr = &(attr->QRep);
514 /* Fetch the name of the current room aide */
515 r = CtdlIPCGetRoomAide(ipc, buf);
517 safestrncpy(raide, buf, sizeof raide);
521 if (strlen(raide) == 0) {
522 strcpy(raide, "none");
525 /* Fetch the expire policy (this will silently fail on old servers,
526 * resulting in "default" policy)
528 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
530 /* Now interact with the user. */
532 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
533 attr->QRfloor = select_floor(ipc, attr->QRfloor);
534 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
535 if (attr->QRflags & QR_PRIVATE) {
536 attr->QRflags = set_room_attr(ipc, attr->QRflags,
537 "Accessible by guessing room name",
541 /* if it's public, clear the privacy classes */
542 if ((attr->QRflags & QR_PRIVATE) == 0) {
543 if (attr->QRflags & QR_GUESSNAME) {
544 attr->QRflags = attr->QRflags - QR_GUESSNAME;
546 if (attr->QRflags & QR_PASSWORDED) {
547 attr->QRflags = attr->QRflags - QR_PASSWORDED;
551 /* if it's private, choose the privacy classes */
552 if ((attr->QRflags & QR_PRIVATE)
553 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
554 attr->QRflags = set_room_attr(ipc, attr->QRflags,
555 "Accessible by entering a password",
558 if ((attr->QRflags & QR_PRIVATE)
559 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
560 strprompt("Room password", attr->QRpasswd, 9);
563 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
564 rbump = boolprompt("Cause current users to forget room", 0);
567 attr->QRflags = set_room_attr(ipc, attr->QRflags,
568 "Preferred users only", QR_PREFONLY);
569 attr->QRflags = set_room_attr(ipc, attr->QRflags,
570 "Read-only room", QR_READONLY);
571 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
572 "Allow message deletion by anyone who can post",
574 attr->QRflags = set_room_attr(ipc, attr->QRflags,
575 "Permanent room", QR_PERMANENT);
576 attr->QRflags = set_room_attr(ipc, attr->QRflags,
577 "Directory room", QR_DIRECTORY);
578 if (attr->QRflags & QR_DIRECTORY) {
579 strprompt("Directory name", attr->QRdirname, 14);
581 set_room_attr(ipc, attr->QRflags,
582 "Uploading allowed", QR_UPLOAD);
584 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
587 set_room_attr(ipc, attr->QRflags,
588 "Visible directory", QR_VISDIR);
590 attr->QRflags = set_room_attr(ipc, attr->QRflags,
591 "Network shared room", QR_NETWORK);
592 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
593 "Self-service list subscribe/unsubscribe",
595 attr->QRflags = set_room_attr(ipc, attr->QRflags,
596 "Automatically make all messages anonymous",
598 if ((attr->QRflags & QR_ANONONLY) == 0) {
599 attr->QRflags = set_room_attr(ipc, attr->QRflags,
600 "Ask users whether to make messages anonymous",
603 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
605 /* Ask about the room aide */
607 strprompt("Room aide (or 'none')", raide, 29);
608 if (!strcasecmp(raide, "none")) {
612 r = CtdlIPCQueryUsername(ipc, raide, buf);
614 scr_printf("%s\n", buf);
616 } while (r / 100 != 2);
618 /* FIXME: Duplicate code??? */
619 if (!strcasecmp(raide, "none")) {
623 /* Angels and demons dancing in my head... */
625 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
626 strprompt("Message expire policy (? for list)", buf, 1);
629 "0. Use the default for this floor\n"
630 "1. Never automatically expire messages\n"
631 "2. Expire by message count\n"
632 "3. Expire by message age\n");
634 } while ((buf[0] < 48) || (buf[0] > 51));
635 attr->QRep.expire_mode = buf[0] - 48;
637 /* ...lunatics and monsters underneath my bed */
638 if (attr->QRep.expire_mode == 2) {
639 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
640 strprompt("Keep how many messages online?", buf, 10);
641 attr->QRep.expire_value = atol(buf);
644 if (attr->QRep.expire_mode == 3) {
645 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
646 strprompt("Keep messages for how many days?", buf, 10);
647 attr->QRep.expire_value = atol(buf);
650 /* Give 'em a chance to change their minds */
651 scr_printf("Save changes (y/n)? ");
654 r = CtdlIPCSetRoomAide(ipc, raide, buf);
656 scr_printf("%s\n", buf);
659 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
661 scr_printf("%s\n", buf);
664 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
665 scr_printf("%s\n", buf);
666 strncpy(buf, attr->QRname, ROOMNAMELEN);
669 dotgoto(ipc, buf, 2, 0);
676 * un-goto the previous room, or a specified room
678 void dotungoto(CtdlIPC *ipc, char *towhere)
680 /* Find this 'towhere' room in the list ungoto from this room to
681 that at the messagepointer position in that room in our ungoto list.
682 I suppose I could be a real dick and just ungoto that many places
687 struct ctdlipcroom *rret = NULL; /* ignored */
692 scr_printf("No rooms to ungoto.\n");
697 scr_printf("Must specify a room to ungoto.\n");
700 if (strlen(towhere) == 0)
702 scr_printf("Must specify a room to ungoto.\n");
705 for (lp = uglistsize-1; lp >= 0; lp--)
707 if (strcasecmp(towhere, uglist[lp]) == 0)
715 scr_printf("Room: %s not in ungoto list.\n", towhere);
719 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
720 if (rret) free(rret); /* ignored */
722 scr_printf("%s\n", buf);
725 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
727 scr_printf("%s\n", buf);
729 safestrncpy(buf, uglist[found], sizeof(buf));
730 /* we queue ungoto information here, because we're not really
731 ungotoing, we're really going to a random spot in some arbitrary
733 dotgoto(ipc, buf, 0, 0);
736 void ungoto(CtdlIPC *ipc)
739 struct ctdlipcroom *rret = NULL; /* ignored */
745 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
746 if (rret) free(rret); /* ignored */
748 scr_printf("%s\n", buf);
751 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
753 scr_printf("%s\n", buf);
755 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
757 free(uglist[uglistsize]);
758 /* Don't queue ungoto info or we end up in a loop */
759 dotgoto(ipc, buf, 0, 1);
764 * saves filelen bytes from file at pathname
766 int save_buffer(void *file, size_t filelen, const char *pathname)
769 size_t bytes_written = 0;
772 fp = fopen(pathname, "w");
774 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
778 block = fwrite((char *)file + bytes_written, 1,
779 filelen - bytes_written, fp);
780 bytes_written += block;
781 } while (errno == EINTR && bytes_written < filelen);
784 if (bytes_written < filelen) {
785 err_printf("Trouble saving '%s': %s\n", pathname,
794 * Save supplied_filename in dest directory; gets the name only
796 void destination_directory(char *dest, const char *supplied_filename)
798 static char save_dir[SIZ] = { 0 };
800 if (strlen(save_dir) == 0) {
801 if (getenv("HOME") == NULL) {
802 strcpy(save_dir, ".");
805 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
806 if (access(save_dir, W_OK) != 0) {
807 sprintf(save_dir, "%s", getenv("HOME"));
808 if (access(save_dir, W_OK) != 0) {
809 sprintf(save_dir, ".");
815 sprintf(dest, "%s/%s", save_dir, supplied_filename);
816 strprompt("Save as", dest, PATH_MAX);
818 /* Remember the directory for next time */
819 strcpy(save_dir, dest);
820 if (strrchr(save_dir, '/') != NULL) {
821 strcpy(strrchr(save_dir, '/'), "");
824 strcpy(save_dir, ".");
830 * download() - download a file or files. The argument passed to this
831 * function determines which protocol to use.
832 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
834 void download(CtdlIPC *ipc, int proto)
837 char filename[PATH_MAX];
838 char tempname[PATH_MAX];
839 char transmit_cmd[SIZ];
843 void *file = NULL; /* The downloaded file */
844 size_t filelen = 0L; /* The downloaded file length */
846 if ((room_flags & QR_DOWNLOAD) == 0) {
847 scr_printf("*** You cannot download from this room.\n");
851 newprompt("Enter filename: ", filename, PATH_MAX);
853 /* Save to local disk, for folks with their own copy of the client */
855 destination_directory(tempname, filename);
856 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
858 scr_printf("%s\n", buf);
861 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
866 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
868 scr_printf("%s\n", buf);
871 filelen = extract_unsigned_long(buf, 0);
873 /* Meta-download for public clients */
874 /* scr_printf("Fetching file from Citadel server...\n"); */
875 mkdir(tempdir, 0700);
876 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
877 tpipe = fopen(tempname, "wb");
878 if (fwrite(file, filelen, 1, tpipe) < filelen) {
879 /* FIXME: restart syscall on EINTR */
883 if (file) free(file);
886 /* FIXME: display internally instead */
887 snprintf(transmit_cmd, sizeof transmit_cmd,
888 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
892 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
894 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
896 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
898 /* FIXME: display internally instead */
899 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
902 stty_ctdl(SB_RESTORE);
903 system(transmit_cmd);
904 stty_ctdl(SB_NO_INTR);
907 /* clean up the temporary directory */
909 ctdl_beep(); /* Beep beep! */
914 * read directory of this room
916 void roomdir(CtdlIPC *ipc)
922 char *listing = NULL; /* Returned directory listing */
925 r = CtdlIPCReadDirectory(ipc, &listing, buf);
927 pprintf("%s\n", buf);
931 extract_token(comment, buf, 0, '|', sizeof comment);
932 extract_token(flnm, buf, 1, '|', sizeof flnm);
933 pprintf("\nDirectory of %s on %s\n", flnm, comment);
934 pprintf("-----------------------\n");
935 while (listing && *listing && strlen(listing)) {
936 extract_token(buf, listing, 0, '\n', sizeof buf);
937 remove_token(listing, 0, '\n');
939 extract_token(flnm, buf, 0, '|', sizeof flnm);
940 extract_token(flsz, buf, 1, '|', sizeof flsz);
941 extract_token(comment, buf, 2, '|', sizeof comment);
942 if (strlen(flnm) <= 14)
943 pprintf("%-14s %8s %s\n", flnm, flsz, comment);
945 pprintf("%s\n%14s %8s %s\n", flnm, "", flsz,
948 if (listing) free(listing);
953 * add a user to a private room
955 void invite(CtdlIPC *ipc)
957 char username[USERNAME_SIZE];
959 int r; /* IPC response code */
961 newprompt("Name of user? ", username, USERNAME_SIZE);
962 if (username[0] == 0)
965 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
966 scr_printf("%s\n", buf);
971 * kick a user out of a room
973 void kickout(CtdlIPC *ipc)
975 char username[USERNAME_SIZE];
977 int r; /* IPC response code */
979 newprompt("Name of user? ", username, USERNAME_SIZE);
980 if (username[0] == 0)
983 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
984 scr_printf("%s\n", buf);
989 * aide command: kill the current room
991 void killroom(CtdlIPC *ipc)
996 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
998 scr_printf("%s\n", aaa);
1002 scr_printf("Are you sure you want to kill this room? ");
1006 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1007 scr_printf("%s\n", aaa);
1010 dotgoto(ipc, "_BASEROOM_", 0, 0);
1013 void forget(CtdlIPC *ipc)
1014 { /* forget the current room */
1017 scr_printf("Are you sure you want to forget this room? ");
1021 remove_march(room_name, 0);
1022 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1023 scr_printf("%s\n", buf);
1027 /* now return to the lobby */
1028 dotgoto(ipc, "_BASEROOM_", 0, 0);
1035 void entroom(CtdlIPC *ipc)
1038 char new_room_name[ROOMNAMELEN];
1040 char new_room_pass[10];
1043 int r; /* IPC response code */
1045 /* Check permission to create room */
1046 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1048 scr_printf("%s\n", buf);
1052 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1053 if (strlen(new_room_name) == 0) {
1056 for (a = 0; a < strlen(new_room_name); ++a) {
1057 if (new_room_name[a] == '|') {
1058 new_room_name[a] = '_';
1062 new_room_floor = select_floor(ipc, (int) curr_floor);
1064 IFNEXPERT formout(ipc, "roomaccess");
1066 scr_printf("<?>Help\n<1>Public room\n<2>Guess-name room\n"
1067 "<3>Passworded room\n<4>Invitation-only room\n"
1068 "<5>Personal room\n"
1069 "Enter room type: ");
1072 } while (((b < '1') || (b > '5')) && (b != '?'));
1075 formout(ipc, "roomaccess");
1077 } while ((b < '1') || (b > '5'));
1078 b -= '0'; /* Portable */
1079 scr_printf("%d\n", b);
1080 new_room_type = b - 1;
1081 if (new_room_type == 2) {
1082 newprompt("Enter a room password: ", new_room_pass, 9);
1083 for (a = 0; a < strlen(new_room_pass); ++a)
1084 if (new_room_pass[a] == '|')
1085 new_room_pass[a] = '_';
1087 strcpy(new_room_pass, "");
1090 scr_printf("\042%s\042, a", new_room_name);
1092 scr_printf(" public room.");
1094 scr_printf(" guess-name room.");
1096 scr_printf(" passworded room, password: %s", new_room_pass);
1098 scr_printf("n invitation-only room.");
1100 scr_printf(" personal room.");
1101 scr_printf("\nInstall it? (y/n) : ");
1106 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1107 new_room_pass, new_room_floor, buf);
1109 scr_printf("%s\n", buf);
1113 /* command succeeded... now GO to the new room! */
1114 dotgoto(ipc, new_room_name, 0, 0);
1119 void readinfo(CtdlIPC *ipc)
1120 { /* read info file for current room */
1123 int r; /* IPC response code */
1126 /* Name of currernt room aide */
1127 r = CtdlIPCGetRoomAide(ipc, buf);
1129 safestrncpy(raide, buf, sizeof raide);
1133 if (strlen(raide) > 0)
1134 scr_printf("Room aide is %s.\n\n", raide);
1136 r = CtdlIPCRoomInfo(ipc, &text, buf);
1141 fmout(screenwidth, NULL, text, NULL,
1142 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1143 (*raide) ? 2 : 0, 1);
1150 * <W>ho knows room...
1152 void whoknows(CtdlIPC *ipc)
1155 char *listing = NULL;
1158 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1160 pprintf("%s\n", buf);
1163 while (strlen(listing) > 0) {
1164 extract_token(buf, listing, 0, '\n', sizeof buf);
1165 remove_token(listing, 0, '\n');
1167 pprintf("%s\n", buf);
1173 void do_edit(CtdlIPC *ipc,
1174 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1178 int b, cksum, editor_exit;
1180 if (strlen(editor_paths[0]) == 0) {
1181 scr_printf("Do you wish to re-enter %s? ", desc);
1186 fp = fopen(temp, "w");
1189 CtdlIPC_chat_send(ipc, check_cmd);
1190 CtdlIPC_chat_recv(ipc, cmd);
1191 if (cmd[0] != '2') {
1192 scr_printf("%s\n", &cmd[4]);
1196 if (strlen(editor_paths[0]) > 0) {
1197 CtdlIPC_chat_send(ipc, read_cmd);
1198 CtdlIPC_chat_recv(ipc, cmd);
1199 if (cmd[0] == '1') {
1200 fp = fopen(temp, "w");
1201 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1202 fprintf(fp, "%s\n", cmd);
1208 cksum = file_checksum(temp);
1210 if (strlen(editor_paths[0]) > 0) {
1213 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1216 stty_ctdl(SB_RESTORE);
1217 editor_pid = fork();
1218 if (editor_pid == 0) {
1220 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1226 b = ka_wait(&editor_exit);
1227 } while ((b != editor_pid) && (b >= 0));
1229 scr_printf("Executed %s\n", editor_paths[0]);
1233 scr_printf("Entering %s. "
1234 "Press return twice when finished.\n", desc);
1235 fp = fopen(temp, "r+");
1240 if (file_checksum(temp) == cksum) {
1241 scr_printf("*** Aborted.\n");
1245 CtdlIPC_chat_send(ipc, write_cmd);
1246 CtdlIPC_chat_recv(ipc, cmd);
1247 if (cmd[0] != '4') {
1248 scr_printf("%s\n", &cmd[4]);
1252 fp = fopen(temp, "r");
1253 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1254 cmd[strlen(cmd) - 1] = 0;
1255 CtdlIPC_chat_send(ipc, cmd);
1258 CtdlIPC_chat_send(ipc, "000");
1265 void enterinfo(CtdlIPC *ipc)
1266 { /* edit info file for current room */
1267 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1270 void enter_bio(CtdlIPC *ipc)
1273 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1274 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1278 * create a new floor
1280 void create_floor(CtdlIPC *ipc)
1283 char newfloorname[SIZ];
1284 int r; /* IPC response code */
1286 load_floorlist(ipc);
1288 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1289 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1290 scr_printf("%s\n", buf);
1294 newprompt("Name for new floor: ", newfloorname, 255);
1295 if (!*newfloorname) return;
1296 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1298 scr_printf("Floor has been created.\n");
1300 scr_printf("%s\n", buf);
1303 load_floorlist(ipc);
1307 * edit the current floor
1309 void edit_floor(CtdlIPC *ipc)
1312 struct ExpirePolicy *ep = NULL;
1313 int r; /* IPC response code */
1315 load_floorlist(ipc);
1317 /* Fetch the expire policy (this will silently fail on old servers,
1318 * resulting in "default" policy)
1320 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1322 /* Interact with the user */
1323 scr_printf("You are editing the floor called \"%s\"\n",
1324 &floorlist[(int) curr_floor][0] );
1325 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1327 /* Angels and demons dancing in my head... */
1329 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1331 ("Floor default message expire policy (? for list)",
1333 if (buf[0] == '?') {
1335 "0. Use the system default\n"
1336 "1. Never automatically expire messages\n"
1337 "2. Expire by message count\n"
1338 "3. Expire by message age\n");
1340 } while ((buf[0] < '0') || (buf[0] > '3'));
1341 ep->expire_mode = buf[0] - '0';
1343 /* ...lunatics and monsters underneath my bed */
1344 if (ep->expire_mode == 2) {
1345 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1346 strprompt("Keep how many messages online?", buf, 10);
1347 ep->expire_value = atol(buf);
1350 if (ep->expire_mode == 3) {
1351 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1352 strprompt("Keep messages for how many days?", buf, 10);
1353 ep->expire_value = atol(buf);
1357 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1358 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1359 scr_printf("%s\n", buf);
1360 load_floorlist(ipc);
1367 * kill the current floor
1369 void kill_floor(CtdlIPC *ipc)
1371 int floornum_to_delete, a;
1374 load_floorlist(ipc);
1376 floornum_to_delete = (-1);
1377 scr_printf("(Press return to abort)\n");
1378 newprompt("Delete which floor? ", buf, 255);
1379 if (strlen(buf) == 0)
1381 for (a = 0; a < 128; ++a)
1382 if (!strcasecmp(&floorlist[a][0], buf))
1383 floornum_to_delete = a;
1384 if (floornum_to_delete < 0) {
1385 scr_printf("No such floor. Select one of:\n");
1386 for (a = 0; a < 128; ++a)
1387 if (floorlist[a][0] != 0)
1388 scr_printf("%s\n", &floorlist[a][0]);
1390 } while (floornum_to_delete < 0);
1391 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1392 scr_printf("%s\n", buf);
1393 load_floorlist(ipc);