2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
34 #include <libcitadel.h>
36 #include "citadel_ipc.h"
37 #include "citadel_decls.h"
45 #include "citadel_dirs.h"
47 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
50 void stty_ctdl(int cmd);
51 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
52 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
53 int pattern(char *search, char *patn);
54 int file_checksum(char *filename);
55 int nukedir(char *dirname);
57 extern unsigned room_flags;
58 extern char room_name[];
60 extern char tempdir[];
61 extern int editor_pid;
62 extern int screenwidth;
63 extern int screenheight;
64 extern char fullname[];
65 extern char sigcaught;
66 extern char floor_mode;
67 extern char curr_floor;
72 extern char *uglist[];
73 extern long uglistlsn[];
74 extern int uglistsize;
76 extern char floorlist[128][SIZ];
79 void load_floorlist(CtdlIPC *ipc)
84 int r; /* IPC response code */
86 for (a = 0; a < 128; ++a)
89 r = CtdlIPCFloorListing(ipc, &listing, buf);
91 strcpy(floorlist[0], "Main Floor");
94 while (*listing && !IsEmptyStr(listing)) {
95 extract_token(buf, listing, 0, '\n', sizeof buf);
96 remove_token(listing, 0, '\n');
97 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
103 void room_tree_list(struct ctdlroomlisting *rp)
106 char rmname[ROOMNAMELEN];
114 if (rp->lnext != NULL) {
115 room_tree_list(rp->lnext);
118 if (sigcaught == 0) {
119 strcpy(rmname, rp->rlname);
121 if ((c + strlen(rmname) + 4) > screenwidth) {
123 /* line break, check the paginator */
127 if (f & QR_MAILBOX) {
128 color(BRIGHT_YELLOW);
129 } else if (f & QR_PRIVATE) {
134 pprintf("%s", rmname);
135 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
137 else if (f & QR_DIRECTORY)
139 else if (f & QR_NETWORK)
143 c = c + strlen(rmname) + 3;
146 if (rp->rnext != NULL) {
147 room_tree_list(rp->rnext);
155 * Room ordering stuff (compare first by floor, then by order)
157 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
159 if ((r1 == NULL) && (r2 == NULL))
165 if (r1->rlfloor < r2->rlfloor)
167 if (r1->rlfloor > r2->rlfloor)
169 if (r1->rlorder < r2->rlorder)
171 if (r1->rlorder > r2->rlorder)
178 * Common code for all room listings
180 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
183 struct ctdlroomlisting *rl = NULL;
184 struct ctdlroomlisting *rp;
185 struct ctdlroomlisting *rs;
188 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
191 if ( (new_only == LISTRMS_NEW_ONLY)
192 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
195 if ( (new_only == LISTRMS_OLD_ONLY)
196 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
199 if ( (floor_only >= 0)
200 && (mptr->march_floor != floor_only))
203 if (flags && (mptr->march_flags & flags) == 0)
206 if (match && (pattern(mptr->march_name, match) == -1))
210 rp = malloc(sizeof(struct ctdlroomlisting));
211 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
212 rp->rlflags = mptr->march_flags;
213 rp->rlfloor = mptr->march_floor;
214 rp->rlorder = mptr->march_order;
223 if (rordercmp(rp, rs) < 0) {
224 if (rs->lnext == NULL) {
231 if (rs->rnext == NULL) {
243 room_tree_list(NULL);
249 void list_other_floors(void)
254 for (a = 0; a < 128; ++a) {
255 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
256 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
260 pprintf("%s: ", floorlist[a]);
261 c = c + strlen(floorlist[a]) + 3;
268 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
269 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
271 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
274 struct march *listing = NULL;
276 int r; /* IPC response code */
280 /* Ask the server for a room list */
281 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
289 if (kn_floor_mode == 0) {
291 pprintf("\n Rooms with unread messages:\n");
292 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
294 pprintf("\n\n No unseen messages in:\n");
295 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
299 if (kn_floor_mode == 1) {
301 pprintf("\n Rooms with unread messages on %s:\n",
302 floorlist[(int) curr_floor]);
303 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
305 pprintf("\n\n Rooms with no new messages on %s:\n",
306 floorlist[(int) curr_floor]);
307 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
309 pprintf("\n\n Other floors:\n");
314 if (kn_floor_mode == 2) {
315 for (a = 0; a < 128; ++a) {
316 if (floorlist[a][0] != 0) {
318 pprintf("\n Rooms on %s:\n",
320 listrms(listing, LISTRMS_ALL, a, 0, NULL);
326 /* Free the room list */
328 mptr = listing->next;
334 IFNEXPERT hit_any_key(ipc);
338 void listzrooms(CtdlIPC *ipc)
339 { /* list public forgotten rooms */
340 struct march *listing = NULL;
342 int r; /* IPC response code */
346 /* Ask the server for a room list */
347 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
353 pprintf("\n Forgotten public rooms:\n");
354 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
357 /* Free the room list */
359 mptr = listing->next;
365 IFNEXPERT hit_any_key(ipc);
368 void dotknown(CtdlIPC *ipc, int what, char *match)
369 { /* list rooms according to attribute */
370 struct march *listing = NULL;
372 int r; /* IPC response code */
375 /* Ask the server for a room list */
376 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
385 pprintf("\n Anonymous rooms:\n");
386 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
390 pprintf("\n Directory rooms:\n");
391 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
395 pprintf("\n Matching \"%s\" rooms:\n", match);
396 listrms(listing, LISTRMS_ALL, -1, 0, match);
400 pprintf("\n Preferred only rooms:\n");
401 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
405 pprintf("\n Private rooms:\n");
406 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
410 pprintf("\n Read only rooms:\n");
411 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
415 pprintf("\n Shared rooms:\n");
416 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
421 /* Free the room list */
423 mptr = listing->next;
429 IFNEXPERT hit_any_key(ipc);
433 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
437 a = boolprompt(prompt, (ibuf & sbit));
438 ibuf = (ibuf | sbit);
440 ibuf = (ibuf ^ sbit);
448 * Select a floor (used in several commands)
449 * The supplied argument is the 'default' floor number.
450 * This function returns the selected floor number.
452 int select_floor(CtdlIPC *ipc, int rfloor)
457 if (floor_mode == 1) {
458 if (floorlist[(int) curr_floor][0] == 0) {
464 safestrncpy(floorstr, floorlist[rfloor],
466 strprompt("Which floor", floorstr, 255);
467 for (a = 0; a < 128; ++a) {
469 (floorstr, &floorlist[a][0]))
474 (floorstr, &floorlist[a][0],
478 && (pattern(&floorlist[a][0], floorstr)
483 scr_printf("\n One of:\n");
484 for (a = 0; a < 128; ++a) {
485 if (floorlist[a][0] != 0) {
491 } while (newfloor < 0);
496 scr_printf("Floor selection bypassed because you have "
497 "floor mode disabled.\n");
507 * .<A>ide <E>dit room
509 void editthisroom(CtdlIPC *ipc)
512 char raide[USERNAME_SIZE];
514 struct ctdlroom *attr = NULL;
515 struct ExpirePolicy *eptr = NULL;
516 int r; /* IPC response code */
518 /* Fetch the existing room config */
519 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
521 scr_printf("%s\n", buf);
524 eptr = &(attr->QRep);
526 /* Fetch the name of the current room aide */
527 r = CtdlIPCGetRoomAide(ipc, buf);
529 safestrncpy(raide, buf, sizeof raide);
533 if (IsEmptyStr(raide)) {
534 strcpy(raide, "none");
537 /* Fetch the expire policy (this will silently fail on old servers,
538 * resulting in "default" policy)
540 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
542 /* Now interact with the user. */
544 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
545 attr->QRfloor = select_floor(ipc, attr->QRfloor);
546 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
547 if (attr->QRflags & QR_PRIVATE) {
548 attr->QRflags = set_room_attr(ipc, attr->QRflags,
549 "Hidden room (accessible to anyone who knows the room name)",
553 /* if it's public, clear the privacy classes */
554 if ((attr->QRflags & QR_PRIVATE) == 0) {
555 if (attr->QRflags & QR_GUESSNAME) {
556 attr->QRflags = attr->QRflags - QR_GUESSNAME;
558 if (attr->QRflags & QR_PASSWORDED) {
559 attr->QRflags = attr->QRflags - QR_PASSWORDED;
563 /* if it's private, choose the privacy classes */
564 if ((attr->QRflags & QR_PRIVATE)
565 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
566 attr->QRflags = set_room_attr(ipc, attr->QRflags,
567 "Accessible by entering a password",
570 if ((attr->QRflags & QR_PRIVATE)
571 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
572 strprompt("Room password", attr->QRpasswd, 9);
575 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
576 rbump = boolprompt("Cause current users to forget room", 0);
579 attr->QRflags = set_room_attr(ipc, attr->QRflags,
580 "Preferred users only", QR_PREFONLY);
581 attr->QRflags = set_room_attr(ipc, attr->QRflags,
582 "Read-only room", QR_READONLY);
583 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
584 "Allow message deletion by anyone who can post",
586 attr->QRflags = set_room_attr(ipc, attr->QRflags,
587 "Permanent room", QR_PERMANENT);
588 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
589 "Subject Required (Force "
590 "users to specify a message "
591 "subject)", QR2_SUBJECTREQ);
592 attr->QRflags = set_room_attr(ipc, attr->QRflags,
593 "Directory room", QR_DIRECTORY);
594 if (attr->QRflags & QR_DIRECTORY) {
595 strprompt("Directory name", attr->QRdirname, 14);
597 set_room_attr(ipc, attr->QRflags,
598 "Uploading allowed", QR_UPLOAD);
600 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
603 set_room_attr(ipc, attr->QRflags,
604 "Visible directory", QR_VISDIR);
606 attr->QRflags = set_room_attr(ipc, attr->QRflags,
607 "Network shared room", QR_NETWORK);
608 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
609 "Self-service list subscribe/unsubscribe",
611 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
612 "public posting to this room via room_roomname@yourcitadel.org",
614 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
615 "moderated mailinglist",
617 attr->QRflags = set_room_attr(ipc, attr->QRflags,
618 "Automatically make all messages anonymous",
620 if ((attr->QRflags & QR_ANONONLY) == 0) {
621 attr->QRflags = set_room_attr(ipc, attr->QRflags,
622 "Ask users whether to make messages anonymous",
625 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
627 /* Ask about the room aide */
629 strprompt("Room aide (or 'none')", raide, 29);
630 if (!strcasecmp(raide, "none")) {
634 r = CtdlIPCQueryUsername(ipc, raide, buf);
636 scr_printf("%s\n", buf);
638 } while (r / 100 != 2);
640 /* Angels and demons dancing in my head... */
642 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
643 strprompt("Message expire policy (? for list)", buf, 1);
646 "0. Use the default for this floor\n"
647 "1. Never automatically expire messages\n"
648 "2. Expire by message count\n"
649 "3. Expire by message age\n");
651 } while ((buf[0] < 48) || (buf[0] > 51));
652 attr->QRep.expire_mode = buf[0] - 48;
654 /* ...lunatics and monsters underneath my bed */
655 if (attr->QRep.expire_mode == 2) {
656 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
657 strprompt("Keep how many messages online?", buf, 10);
658 attr->QRep.expire_value = atol(buf);
661 if (attr->QRep.expire_mode == 3) {
662 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
663 strprompt("Keep messages for how many days?", buf, 10);
664 attr->QRep.expire_value = atol(buf);
667 /* Give 'em a chance to change their minds */
668 scr_printf("Save changes (y/n)? ");
671 r = CtdlIPCSetRoomAide(ipc, raide, buf);
673 scr_printf("%s\n", buf);
676 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
678 scr_printf("%s\n", buf);
681 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
682 scr_printf("%s\n", buf);
683 strncpy(buf, attr->QRname, ROOMNAMELEN);
686 dotgoto(ipc, buf, 2, 0);
693 * un-goto the previous room, or a specified room
695 void dotungoto(CtdlIPC *ipc, char *towhere)
697 /* Find this 'towhere' room in the list ungoto from this room to
698 that at the messagepointer position in that room in our ungoto list.
699 I suppose I could be a real dick and just ungoto that many places
704 struct ctdlipcroom *rret = NULL; /* ignored */
709 scr_printf("No rooms to ungoto.\n");
714 scr_printf("Must specify a room to ungoto.\n");
717 if (IsEmptyStr(towhere))
719 scr_printf("Must specify a room to ungoto.\n");
722 for (lp = uglistsize-1; lp >= 0; lp--)
724 if (strcasecmp(towhere, uglist[lp]) == 0)
732 scr_printf("Room: %s not in ungoto list.\n", towhere);
736 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
737 if (rret) free(rret); /* ignored */
739 scr_printf("%s\n", buf);
742 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
744 scr_printf("%s\n", buf);
746 safestrncpy(buf, uglist[found], sizeof(buf));
747 /* we queue ungoto information here, because we're not really
748 ungotoing, we're really going to a random spot in some arbitrary
750 dotgoto(ipc, buf, 0, 0);
753 void ungoto(CtdlIPC *ipc)
756 struct ctdlipcroom *rret = NULL; /* ignored */
762 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
763 if (rret) free(rret); /* ignored */
765 scr_printf("%s\n", buf);
768 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
770 scr_printf("%s\n", buf);
772 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
774 free(uglist[uglistsize]);
775 /* Don't queue ungoto info or we end up in a loop */
776 dotgoto(ipc, buf, 0, 1);
781 * saves filelen bytes from file at pathname
783 int save_buffer(void *file, size_t filelen, const char *pathname)
786 size_t bytes_written = 0;
789 fp = fopen(pathname, "w");
791 err_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
795 block = fwrite((char *)file + bytes_written, 1,
796 filelen - bytes_written, fp);
797 bytes_written += block;
798 } while (errno == EINTR && bytes_written < filelen);
801 if (bytes_written < filelen) {
802 err_printf("Trouble saving '%s': %s\n", pathname,
811 * Save supplied_filename in dest directory; gets the name only
813 void destination_directory(char *dest, const char *supplied_filename)
815 static char save_dir[SIZ] = { 0 };
817 if (IsEmptyStr(save_dir)) {
818 if (getenv("HOME") == NULL) {
819 strcpy(save_dir, ".");
822 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
823 if (access(save_dir, W_OK) != 0) {
824 sprintf(save_dir, "%s", getenv("HOME"));
825 if (access(save_dir, W_OK) != 0) {
826 sprintf(save_dir, ".");
832 sprintf(dest, "%s/%s", save_dir, supplied_filename);
833 strprompt("Save as", dest, PATH_MAX);
835 /* Remember the directory for next time */
836 strcpy(save_dir, dest);
837 if (strrchr(save_dir, '/') != NULL) {
838 strcpy(strrchr(save_dir, '/'), "");
841 strcpy(save_dir, ".");
847 * download() - download a file or files. The argument passed to this
848 * function determines which protocol to use.
849 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
851 void download(CtdlIPC *ipc, int proto)
854 char filename[PATH_MAX];
855 char tempname[PATH_MAX];
856 char transmit_cmd[SIZ];
861 void *file = NULL; /* The downloaded file */
862 size_t filelen = 0L; /* The downloaded file length */
864 if ((room_flags & QR_DOWNLOAD) == 0) {
865 scr_printf("*** You cannot download from this room.\n");
869 newprompt("Enter filename: ", filename, PATH_MAX);
871 /* Save to local disk, for folks with their own copy of the client */
873 destination_directory(tempname, filename);
874 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
876 scr_printf("%s\n", buf);
879 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
884 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
886 scr_printf("%s\n", buf);
889 filelen = extract_unsigned_long(buf, 0);
891 /* Meta-download for public clients */
892 /* scr_printf("Fetching file from Citadel server...\n"); */
893 mkdir(tempdir, 0700);
894 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
895 tpipe = fopen(tempname, "wb");
896 if (fwrite(file, filelen, 1, tpipe) < filelen) {
897 /* FIXME: restart syscall on EINTR */
901 if (file) free(file);
904 /* FIXME: display internally instead */
905 snprintf(transmit_cmd, sizeof transmit_cmd,
906 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
910 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
912 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
914 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
916 /* FIXME: display internally instead */
917 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
920 stty_ctdl(SB_RESTORE);
921 rv = system(transmit_cmd);
922 stty_ctdl(SB_NO_INTR);
925 /* clean up the temporary directory */
927 ctdl_beep(); /* Beep beep! */
932 * read directory of this room
934 void roomdir(CtdlIPC *ipc)
941 char *listing = NULL; /* Returned directory listing */
944 r = CtdlIPCReadDirectory(ipc, &listing, buf);
946 pprintf("%s\n", buf);
950 extract_token(comment, buf, 0, '|', sizeof comment);
951 extract_token(flnm, buf, 1, '|', sizeof flnm);
952 pprintf("\nDirectory of %s on %s\n", flnm, comment);
953 pprintf("-----------------------\n");
954 while (listing && *listing && !IsEmptyStr(listing)) {
955 extract_token(buf, listing, 0, '\n', sizeof buf);
956 remove_token(listing, 0, '\n');
958 extract_token(flnm, buf, 0, '|', sizeof flnm);
959 extract_token(flsz, buf, 1, '|', sizeof flsz);
960 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
961 extract_token(comment, buf, 3, '|', sizeof comment);
962 if (strlen(flnm) <= 14)
963 pprintf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
965 pprintf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
968 if (listing) free(listing);
973 * add a user to a private room
975 void invite(CtdlIPC *ipc)
977 char username[USERNAME_SIZE];
979 int r; /* IPC response code */
981 newprompt("Name of user? ", username, USERNAME_SIZE);
982 if (username[0] == 0)
985 r = CtdlIPCInviteUserToRoom(ipc, username, buf);
986 scr_printf("%s\n", buf);
991 * kick a user out of a room
993 void kickout(CtdlIPC *ipc)
995 char username[USERNAME_SIZE];
997 int r; /* IPC response code */
999 newprompt("Name of user? ", username, USERNAME_SIZE);
1000 if (username[0] == 0)
1003 r = CtdlIPCKickoutUserFromRoom(ipc, username, buf);
1004 scr_printf("%s\n", buf);
1009 * aide command: kill the current room
1011 void killroom(CtdlIPC *ipc)
1016 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1018 scr_printf("%s\n", aaa);
1022 scr_printf("Are you sure you want to kill this room? ");
1026 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1027 scr_printf("%s\n", aaa);
1030 dotgoto(ipc, "_BASEROOM_", 0, 0);
1033 void forget(CtdlIPC *ipc)
1034 { /* forget the current room */
1037 scr_printf("Are you sure you want to forget this room? ");
1041 remove_march(room_name, 0);
1042 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1043 scr_printf("%s\n", buf);
1047 /* now return to the lobby */
1048 dotgoto(ipc, "_BASEROOM_", 0, 0);
1055 void entroom(CtdlIPC *ipc)
1058 char new_room_name[ROOMNAMELEN];
1060 char new_room_pass[10];
1063 int r; /* IPC response code */
1065 /* Check permission to create room */
1066 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1068 scr_printf("%s\n", buf);
1072 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1073 if (IsEmptyStr(new_room_name)) {
1076 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1077 if (new_room_name[a] == '|') {
1078 new_room_name[a] = '_';
1082 new_room_floor = select_floor(ipc, (int) curr_floor);
1084 IFNEXPERT formout(ipc, "roomaccess");
1086 scr_printf("<?>Help\n"
1087 "<1>Public room (shown to all users by default)\n"
1088 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1089 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1090 "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1091 "<5>Personal room (accessible to you only)\n"
1096 } while (((b < '1') || (b > '5')) && (b != '?'));
1099 formout(ipc, "roomaccess");
1101 } while ((b < '1') || (b > '5'));
1102 b -= '0'; /* Portable */
1103 scr_printf("%d\n", b);
1104 new_room_type = b - 1;
1105 if (new_room_type == 2) {
1106 newprompt("Enter a room password: ", new_room_pass, 9);
1107 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1108 if (new_room_pass[a] == '|')
1109 new_room_pass[a] = '_';
1111 strcpy(new_room_pass, "");
1114 scr_printf("\042%s\042, a", new_room_name);
1116 scr_printf(" public room.");
1118 scr_printf(" hidden room.");
1120 scr_printf(" passworded room, password: %s", new_room_pass);
1122 scr_printf("n invitation-only room.");
1124 scr_printf(" personal room.");
1125 scr_printf("\nInstall it? (y/n) : ");
1130 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1131 new_room_pass, new_room_floor, buf);
1133 scr_printf("%s\n", buf);
1137 /* command succeeded... now GO to the new room! */
1138 dotgoto(ipc, new_room_name, 0, 0);
1143 void readinfo(CtdlIPC *ipc)
1144 { /* read info file for current room */
1147 int r; /* IPC response code */
1150 /* Name of currernt room aide */
1151 r = CtdlIPCGetRoomAide(ipc, buf);
1153 safestrncpy(raide, buf, sizeof raide);
1157 if (!IsEmptyStr(raide))
1158 scr_printf("Room aide is %s.\n\n", raide);
1160 r = CtdlIPCRoomInfo(ipc, &text, buf);
1165 fmout(screenwidth, NULL, text, NULL,
1166 ((userflags & US_PAGINATOR) ? 1 : 0), screenheight,
1167 (*raide) ? 2 : 0, 1);
1174 * <W>ho knows room...
1176 void whoknows(CtdlIPC *ipc)
1179 char *listing = NULL;
1182 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1184 pprintf("%s\n", buf);
1187 while (!IsEmptyStr(listing)) {
1188 extract_token(buf, listing, 0, '\n', sizeof buf);
1189 remove_token(listing, 0, '\n');
1191 pprintf("%s\n", buf);
1197 void do_edit(CtdlIPC *ipc,
1198 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1202 int b, cksum, editor_exit;
1204 if (IsEmptyStr(editor_paths[0])) {
1205 scr_printf("Do you wish to re-enter %s? ", desc);
1210 fp = fopen(temp, "w");
1213 CtdlIPC_chat_send(ipc, check_cmd);
1214 CtdlIPC_chat_recv(ipc, cmd);
1215 if (cmd[0] != '2') {
1216 scr_printf("%s\n", &cmd[4]);
1220 if (!IsEmptyStr(editor_paths[0])) {
1221 CtdlIPC_chat_send(ipc, read_cmd);
1222 CtdlIPC_chat_recv(ipc, cmd);
1223 if (cmd[0] == '1') {
1224 fp = fopen(temp, "w");
1225 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1226 fprintf(fp, "%s\n", cmd);
1232 cksum = file_checksum(temp);
1234 if (!IsEmptyStr(editor_paths[0])) {
1237 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1240 stty_ctdl(SB_RESTORE);
1241 editor_pid = fork();
1242 if (editor_pid == 0) {
1244 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1250 b = ka_wait(&editor_exit);
1251 } while ((b != editor_pid) && (b >= 0));
1253 scr_printf("Executed %s\n", editor_paths[0]);
1257 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1258 fp = fopen(temp, "r+");
1263 if (file_checksum(temp) == cksum) {
1264 scr_printf("*** Aborted.\n");
1268 CtdlIPC_chat_send(ipc, write_cmd);
1269 CtdlIPC_chat_recv(ipc, cmd);
1270 if (cmd[0] != '4') {
1271 scr_printf("%s\n", &cmd[4]);
1275 fp = fopen(temp, "r");
1276 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1277 cmd[strlen(cmd) - 1] = 0;
1278 CtdlIPC_chat_send(ipc, cmd);
1281 CtdlIPC_chat_send(ipc, "000");
1288 void enterinfo(CtdlIPC *ipc)
1289 { /* edit info file for current room */
1290 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1293 void enter_bio(CtdlIPC *ipc)
1296 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1297 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1301 * create a new floor
1303 void create_floor(CtdlIPC *ipc)
1306 char newfloorname[SIZ];
1307 int r; /* IPC response code */
1309 load_floorlist(ipc);
1311 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1312 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1313 scr_printf("%s\n", buf);
1317 newprompt("Name for new floor: ", newfloorname, 255);
1318 if (!*newfloorname) return;
1319 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1321 scr_printf("Floor has been created.\n");
1323 scr_printf("%s\n", buf);
1326 load_floorlist(ipc);
1330 * edit the current floor
1332 void edit_floor(CtdlIPC *ipc)
1335 struct ExpirePolicy *ep = NULL;
1336 int r; /* IPC response code */
1338 load_floorlist(ipc);
1340 /* Fetch the expire policy (this will silently fail on old servers,
1341 * resulting in "default" policy)
1343 r = CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1345 /* Interact with the user */
1346 scr_printf("You are editing the floor called \"%s\"\n",
1347 &floorlist[(int) curr_floor][0] );
1348 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1350 /* Angels and demons dancing in my head... */
1352 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1354 ("Floor default message expire policy (? for list)",
1356 if (buf[0] == '?') {
1358 "0. Use the system default\n"
1359 "1. Never automatically expire messages\n"
1360 "2. Expire by message count\n"
1361 "3. Expire by message age\n");
1363 } while ((buf[0] < '0') || (buf[0] > '3'));
1364 ep->expire_mode = buf[0] - '0';
1366 /* ...lunatics and monsters underneath my bed */
1367 if (ep->expire_mode == 2) {
1368 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1369 strprompt("Keep how many messages online?", buf, 10);
1370 ep->expire_value = atol(buf);
1373 if (ep->expire_mode == 3) {
1374 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1375 strprompt("Keep messages for how many days?", buf, 10);
1376 ep->expire_value = atol(buf);
1380 r = CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1381 r = CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1382 scr_printf("%s\n", buf);
1383 load_floorlist(ipc);
1390 * kill the current floor
1392 void kill_floor(CtdlIPC *ipc)
1394 int floornum_to_delete, a;
1397 load_floorlist(ipc);
1399 floornum_to_delete = (-1);
1400 scr_printf("(Press return to abort)\n");
1401 newprompt("Delete which floor? ", buf, 255);
1402 if (IsEmptyStr(buf))
1404 for (a = 0; a < 128; ++a)
1405 if (!strcasecmp(&floorlist[a][0], buf))
1406 floornum_to_delete = a;
1407 if (floornum_to_delete < 0) {
1408 scr_printf("No such floor. Select one of:\n");
1409 for (a = 0; a < 128; ++a)
1410 if (floorlist[a][0] != 0)
1411 scr_printf("%s\n", &floorlist[a][0]);
1413 } while (floornum_to_delete < 0);
1414 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1415 scr_printf("%s\n", buf);
1416 load_floorlist(ipc);