4 * Client-side functions which perform room operations
6 * Copyright (c) 1987-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
36 #include <libcitadel.h>
38 #include "citadel_ipc.h"
39 #include "citadel_decls.h"
47 #include "citadel_dirs.h"
49 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
52 void stty_ctdl(int cmd);
53 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
54 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
55 int pattern(char *search, char *patn);
56 int file_checksum(char *filename);
57 int nukedir(char *dirname);
59 extern unsigned room_flags;
60 extern char room_name[];
62 extern char tempdir[];
63 extern int editor_pid;
64 extern int screenwidth;
65 extern int screenheight;
66 extern char fullname[];
67 extern char sigcaught;
68 extern char floor_mode;
69 extern char curr_floor;
74 extern char *uglist[];
75 extern long uglistlsn[];
76 extern int uglistsize;
78 extern char floorlist[128][SIZ];
81 void load_floorlist(CtdlIPC *ipc)
86 int r; /* IPC response code */
88 for (a = 0; a < 128; ++a)
91 r = CtdlIPCFloorListing(ipc, &listing, buf);
93 strcpy(floorlist[0], "Main Floor");
96 while (*listing && !IsEmptyStr(listing)) {
97 extract_token(buf, listing, 0, '\n', sizeof buf);
98 remove_token(listing, 0, '\n');
99 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
105 void room_tree_list(struct ctdlroomlisting *rp)
108 char rmname[ROOMNAMELEN];
116 if (rp->lnext != NULL) {
117 room_tree_list(rp->lnext);
120 if (sigcaught == 0) {
121 strcpy(rmname, rp->rlname);
123 if ((c + strlen(rmname) + 4) > screenwidth) {
125 /* line break, check the paginator */
129 if (f & QR_MAILBOX) {
130 color(BRIGHT_YELLOW);
131 } else if (f & QR_PRIVATE) {
136 pprintf("%s", rmname);
137 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
139 else if (f & QR_DIRECTORY)
141 else if (f & QR_NETWORK)
145 c = c + strlen(rmname) + 3;
148 if (rp->rnext != NULL) {
149 room_tree_list(rp->rnext);
157 * Room ordering stuff (compare first by floor, then by order)
159 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
161 if ((r1 == NULL) && (r2 == NULL))
167 if (r1->rlfloor < r2->rlfloor)
169 if (r1->rlfloor > r2->rlfloor)
171 if (r1->rlorder < r2->rlorder)
173 if (r1->rlorder > r2->rlorder)
180 * Common code for all room listings
182 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
185 struct ctdlroomlisting *rl = NULL;
186 struct ctdlroomlisting *rp;
187 struct ctdlroomlisting *rs;
190 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
193 if ( (new_only == LISTRMS_NEW_ONLY)
194 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
197 if ( (new_only == LISTRMS_OLD_ONLY)
198 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
201 if ( (floor_only >= 0)
202 && (mptr->march_floor != floor_only))
205 if (flags && (mptr->march_flags & flags) == 0)
208 if (match && (pattern(mptr->march_name, match) == -1))
212 rp = malloc(sizeof(struct ctdlroomlisting));
213 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
214 rp->rlflags = mptr->march_flags;
215 rp->rlfloor = mptr->march_floor;
216 rp->rlorder = mptr->march_order;
225 if (rordercmp(rp, rs) < 0) {
226 if (rs->lnext == NULL) {
233 if (rs->rnext == NULL) {
245 room_tree_list(NULL);
251 void list_other_floors(void)
256 for (a = 0; a < 128; ++a) {
257 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
258 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
262 pprintf("%s: ", floorlist[a]);
263 c = c + strlen(floorlist[a]) + 3;
270 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
271 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
273 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
276 struct march *listing = NULL;
278 int r; /* IPC response code */
282 /* Ask the server for a room list */
283 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
291 if (kn_floor_mode == 0) {
293 pprintf("\n Rooms with unread messages:\n");
294 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
296 pprintf("\n\n No unseen messages in:\n");
297 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
301 if (kn_floor_mode == 1) {
303 pprintf("\n Rooms with unread messages on %s:\n",
304 floorlist[(int) curr_floor]);
305 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
307 pprintf("\n\n Rooms with no new messages on %s:\n",
308 floorlist[(int) curr_floor]);
309 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
311 pprintf("\n\n Other floors:\n");
316 if (kn_floor_mode == 2) {
317 for (a = 0; a < 128; ++a) {
318 if (floorlist[a][0] != 0) {
320 pprintf("\n Rooms on %s:\n",
322 listrms(listing, LISTRMS_ALL, a, 0, NULL);
328 /* Free the room list */
330 mptr = listing->next;
336 IFNEXPERT hit_any_key(ipc);
340 void listzrooms(CtdlIPC *ipc)
341 { /* list public forgotten rooms */
342 struct march *listing = NULL;
344 int r; /* IPC response code */
348 /* Ask the server for a room list */
349 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
355 pprintf("\n Forgotten public rooms:\n");
356 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
359 /* Free the room list */
361 mptr = listing->next;
367 IFNEXPERT hit_any_key(ipc);
370 void dotknown(CtdlIPC *ipc, int what, char *match)
371 { /* list rooms according to attribute */
372 struct march *listing = NULL;
374 int r; /* IPC response code */
377 /* Ask the server for a room list */
378 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
387 pprintf("\n Anonymous rooms:\n");
388 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
392 pprintf("\n Directory rooms:\n");
393 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
397 pprintf("\n Matching \"%s\" rooms:\n", match);
398 listrms(listing, LISTRMS_ALL, -1, 0, match);
402 pprintf("\n Preferred only rooms:\n");
403 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
407 pprintf("\n Private rooms:\n");
408 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
412 pprintf("\n Read only rooms:\n");
413 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
417 pprintf("\n Shared rooms:\n");
418 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
423 /* Free the room list */
425 mptr = listing->next;
431 IFNEXPERT hit_any_key(ipc);
435 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
439 a = boolprompt(prompt, (ibuf & sbit));
440 ibuf = (ibuf | sbit);
442 ibuf = (ibuf ^ sbit);
450 * Select a floor (used in several commands)
451 * The supplied argument is the 'default' floor number.
452 * This function returns the selected floor number.
454 int select_floor(CtdlIPC *ipc, int rfloor)
459 if (floor_mode == 1) {
460 if (floorlist[(int) curr_floor][0] == 0) {
466 safestrncpy(floorstr, floorlist[rfloor],
468 strprompt("Which floor", floorstr, 255);
469 for (a = 0; a < 128; ++a) {
471 (floorstr, &floorlist[a][0]))
476 (floorstr, &floorlist[a][0],
480 && (pattern(&floorlist[a][0], floorstr)
485 scr_printf("\n One of:\n");
486 for (a = 0; a < 128; ++a) {
487 if (floorlist[a][0] != 0) {
493 } while (newfloor < 0);
498 scr_printf("Floor selection bypassed because you have "
499 "floor mode disabled.\n");
509 * .<A>ide <E>dit room
511 void editthisroom(CtdlIPC *ipc)
514 char raide[USERNAME_SIZE];
516 struct ctdlroom *attr = NULL;
517 struct ExpirePolicy *eptr = NULL;
518 int r; /* IPC response code */
520 /* Fetch the existing room config */
521 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
523 scr_printf("%s\n", buf);
526 eptr = &(attr->QRep);
528 /* Fetch the name of the current room aide */
529 r = CtdlIPCGetRoomAide(ipc, buf);
531 safestrncpy(raide, buf, sizeof raide);
535 if (IsEmptyStr(raide)) {
536 strcpy(raide, "none");
539 /* Fetch the expire policy (this will silently fail on old servers,
540 * resulting in "default" policy)
542 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
544 /* Now interact with the user. */
546 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
547 attr->QRfloor = select_floor(ipc, attr->QRfloor);
548 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
549 if (attr->QRflags & QR_PRIVATE) {
550 attr->QRflags = set_room_attr(ipc, attr->QRflags,
551 "Hidden room (accessible to anyone who knows the room name)",
555 /* if it's public, clear the privacy classes */
556 if ((attr->QRflags & QR_PRIVATE) == 0) {
557 if (attr->QRflags & QR_GUESSNAME) {
558 attr->QRflags = attr->QRflags - QR_GUESSNAME;
560 if (attr->QRflags & QR_PASSWORDED) {
561 attr->QRflags = attr->QRflags - QR_PASSWORDED;
565 /* if it's private, choose the privacy classes */
566 if ((attr->QRflags & QR_PRIVATE)
567 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
568 attr->QRflags = set_room_attr(ipc, attr->QRflags,
569 "Accessible by entering a password",
572 if ((attr->QRflags & QR_PRIVATE)
573 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
574 strprompt("Room password", attr->QRpasswd, 9);
577 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
578 rbump = boolprompt("Cause current users to forget room", 0);
581 attr->QRflags = set_room_attr(ipc, attr->QRflags,
582 "Preferred users only", QR_PREFONLY);
583 attr->QRflags = set_room_attr(ipc, attr->QRflags,
584 "Read-only room", QR_READONLY);
585 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
586 "Allow message deletion by anyone who can post",
588 attr->QRflags = set_room_attr(ipc, attr->QRflags,
589 "Permanent room", QR_PERMANENT);
590 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
591 "Subject Required (Force "
592 "users to specify a message "
593 "subject)", QR2_SUBJECTREQ);
594 attr->QRflags = set_room_attr(ipc, attr->QRflags,
595 "Directory room", QR_DIRECTORY);
596 if (attr->QRflags & QR_DIRECTORY) {
597 strprompt("Directory name", attr->QRdirname, 14);
599 set_room_attr(ipc, attr->QRflags,
600 "Uploading allowed", QR_UPLOAD);
602 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
605 set_room_attr(ipc, attr->QRflags,
606 "Visible directory", QR_VISDIR);
608 attr->QRflags = set_room_attr(ipc, attr->QRflags,
609 "Network shared room", QR_NETWORK);
610 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
611 "Self-service list subscribe/unsubscribe",
613 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
614 "public posting to this room via room_roomname@yourcitadel.org",
616 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
617 "moderated mailinglist",
619 attr->QRflags = set_room_attr(ipc, attr->QRflags,
620 "Automatically make all messages anonymous",
622 if ((attr->QRflags & QR_ANONONLY) == 0) {
623 attr->QRflags = set_room_attr(ipc, attr->QRflags,
624 "Ask users whether to make messages anonymous",
627 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
629 /* Ask about the room aide */
631 strprompt("Room aide (or 'none')", raide, 29);
632 if (!strcasecmp(raide, "none")) {
636 r = CtdlIPCQueryUsername(ipc, raide, buf);
638 scr_printf("%s\n", buf);
640 } while (r / 100 != 2);
642 /* Angels and demons dancing in my head... */
644 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
645 strprompt("Message expire policy (? for list)", buf, 1);
648 "0. Use the default for this floor\n"
649 "1. Never automatically expire messages\n"
650 "2. Expire by message count\n"
651 "3. Expire by message age\n");
653 } while ((buf[0] < 48) || (buf[0] > 51));
654 attr->QRep.expire_mode = buf[0] - 48;
656 /* ...lunatics and monsters underneath my bed */
657 if (attr->QRep.expire_mode == 2) {
658 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
659 strprompt("Keep how many messages online?", buf, 10);
660 attr->QRep.expire_value = atol(buf);
663 if (attr->QRep.expire_mode == 3) {
664 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
665 strprompt("Keep messages for how many days?", buf, 10);
666 attr->QRep.expire_value = atol(buf);
669 /* Give 'em a chance to change their minds */
670 scr_printf("Save changes (y/n)? ");
673 r = CtdlIPCSetRoomAide(ipc, raide, buf);
675 scr_printf("%s\n", buf);
678 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
680 scr_printf("%s\n", buf);
683 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
684 scr_printf("%s\n", buf);
685 strncpy(buf, attr->QRname, ROOMNAMELEN);
688 dotgoto(ipc, buf, 2, 0);
695 * un-goto the previous room, or a specified room
697 void dotungoto(CtdlIPC *ipc, char *towhere)
699 /* Find this 'towhere' room in the list ungoto from this room to
700 that at the messagepointer position in that room in our ungoto list.
701 I suppose I could be a real dick and just ungoto that many places
706 struct ctdlipcroom *rret = NULL; /* ignored */
711 scr_printf("No rooms to ungoto.\n");
716 scr_printf("Must specify a room to ungoto.\n");
719 if (IsEmptyStr(towhere))
721 scr_printf("Must specify a room to ungoto.\n");
724 for (lp = uglistsize-1; lp >= 0; lp--)
726 if (strcasecmp(towhere, uglist[lp]) == 0)
734 scr_printf("Room: %s not in ungoto list.\n", towhere);
738 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
739 if (rret) free(rret); /* ignored */
741 scr_printf("%s\n", buf);
744 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
746 scr_printf("%s\n", buf);
748 safestrncpy(buf, uglist[found], sizeof(buf));
749 /* we queue ungoto information here, because we're not really
750 ungotoing, we're really going to a random spot in some arbitrary
752 dotgoto(ipc, buf, 0, 0);
755 void ungoto(CtdlIPC *ipc)
758 struct ctdlipcroom *rret = NULL; /* ignored */
764 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
765 if (rret) free(rret); /* ignored */
767 scr_printf("%s\n", buf);
770 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
772 scr_printf("%s\n", buf);
774 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
776 free(uglist[uglistsize]);
777 /* Don't queue ungoto info or we end up in a loop */
778 dotgoto(ipc, buf, 0, 1);
783 * saves filelen bytes from file at pathname
785 int save_buffer(void *file, size_t filelen, const char *pathname)
788 size_t bytes_written = 0;
791 fp = fopen(pathname, "w");
793 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
797 block = fwrite((char *)file + bytes_written, 1,
798 filelen - bytes_written, fp);
799 bytes_written += block;
800 } while (errno == EINTR && bytes_written < filelen);
803 if (bytes_written < filelen) {
804 err_printf("Trouble saving '%s': %s\n", pathname,
813 * Save supplied_filename in dest directory; gets the name only
815 void destination_directory(char *dest, const char *supplied_filename)
817 static char save_dir[SIZ] = { 0 };
819 if (IsEmptyStr(save_dir)) {
820 if (getenv("HOME") == NULL) {
821 strcpy(save_dir, ".");
824 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
825 if (access(save_dir, W_OK) != 0) {
826 sprintf(save_dir, "%s", getenv("HOME"));
827 if (access(save_dir, W_OK) != 0) {
828 sprintf(save_dir, ".");
834 sprintf(dest, "%s/%s", save_dir, supplied_filename);
835 strprompt("Save as", dest, PATH_MAX);
837 /* Remember the directory for next time */
838 strcpy(save_dir, dest);
839 if (strrchr(save_dir, '/') != NULL) {
840 strcpy(strrchr(save_dir, '/'), "");
843 strcpy(save_dir, ".");
849 * download() - download a file or files. The argument passed to this
850 * function determines which protocol to use.
851 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
853 void download(CtdlIPC *ipc, int proto)
856 char filename[PATH_MAX];
857 char tempname[PATH_MAX];
858 char transmit_cmd[SIZ];
863 void *file = NULL; /* The downloaded file */
864 size_t filelen = 0L; /* The downloaded file length */
866 if ((room_flags & QR_DOWNLOAD) == 0) {
867 scr_printf("*** You cannot download from this room.\n");
871 newprompt("Enter filename: ", filename, PATH_MAX);
873 /* Save to local disk, for folks with their own copy of the client */
875 destination_directory(tempname, filename);
876 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
878 scr_printf("%s\n", buf);
881 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
886 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
888 scr_printf("%s\n", buf);
891 filelen = extract_unsigned_long(buf, 0);
893 /* Meta-download for public clients */
894 /* scr_printf("Fetching file from Citadel server...\n"); */
895 mkdir(tempdir, 0700);
896 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
897 tpipe = fopen(tempname, "wb");
898 if (fwrite(file, filelen, 1, tpipe) < filelen) {
899 /* FIXME: restart syscall on EINTR */
903 if (file) free(file);
906 /* FIXME: display internally instead */
907 snprintf(transmit_cmd, sizeof transmit_cmd,
908 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
912 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
914 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
916 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
918 /* FIXME: display internally instead */
919 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
922 stty_ctdl(SB_RESTORE);
923 rv = system(transmit_cmd);
924 stty_ctdl(SB_NO_INTR);
927 /* clean up the temporary directory */
929 ctdl_beep(); /* Beep beep! */
934 * read directory of this room
936 void roomdir(CtdlIPC *ipc)
943 char *listing = NULL; /* Returned directory listing */
946 r = CtdlIPCReadDirectory(ipc, &listing, buf);
948 pprintf("%s\n", buf);
952 extract_token(comment, buf, 0, '|', sizeof comment);
953 extract_token(flnm, buf, 1, '|', sizeof flnm);
954 pprintf("\nDirectory of %s on %s\n", flnm, comment);
955 pprintf("-----------------------\n");
956 while (listing && *listing && !IsEmptyStr(listing)) {
957 extract_token(buf, listing, 0, '\n', sizeof buf);
958 remove_token(listing, 0, '\n');
960 extract_token(flnm, buf, 0, '|', sizeof flnm);
961 extract_token(flsz, buf, 1, '|', sizeof flsz);
962 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
963 extract_token(comment, buf, 3, '|', sizeof comment);
964 if (strlen(flnm) <= 14)
965 pprintf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
967 pprintf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
970 if (listing) free(listing);
975 * add a user to a private room
977 void invite(CtdlIPC *ipc)
979 char username[USERNAME_SIZE];
981 int r; /* IPC response code */
983 newprompt("Name of user? ", username, USERNAME_SIZE);
984 if (username[0] == 0)
987 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
988 scr_printf("%s\n", buf);
993 * kick a user out of a room
995 void kickout(CtdlIPC *ipc)
997 char username[USERNAME_SIZE];
999 int r; /* IPC response code */
1001 newprompt("Name of user? ", username, USERNAME_SIZE);
1002 if (username[0] == 0)
1005 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
1006 scr_printf("%s\n", buf);
1011 * aide command: kill the current room
1013 void killroom(CtdlIPC *ipc)
1018 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1020 scr_printf("%s\n", aaa);
1024 scr_printf("Are you sure you want to kill this room? ");
1028 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1029 scr_printf("%s\n", aaa);
1032 dotgoto(ipc, "_BASEROOM_", 0, 0);
1035 void forget(CtdlIPC *ipc)
1036 { /* forget the current room */
1039 scr_printf("Are you sure you want to forget this room? ");
1043 remove_march(room_name, 0);
1044 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1045 scr_printf("%s\n", buf);
1049 /* now return to the lobby */
1050 dotgoto(ipc, "_BASEROOM_", 0, 0);
1057 void entroom(CtdlIPC *ipc)
1060 char new_room_name[ROOMNAMELEN];
1062 char new_room_pass[10];
1065 int r; /* IPC response code */
1067 /* Check permission to create room */
1068 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1070 scr_printf("%s\n", buf);
1074 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1075 if (IsEmptyStr(new_room_name)) {
1078 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1079 if (new_room_name[a] == '|') {
1080 new_room_name[a] = '_';
1084 new_room_floor = select_floor(ipc, (int) curr_floor);
1086 IFNEXPERT formout(ipc, "roomaccess");
1088 scr_printf("<?>Help\n"
1089 "<1>Public room (shown to all users by default)\n"
1090 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1091 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1092 "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1093 "<5>Personal room (accessible to you only)\n"
1098 } while (((b < '1') || (b > '5')) && (b != '?'));
1101 formout(ipc, "roomaccess");
1103 } while ((b < '1') || (b > '5'));
1104 b -= '0'; /* Portable */
1105 scr_printf("%d\n", b);
1106 new_room_type = b - 1;
1107 if (new_room_type == 2) {
1108 newprompt("Enter a room password: ", new_room_pass, 9);
1109 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1110 if (new_room_pass[a] == '|')
1111 new_room_pass[a] = '_';
1113 strcpy(new_room_pass, "");
1116 scr_printf("\042%s\042, a", new_room_name);
1118 scr_printf(" public room.");
1120 scr_printf(" hidden room.");
1122 scr_printf(" passworded room, password: %s", new_room_pass);
1124 scr_printf("n invitation-only room.");
1126 scr_printf(" personal room.");
1127 scr_printf("\nInstall it? (y/n) : ");
1132 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1133 new_room_pass, new_room_floor, buf);
1135 scr_printf("%s\n", buf);
1139 /* command succeeded... now GO to the new room! */
1140 dotgoto(ipc, new_room_name, 0, 0);
1145 void readinfo(CtdlIPC *ipc)
1146 { /* read info file for current room */
1149 int r; /* IPC response code */
1152 /* Name of currernt room aide */
1153 r = CtdlIPCGetRoomAide(ipc, buf);
1155 safestrncpy(raide, buf, sizeof raide);
1159 if (!IsEmptyStr(raide))
1160 scr_printf("Room aide is %s.\n\n", raide);
1162 r = CtdlIPCRoomInfo(ipc, &text, buf);
1167 fmout(screenwidth, NULL, text, NULL,
1168 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1169 (*raide) ? 2 : 0, 1);
1176 * <W>ho knows room...
1178 void whoknows(CtdlIPC *ipc)
1181 char *listing = NULL;
1184 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1186 pprintf("%s\n", buf);
1189 while (!IsEmptyStr(listing)) {
1190 extract_token(buf, listing, 0, '\n', sizeof buf);
1191 remove_token(listing, 0, '\n');
1193 pprintf("%s\n", buf);
1199 void do_edit(CtdlIPC *ipc,
1200 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1204 int b, cksum, editor_exit;
1206 if (IsEmptyStr(editor_paths[0])) {
1207 scr_printf("Do you wish to re-enter %s? ", desc);
1212 fp = fopen(temp, "w");
1215 CtdlIPC_chat_send(ipc, check_cmd);
1216 CtdlIPC_chat_recv(ipc, cmd);
1217 if (cmd[0] != '2') {
1218 scr_printf("%s\n", &cmd[4]);
1222 if (!IsEmptyStr(editor_paths[0])) {
1223 CtdlIPC_chat_send(ipc, read_cmd);
1224 CtdlIPC_chat_recv(ipc, cmd);
1225 if (cmd[0] == '1') {
1226 fp = fopen(temp, "w");
1227 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1228 fprintf(fp, "%s\n", cmd);
1234 cksum = file_checksum(temp);
1236 if (!IsEmptyStr(editor_paths[0])) {
1239 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1242 stty_ctdl(SB_RESTORE);
1243 editor_pid = fork();
1244 if (editor_pid == 0) {
1246 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1252 b = ka_wait(&editor_exit);
1253 } while ((b != editor_pid) && (b >= 0));
1255 scr_printf("Executed %s\n", editor_paths[0]);
1259 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1260 fp = fopen(temp, "r+");
1265 if (file_checksum(temp) == cksum) {
1266 scr_printf("*** Aborted.\n");
1270 CtdlIPC_chat_send(ipc, write_cmd);
1271 CtdlIPC_chat_recv(ipc, cmd);
1272 if (cmd[0] != '4') {
1273 scr_printf("%s\n", &cmd[4]);
1277 fp = fopen(temp, "r");
1278 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1279 cmd[strlen(cmd) - 1] = 0;
1280 CtdlIPC_chat_send(ipc, cmd);
1283 CtdlIPC_chat_send(ipc, "000");
1290 void enterinfo(CtdlIPC *ipc)
1291 { /* edit info file for current room */
1292 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1295 void enter_bio(CtdlIPC *ipc)
1298 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1299 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1303 * create a new floor
1305 void create_floor(CtdlIPC *ipc)
1308 char newfloorname[SIZ];
1309 int r; /* IPC response code */
1311 load_floorlist(ipc);
1313 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1314 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1315 scr_printf("%s\n", buf);
1319 newprompt("Name for new floor: ", newfloorname, 255);
1320 if (!*newfloorname) return;
1321 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1323 scr_printf("Floor has been created.\n");
1325 scr_printf("%s\n", buf);
1328 load_floorlist(ipc);
1332 * edit the current floor
1334 void edit_floor(CtdlIPC *ipc)
1337 struct ExpirePolicy *ep = NULL;
1338 int r; /* IPC response code */
1340 load_floorlist(ipc);
1342 /* Fetch the expire policy (this will silently fail on old servers,
1343 * resulting in "default" policy)
1345 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1347 /* Interact with the user */
1348 scr_printf("You are editing the floor called \"%s\"\n",
1349 &floorlist[(int) curr_floor][0] );
1350 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1352 /* Angels and demons dancing in my head... */
1354 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1356 ("Floor default message expire policy (? for list)",
1358 if (buf[0] == '?') {
1360 "0. Use the system default\n"
1361 "1. Never automatically expire messages\n"
1362 "2. Expire by message count\n"
1363 "3. Expire by message age\n");
1365 } while ((buf[0] < '0') || (buf[0] > '3'));
1366 ep->expire_mode = buf[0] - '0';
1368 /* ...lunatics and monsters underneath my bed */
1369 if (ep->expire_mode == 2) {
1370 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1371 strprompt("Keep how many messages online?", buf, 10);
1372 ep->expire_value = atol(buf);
1375 if (ep->expire_mode == 3) {
1376 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1377 strprompt("Keep messages for how many days?", buf, 10);
1378 ep->expire_value = atol(buf);
1382 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1383 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1384 scr_printf("%s\n", buf);
1385 load_floorlist(ipc);
1392 * kill the current floor
1394 void kill_floor(CtdlIPC *ipc)
1396 int floornum_to_delete, a;
1399 load_floorlist(ipc);
1401 floornum_to_delete = (-1);
1402 scr_printf("(Press return to abort)\n");
1403 newprompt("Delete which floor? ", buf, 255);
1404 if (IsEmptyStr(buf))
1406 for (a = 0; a < 128; ++a)
1407 if (!strcasecmp(&floorlist[a][0], buf))
1408 floornum_to_delete = a;
1409 if (floornum_to_delete < 0) {
1410 scr_printf("No such floor. Select one of:\n");
1411 for (a = 0; a < 128; ++a)
1412 if (floorlist[a][0] != 0)
1413 scr_printf("%s\n", &floorlist[a][0]);
1415 } while (floornum_to_delete < 0);
1416 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1417 scr_printf("%s\n", buf);
1418 load_floorlist(ipc);