2 * Client-side functions which perform room operations
4 * Copyright (c) 1987-2012 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
23 #include <sys/types.h>
28 #include <libcitadel.h>
30 #include "citadel_ipc.h"
31 #include "citadel_decls.h"
39 #include "citadel_dirs.h"
41 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
44 void stty_ctdl(int cmd);
45 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto);
46 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
47 int pattern(char *search, char *patn);
48 int file_checksum(char *filename);
49 int nukedir(char *dirname);
51 extern unsigned room_flags;
52 extern char room_name[];
54 extern char tempdir[];
55 extern int editor_pid;
56 extern int screenwidth;
57 extern int screenheight;
58 extern char fullname[];
59 extern char sigcaught;
60 extern char floor_mode;
61 extern char curr_floor;
66 extern char *uglist[];
67 extern long uglistlsn[];
68 extern int uglistsize;
70 extern char floorlist[128][SIZ];
73 void load_floorlist(CtdlIPC *ipc)
78 int r; /* IPC response code */
80 for (a = 0; a < 128; ++a)
83 r = CtdlIPCFloorListing(ipc, &listing, buf);
85 strcpy(floorlist[0], "Main Floor");
88 while (*listing && !IsEmptyStr(listing)) {
89 extract_token(buf, listing, 0, '\n', sizeof buf);
90 remove_token(listing, 0, '\n');
91 extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', SIZ);
97 void room_tree_list(struct ctdlroomlisting *rp)
100 char rmname[ROOMNAMELEN];
108 if (rp->lnext != NULL) {
109 room_tree_list(rp->lnext);
112 if (sigcaught == 0) {
113 strcpy(rmname, rp->rlname);
115 if ((c + strlen(rmname) + 4) > screenwidth) {
117 /* line break, check the paginator */
121 if (f & QR_MAILBOX) {
122 color(BRIGHT_YELLOW);
123 } else if (f & QR_PRIVATE) {
128 scr_printf("%s", rmname);
129 if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
131 else if (f & QR_DIRECTORY)
133 else if (f & QR_NETWORK)
137 c = c + strlen(rmname) + 3;
140 if (rp->rnext != NULL) {
141 room_tree_list(rp->rnext);
149 * Room ordering stuff (compare first by floor, then by order)
151 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2)
153 if ((r1 == NULL) && (r2 == NULL))
159 if (r1->rlfloor < r2->rlfloor)
161 if (r1->rlfloor > r2->rlfloor)
163 if (r1->rlorder < r2->rlorder)
165 if (r1->rlorder > r2->rlorder)
172 * Common code for all room listings
174 static void listrms(struct march *listing, int new_only, int floor_only, unsigned int flags, char *match)
177 struct ctdlroomlisting *rl = NULL;
178 struct ctdlroomlisting *rp;
179 struct ctdlroomlisting *rs;
182 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
185 if ( (new_only == LISTRMS_NEW_ONLY)
186 && ((mptr->march_access & UA_HASNEWMSGS) == 0))
189 if ( (new_only == LISTRMS_OLD_ONLY)
190 && ((mptr->march_access & UA_HASNEWMSGS) != 0))
193 if ( (floor_only >= 0)
194 && (mptr->march_floor != floor_only))
197 if (flags && (mptr->march_flags & flags) == 0)
200 if (match && (pattern(mptr->march_name, match) == -1))
204 rp = malloc(sizeof(struct ctdlroomlisting));
205 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
206 rp->rlflags = mptr->march_flags;
207 rp->rlfloor = mptr->march_floor;
208 rp->rlorder = mptr->march_order;
217 if (rordercmp(rp, rs) < 0) {
218 if (rs->lnext == NULL) {
225 if (rs->rnext == NULL) {
237 room_tree_list(NULL);
243 void list_other_floors(void)
248 for (a = 0; a < 128; ++a) {
249 if ((strlen(floorlist[a]) > 0) && (a != curr_floor)) {
250 if ((c + strlen(floorlist[a]) + 4) > screenwidth) {
254 scr_printf("%s: ", floorlist[a]);
255 c = c + strlen(floorlist[a]) + 3;
262 * List known rooms. kn_floor_mode should be set to 0 for a 'flat' listing,
263 * 1 to list rooms on the current floor, or 2 to list rooms on all floors.
265 void knrooms(CtdlIPC *ipc, int kn_floor_mode)
268 struct march *listing = NULL;
270 int r; /* IPC response code */
274 /* Ask the server for a room list */
275 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
283 if (kn_floor_mode == 0) {
285 scr_printf("\n Rooms with unread messages:\n");
286 listrms(listing, LISTRMS_NEW_ONLY, -1, 0, NULL);
288 scr_printf("\n\n No unseen messages in:\n");
289 listrms(listing, LISTRMS_OLD_ONLY, -1, 0, NULL);
293 if (kn_floor_mode == 1) {
295 scr_printf("\n Rooms with unread messages on %s:\n",
296 floorlist[(int) curr_floor]);
297 listrms(listing, LISTRMS_NEW_ONLY, curr_floor, 0, NULL);
299 scr_printf("\n\n Rooms with no new messages on %s:\n",
300 floorlist[(int) curr_floor]);
301 listrms(listing, LISTRMS_OLD_ONLY, curr_floor, 0, NULL);
303 scr_printf("\n\n Other floors:\n");
308 if (kn_floor_mode == 2) {
309 for (a = 0; a < 128; ++a) {
310 if (floorlist[a][0] != 0) {
312 scr_printf("\n Rooms on %s:\n",
314 listrms(listing, LISTRMS_ALL, a, 0, NULL);
320 /* Free the room list */
322 mptr = listing->next;
331 void listzrooms(CtdlIPC *ipc)
332 { /* list public forgotten rooms */
333 struct march *listing = NULL;
335 int r; /* IPC response code */
339 /* Ask the server for a room list */
340 r = CtdlIPCKnownRooms(ipc, UnsubscribedRooms, (-1), &listing, buf);
346 scr_printf("\n Forgotten public rooms:\n");
347 listrms(listing, LISTRMS_ALL, -1, 0, NULL);
350 /* Free the room list */
352 mptr = listing->next;
360 void dotknown(CtdlIPC *ipc, int what, char *match)
361 { /* list rooms according to attribute */
362 struct march *listing = NULL;
364 int r; /* IPC response code */
367 /* Ask the server for a room list */
368 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, (-1), &listing, buf);
377 scr_printf("\n Anonymous rooms:\n");
378 listrms(listing, LISTRMS_ALL, -1, QR_ANONONLY|QR_ANONOPT, NULL);
382 scr_printf("\n Directory rooms:\n");
383 listrms(listing, LISTRMS_ALL, -1, QR_DIRECTORY, NULL);
387 scr_printf("\n Matching \"%s\" rooms:\n", match);
388 listrms(listing, LISTRMS_ALL, -1, 0, match);
392 scr_printf("\n Preferred only rooms:\n");
393 listrms(listing, LISTRMS_ALL, -1, QR_PREFONLY, NULL);
397 scr_printf("\n Private rooms:\n");
398 listrms(listing, LISTRMS_ALL, -1, QR_PRIVATE, NULL);
402 scr_printf("\n Read only rooms:\n");
403 listrms(listing, LISTRMS_ALL, -1, QR_READONLY, NULL);
407 scr_printf("\n Shared rooms:\n");
408 listrms(listing, LISTRMS_ALL, -1, QR_NETWORK, NULL);
413 /* Free the room list */
415 mptr = listing->next;
424 int set_room_attr(CtdlIPC *ipc, unsigned int ibuf, char *prompt, unsigned int sbit)
428 a = boolprompt(prompt, (ibuf & sbit));
429 ibuf = (ibuf | sbit);
431 ibuf = (ibuf ^ sbit);
439 * Select a floor (used in several commands)
440 * The supplied argument is the 'default' floor number.
441 * This function returns the selected floor number.
443 int select_floor(CtdlIPC *ipc, int rfloor)
448 if (floor_mode == 1) {
449 if (floorlist[(int) curr_floor][0] == 0) {
455 safestrncpy(floorstr, floorlist[rfloor],
457 strprompt("Which floor", floorstr, 255);
458 for (a = 0; a < 128; ++a) {
460 (floorstr, &floorlist[a][0]))
465 (floorstr, &floorlist[a][0],
469 && (pattern(&floorlist[a][0], floorstr)
474 scr_printf("\n One of:\n");
475 for (a = 0; a < 128; ++a) {
476 if (floorlist[a][0] != 0) {
482 } while (newfloor < 0);
487 scr_printf("Floor selection bypassed because you have "
488 "floor mode disabled.\n");
498 * .<A>ide <E>dit room
500 void editthisroom(CtdlIPC *ipc)
503 char raide[USERNAME_SIZE];
505 struct ctdlroom *attr = NULL;
506 struct ExpirePolicy *eptr = NULL;
507 int r; /* IPC response code */
509 /* Fetch the existing room config */
510 r = CtdlIPCGetRoomAttributes(ipc, &attr, buf);
512 scr_printf("%s\n", buf);
515 eptr = &(attr->QRep);
517 /* Fetch the name of the current room aide */
518 r = CtdlIPCGetRoomAide(ipc, buf);
520 safestrncpy(raide, buf, sizeof raide);
524 if (IsEmptyStr(raide)) {
525 strcpy(raide, "none");
528 /* Fetch the expire policy (this will silently fail on old servers,
529 * resulting in "default" policy)
531 r = CtdlIPCGetMessageExpirationPolicy(ipc, 0, &eptr, buf);
533 /* Now interact with the user. */
535 strprompt("Room name", attr->QRname, ROOMNAMELEN-1);
536 attr->QRfloor = select_floor(ipc, attr->QRfloor);
537 attr->QRflags = set_room_attr(ipc, attr->QRflags, "Private room", QR_PRIVATE);
538 if (attr->QRflags & QR_PRIVATE) {
539 attr->QRflags = set_room_attr(ipc, attr->QRflags,
540 "Hidden room (accessible to anyone who knows the room name)",
544 /* if it's public, clear the privacy classes */
545 if ((attr->QRflags & QR_PRIVATE) == 0) {
546 if (attr->QRflags & QR_GUESSNAME) {
547 attr->QRflags = attr->QRflags - QR_GUESSNAME;
549 if (attr->QRflags & QR_PASSWORDED) {
550 attr->QRflags = attr->QRflags - QR_PASSWORDED;
554 /* if it's private, choose the privacy classes */
555 if ((attr->QRflags & QR_PRIVATE)
556 && ((attr->QRflags & QR_GUESSNAME) == 0)) {
557 attr->QRflags = set_room_attr(ipc, attr->QRflags,
558 "Accessible by entering a password",
561 if ((attr->QRflags & QR_PRIVATE)
562 && ((attr->QRflags & QR_PASSWORDED) == QR_PASSWORDED)) {
563 strprompt("Room password", attr->QRpasswd, 9);
566 if ((attr->QRflags & QR_PRIVATE) == QR_PRIVATE) {
567 rbump = boolprompt("Cause current users to forget room", 0);
570 attr->QRflags = set_room_attr(ipc, attr->QRflags,
571 "Preferred users only", QR_PREFONLY);
572 attr->QRflags = set_room_attr(ipc, attr->QRflags,
573 "Read-only room", QR_READONLY);
574 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
575 "Allow message deletion by anyone who can post",
577 attr->QRflags = set_room_attr(ipc, attr->QRflags,
578 "Permanent room", QR_PERMANENT);
579 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
580 "Subject Required (Force "
581 "users to specify a message "
582 "subject)", QR2_SUBJECTREQ);
583 attr->QRflags = set_room_attr(ipc, attr->QRflags,
584 "Directory room", QR_DIRECTORY);
585 if (attr->QRflags & QR_DIRECTORY) {
586 strprompt("Directory name", attr->QRdirname, 14);
588 set_room_attr(ipc, attr->QRflags,
589 "Uploading allowed", QR_UPLOAD);
591 set_room_attr(ipc, attr->QRflags, "Downloading allowed",
594 set_room_attr(ipc, attr->QRflags,
595 "Visible directory", QR_VISDIR);
597 attr->QRflags = set_room_attr(ipc, attr->QRflags,
598 "Network shared room", QR_NETWORK);
599 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
600 "Self-service list subscribe/unsubscribe",
602 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
603 "public posting to this room via room_roomname@yourcitadel.org",
605 attr->QRflags2 = set_room_attr(ipc, attr->QRflags2,
606 "moderated mailinglist",
608 attr->QRflags = set_room_attr(ipc, attr->QRflags,
609 "Automatically make all messages anonymous",
611 if ((attr->QRflags & QR_ANONONLY) == 0) {
612 attr->QRflags = set_room_attr(ipc, attr->QRflags,
613 "Ask users whether to make messages anonymous",
616 attr->QRorder = intprompt("Listing order", attr->QRorder, 0, 127);
618 /* Ask about the room aide */
620 strprompt("Room aide (or 'none')", raide, 29);
621 if (!strcasecmp(raide, "none")) {
625 r = CtdlIPCQueryUsername(ipc, raide, buf);
627 scr_printf("%s\n", buf);
629 } while (r / 100 != 2);
631 /* Angels and demons dancing in my head... */
633 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_mode);
634 strprompt("Message expire policy (? for list)", buf, 1);
637 "0. Use the default for this floor\n"
638 "1. Never automatically expire messages\n"
639 "2. Expire by message count\n"
640 "3. Expire by message age\n");
642 } while ((buf[0] < 48) || (buf[0] > 51));
643 attr->QRep.expire_mode = buf[0] - 48;
645 /* ...lunatics and monsters underneath my bed */
646 if (attr->QRep.expire_mode == 2) {
647 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
648 strprompt("Keep how many messages online?", buf, 10);
649 attr->QRep.expire_value = atol(buf);
652 if (attr->QRep.expire_mode == 3) {
653 snprintf(buf, sizeof buf, "%d", attr->QRep.expire_value);
654 strprompt("Keep messages for how many days?", buf, 10);
655 attr->QRep.expire_value = atol(buf);
658 /* Give 'em a chance to change their minds */
659 scr_printf("Save changes (y/n)? ");
662 r = CtdlIPCSetRoomAide(ipc, raide, buf);
664 scr_printf("%s\n", buf);
667 r = CtdlIPCSetMessageExpirationPolicy(ipc, 0, eptr, buf);
669 scr_printf("%s\n", buf);
672 r = CtdlIPCSetRoomAttributes(ipc, rbump, attr, buf);
673 scr_printf("%s\n", buf);
674 strncpy(buf, attr->QRname, ROOMNAMELEN);
677 dotgoto(ipc, buf, 2, 0);
684 * un-goto the previous room, or a specified room
686 void dotungoto(CtdlIPC *ipc, char *towhere)
688 /* Find this 'towhere' room in the list ungoto from this room to
689 that at the messagepointer position in that room in our ungoto list.
690 I suppose I could be a real dick and just ungoto that many places
695 struct ctdlipcroom *rret = NULL; /* ignored */
700 scr_printf("No rooms to ungoto.\n");
705 scr_printf("Must specify a room to ungoto.\n");
708 if (IsEmptyStr(towhere))
710 scr_printf("Must specify a room to ungoto.\n");
713 for (lp = uglistsize-1; lp >= 0; lp--)
715 if (strcasecmp(towhere, uglist[lp]) == 0)
723 scr_printf("Room: %s not in ungoto list.\n", towhere);
727 r = CtdlIPCGotoRoom(ipc, uglist[found], "", &rret, buf);
728 if (rret) free(rret); /* ignored */
730 scr_printf("%s\n", buf);
733 r = CtdlIPCSetLastRead(ipc, uglistlsn[found] ? uglistlsn[found] : 1, buf);
735 scr_printf("%s\n", buf);
737 safestrncpy(buf, uglist[found], sizeof(buf));
738 /* we queue ungoto information here, because we're not really
739 ungotoing, we're really going to a random spot in some arbitrary
741 dotgoto(ipc, buf, 0, 0);
744 void ungoto(CtdlIPC *ipc)
747 struct ctdlipcroom *rret = NULL; /* ignored */
753 r = CtdlIPCGotoRoom(ipc, uglist[uglistsize-1], "", &rret, buf);
754 if (rret) free(rret); /* ignored */
756 scr_printf("%s\n", buf);
759 r = CtdlIPCSetLastRead(ipc, uglistlsn[uglistsize-1] ? uglistlsn[uglistsize-1] : 1, buf);
761 scr_printf("%s\n", buf);
763 safestrncpy(buf, uglist[uglistsize-1], sizeof(buf));
765 free(uglist[uglistsize]);
766 /* Don't queue ungoto info or we end up in a loop */
767 dotgoto(ipc, buf, 0, 1);
772 * saves filelen bytes from file at pathname
774 int save_buffer(void *file, size_t filelen, const char *pathname)
777 size_t bytes_written = 0;
780 fp = fopen(pathname, "w");
782 scr_printf("Cannot open '%s': %s\n", pathname, strerror(errno));
786 block = fwrite((char *)file + bytes_written, 1,
787 filelen - bytes_written, fp);
788 bytes_written += block;
789 } while (errno == EINTR && bytes_written < filelen);
792 if (bytes_written < filelen) {
793 scr_printf("Trouble saving '%s': %s\n", pathname,
802 * Save supplied_filename in dest directory; gets the name only
804 void destination_directory(char *dest, const char *supplied_filename)
806 static char save_dir[SIZ] = { 0 };
808 if (IsEmptyStr(save_dir)) {
809 if (getenv("HOME") == NULL) {
810 strcpy(save_dir, ".");
813 sprintf(save_dir, "%s/Desktop", getenv("HOME"));
814 if (access(save_dir, W_OK) != 0) {
815 sprintf(save_dir, "%s", getenv("HOME"));
816 if (access(save_dir, W_OK) != 0) {
817 sprintf(save_dir, ".");
823 sprintf(dest, "%s/%s", save_dir, supplied_filename);
824 strprompt("Save as", dest, PATH_MAX);
826 /* Remember the directory for next time */
827 strcpy(save_dir, dest);
828 if (strrchr(save_dir, '/') != NULL) {
829 strcpy(strrchr(save_dir, '/'), "");
832 strcpy(save_dir, ".");
838 * download() - download a file or files. The argument passed to this
839 * function determines which protocol to use.
840 * proto - 0 = paginate, 1 = xmodem, 2 = raw, 3 = ymodem, 4 = zmodem, 5 = save
842 void download(CtdlIPC *ipc, int proto)
845 char filename[PATH_MAX];
846 char tempname[PATH_MAX];
847 char transmit_cmd[SIZ];
852 void *file = NULL; /* The downloaded file */
853 size_t filelen = 0L; /* The downloaded file length */
855 if ((room_flags & QR_DOWNLOAD) == 0) {
856 scr_printf("*** You cannot download from this room.\n");
860 newprompt("Enter filename: ", filename, PATH_MAX);
862 /* Save to local disk, for folks with their own copy of the client */
864 destination_directory(tempname, filename);
865 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
867 scr_printf("%s\n", buf);
870 save_buffer(file, (size_t)extract_long(buf, 0), tempname);
875 r = CtdlIPCFileDownload(ipc, filename, &file, 0, progress, buf);
877 scr_printf("%s\n", buf);
880 filelen = extract_unsigned_long(buf, 0);
882 /* Meta-download for public clients */
883 /* scr_printf("Fetching file from Citadel server...\n"); */
884 mkdir(tempdir, 0700);
885 snprintf(tempname, sizeof tempname, "%s/%s", tempdir, filename);
886 tpipe = fopen(tempname, "wb");
887 if (fwrite(file, filelen, 1, tpipe) < filelen) {
888 /* FIXME: restart syscall on EINTR
892 if (file) free(file);
895 /* FIXME: display internally instead */
896 snprintf(transmit_cmd, sizeof transmit_cmd,
897 "SHELL=/dev/null; export SHELL; TERM=dumb; export TERM; exec more -d <%s",
901 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sx %s", tempname);
903 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sb %s", tempname);
905 snprintf(transmit_cmd, sizeof transmit_cmd, "exec sz %s", tempname);
907 /* FIXME: display internally instead */
908 snprintf(transmit_cmd, sizeof transmit_cmd, "exec cat %s", tempname);
910 stty_ctdl(SB_RESTORE);
911 rv = system(transmit_cmd);
913 scr_printf("failed to download '%s': %d\n", transmit_cmd, rv);
914 stty_ctdl(SB_NO_INTR);
916 /* clean up the temporary directory */
918 ctdl_beep(); /* Beep beep! */
923 * read directory of this room
925 void roomdir(CtdlIPC *ipc)
932 char *listing = NULL; /* Returned directory listing */
935 r = CtdlIPCReadDirectory(ipc, &listing, buf);
937 scr_printf("%s\n", buf);
941 extract_token(comment, buf, 0, '|', sizeof comment);
942 extract_token(flnm, buf, 1, '|', sizeof flnm);
943 scr_printf("\nDirectory of %s on %s\n", flnm, comment);
944 scr_printf("-----------------------\n");
945 while (listing && *listing && !IsEmptyStr(listing)) {
946 extract_token(buf, listing, 0, '\n', sizeof buf);
947 remove_token(listing, 0, '\n');
949 extract_token(flnm, buf, 0, '|', sizeof flnm);
950 extract_token(flsz, buf, 1, '|', sizeof flsz);
951 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
952 extract_token(comment, buf, 3, '|', sizeof comment);
953 if (strlen(flnm) <= 14)
954 scr_printf("%-14s %8s %s [%s]\n", flnm, flsz, comment, mimetype);
956 scr_printf("%s\n%14s %8s %s [%s]\n", flnm, "", flsz,
959 if (listing) free(listing);
964 * add a user to a private room
966 void invite(CtdlIPC *ipc)
968 char username[USERNAME_SIZE];
971 newprompt("Name of user? ", username, USERNAME_SIZE);
972 if (username[0] == 0)
975 CtdlIPCInviteUserToRoom(ipc, username, buf);
976 scr_printf("%s\n", buf);
981 * kick a user out of a room
983 void kickout(CtdlIPC *ipc)
985 char username[USERNAME_SIZE];
988 newprompt("Name of user? ", username, USERNAME_SIZE);
989 if (username[0] == 0)
992 CtdlIPCKickoutUserFromRoom(ipc, username, buf);
993 scr_printf("%s\n", buf);
998 * aide command: kill the current room
1000 void killroom(CtdlIPC *ipc)
1005 r = CtdlIPCDeleteRoom(ipc, 0, aaa);
1007 scr_printf("%s\n", aaa);
1011 scr_printf("Are you sure you want to kill this room? ");
1015 r = CtdlIPCDeleteRoom(ipc, 1, aaa);
1016 scr_printf("%s\n", aaa);
1019 dotgoto(ipc, "_BASEROOM_", 0, 0);
1022 void forget(CtdlIPC *ipc)
1023 { /* forget the current room */
1026 scr_printf("Are you sure you want to forget this room? ");
1030 remove_march(room_name, 0);
1031 if (CtdlIPCForgetRoom(ipc, buf) / 100 != 2) {
1032 scr_printf("%s\n", buf);
1036 /* now return to the lobby */
1037 dotgoto(ipc, "_BASEROOM_", 0, 0);
1044 void entroom(CtdlIPC *ipc)
1047 char new_room_name[ROOMNAMELEN];
1049 char new_room_pass[10];
1052 int r; /* IPC response code */
1054 /* Check permission to create room */
1055 r = CtdlIPCCreateRoom(ipc, 0, "", 1, "", 0, buf);
1057 scr_printf("%s\n", buf);
1061 newprompt("Name for new room? ", new_room_name, ROOMNAMELEN - 1);
1062 if (IsEmptyStr(new_room_name)) {
1065 for (a = 0; !IsEmptyStr(&new_room_name[a]); ++a) {
1066 if (new_room_name[a] == '|') {
1067 new_room_name[a] = '_';
1071 new_room_floor = select_floor(ipc, (int) curr_floor);
1073 IFNEXPERT formout(ipc, "roomaccess");
1075 scr_printf("<?>Help\n"
1076 "<1>Public room (shown to all users by default)\n"
1077 "<2>Hidden room (accessible to anyone who knows the room name)\n"
1078 "<3>Passworded room (hidden, plus requires a password to enter)\n"
1079 "<4>Invitation-only room (requires access to be granted by an Aide)\n"
1080 "<5>Personal room (accessible to you only)\n"
1085 } while (((b < '1') || (b > '5')) && (b != '?'));
1088 formout(ipc, "roomaccess");
1090 } while ((b < '1') || (b > '5'));
1091 b -= '0'; /* Portable */
1092 scr_printf("%d\n", b);
1093 new_room_type = b - 1;
1094 if (new_room_type == 2) {
1095 newprompt("Enter a room password: ", new_room_pass, 9);
1096 for (a = 0; !IsEmptyStr(&new_room_pass[a]); ++a)
1097 if (new_room_pass[a] == '|')
1098 new_room_pass[a] = '_';
1100 strcpy(new_room_pass, "");
1103 scr_printf("\042%s\042, a", new_room_name);
1105 scr_printf(" public room.");
1107 scr_printf(" hidden room.");
1109 scr_printf(" passworded room, password: %s", new_room_pass);
1111 scr_printf("n invitation-only room.");
1113 scr_printf(" personal room.");
1114 scr_printf("\nInstall it? (y/n) : ");
1119 r = CtdlIPCCreateRoom(ipc, 1, new_room_name, new_room_type,
1120 new_room_pass, new_room_floor, buf);
1122 scr_printf("%s\n", buf);
1126 /* command succeeded... now GO to the new room! */
1127 dotgoto(ipc, new_room_name, 0, 0);
1132 void readinfo(CtdlIPC *ipc)
1133 { /* read info file for current room */
1136 int r; /* IPC response code */
1139 /* Name of currernt room aide */
1140 r = CtdlIPCGetRoomAide(ipc, buf);
1142 safestrncpy(raide, buf, sizeof raide);
1146 if (!IsEmptyStr(raide))
1147 scr_printf("Room aide is %s.\n\n", raide);
1149 r = CtdlIPCRoomInfo(ipc, &text, buf);
1154 fmout(screenwidth, NULL, text, NULL, 1);
1161 * <W>ho knows room...
1163 void whoknows(CtdlIPC *ipc)
1166 char *listing = NULL;
1169 r = CtdlIPCWhoKnowsRoom(ipc, &listing, buf);
1171 scr_printf("%s\n", buf);
1174 while (!IsEmptyStr(listing)) {
1175 extract_token(buf, listing, 0, '\n', sizeof buf);
1176 remove_token(listing, 0, '\n');
1178 scr_printf("%s\n", buf);
1184 void do_edit(CtdlIPC *ipc,
1185 char *desc, char *read_cmd, char *check_cmd, char *write_cmd)
1189 int b, cksum, editor_exit;
1191 if (IsEmptyStr(editor_paths[0])) {
1192 scr_printf("Do you wish to re-enter %s? ", desc);
1197 fp = fopen(temp, "w");
1200 CtdlIPC_chat_send(ipc, check_cmd);
1201 CtdlIPC_chat_recv(ipc, cmd);
1202 if (cmd[0] != '2') {
1203 scr_printf("%s\n", &cmd[4]);
1207 if (!IsEmptyStr(editor_paths[0])) {
1208 CtdlIPC_chat_send(ipc, read_cmd);
1209 CtdlIPC_chat_recv(ipc, cmd);
1210 if (cmd[0] == '1') {
1211 fp = fopen(temp, "w");
1212 while (CtdlIPC_chat_recv(ipc, cmd), strcmp(cmd, "000")) {
1213 fprintf(fp, "%s\n", cmd);
1219 cksum = file_checksum(temp);
1221 if (!IsEmptyStr(editor_paths[0])) {
1224 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", desc);
1226 stty_ctdl(SB_RESTORE);
1227 editor_pid = fork();
1228 if (editor_pid == 0) {
1230 execlp(editor_paths[0], editor_paths[0], temp, NULL);
1236 b = ka_wait(&editor_exit);
1237 } while ((b != editor_pid) && (b >= 0));
1239 scr_printf("Executed %s\n", editor_paths[0]);
1242 scr_printf("Entering %s. Press return twice when finished.\n", desc);
1243 fp = fopen(temp, "r+");
1248 if (file_checksum(temp) == cksum) {
1249 scr_printf("*** Aborted.\n");
1253 CtdlIPC_chat_send(ipc, write_cmd);
1254 CtdlIPC_chat_recv(ipc, cmd);
1255 if (cmd[0] != '4') {
1256 scr_printf("%s\n", &cmd[4]);
1260 fp = fopen(temp, "r");
1261 while (fgets(cmd, SIZ - 1, fp) != NULL) {
1262 cmd[strlen(cmd) - 1] = 0;
1263 CtdlIPC_chat_send(ipc, cmd);
1266 CtdlIPC_chat_send(ipc, "000");
1273 void enterinfo(CtdlIPC *ipc)
1274 { /* edit info file for current room */
1275 do_edit(ipc, "the Info file for this room", "RINF", "EINF 0", "EINF 1");
1278 void enter_bio(CtdlIPC *ipc)
1281 snprintf(cmd, sizeof cmd, "RBIO %s", fullname);
1282 do_edit(ipc, "your Bio", cmd, "NOOP", "EBIO");
1286 * create a new floor
1288 void create_floor(CtdlIPC *ipc)
1291 char newfloorname[SIZ];
1292 int r; /* IPC response code */
1294 load_floorlist(ipc);
1296 r = CtdlIPCCreateFloor(ipc, 0, "", buf);
1297 if ( (r / 100 != 2) && (r != ERROR + ILLEGAL_VALUE) ) {
1298 scr_printf("%s\n", buf);
1302 newprompt("Name for new floor: ", newfloorname, 255);
1303 if (!*newfloorname) return;
1304 r = CtdlIPCCreateFloor(ipc, 1, newfloorname, buf);
1306 scr_printf("Floor has been created.\n");
1308 scr_printf("%s\n", buf);
1311 load_floorlist(ipc);
1315 * edit the current floor
1317 void edit_floor(CtdlIPC *ipc)
1320 struct ExpirePolicy *ep = NULL;
1322 load_floorlist(ipc);
1324 /* Fetch the expire policy (this will silently fail on old servers,
1325 * resulting in "default" policy)
1327 CtdlIPCGetMessageExpirationPolicy(ipc, 1, &ep, buf);
1329 /* Interact with the user */
1330 scr_printf("You are editing the floor called \"%s\"\n",
1331 &floorlist[(int) curr_floor][0] );
1332 strprompt("Floor name", &floorlist[(int) curr_floor][0], 255);
1334 /* Angels and demons dancing in my head... */
1336 snprintf(buf, sizeof buf, "%d", ep->expire_mode);
1338 ("Floor default message expire policy (? for list)",
1340 if (buf[0] == '?') {
1342 "0. Use the system default\n"
1343 "1. Never automatically expire messages\n"
1344 "2. Expire by message count\n"
1345 "3. Expire by message age\n");
1347 } while ((buf[0] < '0') || (buf[0] > '3'));
1348 ep->expire_mode = buf[0] - '0';
1350 /* ...lunatics and monsters underneath my bed */
1351 if (ep->expire_mode == 2) {
1352 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1353 strprompt("Keep how many messages online?", buf, 10);
1354 ep->expire_value = atol(buf);
1357 if (ep->expire_mode == 3) {
1358 snprintf(buf, sizeof buf, "%d", ep->expire_value);
1359 strprompt("Keep messages for how many days?", buf, 10);
1360 ep->expire_value = atol(buf);
1364 CtdlIPCSetMessageExpirationPolicy(ipc, 1, ep, buf);
1365 CtdlIPCEditFloor(ipc, curr_floor, &floorlist[(int)curr_floor][0], buf);
1366 scr_printf("%s\n", buf);
1367 load_floorlist(ipc);
1374 * kill the current floor
1376 void kill_floor(CtdlIPC *ipc)
1378 int floornum_to_delete, a;
1381 load_floorlist(ipc);
1383 floornum_to_delete = (-1);
1384 scr_printf("(Press return to abort)\n");
1385 newprompt("Delete which floor? ", buf, 255);
1386 if (IsEmptyStr(buf))
1388 for (a = 0; a < 128; ++a)
1389 if (!strcasecmp(&floorlist[a][0], buf))
1390 floornum_to_delete = a;
1391 if (floornum_to_delete < 0) {
1392 scr_printf("No such floor. Select one of:\n");
1393 for (a = 0; a < 128; ++a)
1394 if (floorlist[a][0] != 0)
1395 scr_printf("%s\n", &floorlist[a][0]);
1397 } while (floornum_to_delete < 0);
1398 CtdlIPCDeleteFloor(ipc, 1, floornum_to_delete, buf);
1399 scr_printf("%s\n", buf);
1400 load_floorlist(ipc);